Submitted By: Ken Moffat <ken at linuxfromscratch dot org>
Date: 2017-12-20
Initial Package Version: 58.0
Upstream Status: Waiting for review (mozilla bug 847568)
Origin: OpenBSD (via gentoo), plain text version at
https://svnweb.freebsd.org/ports/head/www/firefox/files/patch-bug847568?revision=447501&view=co
Description: Allow use of system versions of graphite2 and harfbuzz.
Add the options --with-system-graphite2 and --with-system-harfbuzz to use this.
Originally taken from gentoo,
https://dev.gentoo.org/~anarchy/mozilla/patchsets/ and
https://dev.gentoo.org/~axs/mozilla/patchsets/.
Adapted for changes to the Python build system in 58.0 and required harfbuzz version increased.

diff -Naur firefox-58.0b10/config/system-headers.mozbuild firefox-58.0b10-working/config/system-headers.mozbuild
--- firefox-58.0b10/config/system-headers.mozbuild	2017-11-11 00:19:59.000000000 +0000
+++ firefox-58.0b10-working/config/system-headers.mozbuild	2017-12-20 18:56:59.616097370 +0000
@@ -1234,6 +1234,13 @@
         'vr/gvr/capi/include/gvr.h',
     ]
 
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    system_headers += [
+	'harfbuzz/hb-glib.h',
+	'harfbuzz/hb-ot.h',
+	'harfbuzz/hb.h',
+    ]
+
 if CONFIG['MOZ_JACK']:
     system_headers += [
         'jack/jack.h',
diff -Naur firefox-58.0b10/config/system-headers.mozbuild.orig firefox-58.0b10-working/config/system-headers.mozbuild.orig
--- firefox-58.0b10/config/system-headers.mozbuild.orig	1970-01-01 01:00:00.000000000 +0100
+++ firefox-58.0b10-working/config/system-headers.mozbuild.orig	2017-11-11 00:19:59.000000000 +0000
@@ -0,0 +1,1346 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+system_headers = [
+    'A4Stuff.h',
+    'activscp.h',
+    'AEDataModel.h',
+    'AEObjects.h',
+    'AEPackObject.h',
+    'AERegistry.h',
+    'AEUtils.h',
+    'afxcmn.h',
+    'afxcoll.h',
+    'afxcview.h',
+    'afxdisp.h',
+    'afxdtctl.h',
+    'afxext.h',
+    'afxmt.h',
+    'afxpriv.h',
+    'afxtempl.h',
+    'afxwin.h',
+    'Aliases.h',
+    'all.h',
+    'alloca.h',
+    'alloc.h',
+    'alsa/asoundlib.h',
+    'ansi_parms.h',
+    'a.out.h',
+    'app/Cursor.h',
+    'Appearance.h',
+    'AppFileInfo.h',
+    'AppKit.h',
+    'AppleEvents.h',
+    'Application.h',
+    'app/Message.h',
+    'app/MessageRunner.h',
+    'arpa/inet.h',
+    'arpa/nameser.h',
+    'array',
+    'asm/page.h',
+    'asm/sigcontext.h',
+    'asm/signal.h',
+    'ASRegistry.h',
+    'assert.h',
+    'atk/atk.h',
+    'atlcom.h',
+    'atlconv.h',
+    'atlctl.cpp',
+    'atlctl.h',
+    'ATLCTL.H',
+    'atlhost.h',
+    'atlimpl.cpp',
+    'atlwin.cpp',
+    'atomic.h',
+    'ATSTypes.h',
+    'ATSUnicode.h',
+    'Balloons.h',
+    'base64.h',
+    'base/pblock.h',
+    'base/PCR_Base.h',
+    'base/session.h',
+    'basetyps.h',
+    'be/app/Application.h',
+    'Beep.h',
+    'be/kernel/image.h',
+    'be/kernel/OS.h',
+    'bfd.h',
+    'Bitmap.h',
+    'bitset',
+    'blapi.h',
+    'blapit.h',
+    'bsd/libc.h',
+    'bsd/syscall.h',
+    'bstring.h',
+    'builtin.h',
+    'Button.h',
+    'byteswap.h',
+    'cairo-atsui.h',
+    'cairo-beos.h',
+    'cairo-directfb.h',
+    'cairo-ft.h',
+    'cairo-glitz.h',
+    'cairo-gobject.h',
+    'cairo.h',
+    'cairo-pdf.h',
+    'cairo-ps.h',
+    'cairo-qpainter.h',
+    'cairo-qt.h',
+    'cairo-quartz.h',
+    'cairo-tee.h',
+    'cairo-win32.h',
+    'cairo-xlib.h',
+    'cairo-xlib-xrender.h',
+    'callconv.h',
+    'Carbon/Carbon.h',
+    'CarbonEvents.h',
+    'Carbon.h',
+    'c_asm.h',
+    'cctype',
+    'cderr.h',
+    'cerrno',
+    'certdb.h',
+    'cert.h',
+    'certt.h',
+    'CFBase.h',
+    'CFBundle.h',
+    'CFData.h',
+    'CFDictionary.h',
+    'cf.h',
+    'CFNumber.h',
+    'CFPlugIn.h',
+    'CFPreferences.h',
+    'CFString.h',
+    'CFURL.h',
+    'CGAffineTransform.h',
+    'CheckBox.h',
+    'ciferfam.h',
+    'Clipboard.h',
+    'cmmf.h',
+    'cmmft.h',
+    'cmplrs/stsupport.h',
+    'cms.h',
+    'cmsreclist.h',
+    'cmst.h',
+    'Cocoa/Cocoa.h',
+    'CodeFragments.h',
+    'comdef.h',
+    'commctrl.h',
+    'COMMCTRL.H',
+    'commdlg.h',
+    'compat.h',
+    'complex',
+    'condapi.h',
+    'ConditionalMacros.h',
+    'conio.h',
+    'console.h',
+    'ControlDefinitions.h',
+    'Controls.h',
+    'CoreFoundation/CoreFoundation.h',
+    'CoreServices/CoreServices.h',
+    'CPalmRec.cpp',
+    'Cpalmrec.h',
+    'CPCatgry.cpp',
+    'CPDbBMgr.h',
+    'CPString.cpp',
+    'CPString.h',
+    'crmf.h',
+    'crmft.h',
+    'crtdbg.h',
+    'crt_externs.h',
+    'crypt.h',
+    'cryptohi.h',
+    'cryptoht.h',
+    'cstddef',
+    'ctime',
+    'ctype.h',
+    'curl/curl.h',
+    'curl/easy.h',
+    'curses.h',
+    'cxxabi.h',
+    'DateTimeUtils.h',
+    'dbus/dbus-glib.h',
+    'dbus/dbus-glib-lowlevel.h',
+    'dbus/dbus.h',
+    'ddeml.h',
+    'Debug.h',
+    'dem.h',
+    'descrip.h',
+    'Devices.h',
+    'dfb_types.h',
+    'dfiff.h',
+    'dgiff.h',
+    'Dialogs.h',
+    'direct/build.h',
+    'direct/clock.h',
+    'direct/conf.h',
+    'direct/debug.h',
+    'direct/direct.h',
+    'directfb_keyboard.h',
+    'directfb_strings.h',
+    'direct.h',
+    'direct/hash.h',
+    'direct/interface.h',
+    'direct/interface_implementation.h',
+    'direct/list.h',
+    'direct/log.h',
+    'direct/memcpy.h',
+    'direct/mem.h',
+    'direct/messages.h',
+    'direct/modules.h',
+    'direct/serial.h',
+    'direct/signals.h',
+    'direct/stream.h',
+    'direct/system.h',
+    'direct/thread.h',
+    'direct/trace.h',
+    'direct/tree.h',
+    'direct/types.h',
+    'direct/utf8.h',
+    'direct/util.h',
+    'dirent.h',
+    'DiskInit.h',
+    'dlfcn.h',
+    'dlgs.h',
+    'dl.h',
+    'docobj.h',
+    'dos/dosextens.h',
+    'dos.h',
+    'Drag.h',
+    'DriverServices.h',
+    'DriverSynchronization.h',
+    'DropInPanel.h',
+    'dvidef.h',
+    'ecl-exp.h',
+    'elf.h',
+    'endian.h',
+    'Entry.h',
+    'err.h',
+    'errno.h',
+    'Errors.h',
+    'Events.h',
+    'exception',
+    'exdisp.h',
+    'ExDisp.h',
+    'exe386.h',
+    'execinfo.h',
+    'extras.h',
+    'fcntl.h',
+    'features.h',
+    'fenv.h',
+    'ffi.h',
+    'fibdef.h',
+    'File.h',
+    'filehdr.h',
+    'files.h',
+    'Files.h',
+    'FindDirectory.h',
+    'Finder.h',
+    'FinderRegistry.h',
+    'FixMath.h',
+    'float.h',
+    'fnmatch.h',
+    'Folders.h',
+    'fontconfig/fcfreetype.h',
+    'fontconfig/fontconfig.h',
+    'Font.h',
+    'Fonts.h',
+    'fp.h',
+    'fpieee.h',
+    'frame/log.h',
+    'frame/req.h',
+    'freetype/freetype.h',
+    'freetype/ftadvanc.h',
+    'freetype/ftbitmap.h',
+    'freetype/ftcache.h',
+    'freetype/ftfntfmt.h',
+    'freetype/ftglyph.h',
+    'freetype/ftlcdfil.h',
+    'freetype/ftoutln.h',
+    'freetype/ftsizes.h',
+    'freetype/ftsynth.h',
+    'freetype/ftxf86.h',
+    'freetype.h',
+    'freetype/t1tables.h',
+    'freetype/ttnameid.h',
+    'freetype/tttables.h',
+    'fribidi/fribidi.h',
+    'FSp_fopen.h',
+    'fstream',
+    'fstream.h',
+    'ft2build.h',
+    'ftadvanc.h',
+    'ftbitmap.h',
+    'ftcache.h',
+    'ftfntfmt.h',
+    'ftglyph.h',
+    'ftlcdfil.h',
+    'ftoutln.h',
+    'fts.h',
+    'ftsizes.h',
+    'ftsynth.h',
+    'ftxf86.h',
+    'fusion/arena.h',
+    'fusion/build.h',
+    'fusion/call.h',
+    'fusion/conf.h',
+    'fusion/fusion.h',
+    'fusion/fusion_internal.h',
+    'fusion/hash.h',
+    'fusion/lock.h',
+    'fusion/object.h',
+    'fusion/property.h',
+    'fusion/protocol.h',
+    'fusion/reactor.h',
+    'fusion/ref.h',
+    'fusion/shmalloc.h',
+    'fusion/shm/pool.h',
+    'fusion/shm/shm.h',
+    'fusion/shm/shm_internal.h',
+    'fusion/types.h',
+    'fusion/vector.h',
+    'gconf/gconf-client.h',
+    'Gdiplus.h',
+    'gdk/gdkdirectfb.h',
+    'gdk/gdk.h',
+    'gdk/gdkkeysyms.h',
+    'gdk/gdkprivate.h',
+    'gdk/gdkwayland.h',
+    'gdk/gdkx.h',
+    'gdk-pixbuf/gdk-pixbuf.h',
+    'Gestalt.h',
+    'getopt.h',
+    'gio/gio.h',
+    'glibconfig.h',
+    'glib.h',
+    'glib-object.h',
+    'glob.h',
+    'gmodule.h',
+    'gnome.h',
+    'gnu/libc-version.h',
+    'gps.h',
+    'grp.h',
+    'gssapi_generic.h',
+    'gssapi/gssapi_generic.h',
+    'gssapi/gssapi.h',
+    'gssapi.h',
+    'gst/app/gstappsink.h',
+    'gst/app/gstappsrc.h',
+    'gst/gst.h',
+    'gst/video/video.h',
+    'gtk/gtk.h',
+    'gtk/gtkunixprint.h',
+    'gtk/gtkx.h',
+    'hasht.h',
+    'HIToolbox/HIToolbox.h',
+    'hlink.h',
+    'ia64/sys/inline.h',
+    'Icons.h',
+    'iconv.h',
+    'ieeefp.h',
+    'ifaddrs.h',
+    'image.h',
+    'imagehlp.h',
+    'imm.h',
+    'initguid.h',
+    'initializer_list',
+    'InterfaceDefs.h',
+    'InternetConfig.h',
+    'IntlResources.h',
+    'ints.h',
+    'intshcut.h',
+    'inttypes.h',
+    'iodef.h',
+    'io.h',
+    'IOKit/IOKitLib.h',
+    'IOKit/IOMessage.h',
+    'IOKit/pwr_mgt/IOPMLib.h',
+    'iomanip',
+    'iostream.h',
+    'jar-ds.h',
+    'jarfile.h',
+    'jar.h',
+    'JavaControl.h',
+    'JavaEmbedding/JavaControl.h',
+    'JavaVM/jni.h',
+    'JManager.h',
+    'JNIEnvTests.h',
+    'jni.h',
+    'JVMManagerTests.h',
+    'Kerberos/Kerberos.h',
+    'kernel/image.h',
+    'kernel/OS.h',
+    'key.h',
+    'keyhi.h',
+    'keyt.h',
+    'keythi.h',
+    'kvm.h',
+    'LAction.h',
+    'langinfo.h',
+    'LApplication.h',
+    'LArray.h',
+    'LArrayIterator.h',
+    'LAttachable.h',
+    'LAttachment.h',
+    'LaunchServices.h',
+    'lber.h',
+    'LBroadcaster.h',
+    'LButton.h',
+    'lcache.h',
+    'LCaption.h',
+    'LCheckBox.h',
+    'LCicnButton.h',
+    'LClipboard.h',
+    'LCommander.h',
+    'LComparator.h',
+    'LControl.h',
+    'ldap.h',
+    'ldaplog.h',
+    'ldappr.h',
+    'ldap_ssl.h',
+    'LDataStream.h',
+    'ldfcn.h',
+    'LDialogBox.h',
+    'ldif.h',
+    'LDocApplication.h',
+    'LDocument.h',
+    'LDragAndDrop.h',
+    'LDragTask.h',
+    'LEditField.h',
+    'LEditText.h',
+    'LEventDispatcher.h',
+    'LFile.h',
+    'LFileStream.h',
+    'LFileTypeList.h',
+    'LFocusBox.h',
+    'LGrafPortView.h',
+    'LHandleStream.h',
+    'libc_r.h',
+    'libelf.h',
+    'libelf/libelf.h',
+    'libgen.h',
+    'libgnome/gnome-url.h',
+    'libgnome/libgnome.h',
+    'libgnomeui/gnome-icon-lookup.h',
+    'libgnomeui/gnome-icon-theme.h',
+    'libgnomeui/gnome-ui-init.h',
+    'libutil.h',
+    'limits.h',
+    'link.h',
+    'linux/ioprio.h',
+    'linux/kernel.h',
+    'linux/limits.h',
+    'linux/rtc.h',
+    'linux/version.h',
+    'List.h',
+    'Lists.h',
+    'LListBox.h',
+    'LListener.h',
+    'LMenuBar.h',
+    'LMenu.h',
+    'LModelDirector.h',
+    'LModelObject.h',
+    'LModelProperty.h',
+    'loader.h',
+    'locale',
+    'locale.h',
+    'LOffscreenView.h',
+    'logkeys.h',
+    'logstrng.h',
+    'Looper.h',
+    'LowMem.h',
+    'LPane.h',
+    'LPeriodical.h',
+    'LPicture.h',
+    'LPlaceHolder.h',
+    'LPrintout.h',
+    'LProgressBar.h',
+    'LPushButton.h',
+    'LRadioGroup.h',
+    'LRadioGroupView.h',
+    'LRunArray.h',
+    'LScroller.h',
+    'LSharable.h',
+    'LSingleDoc.h',
+    'LStaticText.h',
+    'LStdControl.h',
+    'LStream.h',
+    'LString.h',
+    'LTabGroup.h',
+    'LTabGroupView.h',
+    'LTableArrayStorage.h',
+    'LTableMonoGeometry.h',
+    'LTableSingleSelector.h',
+    'LTableView.h',
+    'LTextEditView.h',
+    'LTextTableView.h',
+    'LUndoer.h',
+    'LVariableArray.h',
+    'LView.h',
+    'LWindow.h',
+    'm68881.h',
+    'MacErrors.h',
+    'MacHeadersCarbon.h',
+    'machine/ansi.h',
+    'machine/builtins.h',
+    'machine/clock.h',
+    'machine/endian.h',
+    'machine/frame.h',
+    'machine/inline.h',
+    'machine/limits.h',
+    'machine/signal.h',
+    'machine/trap.h',
+    'mach/mach_host.h',
+    'mach/mach_init.h',
+    'mach/mach_interface.h',
+    'mach/mach_port.h',
+    'mach-o/dyld.h',
+    'MacLocales.h',
+    'MacMemory.h',
+    'MacTCP.h',
+    'MacTypes.h',
+    'MacWindows.h',
+    'malloc.h',
+    'malloc_np.h',
+    'mapicode.h',
+    'mapidefs.h',
+    'mapiguid.h',
+    'mapi.h',
+    'mapitags.h',
+    'mapiutil.h',
+    'mapix.h',
+    'Math64.h',
+    'math.h',
+    'mbstring.h',
+    'mem.h',
+    'memory.h',
+    'Memory.h',
+    'MenuBar.h',
+    'Menu.h',
+    'Menus.h',
+    'Message.h',
+    'Mime.h',
+    'MixedMode.h',
+    'mlang.h',
+    'mmsystem.h',
+    'model.h',
+    'Movies.h',
+    'mpw/errno.h',
+    'mshtmhst.h',
+    'mshtml.h',
+    'mswsock.h',
+    'Multiprocessing.h',
+    'mutex.h',
+    'Navigation.h',
+    'ncompat.h',
+    'ncurses.h',
+    'netCore.h',
+    'netdb.h',
+    'net/if.h',
+    'netinet/in.h',
+    'netinet/in_systm.h',
+    'netinet/tcp.h',
+    'newexe.h',
+    'new.h',
+    'nl_types.h',
+    'NodeInfo.h',
+    'nspr.h',
+    'nssb64.h',
+    'nssb64t.h',
+    'nssbase.h',
+    'nssbaset.h',
+    'nssck.api',
+    'nssckbi.h',
+    'nssckepv.h',
+    'nssckft.h',
+    'nssckfwc.h',
+    'nssckfw.h',
+    'nssckfwt.h',
+    'nssckg.h',
+    'nssckmdt.h',
+    'nssckt.h',
+    'nss.h',
+    'nssilckt.h',
+    'nssilock.h',
+    'nsslocks.h',
+    'nssrwlk.h',
+    'nssrwlkt.h',
+    'nssutil.h',
+    'nsswitch.h',
+    'objbase.h',
+    'objidl.h',
+    'Objsafe.h',
+    'ocsp.h',
+    'ocspt.h',
+    'ojiapitests.h',
+    'ole2.h',
+    'oleidl.h',
+    'OpenGL/OpenGL.h',
+    'OpenTptInternet.h',
+    'OpenTransport.h',
+    'OS.h',
+    'osreldate.h',
+    'OSUtils.h',
+    'p12.h',
+    'p12plcy.h',
+    'p12t.h',
+    'Packages.h',
+    'Palettes.h',
+    'PALM_CMN.H',
+    'pango/pango-break.h',
+    'pango/pangocairo.h',
+    'pango/pangofc-decoder.h',
+    'pango/pangofc-font.h',
+    'pango/pangofc-fontmap.h',
+    'pango/pango-fontmap.h',
+    'pango/pango.h',
+    'pango/pango-modules.h',
+    'pango/pango-utils.h',
+    'pango/pangoxft.h',
+    'pascal.h',
+    'Patches.h',
+    'Path.h',
+    'pcfs/pc_dir.h',
+    'Pgenerr.h',
+    'PGenErr.h',
+    'Ph.h',
+    'pixman.h',
+    'pk11func.h',
+    'pk11pqg.h',
+    'pk11priv.h',
+    'pk11pub.h',
+    'pk11sdr.h',
+    'pkcs11f.h',
+    'pkcs11.h',
+    'pkcs11n.h',
+    'pkcs11p.h',
+    'pkcs11t.h',
+    'pkcs11u.h',
+    'pkcs12.h',
+    'pkcs12t.h',
+    'pkcs7t.h',
+    'plarena.h',
+    'plarenas.h',
+    'plbase64.h',
+    'plerror.h',
+    'plgetopt.h',
+    'plhash.h',
+    'plstr.h',
+    'PLStringFuncs.h',
+    'PMApplication.h',
+    'pmddim.h',
+    'poll.h',
+    'Polygon.h',
+    'portable.h',
+    'port.h',
+    'portreg.h',
+    'Power.h',
+    'PP_ClassHeaders.cp',
+    'PP_Constants.h',
+    'PPCToolbox.h',
+    'PP_DebugHeaders.cp',
+    'PP_KeyCodes.h',
+    'PP_Macros.h',
+    'PP_Messages.h',
+    'PP_Prefix.h',
+    'PP_Resources.h',
+    'PP_Types.h',
+    'pratom.h',
+    'prbit.h',
+    'prclist.h',
+    'prcmon.h',
+    'prcountr.h',
+    'prcpucfg.h',
+    'prcvar.h',
+    'prdtoa.h',
+    'preenc.h',
+    'prenv.h',
+    'prerr.h',
+    'prerror.h',
+    'prinet.h',
+    'prinit.h',
+    'prinrval.h',
+    'Printing.h',
+    'Print/PMPrintingDialogExtensions.h',
+    'prio.h',
+    'pripcsem.h',
+    'private',
+    'prlink.h',
+    'prlock.h',
+    'prlog.h',
+    'prlong.h',
+    'prmem.h',
+    'prmon.h',
+    'prmwait.h',
+    'prnetdb.h',
+    'Processes.h',
+    'process.h',
+    'Process.h',
+    'prolock.h',
+    'proto/dos.h',
+    'proto/exec.h',
+    'prpdce.h',
+    'prprf.h',
+    'prproces.h',
+    'prrng.h',
+    'prrwlock.h',
+    'prshma.h',
+    'prshm.h',
+    'prsystem.h',
+    'prthread.h',
+    'prtime.h',
+    'prtpool.h',
+    'prtrace.h',
+    'prtypes.h',
+    'prvrsion.h',
+    'prwin16.h',
+    'psap.h',
+    'Pt.h',
+    'pthread.h',
+    'pthread_np.h',
+    'pulse/pulseaudio.h',
+    'pwd.h',
+    'Python.h',
+    'QDOffscreen.h',
+    'queue',
+    'Quickdraw.h',
+    'QuickDraw.h',
+    'QuickTimeComponents.h',
+    'quipu/attr.h',
+    'regex.h',
+    'Region.h',
+    'resolv.h',
+    'Resources.h',
+    'Retrace.h',
+    'rld_interface.h',
+    'Roster.h',
+    'rpc.h',
+    'rpcproxy.h',
+    'rpc/types.h',
+    'sane/sane.h',
+    'sane/sanei.h',
+    'sane/saneopts.h',
+    'sanitizer/asan_interface.h',
+    'sched.h',
+    'Scrap.h',
+    'Screen.h',
+    'Script.h',
+    'ScrollBar.h',
+    'secasn1.h',
+    'secasn1t.h',
+    'seccomon.h',
+    'secder.h',
+    'secdert.h',
+    'secdig.h',
+    'secdigt.h',
+    'secerr.h',
+    'sec.h',
+    'sechash.h',
+    'secitem.h',
+    'secmime.h',
+    'secmod.h',
+    'secmodt.h',
+    'secoid.h',
+    'secoidt.h',
+    'secpkcs5.h',
+    'secpkcs7.h',
+    'secport.h',
+    'secrng.h',
+    'security.h',
+    'secutil.h',
+    'semaphore.h',
+    'servprov.h',
+    'setjmp.h',
+    'SFNTLayoutTypes.h',
+    'SFNTTypes.h',
+    'sha1.h',
+    'share.h',
+    'shellapi.h',
+    'shlguid.h',
+    'shlobj.h',
+    'shsign.h',
+    'sigcontext.h',
+    'signal.h',
+    'SimpleGameSound.h',
+    'SIOUX.h',
+    'size_t.h',
+    'smime.h',
+    'sndio.h',
+    'someincludefile.h',
+    'soundcard.h',
+    'Sound.h',
+    'soundtouch/SoundTouchFactory.h',
+    'soundtouch/SoundTouch.h',
+    'spawn.h',
+    'sqlite3.h',
+    'sslerr.h',
+    'ssl.h',
+    'sslproto.h',
+    'sslt.h',
+    'sstream',
+    'StandardFile.h',
+    'starlet.h',
+    'stat.h',
+    'statreg.cpp',
+    'statreg.h',
+    'stdarg.h',
+    'stdbool.h',
+    'stddef.h',
+    'stdint.h',
+    'stdio.h',
+    'stdlib.h',
+    'storage/FindDirectory.h',
+    'StorageKit.h',
+    'StringCompare.h',
+    'string.h',
+    'String.h',
+    'strings.h',
+    'Strings.h',
+    'StringView.h',
+    'stropts.h',
+    'strstrea.h',
+    'structs.h',
+    'stsdef.h',
+    'SupportDefs.h',
+    'support/String.h',
+    'support/SupportDefs.h',
+    'support/TLS.h',
+    'svrcore.h',
+    'symconst.h',
+    'sym.h',
+    'synch.h',
+    'syncmgr.h',
+    'sys/atomic_op.h',
+    'sys/auxv.h',
+    'sys/bitypes.h',
+    'sys/byteorder.h',
+    'syscall.h',
+    'sys/cdefs.h',
+    'sys/cfgodm.h',
+    'sys/elf.h',
+    'sys/endian.h',
+    'sys/epoll.h',
+    'sys/errno.h',
+    'sys/eventfd.h',
+    'sys/fault.h',
+    'sys/fcntl.h',
+    'sys/file.h',
+    'sys/filio.h',
+    'sys/frame.h',
+    'sys/immu.h',
+    'sys/inotify.h',
+    'sys/inttypes.h',
+    'sys/ioccom.h',
+    'sys/ioctl.h',
+    'sys/ipc.h',
+    'sys/klog.h',
+    'sys/ldr.h',
+    'sys/link.h',
+    'sys/locking.h',
+    'syslog.h',
+    'sys/lwp.h',
+    'sys/machine.h',
+    'sys/mman.h',
+    'sys/mmu.h',
+    'sys/mount.h',
+    'sys/mpctl.h',
+    'sys/msg.h',
+    'sys/param.h',
+    'sys/pda.h',
+    'sys/poll.h',
+    'sys/ppc.h',
+    'sys/prctl.h',
+    'sys/priv.h',
+    'sys/procfs.h',
+    'sys/pstat.h',
+    'sys/ptrace.h',
+    'sys/queue.h',
+    'sys/quota.h',
+    'sys/reboot.h',
+    'sys/reg.h',
+    'sys/regset.h',
+    'sys/resource.h',
+    'sys/sched.h',
+    'sys/select.h',
+    'sys/sem.h',
+    'sys/sendfile.h',
+    'sys/shm.h',
+    'sys/siginfo.h',
+    'sys/signal.h',
+    'sys/socket.h',
+    'sys/sockio.h',
+    'sys/sparc/frame.h',
+    'sys/stack.h',
+    'sys/statfs.h',
+    'sys/stat.h',
+    'sys/statvfs.h',
+    'sys/syscall.h',
+    'sys/sysctl.h',
+    'sys/sysinfo.h',
+    'sys/sysmacros.h',
+    'sys/sysmp.h',
+    'sys/syssgi.h',
+    'sys/systeminfo.h',
+    'sys/system_properties.h',
+    'sys/thr.h',
+    'sys/timeb.h',
+    'sys/time.h',
+    'sys/times.h',
+    'sys/ttycom.h',
+    'sys/types.h',
+    'sys/ucontext.h',
+    'sys/uio.h',
+    'sys/un.h',
+    'sys/unistd.h',
+    'sys/user.h',
+    'sys/utsname.h',
+    'sys/vfs.h',
+    'sys/wait.h',
+    't1tables.h',
+    'tables.h',
+    'TArray.h',
+    'TArrayIterator.h',
+    'task.h',
+    'tchar.h',
+    'TCHAR.H',
+    'termios.h',
+    'TextCommon.h',
+    'TextEdit.h',
+    'TextEncodingConverter.h',
+    'TextServices.h',
+    'TextUtils.h',
+    'TextView.h',
+    'th/PCR_Th.h',
+    'thread.h',
+    'ThreadManagerTests.h',
+    'Threads.h',
+    'time.h',
+    'Timer.h',
+    'tlhelp32.h',
+    'ToolUtils.h',
+    'tr1/functional',
+    'trace.h',
+    'Traps.h',
+    'ttnameid.h',
+    'tttables.h',
+    'typeinfo',
+    'types.h',
+    'Types.h',
+    'UAppleEventsMgr.h',
+    'UAttachments.h',
+    'ucontext.h',
+    'uconv.h',
+    'UCursor.h',
+    'UDebugging.h',
+    'UDesktop.h',
+    'UDrawingState.h',
+    'UDrawingUtils.h',
+    'UEnvironment.h',
+    'UEventMgr.h',
+    'UException.h',
+    'UExtractFromAEDesc.h',
+    'UGWorld.h',
+    'UKeyFilters.h',
+    'ulocks.h',
+    'ulserrno.h',
+    'UMemoryMgr.h',
+    'UModalDialogs.h',
+    'UNavServicesDialogs.h',
+    'UnicodeBlockObjects.h',
+    'UnicodeConverter.h',
+    'UnicodeUtilities.h',
+    'unidef.h',
+    'unikbd.h',
+    'unistd.h',
+    'unix.h',
+    'unixio.h',
+    'unknwn.h',
+    'unwind.h',
+    'UPrinting.h',
+    'UQuickTime.h',
+    'UReanimator.h',
+    'URegions.h',
+    'URegistrar.h',
+    'UResourceMgr.h',
+    'urlhist.h',
+    'urlmon.h',
+    'UScrap.h',
+    'UScreenPort.h',
+    'UTCUtils.h',
+    'UTETextAction.h',
+    'UTEViewTextAction.h',
+    'UTextEdit.h',
+    'UTextTraits.h',
+    'utilmodt.h',
+    'utilpars.h',
+    'utilparst.h',
+    'utilrename.h',
+    'utime.h',
+    'UWindows.h',
+    'values.h',
+    'varargs.h',
+    'vcclr.h',
+    'View.h',
+    'Volume.h',
+    'wab.h',
+    'wait.h',
+    'wchar.h',
+    'wctype.h',
+    'winbase.h',
+    'win/compobj.h',
+    'windef.h',
+    'Window.h',
+    'windows.h',
+    'Windows.h',
+    'windowsx.h',
+    'Wininet.h',
+    'winnls.h',
+    'winperf.h',
+    'winreg.h',
+    'Winreg.h',
+    'winsock2.h',
+    'winsock.h',
+    'winspool.h',
+    'winsvc.h',
+    'winuser.h',
+    'winver.h',
+    'wmem.h',
+    'workbench/startup.h',
+    'wtypes.h',
+    'wx/image.h',
+    'wx/listctrl.h',
+    'wx/log.h',
+    'wx/toolbar.h',
+    'wx/wx.h',
+    'wx/xrc/xmlres.h',
+    'X11/cursorfont.h',
+    'X11/extensions/Print.h',
+    'X11/extensions/scrnsaver.h',
+    'X11/extensions/shape.h',
+    'X11/extensions/Xcomposite.h',
+    'X11/extensions/Xdamage.h',
+    'X11/extensions/Xfixes.h',
+    'X11/extensions/Xrender.h',
+    'X11/extensions/XShm.h',
+    'X11/ImUtil.h',
+    'X11/Intrinsic.h',
+    'X11/keysymdef.h',
+    'X11/keysym.h',
+    'X11/Shell.h',
+    'X11/StringDefs.h',
+    'X11/Xatom.h',
+    'X11/Xft/Xft.h',
+    'X11/Xfuncproto.h',
+    'X11/X.h',
+    'X11/XKBlib.h',
+    'X11/Xlib.h',
+    'X11/Xlibint.h',
+    'X11/Xlib-xcb.h',
+    'X11/Xlocale.h',
+    'X11/Xos.h',
+    'X11/Xutil.h',
+    'xcb/shm.h',
+    'xcb/xcb.h',
+    'xlocale.h',
+    'zmouse.h',
+]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    system_headers += [
+        'android/ashmem.h',
+        'android_audio/AudioSystem.h',
+        'android/log.h',
+        'android/looper.h',
+        'android/native_window.h',
+        'android/native_window.h',
+        'android/native_window_jni.h',
+        'audio_effects/effect_aec.h',
+        'audio_effects/effect_ns.h',
+        'AudioParameter.h',
+        'AudioSystem.h',
+        'AudioTrack.h',
+        'avc_utils.h',
+        'binder/Binder.h',
+        'binder/BinderService.h',
+        'binder/IBinder.h',
+        'binder/IInterface.h',
+        'binder/IMemory.h',
+        'binder/IPCThreadState.h',
+        'binder/IPermissionController.h',
+        'binder/IServiceManager.h',
+        'binder/Parcel.h',
+        'binder/ProcessState.h',
+        'camera/Camera.h',
+        'camera/CameraParameters.h',
+        'ColorConverter.h',
+        'cutils/android_reboot.h',
+        'cutils/atomic.h',
+        'cutils/compiler.h',
+        'cutils/log.h',
+        'cutils/native_handle.h',
+        'cutils/properties.h',
+        'cutils/sockets.h',
+        'foundation/ABase.h',
+        'foundation/ABitReader.h',
+        'foundation/ABuffer.h',
+        'foundation/ADebug.h',
+        'foundation/AHandler.h',
+        'foundation/AHandlerReflector.h',
+        'foundation/ALooper.h',
+        'foundation/AMessage.h',
+        'foundation/AString.h',
+        'foundation/base64.h',
+        'foundation/hexdump.h',
+        'gui/BufferQueue.h',
+        'gui/ConsumerBase.h',
+        'gui/GraphicBufferAlloc.h',
+        'gui/IConsumerListener.h',
+        'gui/IGraphicBufferAlloc.h',
+        'gui/IGraphicBufferProducer.h',
+        'gui/ISurfaceComposerClient.h',
+        'gui/ISurfaceComposer.h',
+        'gui/ISurfaceTexture.h',
+        'gui/SurfaceComposerClient.h',
+        'gui/Surface.h',
+        'gui/SurfaceTextureClient.h',
+        'hardware/audio.h',
+        'hardware/gralloc.h',
+        'hardware/hardware.h',
+        'hardware/hwcomposer.h',
+        'hardware_legacy/power.h',
+        'hardware_legacy/uevent.h',
+        'hardware_legacy/vibrator.h',
+        'hardware/lights.h',
+        'hardware/power.h',
+        'HTTPBase.h',
+        'linux/android_alarm.h',
+        'linux/ashmem.h',
+        'media/AudioEffect.h',
+        'media/AudioSystem.h',
+        'media/ICrypto.h',
+        'media/IOMX.h',
+        'media/MediaProfiles.h',
+        'media/MediaRecorderBase.h',
+        'media/openmax/OMX_Audio.h',
+        'media/stagefright/AACWriter.h',
+        'media/stagefright/AMRWriter.h',
+        'media/stagefright/AudioSource.h',
+        'media/stagefright/DataSource.h',
+        'media/stagefright/foundation/ABase.h',
+        'media/stagefright/foundation/ABitReader.h',
+        'media/stagefright/foundation/ABuffer.h',
+        'media/stagefright/foundation/ADebug.h',
+        'media/stagefright/foundation/AHandler.h',
+        'media/stagefright/foundation/AHandlerReflector.h',
+        'media/stagefright/foundation/ALooper.h',
+        'media/stagefright/foundation/AMessage.h',
+        'media/stagefright/foundation/AString.h',
+        'media/stagefright/foundation/base64.h',
+        'media/stagefright/foundation/hexdump.h',
+        'media/stagefright/MediaBufferGroup.h',
+        'media/stagefright/MediaBuffer.h',
+        'media/stagefright/MediaCodec.h',
+        'media/stagefright/MediaCodecList.h',
+        'media/stagefright/MediaCodecSource.h',
+        'media/stagefright/MediaDefs.h',
+        'media/stagefright/MediaErrors.h',
+        'media/stagefright/MediaExtractor.h',
+        'media/stagefright/MediaSource.h',
+        'media/stagefright/MediaWriter.h',
+        'media/stagefright/MetaData.h',
+        'media/stagefright/MPEG2TSWriter.h',
+        'media/stagefright/MPEG4Writer.h',
+        'media/stagefright/OMXClient.h',
+        'media/stagefright/OMXCodec.h',
+        'media/stagefright/openmax/OMX_Core.h',
+        'media/stagefright/openmax/OMX_Index.h',
+        'media/stagefright/openmax/OMX_IVCommon.h',
+        'media/stagefright/openmax/OMX_Types.h',
+        'media/stagefright/openmax/OMX_Video.h',
+        'media/stagefright/Utils.h',
+        'OMX_Component.h',
+        'OMX.h',
+        'stagefright/AACWriter.h',
+        'stagefright/AMRWriter.h',
+        'stagefright/AudioSource.h',
+        'stagefright/DataSource.h',
+        'stagefright/foundation/ABase.h',
+        'stagefright/foundation/ABitReader.h',
+        'stagefright/foundation/ABuffer.h',
+        'stagefright/foundation/ADebug.h',
+        'stagefright/foundation/AHandler.h',
+        'stagefright/foundation/AHandlerReflector.h',
+        'stagefright/foundation/ALooper.h',
+        'stagefright/foundation/AMessage.h',
+        'stagefright/foundation/AString.h',
+        'stagefright/foundation/base64.h',
+        'stagefright/foundation/hexdump.h',
+        'stagefright/MediaBufferGroup.h',
+        'stagefright/MediaBuffer.h',
+        'stagefright/MediaCodec.h',
+        'stagefright/MediaDefs.h',
+        'stagefright/MediaErrors.h',
+        'stagefright/MediaExtractor.h',
+        'stagefright/MediaSource.h',
+        'stagefright/MediaWriter.h',
+        'stagefright/MetaData.h',
+        'stagefright/MPEG2TSWriter.h',
+        'stagefright/MPEG4Writer.h',
+        'stagefright/OMXClient.h',
+        'stagefright/OMXCodec.h',
+        'stagefright/openmax/OMX_Component.h',
+        'stagefright/openmax/OMX_Core.h',
+        'stagefright/openmax/OMX_Index.h',
+        'stagefright/openmax/OMX_IVCommon.h',
+        'stagefright/openmax/OMX_Types.h',
+        'stagefright/openmax/OMX_Video.h',
+        'stagefright/Utils.h',
+        'suspend/autosuspend.h',
+        'system/audio.h',
+        'system/graphics.h',
+        'system/window.h',
+        'sysutils/NetlinkEvent.h',
+        'ui/ANativeObjectBase.h',
+        'ui/egl/android_natives.h',
+        'ui/Fence.h',
+        'ui/FramebufferNativeWindow.h',
+        'ui/GraphicBuffer.h',
+        'ui/Rect.h',
+        'ui/Region.h',
+        'utils/BitSet.h',
+        'utils/CallStack.h',
+        'utils/Errors.h',
+        'utils/FileMap.h',
+        'utils/KeyedVector.h',
+        'utils/List.h',
+        'utils/Log.h',
+        'utils/Looper.h',
+        'utils/PropertyMap.h',
+        'utils/RefBase.h',
+        'utils/String16.h',
+        'utils/String8.h',
+        'utils/TextOutput.h',
+        'utils/threads.h',
+        'utils/Timers.h',
+        'utils/Trace.h',
+        'utils/TypeHelpers.h',
+        'utils/Unicode.h',
+        'utils/Vector.h',
+        'utils/VectorImpl.h',
+        'vr/gvr/capi/include/gvr_controller.h',
+        'vr/gvr/capi/include/gvr.h',
+    ]
+
+if CONFIG['MOZ_JACK']:
+    system_headers += [
+        'jack/jack.h',
+        'jack/statistics.h',
+    ]
+
+if CONFIG['MOZ_SYSTEM_JPEG']:
+    system_headers += [
+        'jpeglib.h',
+    ]
+
+if CONFIG['MOZ_LIBAV_FFT']:
+    system_headers += [
+        'libavcodec/avfft.h',
+    ]
+
+if CONFIG['MOZ_SYSTEM_PNG']:
+    system_headers += [
+        'png.h',
+    ]
+
+if CONFIG['MOZ_SYSTEM_ZLIB']:
+    system_headers += [
+        'zlib.h',
+    ]
+
+if CONFIG['MOZ_ENABLE_STARTUP_NOTIFICATION']:
+    system_headers += [
+        'libsn/sn-common.h',
+        'libsn/sn.h',
+        'libsn/sn-launchee.h',
+        'libsn/sn-launcher.h',
+        'libsn/sn-monitor.h',
+        'libsn/sn-util.h',
+    ]
+
+if CONFIG['MOZ_SYSTEM_HUNSPELL']:
+    system_headers += [
+        'hunspell.hxx',
+    ]
+
+if CONFIG['MOZ_SYSTEM_BZ2']:
+    system_headers += [
+        'bzlib.h',
+    ]
+
+if CONFIG['MOZ_SYSTEM_LIBEVENT']:
+    system_headers += [
+        'event2/event_compat.h',
+        'event2/event.h',
+        'event2/event_struct.h',
+        'event.h',
+    ]
+else:
+    system_headers += [
+        'sys/event.h',
+    ]
+
+if CONFIG['MOZ_ENABLE_LIBPROXY']:
+    system_headers += [
+        'proxy.h',
+    ]
+
+if CONFIG['MOZ_ENABLE_CONTENTMANAGER']:
+    system_headers += [
+        'QtSparql/qsparqlconnection.h',
+        'QtSparql/qsparqlquery.h',
+        'QtSparql/qsparqlresult.h',
+        'SelectMultipleContentItemsPage.h',
+        'SelectSingleContentItemPage.h',
+    ]
+
+if not CONFIG['MOZ_TREE_PIXMAN']:
+    system_headers += [
+        'pixman.h',
+    ]
+
+if CONFIG['MOZ_SYSTEM_LIBVPX']:
+    system_headers += [
+        'vpx_mem/vpx_mem.h',
+        'vpx/svc_context.h',
+        'vpx/vp8cx.h',
+        'vpx/vp8dx.h',
+        'vpx/vpx_codec.h',
+        'vpx/vpx_decoder.h',
+        'vpx/vpx_encoder.h',
+    ]
+
+if CONFIG['MOZ_SYSTEM_ICU']:
+    system_headers += [
+        'unicode/locid.h',
+        'unicode/numsys.h',
+        'unicode/plurrule.h',
+        'unicode/timezone.h',
+        'unicode/ucal.h',
+        'unicode/uchar.h',
+        'unicode/uclean.h',
+        'unicode/ucol.h',
+        'unicode/udat.h',
+        'unicode/udatpg.h',
+        'unicode/udisplaycontext.h',
+        'unicode/uenum.h',
+        'unicode/unistr.h',
+        'unicode/unorm.h',
+        'unicode/unum.h',
+        'unicode/upluralrules.h',
+        'unicode/ureldatefmt.h',
+        'unicode/ustring.h',
+        'unicode/utypes.h',
+    ]
diff -Naur firefox-58.0b10/dom/base/moz.build firefox-58.0b10-working/dom/base/moz.build
--- firefox-58.0b10/dom/base/moz.build	2017-11-11 00:19:59.000000000 +0000
+++ firefox-58.0b10-working/dom/base/moz.build	2017-12-20 18:56:05.387531357 +0000
@@ -470,6 +470,9 @@
 if CONFIG['MOZ_X11']:
     CXXFLAGS += CONFIG['TK_CFLAGS']
 
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
+
 GENERATED_FILES += [
     'PropertyUseCounterMap.inc',
     'UseCounterList.h',
diff -Naur firefox-58.0b10/gfx/graphite2/moz-gr-update.sh firefox-58.0b10-working/gfx/graphite2/moz-gr-update.sh
--- firefox-58.0b10/gfx/graphite2/moz-gr-update.sh	2016-06-06 21:14:58.000000000 +0100
+++ firefox-58.0b10-working/gfx/graphite2/moz-gr-update.sh	2017-12-20 18:56:05.387531357 +0000
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 # Script used to update the Graphite2 library in the mozilla source tree
+# and bump version for --with-system-graphite2
 
 # This script lives in gfx/graphite2, along with the library source,
 # but must be run from the top level of the mozilla-central tree.
@@ -37,12 +38,16 @@
 #find gfx/graphite2/ -name "*.cpp" -exec perl -p -i -e "s/<cstdio>/<stdio.h>/;s/Windows.h/windows.h/;" {} \;
 #find gfx/graphite2/ -name "*.h" -exec perl -p -i -e "s/<cstdio>/<stdio.h>/;s/Windows.h/windows.h/;" {} \;
 
+# chase version for --with-system-graphite2
+perl -p -i -e "s/[0-9]+\,[0-9]+\,[0-9]+/$RELEASE/ and tr/./,/ \
+  if /GR2_VERSION_REQUIRE/" old-configure.in
+
 # summarize what's been touched
 echo Updated to $RELEASE.
 echo Here is what changed in the gfx/graphite2 directory:
 echo
 
-hg stat gfx/graphite2
+hg stat old-configure.in gfx/graphite2
 
 echo
 echo If gfx/graphite2/src/files.mk has changed, please make corresponding
diff -Naur firefox-58.0b10/gfx/harfbuzz/README-mozilla firefox-58.0b10-working/gfx/harfbuzz/README-mozilla
--- firefox-58.0b10/gfx/harfbuzz/README-mozilla	2017-11-02 20:23:11.000000000 +0000
+++ firefox-58.0b10-working/gfx/harfbuzz/README-mozilla	2017-12-20 18:56:05.387531357 +0000
@@ -19,3 +19,8 @@
 
 If the collection of source files changes, manual updates to moz.build may be
 needed, as we don't use the upstream makefiles.
+
+The in-tree copy may be omitted during build by --with-system-harfbuzz.
+Make sure to keep pkg-config version check within toolkit/moz.configure in sync
+with checkout version or increment latest tag by one if it's not based
+on upstream release.
diff -Naur firefox-58.0b10/gfx/moz.build firefox-58.0b10-working/gfx/moz.build
--- firefox-58.0b10/gfx/moz.build	2017-11-02 20:23:12.000000000 +0000
+++ firefox-58.0b10-working/gfx/moz.build	2017-12-20 18:56:05.387531357 +0000
@@ -10,6 +10,12 @@
 if CONFIG['MOZ_TREE_CAIRO']:
     DIRS += ['cairo']
 
+if not CONFIG['MOZ_SYSTEM_GRAPHITE2']:
+    DIRS += ['graphite2/src' ]
+
+if not CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    DIRS += ['harfbuzz/src']
+
 DIRS += [
     '2d',
     'ycbcr',
@@ -18,8 +24,6 @@
     'qcms',
     'gl',
     'layers',
-    'graphite2/src',
-    'harfbuzz/src',
     'ots/src',
     'thebes',
     'ipc',
diff -Naur firefox-58.0b10/gfx/skia/generate_mozbuild.py firefox-58.0b10-working/gfx/skia/generate_mozbuild.py
--- firefox-58.0b10/gfx/skia/generate_mozbuild.py	2017-11-02 20:23:12.000000000 +0000
+++ firefox-58.0b10-working/gfx/skia/generate_mozbuild.py	2017-12-20 18:56:05.387531357 +0000
@@ -135,6 +135,9 @@
         '-Wno-unused-private-field',
     ]
 
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
+
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android'):
     CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
     CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
diff -Naur firefox-58.0b10/gfx/skia/moz.build firefox-58.0b10-working/gfx/skia/moz.build
--- firefox-58.0b10/gfx/skia/moz.build	2017-11-02 20:23:12.000000000 +0000
+++ firefox-58.0b10-working/gfx/skia/moz.build	2017-12-20 18:56:05.388531349 +0000
@@ -780,6 +780,9 @@
         '-Wno-unused-private-field',
     ]
 
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
+
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android'):
     CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
     CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
diff -Naur firefox-58.0b10/gfx/thebes/moz.build firefox-58.0b10-working/gfx/thebes/moz.build
--- firefox-58.0b10/gfx/thebes/moz.build	2017-11-02 20:23:12.000000000 +0000
+++ firefox-58.0b10-working/gfx/thebes/moz.build	2017-12-20 18:56:05.388531349 +0000
@@ -267,7 +267,13 @@
 
 LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
 
-DEFINES['GRAPHITE2_STATIC'] = True
+if CONFIG['MOZ_SYSTEM_GRAPHITE2']:
+    CXXFLAGS += CONFIG['MOZ_GRAPHITE2_CFLAGS']
+else:
+    DEFINES['GRAPHITE2_STATIC'] = True
+
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
 
 if CONFIG['CLANG_CXX']:
     # Suppress warnings from Skia header files.
diff -Naur firefox-58.0b10/intl/unicharutil/util/moz.build firefox-58.0b10-working/intl/unicharutil/util/moz.build
--- firefox-58.0b10/intl/unicharutil/util/moz.build	2017-11-02 20:23:12.000000000 +0000
+++ firefox-58.0b10-working/intl/unicharutil/util/moz.build	2017-12-20 18:56:05.388531349 +0000
@@ -25,4 +25,7 @@
     'nsUnicodeProperties.cpp',
 ]
 
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
+
 FINAL_LIBRARY = 'xul'
