Ravenports generated: 26 Sep 2020 03:49
[ravenports.git] / bucket_67 / thunderbird
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               thunderbird
4 VERSION=                78.3.1
5 KEYWORDS=               mail net_im news
6 VARIANTS=               standard
7 SDESC[standard]=        Mozilla Thunderbird mail/newsgroup client
8 HOMEPAGE=               https://www.thunderbird.net/
9 CONTACT=                nobody
10
11 DOWNLOAD_GROUPS=        main
12 SITES[main]=            MOZILLA/thunderbird/releases/78.3.1/source
13 DISTFILE[1]=            thunderbird-78.3.1.source.tar.xz:main
14 DF_INDEX=               1
15 SPKGS[standard]=        single
16
17 OPTIONS_AVAILABLE=      none
18 OPTIONS_STANDARD=       none
19
20 BUILD_DEPENDS=          rust:single:standard
21                         cbindgen:single:standard
22                         autoconf213:single:standard
23                         yasm:single:standard
24                         nasm:primary:standard
25                         zip:single:standard
26                         bzip2:static:standard
27                         nodejs:primary:standard
28                         libvpx:single:standard
29                         clang:compiler:standard
30                         evdev-proto:single:standard
31                         autoselect-python:single:standard
32                         python-sqlite3:single:python_used
33 BUILDRUN_DEPENDS=       nss:primary:standard
34                         icu:single:standard
35                         libffi:single:standard
36                         libproxy:single:standard
37                         libevent:single:standard
38                         libcanberra:primary:standard
39                         libnotify:primary:standard
40                         harfbuzz:primary:standard
41                         aom:single:standard
42                         WebP:single:standard
43                         dav1d:single:standard
44                         bzip2:shared:standard
45                         ffmpeg:primary:standard
46                         dbus-glib:primary:standard
47                         startup-notification:single:standard
48
49 USES=                   cpe desktop-utils:single gmake jpeg png zlib
50                         perl:build pkgconfig iconv python:build
51                         gettext-runtime
52 GNOME_COMPONENTS=       gconf gtk2 gtk3 gdkpixbuf pango
53 XORG_COMPONENTS=        x11 xcb xcomposite xdamage xext xfixes xrender xt
54                         pixman
55
56 LICENSE=                MPL:single
57 LICENSE_TERMS=          single:{{WRKSRC}}/toolkit/content/license.html
58 LICENSE_FILE=           MPL:stock
59 LICENSE_SCHEME=         solo
60
61 CPE_VENDOR=             mozilla
62 FPC_EQUIVALENT=         mail/thunderbird
63
64 MUST_CONFIGURE=         yes
65 CONFIGURE_OUTSOURCE=    yes
66 CONFIGURE_ENV=          PYTHON3={{PYTHON_CMD}}
67                         SETUPTOOLS_USE_DISTUTILS=stdlib
68
69 MAKE_ENV=               PYTHON3={{PYTHON_CMD}}
70                         CXXSTDLIB="stdc++"
71
72 QMAKE_ARGS=             --prefix="{{PREFIX}}"
73                         --with-system-nss
74                         --with-system-nspr
75                         --with-system-zlib
76                         --with-system-icu
77                         --with-system-png="{{LOCALBASE}}"
78                         --with-system-jpeg="{{LOCALBASE}}"
79                         --with-system-libevent
80                         --with-system-harfbuzz
81                         --with-system-graphite2
82                         --with-system-av1
83                         --with-system-webp
84                         --enable-system-ffi
85                         --enable-system-pixman
86                         --enable-install-strip
87                         --enable-strip
88                         --enable-calendar
89                         --enable-libproxy
90                         --enable-release
91                         --enable-optimize
92                         --enable-official-branding
93                         --enable-application=comm/mail
94                         --enable-update-channel=release
95                         --enable-rust-simd
96                         --with-intl-api
97                         --disable-alsa
98                         --disable-debug
99                         --disable-debug-symbols
100                         --disable-dtrace
101                         --disable-jack
102                         --disable-webrtc
103                         --disable-profiling
104                         --disable-pulseaudio
105                         --disable-tests
106                         --disable-updater
107                         --disable-hardening
108 VAR_OPSYS[freebsd]=     CONFIGURE_ARGS=--enable-jemalloc
109 VAR_OPSYS[linux]=       QMAKE_ARGS=--disable-elf-hack
110
111 post-patch:
112         ${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|g' \
113                 ${WRKSRC}/comm/mail/app/nsMailApp.cpp \
114                 ${WRKSRC}/browser/app/nsBrowserApp.cpp
115         (cd ${WRKSRC}/gfx/angle/checkout/src/compiler/translator && \
116                 ${REINPLACE_CMD} -e 's|<math.h>|<cmath>|' \
117                 InfoSink.h IntermNode.cpp)
118         # disable SCTP
119         ${REINPLACE_CMD} -e 's|MOZ_SCTP|MOZ_DISABLE_SCTP|' \
120                 ${WRKSRC}/netwerk/moz.build
121         # alsa headers use 'u_int32_t' and other BerkeleyDB/nvi
122         # fixed types (_XOPEN_SOURCE)
123         ${REINPLACE_CMD} -e 's@_XOPEN_SOURCE@&___@g' \
124                 ${WRKSRC}/media/libcubeb/src/cubeb_alsa.c
125         ${REINPLACE_CMD} -e 's@_POSIX_SOURCE@&___@g' \
126                 ${WRKSRC}/media/libcubeb/src/cubeb_jack.cpp
127         # Set mozilla options
128         @${ECHO_CMD} "--=> Setting configuration <=--"
129         @for arg in ${QMAKE_ARGS}; do \
130                 ${ECHO_CMD} ".mozconfig <<  $$arg" ;\
131                 ${ECHO_CMD} ac_add_options $$arg >> ${WRKSRC}/.mozconfig ;\
132         done
133         @${ECHO_CMD} LDFLAGS=\"-Wl,-rpath,${PREFIX}/lib/thunderbird\" \
134                 >> ${WRKSRC}/.mozconfig
135
136 post-patch-dragonfly:
137         ${REINPLACE_CMD} -e '/<malloc.h>/d' \
138                 ${WRKSRC}/comm/ldap/c-sdk/libraries/liblber/lber-int.h
139
140 post-install:
141         ${MKDIR} ${STAGEDIR}${PREFIX}/share/applications
142         ${MKDIR} ${STAGEDIR}${PREFIX}/share/pixmaps
143         ${INSTALL_DATA} ${FILESDIR}/thunderbird.desktop \
144                 ${STAGEDIR}${PREFIX}/share/applications
145         (cd ${STAGEDIR}${PREFIX}/share/pixmaps && ${LN} -sf \
146                 ../../lib/thunderbird/chrome/icons/default/default48.png \
147                 thunderbird.png)
148         # regenerate symlink to avoid absolute paths
149         ${RM} ${STAGEDIR}${PREFIX}/bin/thunderbird
150         (cd ${STAGEDIR}${PREFIX}/bin && \
151                 ${LN} -sf ../lib/thunderbird/thunderbird thunderbird)
152
153 pre-configure:
154         (cd ${WRKSRC} && ${LOCALBASE}/bin/autoconf-2.13)
155         (cd ${WRKSRC}/js/src/ && ${LOCALBASE}/bin/autoconf-2.13)
156
157 [FILE:391:descriptions/desc.single]
158 Thunderbird is a free and open source email, newsfeed, chat, and
159 calendaring client, that's easy to set up and customize. One of the core
160 principles of Thunderbird is the use and promotion of open standards -
161 this focus is a rejection of our world of closed platforms and services
162 that can't communicate with each other. We want our users to have
163 freedom and choice in how they communicate.
164
165
166 [FILE:111:distinfo]
167 4ea61f59a819f5a8a4574b0735952e23b4c86387b8da24906129c45e71bf2718    353920472 thunderbird-78.3.1.source.tar.xz
168
169
170 [FILE:949:manifests/plist.single]
171 bin/thunderbird
172 lib/thunderbird/
173  application.ini
174  dependentlibs.list
175  libldap60.so
176  libldif60.so
177  liblgpllibs.so
178  libmozgtk.so
179  libmozsqlite3.so
180  libprldap60.so
181  librnp.so
182  libxul.so
183  omni.ja
184  pingsender
185  platform.ini
186  plugin-container
187  removed-files
188  thunderbird
189  thunderbird-bin
190 lib/thunderbird/chrome/icons/default/
191  calendar-alarm-dialog.png
192  calendar-event-dialog.png
193  calendar-event-summary-dialog.png
194  calendar-task-dialog.png
195  calendar-task-summary-dialog.png
196  default128.png
197  default16.png
198  default22.png
199  default24.png
200  default256.png
201  default32.png
202  default48.png
203  default64.png
204 lib/thunderbird/defaults/messenger/mailViews.dat
205 lib/thunderbird/defaults/pref/channel-prefs.js
206 lib/thunderbird/features/wetransfer@extensions.thunderbird.net.xpi
207 lib/thunderbird/gtk2/libmozgtk.so
208 lib/thunderbird/isp/
209  Bogofilter.sfd
210  DSPAM.sfd
211  POPFile.sfd
212  SpamAssassin.sfd
213  SpamPal.sfd
214 share/applications/thunderbird.desktop
215 share/pixmaps/thunderbird.png
216
217
218 [FILE:5540:patches/patch-addon-search]
219 https://github.com/mozilla/addons/issues/708
220 https://github.com/mozilla/addons-frontend/issues/4610
221
222 diff --git mail/app/profile/all-thunderbird.js mail/app/profile/all-thunderbird.js
223 index 75c2c5e435e35..4d8c09c02759b 100644
224 --- comm/mail/app/profile/all-thunderbird.js
225 +++ comm/mail/app/profile/all-thunderbird.js
226 @@ -153,10 +153,10 @@ pref("extensions.getAddons.maxResults", 15);
227  pref("extensions.getAddons.get.url", "https://services.addons.thunderbird.net/api/v3/addons/search/?guid=%IDS%&lang=%LOCALE%");
228  pref("extensions.getAddons.compatOverides.url", "https://services.addons.thunderbird.net/api/v3/addons/compat-override/?guid=%IDS%&lang=%LOCALE%");
229  pref("extensions.getAddons.link.url", "https://addons.thunderbird.net/%LOCALE%/%APP%/");
230 -pref("extensions.getAddons.recommended.url", "https://services.addons.thunderbird.net/%LOCALE%/%APP%/api/%API_VERSION%/list/recommended/all/%MAX_RESULTS%/%OS%/%VERSION%?src=thunderbird");
231 +pref("extensions.getAddons.recommended.url", "https://services.addons.thunderbird.net/%LOCALE%/%APP%/api/%API_VERSION%/list/recommended/all/%MAX_RESULTS%/Linux/%VERSION%?src=thunderbird");
232  pref("extensions.getAddons.search.browseURL", "https://addons.thunderbird.net/%LOCALE%/%APP%/search/?q=%TERMS%");
233 -pref("extensions.getAddons.search.url", "https://services.addons.thunderbird.net/%LOCALE%/%APP%/api/%API_VERSION%/search/%TERMS%/all/%MAX_RESULTS%/%OS%/%VERSION%/%COMPATIBILITY_MODE%?src=thunderbird");
234 -pref("extensions.webservice.discoverURL", "https://services.addons.thunderbird.net/%LOCALE%/%APP%/discovery/pane/%VERSION%/%OS%");
235 +pref("extensions.getAddons.search.url", "https://services.addons.thunderbird.net/%LOCALE%/%APP%/api/%API_VERSION%/search/%TERMS%/all/%MAX_RESULTS%/Linux/%VERSION%/%COMPATIBILITY_MODE%?src=thunderbird");
236 +pref("extensions.webservice.discoverURL", "https://services.addons.thunderbird.net/%LOCALE%/%APP%/discovery/pane/%VERSION%/Linux");
237  pref("extensions.getAddons.siteRegExp", "^https://.*addons\\.thunderbird\\.net");
238  pref("extensions.getAddons.langpacks.url", "https://services.addons.thunderbird.net/api/v3/addons/language-tools/?app=thunderbird&type=language&appversion=%VERSION%");
239  
240 @@ -180,9 +180,9 @@ pref("security.cert_pinning.enforcement_level", 1);
241  //  .. etc ..
242  //
243  pref("extensions.update.enabled", true);
244 -pref("extensions.update.url", "https://versioncheck.addons.thunderbird.net/update/VersionCheck.php?reqVersion=%REQ_VERSION%&id=%ITEM_ID%&version=%ITEM_VERSION%&maxAppVersion=%ITEM_MAXAPPVERSION%&status=%ITEM_STATUS%&appID=%APP_ID%&appVersion=%APP_VERSION%&appOS=%APP_OS%&appABI=%APP_ABI%&locale=%APP_LOCALE%&currentAppVersion=%CURRENT_APP_VERSION%&updateType=%UPDATE_TYPE%&compatMode=%COMPATIBILITY_MODE%");
245 +pref("extensions.update.url", "https://versioncheck.addons.thunderbird.net/update/VersionCheck.php?reqVersion=%REQ_VERSION%&id=%ITEM_ID%&version=%ITEM_VERSION%&maxAppVersion=%ITEM_MAXAPPVERSION%&status=%ITEM_STATUS%&appID=%APP_ID%&appVersion=%APP_VERSION%&appOS=Linux&appABI=%APP_ABI%&locale=%APP_LOCALE%&currentAppVersion=%CURRENT_APP_VERSION%&updateType=%UPDATE_TYPE%&compatMode=%COMPATIBILITY_MODE%");
246  
247 -pref("extensions.update.background.url", "https://versioncheck-bg.addons.thunderbird.net/update/VersionCheck.php?reqVersion=%REQ_VERSION%&id=%ITEM_ID%&version=%ITEM_VERSION%&maxAppVersion=%ITEM_MAXAPPVERSION%&status=%ITEM_STATUS%&appID=%APP_ID%&appVersion=%APP_VERSION%&appOS=%APP_OS%&appABI=%APP_ABI%&locale=%APP_LOCALE%&currentAppVersion=%CURRENT_APP_VERSION%&updateType=%UPDATE_TYPE%&compatMode=%COMPATIBILITY_MODE%");
248 +pref("extensions.update.background.url", "https://versioncheck-bg.addons.thunderbird.net/update/VersionCheck.php?reqVersion=%REQ_VERSION%&id=%ITEM_ID%&version=%ITEM_VERSION%&maxAppVersion=%ITEM_MAXAPPVERSION%&status=%ITEM_STATUS%&appID=%APP_ID%&appVersion=%APP_VERSION%&appOS=Linux&appABI=%APP_ABI%&locale=%APP_LOCALE%&currentAppVersion=%CURRENT_APP_VERSION%&updateType=%UPDATE_TYPE%&compatMode=%COMPATIBILITY_MODE%");
249  
250  pref("extensions.update.interval", 86400);  // Check for updates to Extensions and
251                                              // Themes every day
252 diff --git toolkit/mozapps/extensions/internal/AddonRepository.jsm toolkit/mozapps/extensions/internal/AddonRepository.jsm
253 index f70fd8d7e3bd8..81e8cd7764fdf 100644
254 --- toolkit/mozapps/extensions/internal/AddonRepository.jsm
255 +++ toolkit/mozapps/extensions/internal/AddonRepository.jsm
256 @@ -602,7 +602,7 @@ var AddonRepository = {
257        addon.version = String(aEntry.current_version.version);
258        if (Array.isArray(aEntry.current_version.files)) {
259          for (let file of aEntry.current_version.files) {
260 -          if (file.platform == "all" || file.platform == PLATFORM) {
261 +          if (file.platform == "all" || file.platform == "linux" || file.platform == PLATFORM) {
262              if (file.url) {
263                addon.sourceURI = NetUtil.newURI(file.url);
264              }
265 diff --git toolkit/mozapps/extensions/internal/XPIDatabase.jsm toolkit/mozapps/extensions/internal/XPIDatabase.jsm
266 index f70fd8d7e3bd8..81e8cd7764fdf 100644
267 --- toolkit/mozapps/extensions/internal/XPIDatabase.jsm
268 +++ toolkit/mozapps/extensions/internal/XPIDatabase.jsm
269 @@ -355,7 +355,7 @@ class AddonInternal {
270      // Something is causing errors in here
271      try {
272        for (let platform of this.targetPlatforms) {
273 -        if (platform.os == Services.appinfo.OS) {
274 +        if (platform.os == "Linux" || platform.os == Services.appinfo.OS) {
275            if (platform.abi) {
276              needsABI = true;
277              if (platform.abi === abi)
278
279
280 [FILE:445:patches/patch-browser-app-nsBrowserApp.cpp]
281 --- browser/app/nsBrowserApp.cpp.orig   2016-09-19 16:19:28 UTC
282 +++ browser/app/nsBrowserApp.cpp
283 @@ -324,6 +324,9 @@ int main(int argc, char* argv[], char* e
284  {
285    mozilla::TimeStamp start = mozilla::TimeStamp::Now();
286  
287 +  setenv("MOZ_GMP_PATH", "%%LOCALBASE%%/lib/browser_plugins/symlinks/gecko", 0);
288 +  setenv("MOZ_PLUGIN_PATH", "%%LOCALBASE%%/lib/browser_plugins/symlinks/gecko", 0);
289 +
290  #ifdef HAS_DLL_BLOCKLIST
291    DllBlocklist_Initialize();
292  
293
294
295 [FILE:1800:patches/patch-bug1288587]
296 diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure
297 index 855214a..1e91d51 100644
298 --- build/moz.configure/init.configure
299 +++ build/moz.configure/init.configure
300 @@ -251,6 +251,7 @@ option(env='PYTHON3', nargs=1, help='Python 3 interpre
301  @imports(_from='mozbuild.pythonutil', _import='find_python3_executable')
302  @imports(_from='mozbuild.pythonutil', _import='python_executable_version')
303  @imports(_from='six', _import='ensure_text')
304 +@imports(_from='__builtin__', _import='KeyError')
305  def virtualenv_python3(env_python, build_env, mozconfig, help):
306      # Avoid re-executing python when running configure --help.
307      if help:
308 @@ -283,6 +284,12 @@ def virtualenv_python3(env_python, build_env, mozconfi
309              python = mozconfig['vars']['added']['PYTHON3']
310          elif 'PYTHON3' in mozconfig['vars']['modified']:
311              python = mozconfig['vars']['modified']['PYTHON3'][1]
312 +        for i in ('env', 'vars'):
313 +            for j in ('added', 'modified'):
314 +                try:
315 +                    del mozconfig[i][j]['PYTHON3']
316 +                except KeyError:
317 +                    pass
318  
319      log.debug("python3: executable from configuration: %r" % python)
320  
321 @@ -365,7 +372,10 @@ def virtualenv_python3(env_python, build_env, mozconfi
322              sys.executable, manager.python_path))
323          log.info('Re-executing in the virtualenv')
324          if env_python:
325 -            del os.environ['PYTHON3']
326 +                try:
327 +                    del os.environ['PYTHON3']
328 +                except KeyError:
329 +                    pass
330          # Homebrew on macOS will change Python's sys.executable to a custom
331          # value which messes with mach's virtualenv handling code. Override
332          # Homebrew's changes with the correct sys.executable value.
333
334
335 [FILE:3590:patches/patch-bug1559213]
336 commit 717bba28411c
337 Author: Jory A. Pratt <anarchy@gentoo.org>
338 Date:   Thu Jun 13 11:53:00 2019 -0700
339
340     Bug 1559213 - Allow to use system av1 libs instead of bundled.
341 ---
342  config/external/moz.build      |  5 +++--
343  config/system-headers.mozbuild |  8 ++++++++
344  dom/media/platforms/moz.build  |  5 +++++
345  toolkit/moz.configure          | 19 ++++++++++++++++++-
346  4 files changed, 34 insertions(+), 3 deletions(-)
347
348 diff --git config/external/moz.build config/external/moz.build
349 index 03e4fa143bd1..a67d10b11fe6 100644
350 --- config/external/moz.build
351 +++ config/external/moz.build
352 @@ -37,8 +37,9 @@ if not CONFIG['MOZ_SYSTEM_LIBVPX']:
353      external_dirs += ['media/libvpx']
354  
355  if CONFIG['MOZ_AV1']:
356 -    external_dirs += ['media/libaom']
357 -    external_dirs += ['media/libdav1d']
358 +    if not CONFIG['MOZ_SYSTEM_AV1']:
359 +        external_dirs += ['media/libaom']
360 +        external_dirs += ['media/libdav1d']
361  
362  if not CONFIG['MOZ_SYSTEM_PNG']:
363      external_dirs += ['media/libpng']
364 diff --git config/system-headers.mozbuild config/system-headers.mozbuild
365 index bcf5c4925564..48964a999a9b 100644
366 --- config/system-headers.mozbuild
367 +++ config/system-headers.mozbuild
368 @@ -1304,6 +1304,14 @@ if CONFIG['MOZ_ENABLE_CONTENTMANAGER']:
369          'SelectSingleContentItemPage.h',
370      ]
371  
372 +if CONFIG['MOZ_SYSTEM_AV1']:
373 +    system_headers += [
374 +        'aom/aom_decoder.h',
375 +        'aom/aomdx.h',
376 +        'aom/aom_image.h',
377 +        'dav1d/dav1d.h',
378 +    ]
379 +
380  if CONFIG['MOZ_SYSTEM_LIBVPX']:
381      system_headers += [
382          'vpx_mem/vpx_mem.h',
383 diff --git dom/media/platforms/moz.build dom/media/platforms/moz.build
384 index 092cee0c9b66..38e45de5b5f0 100644
385 --- dom/media/platforms/moz.build
386 +++ dom/media/platforms/moz.build
387 @@ -80,6 +80,11 @@ if CONFIG['MOZ_AV1']:
388          'agnostic/AOMDecoder.cpp',
389          'agnostic/DAV1DDecoder.cpp',
390      ]
391 +    if CONFIG['MOZ_SYSTEM_AV1']:
392 +        CXXFLAGS += CONFIG['MOZ_SYSTEM_LIBAOM_CFLAGS']
393 +        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBAOM_LIBS']
394 +        CXXFLAGS += CONFIG['MOZ_SYSTEM_LIBDAV1D_CFLAGS']
395 +        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBDAV1D_LIBS']
396  
397  if CONFIG['MOZ_OMX']:
398      EXPORTS += [
399 diff --git toolkit/moz.configure toolkit/moz.configure
400 index 82b5a59acf42..e2329560b42b 100644
401 --- toolkit/moz.configure
402 +++ toolkit/moz.configure
403 @@ -441,7 +441,23 @@ def av1(value):
404      if value:
405          return True
406  
407 -@depends(target, nasm_version, when=av1 & compile_environment)
408 +option('--with-system-av1',
409 +       help="Use system av1 (located with pkgconfig)")
410 +
411 +system_libaom_info = pkg_check_modules('MOZ_SYSTEM_LIBAOM', 'aom >= 1.0.0',
412 +                                       when='--with-system-av1')
413 +
414 +system_libdav1d_info = pkg_check_modules('MOZ_SYSTEM_LIBDAV1D', 'dav1d >= 0.1.1',
415 +                                         when='--with-system-av1')
416 +
417 +@depends(system_libaom_info, system_libdav1d_info)
418 +def system_av1(system_libaom_info, system_libdav1d_info):
419 +    has_av1_libs = False
420 +    if system_libaom_info and system_libdav1d_info:
421 +        has_av1_libs = True
422 +    return has_av1_libs
423 +
424 +@depends(target, nasm_version, when=av1 & depends(system_av1)(lambda v: not v) & compile_environment)
425  def dav1d_asm(target, nasm_version):
426      if target.os != 'Android':
427          if target.cpu == 'aarch64':
428 @@ -457,6 +473,7 @@ set_config('MOZ_DAV1D_ASM', dav1d_asm)
429  set_define('MOZ_DAV1D_ASM', dav1d_asm)
430  set_config('MOZ_AV1', av1)
431  set_define('MOZ_AV1', av1)
432 +set_config('MOZ_SYSTEM_AV1', depends_if(system_av1)(lambda _: True))
433  
434  # Built-in fragmented MP4 support.
435  # ==============================================================
436
437
438 [FILE:1254:patches/patch-bug1618914]
439 [Wayland] Fall back to ftruncate if posix_fallocate isn't supported by filesystem.
440
441 diff --git widget/gtk/WindowSurfaceWayland.cpp widget/gtk/WindowSurfaceWayland.cpp
442 index 9a73326399bd5..9e42a7f1c5d18 100644
443 --- widget/gtk/WindowSurfaceWayland.cpp
444 +++ widget/gtk/WindowSurfaceWayland.cpp
445 @@ -222,20 +222,21 @@ static int WaylandAllocateShmMemory(int aSize) {
446  #ifdef HAVE_POSIX_FALLOCATE
447    do {
448      ret = posix_fallocate(fd, 0, aSize);
449    } while (ret == EINTR);
450 -  if (ret != 0) {
451 +  if (ret == 0) {
452 +    return fd;
453 +  } else if (ret != ENODEV && ret != EINVAL && ret != EOPNOTSUPP) {
454      close(fd);
455      MOZ_CRASH("posix_fallocate() fails to allocate shm memory");
456    }
457 -#else
458 +#endif
459    do {
460      ret = ftruncate(fd, aSize);
461    } while (ret < 0 && errno == EINTR);
462    if (ret < 0) {
463      close(fd);
464      MOZ_CRASH("ftruncate() fails to allocate shm memory");
465    }
466 -#endif
467  
468    return fd;
469  }
470 @@ -265,8 +266,8 @@ bool WaylandShmPool::Resize(int aSize) {
471  #ifdef HAVE_POSIX_FALLOCATE
472    do {
473      errno = posix_fallocate(mShmPoolFd, 0, aSize);
474    } while (errno == EINTR);
475 -  if (errno != 0) return false;
476 +  if (errno != 0 && errno != ENODEV && errno != EINVAL && errno != EOPNOTSUPP) return false;
477  #endif
478  
479    wl_shm_pool_resize(mShmPool, aSize);
480
481
482 [FILE:11510:patches/patch-bug292127]
483 --- comm/ldap/c-sdk/include/ldap.h~
484 +++ comm/ldap/c-sdk/include/ldap.h
485 @@ -40,6 +40,229 @@
486  #ifndef _LDAP_H
487  #define _LDAP_H
488  
489 +/* rename symbols to not clash with openldap (bug 292127) */
490 +#define ldap_abandon moz_ldap_abandon
491 +#define ldap_abandon_ext moz_ldap_abandon_ext
492 +#define ldap_abandoned moz_ldap_abandoned
493 +#define ldap_add moz_ldap_add
494 +#define ldap_add_ext moz_ldap_add_ext
495 +#define ldap_add_ext_s moz_ldap_add_ext_s
496 +#define ldap_add_result_entry moz_ldap_add_result_entry
497 +#define ldap_add_s moz_ldap_add_s
498 +#define ldap_ber_free moz_ldap_ber_free
499 +#define ldap_bind moz_ldap_bind
500 +#define ldap_bind_s moz_ldap_bind_s
501 +#define ldap_build_filter moz_ldap_build_filter
502 +#define ldap_cache_flush moz_ldap_cache_flush
503 +#define ldap_charray_add moz_ldap_charray_add
504 +#define ldap_charray_dup moz_ldap_charray_dup
505 +#define ldap_charray_free moz_ldap_charray_free
506 +#define ldap_charray_inlist moz_ldap_charray_inlist
507 +#define ldap_charray_merge moz_ldap_charray_merge
508 +#define ldap_charray_position moz_ldap_charray_position
509 +#define ldap_compare moz_ldap_compare
510 +#define ldap_compare_ext moz_ldap_compare_ext
511 +#define ldap_compare_ext_s moz_ldap_compare_ext_s
512 +#define ldap_compare_s moz_ldap_compare_s
513 +#define ldap_control_free moz_ldap_control_free
514 +#define ldap_controls_free moz_ldap_controls_free
515 +#define ldap_count_entries moz_ldap_count_entries
516 +#define ldap_count_messages moz_ldap_count_messages
517 +#define ldap_count_references moz_ldap_count_references
518 +#define ldap_count_values moz_ldap_count_values
519 +#define ldap_count_values_len moz_ldap_count_values_len
520 +#define ldap_create_authzid_control moz_ldap_create_authzid_control
521 +#define ldap_create_filter moz_ldap_create_filter
522 +#define ldap_create_geteffectiveRights_control moz_ldap_create_geteffectiveRights_control
523 +#define ldap_create_passwordpolicy_control moz_ldap_create_passwordpolicy_control
524 +#define ldap_create_passwordpolicy_control_ext moz_ldap_create_passwordpolicy_control_ext
525 +#define ldap_create_persistentsearch_control moz_ldap_create_persistentsearch_control
526 +#define ldap_create_proxiedauth_control moz_ldap_create_proxiedauth_control
527 +#define ldap_create_proxyauth_control moz_ldap_create_proxyauth_control
528 +#define ldap_create_sort_control moz_ldap_create_sort_control
529 +#define ldap_create_sort_keylist moz_ldap_create_sort_keylist
530 +#define ldap_create_userstatus_control moz_ldap_create_userstatus_control
531 +#define ldap_create_virtuallist_control moz_ldap_create_virtuallist_control
532 +#define ldap_delete moz_ldap_delete
533 +#define ldap_delete_ext moz_ldap_delete_ext
534 +#define ldap_delete_ext_s moz_ldap_delete_ext_s
535 +#define ldap_delete_result_entry moz_ldap_delete_result_entry
536 +#define ldap_delete_s moz_ldap_delete_s
537 +#define ldap_dn2ufn moz_ldap_dn2ufn
538 +#define ldap_entry2html moz_ldap_entry2html
539 +#define ldap_entry2html_search moz_ldap_entry2html_search
540 +#define ldap_entry2text moz_ldap_entry2text
541 +#define ldap_entry2text_search moz_ldap_entry2text_search
542 +#define ldap_err2string moz_ldap_err2string
543 +#define ldap_errlist moz_ldap_errlist
544 +#define ldap_explode moz_ldap_explode
545 +#define ldap_explode_dn moz_ldap_explode_dn
546 +#define ldap_explode_dns moz_ldap_explode_dns
547 +#define ldap_explode_rdn moz_ldap_explode_rdn
548 +#define ldap_extended_operation moz_ldap_extended_operation
549 +#define ldap_extended_operation_s moz_ldap_extended_operation_s
550 +#define ldap_find_control moz_ldap_find_control
551 +#define ldap_first_attribute moz_ldap_first_attribute
552 +#define ldap_first_disptmpl moz_ldap_first_disptmpl
553 +#define ldap_first_entry moz_ldap_first_entry
554 +#define ldap_first_message moz_ldap_first_message
555 +#define ldap_first_reference moz_ldap_first_reference
556 +#define ldap_first_searchobj moz_ldap_first_searchobj
557 +#define ldap_first_tmplcol moz_ldap_first_tmplcol
558 +#define ldap_first_tmplrow moz_ldap_first_tmplrow
559 +#define ldap_free_friendlymap moz_ldap_free_friendlymap
560 +#define ldap_free_searchprefs moz_ldap_free_searchprefs
561 +#define ldap_free_sort_keylist moz_ldap_free_sort_keylist
562 +#define ldap_free_templates moz_ldap_free_templates
563 +#define ldap_free_urldesc moz_ldap_free_urldesc
564 +#define ldap_friendly_name moz_ldap_friendly_name
565 +#define ldap_get_dn moz_ldap_get_dn
566 +#define ldap_get_entry_controls moz_ldap_get_entry_controls
567 +#define ldap_get_lang_values moz_ldap_get_lang_values
568 +#define ldap_get_lang_values_len moz_ldap_get_lang_values_len
569 +#define ldap_get_lderrno moz_ldap_get_lderrno
570 +#define ldap_get_option moz_ldap_get_option
571 +#define ldap_get_values moz_ldap_get_values
572 +#define ldap_get_values_len moz_ldap_get_values_len
573 +#define ldap_getfilter_free moz_ldap_getfilter_free
574 +#define ldap_getfirstfilter moz_ldap_getfirstfilter
575 +#define ldap_getnextfilter moz_ldap_getnextfilter
576 +#define ldap_init moz_ldap_init
577 +#define ldap_init_getfilter moz_ldap_init_getfilter
578 +#define ldap_init_getfilter_buf moz_ldap_init_getfilter_buf
579 +#define ldap_init_searchprefs moz_ldap_init_searchprefs
580 +#define ldap_init_searchprefs_buf moz_ldap_init_searchprefs_buf
581 +#define ldap_init_templates moz_ldap_init_templates
582 +#define ldap_init_templates_buf moz_ldap_init_templates_buf
583 +#define ldap_is_dns_dn moz_ldap_is_dns_dn
584 +#define ldap_is_ldap_url moz_ldap_is_ldap_url
585 +#define ldap_keysort_entries moz_ldap_keysort_entries
586 +#define ldap_ld_free moz_ldap_ld_free
587 +#define ldap_memcache_abandon moz_ldap_memcache_abandon
588 +#define ldap_memcache_append moz_ldap_memcache_append
589 +#define ldap_memcache_createkey moz_ldap_memcache_createkey
590 +#define ldap_memcache_destroy moz_ldap_memcache_destroy
591 +#define ldap_memcache_flush moz_ldap_memcache_flush
592 +#define ldap_memcache_flush_results moz_ldap_memcache_flush_results
593 +#define ldap_memcache_get moz_ldap_memcache_get
594 +#define ldap_memcache_init moz_ldap_memcache_init
595 +#define ldap_memcache_new moz_ldap_memcache_new
596 +#define ldap_memcache_result moz_ldap_memcache_result
597 +#define ldap_memcache_set moz_ldap_memcache_set
598 +#define ldap_memcache_update moz_ldap_memcache_update
599 +#define ldap_memfree moz_ldap_memfree
600 +#define ldap_modify moz_ldap_modify
601 +#define ldap_modify_ext moz_ldap_modify_ext
602 +#define ldap_modify_ext_s moz_ldap_modify_ext_s
603 +#define ldap_modify_s moz_ldap_modify_s
604 +#define ldap_modrdn moz_ldap_modrdn
605 +#define ldap_modrdn2 moz_ldap_modrdn2
606 +#define ldap_modrdn2_s moz_ldap_modrdn2_s
607 +#define ldap_modrdn_s moz_ldap_modrdn_s
608 +#define ldap_mods_free moz_ldap_mods_free
609 +#define ldap_msgdelete moz_ldap_msgdelete
610 +#define ldap_msgfree moz_ldap_msgfree
611 +#define ldap_msgid moz_ldap_msgid
612 +#define ldap_msgtype moz_ldap_msgtype
613 +#define ldap_multisort_entries moz_ldap_multisort_entries
614 +#define ldap_name2template moz_ldap_name2template
615 +#define ldap_next_attribute moz_ldap_next_attribute
616 +#define ldap_next_disptmpl moz_ldap_next_disptmpl
617 +#define ldap_next_entry moz_ldap_next_entry
618 +#define ldap_next_message moz_ldap_next_message
619 +#define ldap_next_reference moz_ldap_next_reference
620 +#define ldap_next_searchobj moz_ldap_next_searchobj
621 +#define ldap_next_tmplcol moz_ldap_next_tmplcol
622 +#define ldap_next_tmplrow moz_ldap_next_tmplrow
623 +#define ldap_oc2template moz_ldap_oc2template
624 +#define ldap_open moz_ldap_open
625 +#define ldap_parse_authzid_control moz_ldap_parse_authzid_control
626 +#define ldap_parse_entrychange_control moz_ldap_parse_entrychange_control
627 +#define ldap_parse_extended_result moz_ldap_parse_extended_result
628 +#define ldap_parse_passwd moz_ldap_parse_passwd
629 +#define ldap_parse_passwordpolicy_control moz_ldap_parse_passwordpolicy_control
630 +#define ldap_parse_passwordpolicy_control_ext moz_ldap_parse_passwordpolicy_control_ext
631 +#define ldap_parse_reference moz_ldap_parse_reference
632 +#define ldap_parse_result moz_ldap_parse_result
633 +#define ldap_parse_sasl_bind_result moz_ldap_parse_sasl_bind_result
634 +#define ldap_parse_sort_control moz_ldap_parse_sort_control
635 +#define ldap_parse_userstatus_control moz_ldap_parse_userstatus_control
636 +#define ldap_parse_virtuallist_control moz_ldap_parse_virtuallist_control
637 +#define ldap_parse_whoami moz_ldap_parse_whoami
638 +#define ldap_passwd moz_ldap_passwd
639 +#define ldap_passwd_s moz_ldap_passwd_s
640 +#define ldap_passwordpolicy_err2txt moz_ldap_passwordpolicy_err2txt
641 +#define ldap_perror moz_ldap_perror
642 +#define ldap_rename moz_ldap_rename
643 +#define ldap_rename_s moz_ldap_rename_s
644 +#define ldap_result moz_ldap_result
645 +#define ldap_result2error moz_ldap_result2error
646 +#define ldap_sasl_bind moz_ldap_sasl_bind
647 +#define ldap_sasl_bind_s moz_ldap_sasl_bind_s
648 +#define ldap_sasl_interactive_bind_ext_s moz_ldap_sasl_interactive_bind_ext_s
649 +#define ldap_sasl_interactive_bind_s moz_ldap_sasl_interactive_bind_s
650 +#define ldap_search moz_ldap_search
651 +#define ldap_search_ext moz_ldap_search_ext
652 +#define ldap_search_ext_s moz_ldap_search_ext_s
653 +#define ldap_search_s moz_ldap_search_s
654 +#define ldap_search_st moz_ldap_search_st
655 +#define ldap_set_filter_additions moz_ldap_set_filter_additions
656 +#define ldap_set_lderrno moz_ldap_set_lderrno
657 +#define ldap_set_option moz_ldap_set_option
658 +#define ldap_set_rebind_proc moz_ldap_set_rebind_proc
659 +#define ldap_setfilteraffixes moz_ldap_setfilteraffixes
660 +#define ldap_simple_bind moz_ldap_simple_bind
661 +#define ldap_simple_bind_s moz_ldap_simple_bind_s
662 +#define ldap_sort_entries moz_ldap_sort_entries
663 +#define ldap_sort_strcasecmp moz_ldap_sort_strcasecmp
664 +#define ldap_sort_values moz_ldap_sort_values
665 +#define ldap_start_tls_s moz_ldap_start_tls_s
666 +#define ldap_str2charray moz_ldap_str2charray
667 +#define ldap_tmplattrs moz_ldap_tmplattrs
668 +#define ldap_tmplerr2string moz_ldap_tmplerr2string
669 +#define ldap_tmplerrlist moz_ldap_tmplerrlist
670 +#define ldap_ufn_search_c moz_ldap_ufn_search_c
671 +#define ldap_ufn_search_ct moz_ldap_ufn_search_ct
672 +#define ldap_ufn_search_ctx moz_ldap_ufn_search_ctx
673 +#define ldap_ufn_search_s moz_ldap_ufn_search_s
674 +#define ldap_ufn_setfilter moz_ldap_ufn_setfilter
675 +#define ldap_ufn_setprefix moz_ldap_ufn_setprefix
676 +#define ldap_ufn_timeout moz_ldap_ufn_timeout
677 +#define ldap_unbind moz_ldap_unbind
678 +#define ldap_unbind_ext moz_ldap_unbind_ext
679 +#define ldap_unbind_s moz_ldap_unbind_s
680 +#define ldap_url_parse moz_ldap_url_parse
681 +#define ldap_url_parse_no_defaults moz_ldap_url_parse_no_defaults
682 +#define ldap_url_search moz_ldap_url_search
683 +#define ldap_url_search_s moz_ldap_url_search_s
684 +#define ldap_url_search_st moz_ldap_url_search_st
685 +#define ldap_utf8characters moz_ldap_utf8characters
686 +#define ldap_utf8copy moz_ldap_utf8copy
687 +#define ldap_utf8getcc moz_ldap_utf8getcc
688 +#define ldap_utf8isalnum moz_ldap_utf8isalnum
689 +#define ldap_utf8isalpha moz_ldap_utf8isalpha
690 +#define ldap_utf8isdigit moz_ldap_utf8isdigit
691 +#define ldap_utf8isspace moz_ldap_utf8isspace
692 +#define ldap_utf8isxdigit moz_ldap_utf8isxdigit
693 +#define ldap_utf8len moz_ldap_utf8len
694 +#define ldap_utf8next moz_ldap_utf8next
695 +#define ldap_utf8prev moz_ldap_utf8prev
696 +#define ldap_utf8strtok_r moz_ldap_utf8strtok_r
697 +#define ldap_vals2html moz_ldap_vals2html
698 +#define ldap_vals2text moz_ldap_vals2text
699 +#define ldap_value_free moz_ldap_value_free
700 +#define ldap_value_free_len moz_ldap_value_free_len
701 +#define ldap_version moz_ldap_version
702 +#define ldap_whoami moz_ldap_whoami
703 +#define ldap_whoami_s moz_ldap_whoami_s
704 +#define ldap_x_calloc moz_ldap_x_calloc
705 +#define ldap_x_free moz_ldap_x_free
706 +#define ldap_x_hostlist_first moz_ldap_x_hostlist_first
707 +#define ldap_x_hostlist_next moz_ldap_x_hostlist_next
708 +#define ldap_x_hostlist_statusfree moz_ldap_x_hostlist_statusfree
709 +#define ldap_x_malloc moz_ldap_x_malloc
710 +#define ldap_x_realloc moz_ldap_x_realloc
711 +
712  /* Standard LDAP API functions and declarations */
713  #include "ldap-standard.h"
714  
715
716
717 [FILE:9904:patches/patch-bug847568]
718 # Allow building against system-wide graphite2/harfbuzz.
719
720 diff --git config/system-headers.mozbuild config/system-headers.mozbuild
721 index 7620b4d00623..09d3db5ca8c0 100644
722 --- config/system-headers.mozbuild
723 +++ config/system-headers.mozbuild
724 @@ -1299,6 +1299,19 @@ if CONFIG['MOZ_ENABLE_LIBPROXY']:
725          'proxy.h',
726      ]
727  
728 +if CONFIG['MOZ_SYSTEM_GRAPHITE2']:
729 +    system_headers += [
730 +        'graphite2/Font.h',
731 +        'graphite2/Segment.h',
732 +    ]
733 +
734 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
735 +    system_headers += [
736 +        'harfbuzz/hb-glib.h',
737 +        'harfbuzz/hb-ot.h',
738 +        'harfbuzz/hb.h',
739 +    ]
740 +
741  if CONFIG['MOZ_SYSTEM_LIBVPX']:
742      system_headers += [
743          'vpx_mem/vpx_mem.h',
744 diff --git dom/base/moz.build dom/base/moz.build
745 index 8e19020315ae..2fcdbb6f7b42 100644
746 --- dom/base/moz.build
747 +++ dom/base/moz.build
748 @@ -543,6 +543,9 @@ if CONFIG['MOZ_BUILD_APP'] in ['browser', 'mobile/android', 'xulrunner']:
749  if CONFIG['MOZ_X11']:
750      CXXFLAGS += CONFIG['TK_CFLAGS']
751  
752 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
753 +    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
754 +
755  GeneratedFile('UseCounterList.h', script='gen-usecounters.py',
756                entry_point='use_counter_list', inputs=['UseCounters.conf'])
757  
758 diff --git gfx/graphite2/geckoextra/moz.build gfx/graphite2/geckoextra/moz.build
759 new file mode 100644
760 index 0000000000000..24e8d7a03274a
761 --- /dev/null
762 +++ gfx/graphite2/geckoextra/moz.build
763 @@ -0,0 +1,21 @@
764 +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
765 +# vim: set filetype=python:
766 +# This Source Code Form is subject to the terms of the Mozilla Public
767 +# License, v. 2.0. If a copy of the MPL was not distributed with this
768 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
769 +
770 +EXPORTS.graphite2 += [
771 +    'include/GraphiteExtra.h',
772 +    'include/GraphiteStructsForRLBox.h',
773 +]
774 +
775 +UNIFIED_SOURCES += [
776 +    '../geckoextra/src/GraphiteExtra.cpp',
777 +]
778 +
779 +CXXFLAGS += CONFIG['MOZ_GRAPHITE2_CFLAGS']
780 +
781 +# Match bundled graphite2 configuration
782 +AllowCompilerWarnings()
783 +
784 +FINAL_LIBRARY = 'gkmedias'
785 diff --git gfx/graphite2/moz-gr-update.sh gfx/graphite2/moz-gr-update.sh
786 index faaab1b17971..04eff5f09882 100644
787 --- gfx/graphite2/moz-gr-update.sh
788 +++ gfx/graphite2/moz-gr-update.sh
789 @@ -1,6 +1,7 @@
790  #!/bin/bash
791  
792  # Script used to update the Graphite2 library in the mozilla source tree
793 +# and bump version for --with-system-graphite2
794  
795  # This script lives in gfx/graphite2, along with the library source,
796  # but must be run from the top level of the mozilla-central tree.
797 @@ -37,12 +38,16 @@ echo "See" $0 "for update procedure." >> gfx/graphite2/README.mozilla
798  #find gfx/graphite2/ -name "*.cpp" -exec perl -p -i -e "s/<cstdio>/<stdio.h>/;s/Windows.h/windows.h/;" {} \;
799  #find gfx/graphite2/ -name "*.h" -exec perl -p -i -e "s/<cstdio>/<stdio.h>/;s/Windows.h/windows.h/;" {} \;
800  
801 +# chase version for --with-system-graphite2
802 +perl -p -i -e "s/[0-9]+\,[0-9]+\,[0-9]+/$RELEASE/ and tr/./,/ \
803 +  if /GR2_VERSION_REQUIRE/" old-configure.in
804 +
805  # summarize what's been touched
806  echo Updated to $RELEASE.
807  echo Here is what changed in the gfx/graphite2 directory:
808  echo
809  
810 -hg stat gfx/graphite2
811 +hg stat old-configure.in gfx/graphite2
812  
813  echo
814  echo If gfx/graphite2/src/files.mk has changed, please make corresponding
815 diff --git gfx/harfbuzz/README-mozilla gfx/harfbuzz/README-mozilla
816 index 22c76a7df020..a01490bd49ee 100644
817 --- gfx/harfbuzz/README-mozilla
818 +++ gfx/harfbuzz/README-mozilla
819 @@ -15,3 +15,8 @@ from within the gfx/harfbuzz directory.
820  
821  If the collection of source files changes, manual updates to moz.build may be
822  needed as we don't use the upstream makefiles.
823 +
824 +The in-tree copy may be omitted during build by --with-system-harfbuzz.
825 +Make sure to keep pkg-config version check within toolkit/moz.configure in sync
826 +with checkout version or increment latest tag by one if it's not based
827 +on upstream release.
828 diff --git gfx/moz.build gfx/moz.build
829 index 771f652e837a..3b358d84e384 100644
830 --- gfx/moz.build
831 +++ gfx/moz.build
832 @@ -13,6 +13,14 @@ with Files('wr/**'):
833  if CONFIG['MOZ_TREE_CAIRO']:
834      DIRS += ['cairo']
835  
836 +if CONFIG['MOZ_SYSTEM_GRAPHITE2']:
837 +    DIRS += ['graphite2/geckoextra']
838 +else:
839 +    DIRS += ['graphite2/src' ]
840 +
841 +if not CONFIG['MOZ_SYSTEM_HARFBUZZ']:
842 +    DIRS += ['harfbuzz/src']
843 +
844  DIRS += [
845      '2d',
846      'ycbcr',
847 @@ -21,8 +29,6 @@ DIRS += [
848      'qcms',
849      'gl',
850      'layers',
851 -    'graphite2/src',
852 -    'harfbuzz/src',
853      'ots/src',
854      'thebes',
855      'ipc',
856 diff --git gfx/skia/generate_mozbuild.py gfx/skia/generate_mozbuild.py
857 index e06ae3457a47..93faa61594a3 100755
858 --- gfx/skia/generate_mozbuild.py
859 +++ gfx/skia/generate_mozbuild.py
860 @@ -117,6 +117,9 @@ if CONFIG['CC_TYPE'] in ('clang', 'clang-cl'):
861          '-Wno-unused-private-field',
862      ]
863  
864 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
865 +    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
866 +
867  if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk', 'android'):
868      CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
869      CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
870 diff --git gfx/skia/moz.build gfx/skia/moz.build
871 index 2118677ca3a8..e4978b413784 100644
872 --- gfx/skia/moz.build
873 +++ gfx/skia/moz.build
874 @@ -493,6 +493,9 @@ if CONFIG['CC_TYPE'] in ('clang', 'clang-cl'):
875          '-Wno-unused-private-field',
876      ]
877  
878 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
879 +    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
880 +
881  if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk', 'android'):
882      CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
883      CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
884 diff --git gfx/thebes/moz.build gfx/thebes/moz.build
885 index 56f1b9fe3f4b..0ac1100b0df3 100644
886 --- gfx/thebes/moz.build
887 +++ gfx/thebes/moz.build
888 @@ -284,7 +284,13 @@ if CONFIG['MOZ_WAYLAND']:
889  
890  LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
891  
892 -DEFINES['GRAPHITE2_STATIC'] = True
893 +if CONFIG['MOZ_SYSTEM_GRAPHITE2']:
894 +    CXXFLAGS += CONFIG['MOZ_GRAPHITE2_CFLAGS']
895 +else:
896 +    DEFINES['GRAPHITE2_STATIC'] = True
897 +
898 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
899 +    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
900  
901  if CONFIG['CC_TYPE'] == 'clang':
902      # Suppress warnings from Skia header files.
903 diff --git intl/unicharutil/util/moz.build intl/unicharutil/util/moz.build
904 index cb1233c56d7e..06fb1f9f174b 100644
905 --- intl/unicharutil/util/moz.build
906 +++ intl/unicharutil/util/moz.build
907 @@ -25,4 +25,7 @@ UNIFIED_SOURCES += [
908      'nsUnicodeProperties.cpp',
909  ]
910  
911 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
912 +    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
913 +
914  FINAL_LIBRARY = 'xul'
915 diff --git netwerk/dns/moz.build netwerk/dns/moz.build
916 index 79c26e3e7001..c4d93bc5f7dc 100644
917 --- netwerk/dns/moz.build
918 +++ netwerk/dns/moz.build
919 @@ -86,3 +86,6 @@ USE_LIBS += ['icu']
920  
921  if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
922      CXXFLAGS += ['-Wno-error=shadow']
923 +
924 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
925 +    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
926 diff --git old-configure.in old-configure.in
927 index 95a58b634593..b614eef85c89 100644
928 --- old-configure.in
929 +++ old-configure.in
930 @@ -2639,6 +2639,27 @@ dnl ========================================================
931  
932  AC_SUBST(MOZ_LINUX_32_SSE2_STARTUP_ERROR)
933  
934 +dnl ========================================================
935 +dnl Check for graphite2
936 +dnl ========================================================
937 +if test -n "$MOZ_SYSTEM_GRAPHITE2"; then
938 +    dnl graphite2.pc has bogus version, check manually
939 +    _SAVE_CFLAGS=$CFLAGS
940 +    CFLAGS="$CFLAGS $MOZ_GRAPHITE2_CFLAGS"
941 +    AC_TRY_COMPILE([ #include <graphite2/Font.h>
942 +                     #define GR2_VERSION_REQUIRE(major,minor,bugfix)  \
943 +                             ( GR2_VERSION_MAJOR * 10000 + GR2_VERSION_MINOR \
944 +                               * 100 + GR2_VERSION_BUGFIX >= \
945 +                               (major) * 10000 + (minor) * 100 + (bugfix) )
946 +                   ], [
947 +                     #if !GR2_VERSION_REQUIRE(1,3,14)
948 +                     #error "Insufficient graphite2 version."
949 +                     #endif
950 +                   ], [],
951 +                   [AC_MSG_ERROR([--with-system-graphite2 requested but no working libgraphite2 found])])
952 +    CFLAGS=$_SAVE_CFLAGS
953 +fi
954 +
955  dnl ========================================================
956  dnl Check for pixman and cairo
957  dnl ========================================================
958 diff --git toolkit/library/moz.build toolkit/library/moz.build
959 index 24f940e1ed7e..079a575adec3 100644
960 --- toolkit/library/moz.build
961 +++ toolkit/library/moz.build
962 @@ -248,6 +248,12 @@ if CONFIG['MOZ_SYSTEM_PNG']:
963  if CONFIG['MOZ_SYSTEM_WEBP']:
964      OS_LIBS += CONFIG['MOZ_WEBP_LIBS']
965  
966 +if CONFIG['MOZ_SYSTEM_GRAPHITE2']:
967 +    OS_LIBS += CONFIG['MOZ_GRAPHITE2_LIBS']
968 +
969 +if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
970 +    OS_LIBS += CONFIG['MOZ_HARFBUZZ_LIBS']
971 +
972  if CONFIG['MOZ_SYSTEM_LIBEVENT']:
973      OS_LIBS += CONFIG['MOZ_LIBEVENT_LIBS']
974  
975 diff --git toolkit/moz.configure toolkit/moz.configure
976 index 9297e4d6f501..d8e273887e4b 100644
977 --- toolkit/moz.configure
978 +++ toolkit/moz.configure
979 @@ -937,6 +937,25 @@ add_old_configure_assignment('FT2_LIBS',
980  add_old_configure_assignment('FT2_CFLAGS',
981                               ft2_info.cflags)
982  
983 +# Graphite2
984 +# ==============================================================
985 +option('--with-system-graphite2',
986 +       help="Use system graphite2 (located with pkgconfig)")
987 +
988 +system_graphite2 = pkg_check_modules('MOZ_GRAPHITE2', 'graphite2',
989 +                                     when='--with-system-graphite2')
990 +
991 +set_config('MOZ_SYSTEM_GRAPHITE2', depends_if(system_graphite2)(lambda _: True))
992 +
993 +# HarfBuzz
994 +# ==============================================================
995 +option('--with-system-harfbuzz',
996 +       help="Use system harfbuzz (located with pkgconfig)")
997 +
998 +system_harfbuzz = pkg_check_modules('MOZ_HARFBUZZ', 'harfbuzz >= 2.6.6',
999 +                                    when='--with-system-harfbuzz')
1000 +
1001 +set_config('MOZ_SYSTEM_HARFBUZZ', depends_if(system_harfbuzz)(lambda _: True))
1002  
1003  # Remote agent (part of CDP based remote protocol)
1004  # ==============================================================
1005
1006
1007 [FILE:1292:patches/patch-comm_ldap_c-sdk_include_portable.h]
1008 --- comm/ldap/c-sdk/include/portable.h.orig     2020-05-21 20:31:05 UTC
1009 +++ comm/ldap/c-sdk/include/portable.h
1010 @@ -119,11 +119,15 @@
1011  #  define OPENLOG_OPTIONS (LOG_PID | LOG_NOWAIT)
1012  #endif
1013  
1014 +#ifdef __DragonFly__
1015 +#define DRAGONFLY
1016 +#endif
1017 +
1018  /*
1019   * some systems don't have the BSD re_comp and re_exec routines
1020   */
1021  #ifndef NEED_BSDREGEX
1022 -#  if (defined(SYSV) || defined(NETBSD) || defined(FREEBSD) ||       \
1023 +#  if (defined(SYSV) || defined(NETBSD) || defined(FREEBSD) || defined(DRAGONFLY) || \
1024         defined(__OpenBSD__) || defined(linux) || defined(DARWIN)) && \
1025        !defined(sgi)
1026  #    define NEED_BSDREGEX
1027 @@ -274,7 +278,7 @@ int strncasecmp(const char *, const char
1028        defined(SUNOS4) || defined(SNI) || defined(BSDI) || defined(NCR) ||      \
1029        defined(OSF1) || defined(NEC) || defined(VMS) ||                         \
1030        (defined(HPUX10) && !defined(_REENTRANT)) || defined(HPUX11) ||          \
1031 -      defined(UnixWare) || defined(NETBSD) || defined(FREEBSD) ||              \
1032 +      defined(UnixWare) || defined(NETBSD) || defined(FREEBSD) || defined(DRAGONFLY) || \
1033        defined(OPENBSD) || (defined(LINUX) && __GLIBC__ < 2) ||                 \
1034        (defined(AIX) && !defined(USE_REENTRANT_LIBC))
1035  #    define GETHOSTBYNAME(n, r, b, l, e) gethostbyname(n)
1036
1037
1038 [FILE:421:patches/patch-comm_mail_app_nsMailApp.cpp]
1039 --- comm/mail/app/nsMailApp.cpp.orig    2020-07-13 18:10:03 UTC
1040 +++ comm/mail/app/nsMailApp.cpp
1041 @@ -306,6 +306,9 @@ int main(int argc, char* argv[], char* e
1042    }
1043  #endif
1044  
1045 +  setenv("MOZ_GMP_PATH", "%%LOCALBASE%%/lib/browser_plugins/symlinks/gecko", 0);
1046 +  setenv("MOZ_PLUGIN_PATH", "%%LOCALBASE%%/lib/browser_plugins/symlinks/gecko", 0);
1047 +
1048  #ifdef HAS_DLL_BLOCKLIST
1049    DllBlocklist_Initialize(gBlocklistInitFlags);
1050  #endif
1051
1052
1053 [FILE:679:patches/patch-comm_third__party_botan_configure.py]
1054 --- comm/third_party/botan/configure.py.orig    2020-07-13 18:10:04 UTC
1055 +++ comm/third_party/botan/configure.py
1056 @@ -2936,11 +2936,7 @@ def set_defaults_for_unset_options(optio
1057          options.os = find_canonical_os_name(options.os)
1058  
1059      def deduce_compiler_type_from_cc_bin(cc_bin):
1060 -        if cc_bin.find('clang') != -1 or cc_bin in ['emcc', 'em++']:
1061 -            return 'clang'
1062 -        if cc_bin.find('-g++') != -1 or cc_bin.find('g++') != -1:
1063 -            return 'gcc'
1064 -        return None
1065 +        return 'gcc'
1066  
1067      if options.compiler is None and options.compiler_binary is not None:
1068          options.compiler = deduce_compiler_type_from_cc_bin(options.compiler_binary)
1069
1070
1071 [FILE:286:patches/patch-comm_third__party_botan_src_build-data_os_freebsd.txt]
1072 FreeBSD 11.3 doesn't have sys/auxv.h
1073
1074 --- comm/third_party/botan/src/build-data/os/freebsd.txt.orig   2020-09-08 23:21:51 UTC
1075 +++ comm/third_party/botan/src/build-data/os/freebsd.txt
1076 @@ -11,7 +11,6 @@ dev_random
1077  arc4random
1078  explicit_bzero
1079  cap_enter
1080 -elf_aux_info
1081  getentropy
1082  
1083  atomics
1084
1085
1086 [FILE:33130:patches/patch-cubeb-oss]
1087 https://github.com/kinetiknz/cubeb/pull/600
1088
1089 --- dom/media/CubebUtils.cpp.orig       2020-08-19 02:08:51 UTC
1090 +++ dom/media/CubebUtils.cpp
1091 @@ -126,7 +126,7 @@ const char kBrandBundleURL[] = "chrome://branding/locale/brand.properties";
1092  
1093  const char* AUDIOSTREAM_BACKEND_ID_STR[] = {
1094      "jack",  "pulse",       "alsa",  "audiounit", "audioqueue", "wasapi",
1095 -    "winmm", "directsound", "sndio", "opensl",    "audiotrack", "kai"};
1096 +    "winmm", "directsound", "sndio", "opensl", "oss", "audiotrack", "kai"};
1097  /* Index for failures to create an audio stream the first time. */
1098  const int CUBEB_BACKEND_INIT_FAILURE_FIRST =
1099      ArrayLength(AUDIOSTREAM_BACKEND_ID_STR);
1100 --- media/libcubeb/src/moz.build.orig   2020-08-19 02:09:19 UTC
1101 +++ media/libcubeb/src/moz.build
1102 @@ -40,6 +40,12 @@ if CONFIG['MOZ_JACK']:
1103      ]
1104      DEFINES['USE_JACK'] = True
1105  
1106 +if CONFIG['OS_ARCH'] in ('DragonFly', 'FreeBSD', 'SunOS'):
1107 +    SOURCES += [
1108 +        'cubeb_oss.c',
1109 +    ]
1110 +    DEFINES['USE_OSS'] = True
1111 +
1112  if CONFIG['OS_ARCH'] == 'OpenBSD':
1113      SOURCES += [
1114          'cubeb_sndio.c',
1115 --- media/libcubeb/src/cubeb.c.orig     2020-08-19 02:09:26 UTC
1116 +++ media/libcubeb/src/cubeb.c
1117 @@ -60,6 +60,9 @@ int sun_init(cubeb ** context, char const * context_name);
1118  #if defined(USE_OPENSL)
1119  int opensl_init(cubeb ** context, char const * context_name);
1120  #endif
1121 +#if defined(USE_OSS)
1122 +int oss_init(cubeb ** context, char const * context_name);
1123 +#endif
1124  #if defined(USE_AUDIOTRACK)
1125  int audiotrack_init(cubeb ** context, char const * context_name);
1126  #endif
1127 @@ -165,6 +168,10 @@ cubeb_init(cubeb ** context, char const * context_name, char const * backend_nam
1128  #if defined(USE_OPENSL)
1129        init_oneshot = opensl_init;
1130  #endif
1131 +    } else if (!strcmp(backend_name, "oss")) {
1132 +#if defined(USE_OSS)
1133 +      init_oneshot = oss_init;
1134 +#endif
1135      } else if (!strcmp(backend_name, "audiotrack")) {
1136  #if defined(USE_AUDIOTRACK)
1137        init_oneshot = audiotrack_init;
1138 @@ -200,6 +207,9 @@ cubeb_init(cubeb ** context, char const * context_name, char const * backend_nam
1139  #if defined(USE_ALSA)
1140      alsa_init,
1141  #endif
1142 +#if defined (USE_OSS)
1143 +    oss_init,
1144 +#endif
1145  #if defined(USE_AUDIOUNIT_RUST)
1146      audiounit_rust_init,
1147  #endif
1148 --- /dev/null
1149 +++ media/libcubeb/src/cubeb_oss.c
1150 @@ -0,0 +1,1152 @@
1151 +/*
1152 + * Copyright Â© 2019-2020 Nia Alarie <nia@NetBSD.org>
1153 + * Copyright Â© 2020 Ka Ho Ng <khng300@gmail.com>
1154 + *
1155 + * This program is made available under an ISC-style license.  See the
1156 + * accompanying file LICENSE for details.
1157 + */
1158 +
1159 +#if defined(__FreeBSD__) && __FreeBSD__ < 12
1160 +#define _WITH_GETLINE
1161 +#endif
1162 +#include <assert.h>
1163 +#include <ctype.h>
1164 +#include <errno.h>
1165 +#include <sys/types.h>
1166 +#include <sys/soundcard.h>
1167 +#include <sys/ioctl.h>
1168 +#include <fcntl.h>
1169 +#include <unistd.h>
1170 +#include <pthread.h>
1171 +#include <stdbool.h>
1172 +#include <stdlib.h>
1173 +#include <stdio.h>
1174 +#include <string.h>
1175 +#include <poll.h>
1176 +#include "cubeb/cubeb.h"
1177 +#include "cubeb_mixer.h"
1178 +#include "cubeb_strings.h"
1179 +#include "cubeb-internal.h"
1180 +
1181 +/* Supported well by most hardware. */
1182 +#ifndef OSS_PREFER_RATE
1183 +#define OSS_PREFER_RATE (48000)
1184 +#endif
1185 +
1186 +/* Standard acceptable minimum. */
1187 +#ifndef OSS_LATENCY_MS
1188 +#define OSS_LATENCY_MS (40)
1189 +#endif
1190 +
1191 +#ifndef OSS_DEFAULT_DEVICE
1192 +#define OSS_DEFAULT_DEVICE "/dev/dsp"
1193 +#endif
1194 +
1195 +#ifndef OSS_DEFAULT_MIXER
1196 +#define OSS_DEFAULT_MIXER "/dev/mixer"
1197 +#endif
1198 +
1199 +#ifndef OSS_DEFAULT_NFRAMES
1200 +#define OSS_DEFAULT_NFRAMES (32)
1201 +#endif
1202 +
1203 +#define ENV_AUDIO_DEVICE "AUDIO_DEVICE"
1204 +
1205 +#ifndef OSS_MAX_CHANNELS
1206 +# if defined(__FreeBSD__) || defined(__DragonFly__)
1207 +/*
1208 + * The current maximum number of channels supported
1209 + * on FreeBSD is 8.
1210 + *
1211 + * Reference: FreeBSD 12.1-RELEASE
1212 + */
1213 +#  define OSS_MAX_CHANNELS (8)
1214 +# elif defined(__sun__)
1215 +/*
1216 + * The current maximum number of channels supported
1217 + * on Illumos is 16.
1218 + *
1219 + * Reference: PSARC 2008/318
1220 + */
1221 +#  define OSS_MAX_CHANNELS (16)
1222 +# else
1223 +#  define OSS_MAX_CHANNELS (2)
1224 +# endif
1225 +#endif
1226 +
1227 +#if defined(__FreeBSD__) || defined(__DragonFly__)
1228 +#define SNDSTAT_BEGIN_STR "Installed devices:"
1229 +#define SNDSTAT_USER_BEGIN_STR "Installed devices from userspace:"
1230 +#define SNDSTAT_FV_BEGIN_STR "File Versions:"
1231 +#endif
1232 +
1233 +static struct cubeb_ops const oss_ops;
1234 +
1235 +struct cubeb {
1236 +  struct cubeb_ops const * ops;
1237 +
1238 +  /* Our intern string store */
1239 +  pthread_mutex_t mutex; /* protects devid_strs */
1240 +  cubeb_strings *devid_strs;
1241 +};
1242 +
1243 +struct oss_stream {
1244 +  oss_devnode_t name;
1245 +  int fd;
1246 +  void * buf;
1247 +
1248 +  struct stream_info {
1249 +    int channels;
1250 +    int sample_rate;
1251 +    int fmt;
1252 +    int precision;
1253 +  } info;
1254 +
1255 +  unsigned int frame_size; /* precision in bytes * channels */
1256 +  bool floating;
1257 +};
1258 +
1259 +struct cubeb_stream {
1260 +  struct cubeb * context;
1261 +  void * user_ptr;
1262 +  pthread_t thread;
1263 +  pthread_mutex_t mutex; /* protects running, volume, frames_written */
1264 +  bool running;
1265 +  float volume;
1266 +  struct oss_stream play;
1267 +  struct oss_stream record;
1268 +  cubeb_data_callback data_cb;
1269 +  cubeb_state_callback state_cb;
1270 +  uint64_t frames_written;
1271 +  unsigned int nfr; /* Number of frames allocated */
1272 +};
1273 +
1274 +static char const *
1275 +oss_cubeb_devid_intern(cubeb *context, char const * devid)
1276 +{
1277 +  char const *is;
1278 +  pthread_mutex_lock(&context->mutex);
1279 +  is = cubeb_strings_intern(context->devid_strs, devid);
1280 +  pthread_mutex_unlock(&context->mutex);
1281 +  return is;
1282 +}
1283 +
1284 +int
1285 +oss_init(cubeb **context, char const *context_name) {
1286 +  cubeb * c;
1287 +
1288 +  (void)context_name;
1289 +  if ((c = calloc(1, sizeof(cubeb))) == NULL) {
1290 +    return CUBEB_ERROR;
1291 +  }
1292 +
1293 +  if (cubeb_strings_init(&c->devid_strs) == CUBEB_ERROR) {
1294 +    goto fail;
1295 +  }
1296 +
1297 +  if (pthread_mutex_init(&c->mutex, NULL) != 0) {
1298 +    goto fail;
1299 +  }
1300 +
1301 +  c->ops = &oss_ops;
1302 +  *context = c;
1303 +  return CUBEB_OK;
1304 +
1305 +fail:
1306 +  cubeb_strings_destroy(c->devid_strs);
1307 +  free(c);
1308 +  return CUBEB_ERROR;
1309 +}
1310 +
1311 +static void
1312 +oss_destroy(cubeb * context)
1313 +{
1314 +  pthread_mutex_destroy(&context->mutex);
1315 +  cubeb_strings_destroy(context->devid_strs);
1316 +  free(context);
1317 +}
1318 +
1319 +static char const *
1320 +oss_get_backend_id(cubeb * context)
1321 +{
1322 +  return "oss";
1323 +}
1324 +
1325 +static int
1326 +oss_get_preferred_sample_rate(cubeb * context, uint32_t * rate)
1327 +{
1328 +  (void)context;
1329 +
1330 +  *rate = OSS_PREFER_RATE;
1331 +  return CUBEB_OK;
1332 +}
1333 +
1334 +static int
1335 +oss_get_max_channel_count(cubeb * context, uint32_t * max_channels)
1336 +{
1337 +  (void)context;
1338 +
1339 +  *max_channels = OSS_MAX_CHANNELS;
1340 +  return CUBEB_OK;
1341 +}
1342 +
1343 +static int
1344 +oss_get_min_latency(cubeb * context, cubeb_stream_params params,
1345 +                    uint32_t * latency_frames)
1346 +{
1347 +  (void)context;
1348 +
1349 +  *latency_frames = OSS_LATENCY_MS * params.rate / 1000;
1350 +  return CUBEB_OK;
1351 +}
1352 +
1353 +static void
1354 +oss_free_cubeb_device_info_strings(cubeb_device_info *cdi)
1355 +{
1356 +  free((char *)cdi->device_id);
1357 +  free((char *)cdi->friendly_name);
1358 +  free((char *)cdi->group_id);
1359 +  cdi->device_id = NULL;
1360 +  cdi->friendly_name = NULL;
1361 +  cdi->group_id = NULL;
1362 +}
1363 +
1364 +#if defined(__FreeBSD__) || defined(__DragonFly__)
1365 +/*
1366 + * Check if the specified DSP is okay for the purpose specified
1367 + * in type. Here type can only specify one operation each time
1368 + * this helper is called.
1369 + *
1370 + * Return 0 if OK, otherwise 1.
1371 + */
1372 +static int
1373 +oss_probe_open(const char *dsppath, cubeb_device_type type,
1374 +               int *fdp, oss_audioinfo *resai)
1375 +{
1376 +  oss_audioinfo ai;
1377 +  int error;
1378 +  int oflags = (type == CUBEB_DEVICE_TYPE_INPUT) ? O_RDONLY : O_WRONLY;
1379 +  int dspfd = open(dsppath, oflags);
1380 +  if (dspfd == -1)
1381 +    return 1;
1382 +
1383 +  ai.dev = -1;
1384 +  error = ioctl(dspfd, SNDCTL_AUDIOINFO, &ai);
1385 +  if (error < 0) {
1386 +    close(dspfd);
1387 +    return 1;
1388 +  }
1389 +
1390 +  if (resai)
1391 +    *resai = ai;
1392 +  if (fdp)
1393 +    *fdp = dspfd;
1394 +  else
1395 +    close(dspfd);
1396 +  return 0;
1397 +}
1398 +
1399 +struct sndstat_info {
1400 +  oss_devnode_t devname;
1401 +  const char *desc;
1402 +  cubeb_device_type type;
1403 +  int preferred;
1404 +};
1405 +
1406 +static int
1407 +oss_sndstat_line_parse(char *line, int is_ud, struct sndstat_info *sinfo)
1408 +{
1409 +    char *matchptr = line, *n = NULL;
1410 +    struct sndstat_info res;
1411 +
1412 +    memset(&res, 0, sizeof(res));
1413 +
1414 +    n = strchr(matchptr, ':');
1415 +    if (n == NULL)
1416 +      goto fail;
1417 +    if (is_ud == 0) {
1418 +      unsigned int devunit;
1419 +
1420 +      if (sscanf(matchptr, "pcm%u: ", &devunit) < 1)
1421 +        goto fail;
1422 +
1423 +      if (snprintf(res.devname, sizeof(res.devname), "/dev/dsp%u", devunit) < 1)
1424 +        goto fail;
1425 +    } else {
1426 +      if (n - matchptr >= (ssize_t)(sizeof(res.devname) - strlen("/dev/")))
1427 +        goto fail;
1428 +
1429 +      strlcpy(res.devname, "/dev/", sizeof(res.devname));
1430 +      strncat(res.devname, matchptr, n - matchptr);
1431 +    }
1432 +    matchptr = n + 1;
1433 +
1434 +    n = strchr(matchptr, '<');
1435 +    if (n == NULL)
1436 +      goto fail;
1437 +    matchptr = n + 1;
1438 +    n = strrchr(matchptr, '>');
1439 +    if (n == NULL)
1440 +      goto fail;
1441 +    *n = 0;
1442 +    res.desc = matchptr;
1443 +    matchptr = n + 1;
1444 +
1445 +    n = strchr(matchptr, '(');
1446 +    if (n == NULL)
1447 +      goto fail;
1448 +    matchptr = n + 1;
1449 +    n = strrchr(matchptr, ')');
1450 +    if (n == NULL)
1451 +      goto fail;
1452 +    *n = 0;
1453 +    if (!isdigit(matchptr[0])) {
1454 +      if (strstr(matchptr, "play") != NULL)
1455 +        res.type |= CUBEB_DEVICE_TYPE_OUTPUT;
1456 +      if (strstr(matchptr, "rec") != NULL)
1457 +        res.type |= CUBEB_DEVICE_TYPE_INPUT;
1458 +    } else {
1459 +      int p, r;
1460 +      if (sscanf(matchptr, "%dp:%*dv/%dr:%*dv", &p, &r) != 2)
1461 +        goto fail;
1462 +      if (p > 0)
1463 +        res.type |= CUBEB_DEVICE_TYPE_OUTPUT;
1464 +      if (r > 0)
1465 +        res.type |= CUBEB_DEVICE_TYPE_INPUT;
1466 +    }
1467 +    matchptr = n + 1;
1468 +    if (strstr(matchptr, "default") != NULL)
1469 +      res.preferred = 1;
1470 +
1471 +    *sinfo = res;
1472 +    return 0;
1473 +
1474 +fail:
1475 +    return 1;
1476 +}
1477 +
1478 +/*
1479 + * XXX: On FreeBSD we have to rely on SNDCTL_CARDINFO to get all
1480 + * the usable audio devices currently, as SNDCTL_AUDIOINFO will
1481 + * never return directly usable audio device nodes.
1482 + */
1483 +static int
1484 +oss_enumerate_devices(cubeb * context, cubeb_device_type type,
1485 +                      cubeb_device_collection * collection)
1486 +{
1487 +  cubeb_device_info *devinfop = NULL;
1488 +  char *line = NULL;
1489 +  size_t linecap = 0;
1490 +  FILE *sndstatfp = NULL;
1491 +  int collection_cnt = 0;
1492 +  int is_ud = 0;
1493 +  int skipall = 0;
1494 +
1495 +  devinfop = calloc(1, sizeof(cubeb_device_info));
1496 +  if (devinfop == NULL)
1497 +    goto fail;
1498 +
1499 +  sndstatfp = fopen("/dev/sndstat", "r");
1500 +  if (sndstatfp == NULL)
1501 +    goto fail;
1502 +  while (getline(&line, &linecap, sndstatfp) > 0) {
1503 +    const char *devid = NULL;
1504 +    struct sndstat_info sinfo;
1505 +    oss_audioinfo ai;
1506 +
1507 +    if (!strncmp(line, SNDSTAT_FV_BEGIN_STR, strlen(SNDSTAT_FV_BEGIN_STR))) {
1508 +      skipall = 1;
1509 +      continue;
1510 +    }
1511 +    if (!strncmp(line, SNDSTAT_BEGIN_STR, strlen(SNDSTAT_BEGIN_STR))) {
1512 +      is_ud = 0;
1513 +      skipall = 0;
1514 +      continue;
1515 +    }
1516 +    if (!strncmp(line, SNDSTAT_USER_BEGIN_STR, strlen(SNDSTAT_USER_BEGIN_STR))) {
1517 +      is_ud = 1;
1518 +      skipall = 0;
1519 +      continue;
1520 +    }
1521 +    if (skipall || isblank(line[0]))
1522 +      continue;
1523 +
1524 +    if (oss_sndstat_line_parse(line, is_ud, &sinfo))
1525 +      continue;
1526 +
1527 +    devinfop[collection_cnt].type = 0;
1528 +    switch (sinfo.type) {
1529 +    case CUBEB_DEVICE_TYPE_INPUT:
1530 +      if (type & CUBEB_DEVICE_TYPE_OUTPUT)
1531 +        continue;
1532 +      break;
1533 +    case CUBEB_DEVICE_TYPE_OUTPUT:
1534 +      if (type & CUBEB_DEVICE_TYPE_INPUT)
1535 +        continue;
1536 +      break;
1537 +    case 0:
1538 +      continue;
1539 +    }
1540 +
1541 +    if (oss_probe_open(sinfo.devname, type, NULL, &ai))
1542 +      continue;
1543 +
1544 +    devid = oss_cubeb_devid_intern(context, sinfo.devname);
1545 +    if (devid == NULL)
1546 +      continue;
1547 +
1548 +    devinfop[collection_cnt].device_id = strdup(sinfo.devname);
1549 +    asprintf((char **)&devinfop[collection_cnt].friendly_name, "%s: %s",
1550 +             sinfo.devname, sinfo.desc);
1551 +    devinfop[collection_cnt].group_id = strdup(sinfo.devname);
1552 +    devinfop[collection_cnt].vendor_name = NULL;
1553 +    if (devinfop[collection_cnt].device_id == NULL ||
1554 +        devinfop[collection_cnt].friendly_name == NULL ||
1555 +        devinfop[collection_cnt].group_id == NULL) {
1556 +      oss_free_cubeb_device_info_strings(&devinfop[collection_cnt]);
1557 +      continue;
1558 +    }
1559 +
1560 +    devinfop[collection_cnt].type = type;
1561 +    devinfop[collection_cnt].devid = devid;
1562 +    devinfop[collection_cnt].state = CUBEB_DEVICE_STATE_ENABLED;
1563 +    devinfop[collection_cnt].preferred =
1564 +        (sinfo.preferred) ? CUBEB_DEVICE_PREF_ALL : CUBEB_DEVICE_PREF_NONE;
1565 +    devinfop[collection_cnt].format = CUBEB_DEVICE_FMT_S16NE;
1566 +    devinfop[collection_cnt].default_format = CUBEB_DEVICE_FMT_S16NE;
1567 +    devinfop[collection_cnt].max_channels = ai.max_channels;
1568 +    devinfop[collection_cnt].default_rate = OSS_PREFER_RATE;
1569 +    devinfop[collection_cnt].max_rate = ai.max_rate;
1570 +    devinfop[collection_cnt].min_rate = ai.min_rate;
1571 +    devinfop[collection_cnt].latency_lo = 0;
1572 +    devinfop[collection_cnt].latency_hi = 0;
1573 +
1574 +    collection_cnt++;
1575 +
1576 +    void *newp = reallocarray(devinfop, collection_cnt + 1,
1577 +                              sizeof(cubeb_device_info));
1578 +    if (newp == NULL)
1579 +      goto fail;
1580 +    devinfop = newp;
1581 +  }
1582 +
1583 +  free(line);
1584 +  fclose(sndstatfp);
1585 +
1586 +  collection->count = collection_cnt;
1587 +  collection->device = devinfop;
1588 +
1589 +  return CUBEB_OK;
1590 +
1591 +fail:
1592 +  free(line);
1593 +  if (sndstatfp)
1594 +    fclose(sndstatfp);
1595 +  free(devinfop);
1596 +  return CUBEB_ERROR;
1597 +}
1598 +
1599 +#else
1600 +
1601 +static int
1602 +oss_enumerate_devices(cubeb * context, cubeb_device_type type,
1603 +                      cubeb_device_collection * collection)
1604 +{
1605 +  oss_sysinfo si;
1606 +  int error, i;
1607 +  cubeb_device_info *devinfop = NULL;
1608 +  int collection_cnt = 0;
1609 +  int mixer_fd = -1;
1610 +
1611 +  mixer_fd = open(OSS_DEFAULT_MIXER, O_RDWR);
1612 +  if (mixer_fd == -1) {
1613 +    LOG("Failed to open mixer %s. errno: %d", OSS_DEFAULT_MIXER, errno);
1614 +    return CUBEB_ERROR;
1615 +  }
1616 +
1617 +  error = ioctl(mixer_fd, SNDCTL_SYSINFO, &si);
1618 +  if (error) {
1619 +    LOG("Failed to run SNDCTL_SYSINFO on mixer %s. errno: %d", OSS_DEFAULT_MIXER, errno);
1620 +    goto fail;
1621 +  }
1622 +
1623 +  devinfop = calloc(si.numaudios, sizeof(cubeb_device_info));
1624 +  if (devinfop == NULL)
1625 +    goto fail;
1626 +
1627 +  collection->count = 0;
1628 +  for (i = 0; i < si.numaudios; i++) {
1629 +    oss_audioinfo ai;
1630 +    cubeb_device_info cdi = { 0 };
1631 +    const char *devid = NULL;
1632 +
1633 +    ai.dev = i;
1634 +    error = ioctl(mixer_fd, SNDCTL_AUDIOINFO, &ai);
1635 +    if (error)
1636 +      goto fail;
1637 +
1638 +    assert(ai.dev < si.numaudios);
1639 +    if (!ai.enabled)
1640 +      continue;
1641 +
1642 +    cdi.type = 0;
1643 +    switch (ai.caps & DSP_CAP_DUPLEX) {
1644 +    case DSP_CAP_INPUT:
1645 +      if (type & CUBEB_DEVICE_TYPE_OUTPUT)
1646 +        continue;
1647 +      break;
1648 +    case DSP_CAP_OUTPUT:
1649 +      if (type & CUBEB_DEVICE_TYPE_INPUT)
1650 +        continue;
1651 +      break;
1652 +    case 0:
1653 +      continue;
1654 +    }
1655 +    cdi.type = type;
1656 +
1657 +    devid = oss_cubeb_devid_intern(context, ai.devnode);
1658 +    cdi.device_id = strdup(ai.name);
1659 +    cdi.friendly_name = strdup(ai.name);
1660 +    cdi.group_id = strdup(ai.name);
1661 +    if (devid == NULL || cdi.device_id == NULL || cdi.friendly_name == NULL ||
1662 +        cdi.group_id == NULL) {
1663 +      oss_free_cubeb_device_info_strings(&cdi);
1664 +      continue;
1665 +    }
1666 +
1667 +    cdi.devid = devid;
1668 +    cdi.vendor_name = NULL;
1669 +    cdi.state = CUBEB_DEVICE_STATE_ENABLED;
1670 +    cdi.preferred = CUBEB_DEVICE_PREF_NONE;
1671 +    cdi.format = CUBEB_DEVICE_FMT_S16NE;
1672 +    cdi.default_format = CUBEB_DEVICE_FMT_S16NE;
1673 +    cdi.max_channels = ai.max_channels;
1674 +    cdi.default_rate = OSS_PREFER_RATE;
1675 +    cdi.max_rate = ai.max_rate;
1676 +    cdi.min_rate = ai.min_rate;
1677 +    cdi.latency_lo = 0;
1678 +    cdi.latency_hi = 0;
1679 +
1680 +    devinfop[collection_cnt++] = cdi;
1681 +  }
1682 +
1683 +  collection->count = collection_cnt;
1684 +  collection->device = devinfop;
1685 +
1686 +  if (mixer_fd != -1)
1687 +    close(mixer_fd);
1688 +  return CUBEB_OK;
1689 +
1690 +fail:
1691 +  if (mixer_fd != -1)
1692 +    close(mixer_fd);
1693 +  free(devinfop);
1694 +  return CUBEB_ERROR;
1695 +}
1696 +
1697 +#endif
1698 +
1699 +static int
1700 +oss_device_collection_destroy(cubeb * context,
1701 +                              cubeb_device_collection * collection)
1702 +{
1703 +  size_t i;
1704 +  for (i = 0; i < collection->count; i++) {
1705 +    oss_free_cubeb_device_info_strings(&collection->device[i]);
1706 +  }
1707 +  free(collection->device);
1708 +  collection->device = NULL;
1709 +  collection->count = 0;
1710 +  return 0;
1711 +}
1712 +
1713 +static unsigned int
1714 +oss_chn_from_cubeb(cubeb_channel chn)
1715 +{
1716 +  switch (chn) {
1717 +    case CHANNEL_FRONT_LEFT:
1718 +      return CHID_L;
1719 +    case CHANNEL_FRONT_RIGHT:
1720 +      return CHID_R;
1721 +    case CHANNEL_FRONT_CENTER:
1722 +      return CHID_C;
1723 +    case CHANNEL_LOW_FREQUENCY:
1724 +      return CHID_LFE;
1725 +    case CHANNEL_BACK_LEFT:
1726 +      return CHID_LR;
1727 +    case CHANNEL_BACK_RIGHT:
1728 +      return CHID_RR;
1729 +    case CHANNEL_SIDE_LEFT:
1730 +      return CHID_LS;
1731 +    case CHANNEL_SIDE_RIGHT:
1732 +      return CHID_RS;
1733 +    default:
1734 +      return CHID_UNDEF;
1735 +  }
1736 +}
1737 +
1738 +static unsigned long long
1739 +oss_cubeb_layout_to_chnorder(cubeb_channel_layout layout)
1740 +{
1741 +  unsigned int i, nchns = 0;
1742 +  unsigned long long chnorder = 0;
1743 +
1744 +  for (i = 0; layout; i++, layout >>= 1) {
1745 +    unsigned long long chid = oss_chn_from_cubeb((layout & 1) << i);
1746 +    if (chid == CHID_UNDEF)
1747 +      continue;
1748 +
1749 +    chnorder |= (chid & 0xf) << nchns * 4;
1750 +    nchns++;
1751 +  }
1752 +
1753 +  return chnorder;
1754 +}
1755 +
1756 +static int
1757 +oss_copy_params(int fd, cubeb_stream * stream, cubeb_stream_params * params,
1758 +                struct stream_info * sinfo)
1759 +{
1760 +  unsigned long long chnorder;
1761 +
1762 +  sinfo->channels = params->channels;
1763 +  sinfo->sample_rate = params->rate;
1764 +  switch (params->format) {
1765 +  case CUBEB_SAMPLE_S16LE:
1766 +    sinfo->fmt = AFMT_S16_LE;
1767 +    sinfo->precision = 16;
1768 +    break;
1769 +  case CUBEB_SAMPLE_S16BE:
1770 +    sinfo->fmt = AFMT_S16_BE;
1771 +    sinfo->precision = 16;
1772 +    break;
1773 +  case CUBEB_SAMPLE_FLOAT32NE:
1774 +    sinfo->fmt = AFMT_S32_NE;
1775 +    sinfo->precision = 32;
1776 +    break;
1777 +  default:
1778 +    LOG("Unsupported format");
1779 +    return CUBEB_ERROR_INVALID_FORMAT;
1780 +  }
1781 +  if (ioctl(fd, SNDCTL_DSP_CHANNELS, &sinfo->channels) == -1) {
1782 +    return CUBEB_ERROR;
1783 +  }
1784 +  if (ioctl(fd, SNDCTL_DSP_SETFMT, &sinfo->fmt) == -1) {
1785 +    return CUBEB_ERROR;
1786 +  }
1787 +  if (ioctl(fd, SNDCTL_DSP_SPEED, &sinfo->sample_rate) == -1) {
1788 +    return CUBEB_ERROR;
1789 +  }
1790 +  /* Mono layout is an exception */
1791 +  if (params->layout != CUBEB_LAYOUT_UNDEFINED && params->layout != CUBEB_LAYOUT_MONO) {
1792 +    chnorder = oss_cubeb_layout_to_chnorder(params->layout);
1793 +    if (ioctl(fd, SNDCTL_DSP_SET_CHNORDER, &chnorder) == -1)
1794 +      LOG("Non-fatal error %d occured when setting channel order.", errno);
1795 +  }
1796 +  return CUBEB_OK;
1797 +}
1798 +
1799 +static int
1800 +oss_stream_stop(cubeb_stream * s)
1801 +{
1802 +  pthread_mutex_lock(&s->mutex);
1803 +  if (s->running) {
1804 +    s->running = false;
1805 +    pthread_mutex_unlock(&s->mutex);
1806 +    pthread_join(s->thread, NULL);
1807 +  } else {
1808 +    pthread_mutex_unlock(&s->mutex);
1809 +  }
1810 +  return CUBEB_OK;
1811 +}
1812 +
1813 +static void
1814 +oss_stream_destroy(cubeb_stream * s)
1815 +{
1816 +  oss_stream_stop(s);
1817 +  pthread_mutex_destroy(&s->mutex);
1818 +  if (s->play.fd != -1) {
1819 +    close(s->play.fd);
1820 +  }
1821 +  if (s->record.fd != -1) {
1822 +    close(s->record.fd);
1823 +  }
1824 +  free(s->play.buf);
1825 +  free(s->record.buf);
1826 +  free(s);
1827 +}
1828 +
1829 +static void
1830 +oss_float_to_linear32(void * buf, unsigned sample_count, float vol)
1831 +{
1832 +  float * in = buf;
1833 +  int32_t * out = buf;
1834 +  int32_t * tail = out + sample_count;
1835 +
1836 +  while (out < tail) {
1837 +    int64_t f = *(in++) * vol * 0x80000000LL;
1838 +    if (f < -INT32_MAX)
1839 +      f = -INT32_MAX;
1840 +    else if (f > INT32_MAX)
1841 +      f = INT32_MAX;
1842 +    *(out++) = f;
1843 +  }
1844 +}
1845 +
1846 +static void
1847 +oss_linear32_to_float(void * buf, unsigned sample_count)
1848 +{
1849 +  int32_t * in = buf;
1850 +  float * out = buf;
1851 +  float * tail = out + sample_count;
1852 +
1853 +  while (out < tail) {
1854 +    *(out++) = (1.0 / 0x80000000LL) * *(in++);
1855 +  }
1856 +}
1857 +
1858 +static void
1859 +oss_linear16_set_vol(int16_t * buf, unsigned sample_count, float vol)
1860 +{
1861 +  unsigned i;
1862 +  int32_t multiplier = vol * 0x8000;
1863 +
1864 +  for (i = 0; i < sample_count; ++i) {
1865 +    buf[i] = (buf[i] * multiplier) >> 15;
1866 +  }
1867 +}
1868 +
1869 +static void *
1870 +oss_io_routine(void * arg)
1871 +{
1872 +  cubeb_stream *s = arg;
1873 +  cubeb_state state = CUBEB_STATE_STARTED;
1874 +  size_t to_read = 0;
1875 +  size_t to_write = 0;
1876 +  long cb_nfr = 0;
1877 +  size_t write_ofs = 0;
1878 +  size_t read_ofs = 0;
1879 +  int drain = 0;
1880 +  int trig = 0;
1881 +
1882 +  s->state_cb(s, s->user_ptr, CUBEB_STATE_STARTED);
1883 +
1884 +  if (s->record.fd != -1) {
1885 +    if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
1886 +      LOG("Error %d occured when setting trigger on record fd", errno);
1887 +      state = CUBEB_STATE_ERROR;
1888 +      goto out;
1889 +    }
1890 +  }
1891 +
1892 +  while (state == CUBEB_STATE_STARTED) {
1893 +    pthread_mutex_lock(&s->mutex);
1894 +    if (!s->running) {
1895 +      pthread_mutex_unlock(&s->mutex);
1896 +      state = CUBEB_STATE_STOPPED;
1897 +      break;
1898 +    }
1899 +    pthread_mutex_unlock(&s->mutex);
1900 +    if (s->play.fd == -1 && s->record.fd == -1) {
1901 +      /*
1902 +       * Stop here if the stream is not play & record stream,
1903 +       * play-only stream or record-only stream
1904 +       */
1905 +
1906 +      state = CUBEB_STATE_STOPPED;
1907 +      break;
1908 +    }
1909 +    if (s->record.fd != -1 && s->record.floating) {
1910 +      oss_linear32_to_float(s->record.buf,
1911 +                            s->record.info.channels * s->nfr);
1912 +    }
1913 +    cb_nfr = s->data_cb(s, s->user_ptr, s->record.buf, s->play.buf, s->nfr);
1914 +    if (cb_nfr == CUBEB_ERROR) {
1915 +      state = CUBEB_STATE_ERROR;
1916 +      break;
1917 +    }
1918 +    if (s->play.fd != -1) {
1919 +      float vol;
1920 +
1921 +      pthread_mutex_lock(&s->mutex);
1922 +      vol = s->volume;
1923 +      pthread_mutex_unlock(&s->mutex);
1924 +
1925 +      if (s->play.floating) {
1926 +        oss_float_to_linear32(s->play.buf,
1927 +                              s->play.info.channels * cb_nfr, vol);
1928 +      } else {
1929 +        oss_linear16_set_vol(s->play.buf,
1930 +                             s->play.info.channels * cb_nfr, vol);
1931 +      }
1932 +    }
1933 +    if (cb_nfr < (long)s->nfr) {
1934 +      if (s->play.fd != -1) {
1935 +        drain = 1;
1936 +      } else {
1937 +        /*
1938 +         * This is a record-only stream and number of frames
1939 +         * returned from data_cb() is smaller than number
1940 +         * of frames required to read. Stop here.
1941 +         */
1942 +
1943 +        state = CUBEB_STATE_STOPPED;
1944 +        break;
1945 +      }
1946 +    }
1947 +
1948 +    if (s->record.fd != -1 && !trig) {
1949 +      trig |= PCM_ENABLE_INPUT;
1950 +      if (ioctl(s->record.fd, SNDCTL_DSP_SETTRIGGER, &trig)) {
1951 +        LOG("Error %d occured when setting trigger on record fd", errno);
1952 +        state = CUBEB_STATE_ERROR;
1953 +        break;
1954 +      }
1955 +    }
1956 +
1957 +    to_write = s->play.fd != -1 ? cb_nfr : 0;
1958 +    to_read = s->record.fd != -1 ? s->nfr : 0;
1959 +    write_ofs = 0;
1960 +    read_ofs = 0;
1961 +    while (to_write > 0 || to_read > 0) {
1962 +      size_t bytes;
1963 +      ssize_t n, frames;
1964 +      struct pollfd pfds[2];
1965 +
1966 +      pfds[0].fd = s->play.fd;
1967 +      pfds[0].events = POLLOUT;
1968 +      pfds[0].revents = 0;
1969 +      pfds[1].fd = s->record.fd;
1970 +      pfds[1].events = POLLIN;
1971 +      pfds[1].revents = 0;
1972 +
1973 +      if (to_write > 0 && to_read > 0) {
1974 +        int nfds;
1975 +
1976 +        nfds = poll(pfds, 2, 10000);
1977 +        if (nfds == -1) {
1978 +          if (errno == EINTR)
1979 +            continue;
1980 +          LOG("Error %d occured when polling playback and record fd", errno);
1981 +          state = CUBEB_STATE_ERROR;
1982 +          break;
1983 +        } else if (nfds == 0)
1984 +          continue;
1985 +
1986 +        if ((pfds[0].revents & (POLLERR|POLLHUP)) ||
1987 +            (pfds[1].revents & (POLLERR|POLLHUP))) {
1988 +          LOG("Error %d occured on playback or record fds", errno);
1989 +          state = CUBEB_STATE_ERROR;
1990 +          break;
1991 +        }
1992 +      } else if (to_write > 0) {
1993 +        pfds[0].revents = POLLOUT;
1994 +      } else {
1995 +        pfds[1].revents = POLLIN;
1996 +      }
1997 +
1998 +      if (to_write > 0 && pfds[0].revents) {
1999 +        bytes = to_write * s->play.frame_size;
2000 +        if ((n = write(s->play.fd, (uint8_t *)s->play.buf + write_ofs, bytes)) < 0) {
2001 +          state = CUBEB_STATE_ERROR;
2002 +          break;
2003 +        }
2004 +        frames = n / s->play.frame_size;
2005 +        pthread_mutex_lock(&s->mutex);
2006 +        s->frames_written += frames;
2007 +        pthread_mutex_unlock(&s->mutex);
2008 +        to_write -= frames;
2009 +        write_ofs += n;
2010 +      }
2011 +      if (to_read > 0 && pfds[1].revents) {
2012 +        bytes = to_read * s->record.frame_size;
2013 +        if ((n = read(s->record.fd, (uint8_t *)s->record.buf + read_ofs, bytes)) < 0) {
2014 +          state = CUBEB_STATE_ERROR;
2015 +          break;
2016 +        }
2017 +        frames = n / s->record.frame_size;
2018 +        to_read -= frames;
2019 +        read_ofs += n;
2020 +      }
2021 +    }
2022 +    if (drain && state != CUBEB_STATE_ERROR) {
2023 +      state = CUBEB_STATE_DRAINED;
2024 +      break;
2025 +    }
2026 +  }
2027 +out:
2028 +  if (s->record.fd != -1)
2029 +    ioctl(s->record.fd, SNDCTL_DSP_HALT_INPUT, NULL);
2030 +  s->state_cb(s, s->user_ptr, state);
2031 +  return NULL;
2032 +}
2033 +
2034 +static int
2035 +oss_calc_frag_params(unsigned int frames, unsigned int frame_size)
2036 +{
2037 +  int n = 4;
2038 +  int blksize = OSS_DEFAULT_NFRAMES * frame_size;
2039 +  int nblks = (frames * frame_size + blksize - 1) / blksize;
2040 +  while ((1 << n) < blksize)
2041 +    n++;
2042 +  return nblks << 16 | n;
2043 +}
2044 +
2045 +static int
2046 +oss_stream_init(cubeb * context,
2047 +                cubeb_stream ** stream,
2048 +                char const * stream_name,
2049 +                cubeb_devid input_device,
2050 +                cubeb_stream_params * input_stream_params,
2051 +                cubeb_devid output_device,
2052 +                cubeb_stream_params * output_stream_params,
2053 +                unsigned latency_frames,
2054 +                cubeb_data_callback data_callback,
2055 +                cubeb_state_callback state_callback,
2056 +                void * user_ptr)
2057 +{
2058 +  int ret = CUBEB_OK;
2059 +  unsigned int playnfr = 1;
2060 +  unsigned int recnfr = 1;
2061 +  cubeb_stream *s = NULL;
2062 +  const char *defdsp;
2063 +
2064 +  if (!(defdsp = getenv(ENV_AUDIO_DEVICE)) || *defdsp == '\0')
2065 +    defdsp = OSS_DEFAULT_DEVICE;
2066 +
2067 +  (void)stream_name;
2068 +  if ((s = calloc(1, sizeof(cubeb_stream))) == NULL) {
2069 +    ret = CUBEB_ERROR;
2070 +    goto error;
2071 +  }
2072 +  s->record.fd = -1;
2073 +  s->play.fd = -1;
2074 +  s->nfr = OSS_DEFAULT_NFRAMES;
2075 +  if (input_device != NULL) {
2076 +    strlcpy(s->record.name, input_device, sizeof(s->record.name));
2077 +  } else {
2078 +    strlcpy(s->record.name, defdsp, sizeof(s->record.name));
2079 +  }
2080 +  if (output_device != NULL) {
2081 +    strlcpy(s->play.name, output_device, sizeof(s->play.name));
2082 +  } else {
2083 +    strlcpy(s->play.name, defdsp, sizeof(s->play.name));
2084 +  }
2085 +  if (input_stream_params != NULL) {
2086 +    unsigned int nb_channels;
2087 +    if (input_stream_params->prefs & CUBEB_STREAM_PREF_LOOPBACK) {
2088 +      LOG("Loopback not supported");
2089 +      ret = CUBEB_ERROR_NOT_SUPPORTED;
2090 +      goto error;
2091 +    }
2092 +    nb_channels = cubeb_channel_layout_nb_channels(input_stream_params->layout);
2093 +    if (input_stream_params->layout != CUBEB_LAYOUT_UNDEFINED &&
2094 +        nb_channels != input_stream_params->channels) {
2095 +      LOG("input_stream_params->layout does not match input_stream_params->channels");
2096 +      ret = CUBEB_ERROR_INVALID_PARAMETER;
2097 +      goto error;
2098 +    }
2099 +    if (s->record.fd == -1) {
2100 +      if ((s->record.fd = open(s->record.name, O_RDONLY)) == -1) {
2101 +        LOG("Audio device \"%s\" could not be opened as read-only",
2102 +            s->record.name);
2103 +        ret = CUBEB_ERROR_DEVICE_UNAVAILABLE;
2104 +        goto error;
2105 +      }
2106 +    }
2107 +    if ((ret = oss_copy_params(s->record.fd, s, input_stream_params,
2108 +                               &s->record.info)) != CUBEB_OK) {
2109 +      LOG("Setting record params failed");
2110 +      goto error;
2111 +    }
2112 +    s->record.floating = (input_stream_params->format == CUBEB_SAMPLE_FLOAT32NE);
2113 +  }
2114 +  if (output_stream_params != NULL) {
2115 +    unsigned int nb_channels;
2116 +    if (output_stream_params->prefs & CUBEB_STREAM_PREF_LOOPBACK) {
2117 +      LOG("Loopback not supported");
2118 +      ret = CUBEB_ERROR_NOT_SUPPORTED;
2119 +      goto error;
2120 +    }
2121 +    nb_channels = cubeb_channel_layout_nb_channels(output_stream_params->layout);
2122 +    if (output_stream_params->layout != CUBEB_LAYOUT_UNDEFINED &&
2123 +        nb_channels != output_stream_params->channels) {
2124 +      LOG("output_stream_params->layout does not match output_stream_params->channels");
2125 +      ret = CUBEB_ERROR_INVALID_PARAMETER;
2126 +      goto error;
2127 +    }
2128 +    if (s->play.fd == -1) {
2129 +      if ((s->play.fd = open(s->play.name, O_WRONLY)) == -1) {
2130 +        LOG("Audio device \"%s\" could not be opened as write-only",
2131 +            s->play.name);
2132 +        ret = CUBEB_ERROR_DEVICE_UNAVAILABLE;
2133 +        goto error;
2134 +      }
2135 +    }
2136 +    if ((ret = oss_copy_params(s->play.fd, s, output_stream_params,
2137 +                               &s->play.info)) != CUBEB_OK) {
2138 +      LOG("Setting play params failed");
2139 +      goto error;
2140 +    }
2141 +    s->play.floating = (output_stream_params->format == CUBEB_SAMPLE_FLOAT32NE);
2142 +  }
2143 +  s->context = context;
2144 +  s->volume = 1.0;
2145 +  s->state_cb = state_callback;
2146 +  s->data_cb = data_callback;
2147 +  s->user_ptr = user_ptr;
2148 +  if (pthread_mutex_init(&s->mutex, NULL) != 0) {
2149 +    LOG("Failed to create mutex");
2150 +    goto error;
2151 +  }
2152 +  s->play.frame_size = s->play.info.channels *
2153 +                      (s->play.info.precision / 8);
2154 +  if (s->play.fd != -1) {
2155 +    audio_buf_info bi;
2156 +    int frag = oss_calc_frag_params(latency_frames, s->play.frame_size);
2157 +    if (ioctl(s->play.fd, SNDCTL_DSP_SETFRAGMENT, &frag))
2158 +      LOG("Failed to set play fd with SNDCTL_DSP_SETFRAGMENT. frag: 0x%x", frag);
2159 +    if (ioctl(s->play.fd, SNDCTL_DSP_GETOSPACE, &bi) == 0) {
2160 +      unsigned int nfr = bi.fragsize / s->play.frame_size;
2161 +      if (playnfr < nfr) {
2162 +        playnfr = nfr;
2163 +      }
2164 +    }
2165 +  }
2166 +  s->record.frame_size = s->record.info.channels *
2167 +                        (s->record.info.precision / 8);
2168 +  if (s->record.fd != -1) {
2169 +    audio_buf_info bi;
2170 +    int frag = oss_calc_frag_params(latency_frames, s->record.frame_size);
2171 +    if (ioctl(s->record.fd, SNDCTL_DSP_SETFRAGMENT, &frag))
2172 +      LOG("Failed to set record fd with SNDCTL_DSP_SETFRAGMENT. frag: 0x%x",
2173 +          frag);
2174 +    if (ioctl(s->record.fd, SNDCTL_DSP_GETISPACE, &bi) == 0) {
2175 +      unsigned int nfr = bi.fragsize / s->record.frame_size;
2176 +      if (recnfr < nfr) {
2177 +        recnfr = nfr;
2178 +      }
2179 +    }
2180 +  }
2181 +  if (s->play.fd != -1 && s->record.fd != -1)
2182 +    s->nfr = (playnfr < recnfr) ? playnfr : recnfr;
2183 +  else if (s->play.fd != -1)
2184 +    s->nfr = playnfr;
2185 +  else if (s->record.fd != -1)
2186 +    s->nfr = recnfr;
2187 +
2188 +  if (s->play.fd != -1) {
2189 +    if ((s->play.buf = calloc(s->nfr, s->play.frame_size)) == NULL) {
2190 +      ret = CUBEB_ERROR;
2191 +      goto error;
2192 +    }
2193 +  }
2194 +  if (s->record.fd != -1) {
2195 +    if ((s->record.buf = calloc(s->nfr, s->record.frame_size)) == NULL) {
2196 +      ret = CUBEB_ERROR;
2197 +      goto error;
2198 +    }
2199 +  }
2200 +
2201 +  *stream = s;
2202 +  return CUBEB_OK;
2203 +error:
2204 +  if (s != NULL) {
2205 +    oss_stream_destroy(s);
2206 +  }
2207 +  return ret;
2208 +}
2209 +
2210 +static int
2211 +oss_stream_start(cubeb_stream * s)
2212 +{
2213 +  s->running = true;
2214 +  if (pthread_create(&s->thread, NULL, oss_io_routine, s) != 0) {
2215 +    LOG("Couldn't create thread");
2216 +    return CUBEB_ERROR;
2217 +  }
2218 +  return CUBEB_OK;
2219 +}
2220 +
2221 +static int
2222 +oss_stream_get_position(cubeb_stream * s, uint64_t * position)
2223 +{
2224 +  pthread_mutex_lock(&s->mutex);
2225 +  *position = s->frames_written;
2226 +  pthread_mutex_unlock(&s->mutex);
2227 +  return CUBEB_OK;
2228 +}
2229 +
2230 +static int
2231 +oss_stream_get_latency(cubeb_stream * s, uint32_t * latency)
2232 +{
2233 +  int delay;
2234 +
2235 +  if (ioctl(s->play.fd, SNDCTL_DSP_GETODELAY, &delay) == -1) {
2236 +    return CUBEB_ERROR;
2237 +  }
2238 +
2239 +  /* Return number of frames there */
2240 +  *latency = delay / s->play.frame_size;
2241 +  return CUBEB_OK;
2242 +}
2243 +
2244 +static int
2245 +oss_stream_set_volume(cubeb_stream * stream, float volume)
2246 +{
2247 +  if (volume < 0.0)
2248 +    volume = 0.0;
2249 +  else if (volume > 1.0)
2250 +    volume = 1.0;
2251 +  pthread_mutex_lock(&stream->mutex);
2252 +  stream->volume = volume;
2253 +  pthread_mutex_unlock(&stream->mutex);
2254 +  return CUBEB_OK;
2255 +}
2256 +
2257 +static int
2258 +oss_get_current_device(cubeb_stream * stream, cubeb_device ** const device)
2259 +{
2260 +  *device = calloc(1, sizeof(cubeb_device));
2261 +  if (*device == NULL) {
2262 +    return CUBEB_ERROR;
2263 +  }
2264 +  (*device)->input_name = stream->record.fd != -1 ?
2265 +    strdup(stream->record.name) : NULL;
2266 +  (*device)->output_name = stream->play.fd != -1 ?
2267 +    strdup(stream->play.name) : NULL;
2268 +  return CUBEB_OK;
2269 +}
2270 +
2271 +static int
2272 +oss_stream_device_destroy(cubeb_stream * stream, cubeb_device * device)
2273 +{
2274 +  (void)stream;
2275 +  free(device->input_name);
2276 +  free(device->output_name);
2277 +  free(device);
2278 +  return CUBEB_OK;
2279 +}
2280 +
2281 +static struct cubeb_ops const oss_ops = {
2282 +    .init = oss_init,
2283 +    .get_backend_id = oss_get_backend_id,
2284 +    .get_max_channel_count = oss_get_max_channel_count,
2285 +    .get_min_latency = oss_get_min_latency,
2286 +    .get_preferred_sample_rate = oss_get_preferred_sample_rate,
2287 +    .enumerate_devices = oss_enumerate_devices,
2288 +    .device_collection_destroy = oss_device_collection_destroy,
2289 +    .destroy = oss_destroy,
2290 +    .stream_init = oss_stream_init,
2291 +    .stream_destroy = oss_stream_destroy,
2292 +    .stream_start = oss_stream_start,
2293 +    .stream_stop = oss_stream_stop,
2294 +    .stream_reset_default_device = NULL,
2295 +    .stream_get_position = oss_stream_get_position,
2296 +    .stream_get_latency = oss_stream_get_latency,
2297 +    .stream_get_input_latency = NULL,
2298 +    .stream_set_volume = oss_stream_set_volume,
2299 +    .stream_get_current_device = oss_get_current_device,
2300 +    .stream_device_destroy = oss_stream_device_destroy,
2301 +    .stream_register_device_changed_callback = NULL,
2302 +    .register_device_collection_changed = NULL};
2303
2304
2305 [FILE:886:patches/patch-env-api-keys]
2306 # Accept API keys from environment like before bug 1294585
2307
2308 --- build/moz.configure/keyfiles.configure
2309 +++ build/moz.configure/keyfiles.configure
2310 @@ -18,6 +18,7 @@ def keyfile(desc, help=None, callback=lambda x: x):
2311      @checking('for the %s key' % desc, lambda x: x and x is not no_key)
2312      @imports(_from='__builtin__', _import='open')
2313      @imports(_from='__builtin__', _import='IOError')
2314 +    @imports(_from='os', _import='environ')
2315      def keyfile(value):
2316          if value:
2317              try:
2318 @@ -28,7 +29,7 @@ def keyfile(desc, help=None, callback=lambda x: x):
2319                      raise FatalCheckError("'%s' is empty." % value[0])
2320              except IOError as e:
2321                  raise FatalCheckError("'%s': %s." % (value[0], e.strerror))
2322 -        return no_key
2323 +        return environ.get('MOZ_%s_KEY' % desc.upper().replace(' ', '_')) or no_key
2324  
2325      return keyfile
2326  
2327
2328
2329 [FILE:2142:patches/patch-freebsd11.3]
2330 Drop after FreeBSD 11.3 EOL around 2020-09-20.
2331 https://svnweb.freebsd.org/changeset/base/351766
2332
2333 mozglue/baseprofiler/core/shared-libraries-linux.cc:374:34: error: use of undeclared
2334       identifier 'NT_GNU_BUILD_ID'
2335       if (note_header->n_type == NT_GNU_BUILD_ID) break;
2336                                  ^
2337 In file included from Unified_cpp_mozglue_baseprofiler0.cpp:137:
2338 mozglue/baseprofiler/lul/LulElf.cpp:762:32: error: use of undeclared identifier
2339       'NT_GNU_BUILD_ID'
2340     if (note_header->n_type == NT_GNU_BUILD_ID) break;
2341                                ^
2342 In file included from Unified_cpp_tools_profiler1.cpp:38:
2343 tools/profiler/lul/LulElf.cpp:776:32: error: use of undeclared identifier
2344       'NT_GNU_BUILD_ID'
2345     if (note_header->n_type == NT_GNU_BUILD_ID) break;
2346                                ^
2347
2348 --- mozglue/baseprofiler/core/shared-libraries-linux.cc.orig    2020-06-25 17:04:48 UTC
2349 +++ mozglue/baseprofiler/core/shared-libraries-linux.cc
2350 @@ -50,6 +50,11 @@ extern "C" MOZ_EXPORT __attribute__((weak)) int dl_ite
2351  #  define ElfW(type) Elf_##type
2352  #endif
2353  
2354 +#if defined(GP_OS_freebsd) && !defined(NT_GNU_BUILD_ID)
2355 +// FreeBSD < 11.4 doesn't define NT_GNU_BUILD_ID
2356 +#  define NT_GNU_BUILD_ID 3
2357 +#endif
2358 +
2359  // ----------------------------------------------------------------------------
2360  // Starting imports from toolkit/crashreporter/google-breakpad/, as needed by
2361  // this file when moved to mozglue.
2362 --- mozglue/baseprofiler/lul/LulElf.cpp.orig    2020-06-25 17:04:48 UTC
2363 +++ mozglue/baseprofiler/lul/LulElf.cpp
2364 @@ -79,6 +79,11 @@
2365  #  define EM_AARCH64 183
2366  #endif
2367  
2368 +#if defined(GP_OS_freebsd) && !defined(NT_GNU_BUILD_ID)
2369 +// FreeBSD < 11.4 doesn't define NT_GNU_BUILD_ID
2370 +#  define NT_GNU_BUILD_ID 3
2371 +#endif
2372 +
2373  // This namespace contains helper functions.
2374  namespace {
2375  
2376 --- tools/profiler/lul/LulElf.cpp.orig  2020-06-25 17:05:05 UTC
2377 +++ tools/profiler/lul/LulElf.cpp
2378 @@ -84,6 +84,11 @@
2379  #  define EM_AARCH64 183
2380  #endif
2381  
2382 +#if defined(GP_OS_freebsd) && !defined(NT_GNU_BUILD_ID)
2383 +// FreeBSD < 11.4 doesn't define NT_GNU_BUILD_ID
2384 +#  define NT_GNU_BUILD_ID 3
2385 +#endif
2386 +
2387  // This namespace contains helper functions.
2388  namespace {
2389  
2390
2391
2392 [FILE:890:patches/patch-gfx_skia_skia_src_core_SkCpu.cpp]
2393 Regressed by https://svnweb.freebsd.org/changeset/base/324815
2394
2395 gfx/skia/skia/src/core/SkCpu.cpp:81:27: error: use of undeclared identifier 'getauxval'
2396         uint32_t hwcaps = getauxval(AT_HWCAP);
2397                           ^
2398
2399 --- gfx/skia/skia/src/core/SkCpu.cpp.orig       2020-07-13 18:06:57 UTC
2400 +++ gfx/skia/skia/src/core/SkCpu.cpp
2401 @@ -72,6 +72,20 @@
2402          return features;
2403      }
2404  
2405 +#elif defined(SK_CPU_ARM64) && defined(__FreeBSD__)
2406 +    #include <machine/armreg.h>
2407 +
2408 +    static uint32_t read_cpu_features() {
2409 +        uint32_t features = 0;
2410 +        uint64_t id_aa64isar0;
2411 +
2412 +        id_aa64isar0 = READ_SPECIALREG(ID_AA64ISAR0_EL1);
2413 +        if (ID_AA64ISAR0_CRC32(id_aa64isar0) == ID_AA64ISAR0_CRC32_BASE) {
2414 +            features |= SkCpu::CRC32;
2415 +        }
2416 +        return features;
2417 +    }
2418 +
2419  #elif defined(SK_CPU_ARM64) && __has_include(<sys/auxv.h>)
2420      #include <sys/auxv.h>
2421  
2422
2423
2424 [FILE:290:files/thunderbird.desktop]
2425 [Desktop Entry]
2426 Encoding=UTF-8
2427 Name=Thunderbird
2428 GenericName=Mail Client
2429 Comment=Mail client and News Reader
2430 Exec=thunderbird %u
2431 Icon=thunderbird.png
2432 StartupNotify=true
2433 Terminal=false
2434 Type=Application
2435 Categories=Network;Email;News;InstantMessaging;
2436 MimeType=application/mbox;message/rfc822;
2437