diff -Naur firefox-58.0b10/netwerk/dns/moz.build firefox-58.0b10-working/netwerk/dns/moz.build
--- firefox-58.0b10/netwerk/dns/moz.build	2017-11-02 20:23:11.000000000 +0000
+++ firefox-58.0b10-working/netwerk/dns/moz.build	2017-12-20 19:00:22.323193157 +0000
@@ -69,6 +69,9 @@
     '/netwerk/base',
 ]
 
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    CXXFLAGS += CONFIG['MOZ_HARFBUZZ_CFLAGS']
+
 USE_LIBS += ['icu']
 
 if CONFIG['GNU_CXX']:
diff -Naur firefox-58.0b10/old-configure.in firefox-58.0b10-working/old-configure.in
--- firefox-58.0b10/old-configure.in	2017-11-29 16:25:29.000000000 +0000
+++ firefox-58.0b10-working/old-configure.in	2017-12-20 18:56:05.388531349 +0000
@@ -4260,6 +4260,27 @@
 AC_SUBST(MOZ_LINUX_32_SSE2_STARTUP_ERROR)
 
 dnl ========================================================
+dnl Check for graphite2
+dnl ========================================================
+if test -n "$MOZ_SYSTEM_GRAPHITE2"; then
+    dnl graphite2.pc has bogus version, check manually
+    _SAVE_CFLAGS=$CFLAGS
+    CFLAGS="$CFLAGS $MOZ_GRAPHITE2_CFLAGS"
+    AC_TRY_COMPILE([ #include <graphite2/Font.h>
+                     #define GR2_VERSION_REQUIRE(major,minor,bugfix)  \
+                             ( GR2_VERSION_MAJOR * 10000 + GR2_VERSION_MINOR \
+                               * 100 + GR2_VERSION_BUGFIX >= \
+                               (major) * 10000 + (minor) * 100 + (bugfix) )
+                   ], [
+                     #if !GR2_VERSION_REQUIRE(1,3,10)
+                     #error "Insufficient graphite2 version."
+                     #endif
+                   ], [],
+                   [AC_MSG_ERROR([--with-system-graphite2 requested but no working libgraphite2 found])])
+    CFLAGS=$_SAVE_CFLAGS
+fi
+
+dnl ========================================================
 dnl Check for pixman and cairo
 dnl ========================================================
 
diff -Naur firefox-58.0b10/toolkit/library/moz.build firefox-58.0b10-working/toolkit/library/moz.build
--- firefox-58.0b10/toolkit/library/moz.build	2017-11-09 04:21:56.000000000 +0000
+++ firefox-58.0b10-working/toolkit/library/moz.build	2017-12-20 18:56:05.389531341 +0000
@@ -231,6 +231,12 @@
 if CONFIG['MOZ_SYSTEM_PNG']:
     OS_LIBS += CONFIG['MOZ_PNG_LIBS']
 
+if CONFIG['MOZ_SYSTEM_GRAPHITE2']:
+    OS_LIBS += CONFIG['MOZ_GRAPHITE2_LIBS']
+
+if CONFIG['MOZ_SYSTEM_HARFBUZZ']:
+    OS_LIBS += CONFIG['MOZ_HARFBUZZ_LIBS']
+
 if CONFIG['MOZ_SYSTEM_HUNSPELL']:
     OS_LIBS += CONFIG['MOZ_HUNSPELL_LIBS']
 
diff -Naur firefox-58.0b10/toolkit/moz.configure firefox-58.0b10-working/toolkit/moz.configure
--- firefox-58.0b10/toolkit/moz.configure	2017-11-13 04:17:01.000000000 +0000
+++ firefox-58.0b10-working/toolkit/moz.configure	2017-12-20 22:21:15.686778460 +0000
@@ -317,6 +317,34 @@
 add_old_configure_assignment('_HAVE_FREETYPE2',
                              depends_if(freetype2_info)(lambda _: True))
 
+# Graphite2
+# ==============================================================
+option('--with-system-graphite2',
+       help="Use system graphite2 (located with pkgconfig)")
+
+@depends('--with-system-graphite2')
+def check_for_graphite2(value):
+    return bool(value)
+
+system_graphite2 = pkg_check_modules('MOZ_GRAPHITE2', 'graphite2',
+                                     when=check_for_graphite2)
+
+set_config('MOZ_SYSTEM_GRAPHITE2', depends_if(system_graphite2)(lambda _: True))
+
+# HarfBuzz
+# ==============================================================
+option('--with-system-harfbuzz',
+       help="Use system harfbuzz (located with pkgconfig)")
+
+@depends('--with-system-harfbuzz')
+def check_for_harfbuzz(value):
+    return bool(value)
+
+system_harfbuzz = pkg_check_modules('MOZ_HARFBUZZ', 'harfbuzz >= 1.6.3',
+                                    when=check_for_harfbuzz)
+
+set_config('MOZ_SYSTEM_HARFBUZZ', depends_if(system_harfbuzz)(lambda _: True))
+
 # Apple platform decoder support
 # ==============================================================
 @depends(toolkit)
