Bug 1698786: part 2) Change some compile-time dependent `printf`s to `MOZ_LOG` in...
[gecko.git] / toolkit / library / moz.build
blob94e5474248fd14415951fdd4d099e0e75d89a258
1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 @template
9 def Libxul_defines():
10     LIBRARY_DEFINES["MOZILLA_INTERNAL_API"] = True
11     LIBRARY_DEFINES["IMPL_LIBXUL"] = True
12     if not CONFIG["JS_SHARED_LIBRARY"]:
13         LIBRARY_DEFINES["STATIC_EXPORTABLE_JS_API"] = True
16 @template
17 def Libxul(name, output_category=None):
18     if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
19         # This is going to be a framework named "XUL", not an ordinary library named
20         # "libxul.dylib"
21         GeckoFramework(name, output_category=output_category, linkage=None)
22         SHARED_LIBRARY_NAME = "XUL"
23     else:
24         GeckoSharedLibrary(name, output_category=output_category, linkage=None)
25         SHARED_LIBRARY_NAME = "xul"
27     DELAYLOAD_DLLS += [
28         "comdlg32.dll",
29         "credui.dll",
30         "d3d11.dll",
31         "D3DCompiler_47.dll",
32         "dxgi.dll",
33         "hid.dll",
34         "msimg32.dll",
35         "netapi32.dll",
36         "secur32.dll",
37         "urlmon.dll",
38         "wininet.dll",
39         "winspool.drv",
40     ]
42     if CONFIG["ACCESSIBILITY"]:
43         DELAYLOAD_DLLS += ["oleacc.dll"]
45     if CONFIG["MOZ_WEBRTC"]:
46         DELAYLOAD_DLLS += ["msdmo.dll"]
48     if CONFIG["OS_ARCH"] == "WINNT":
49         DELAYLOAD_DLLS += [
50             "api-ms-win-core-winrt-l1-1-0.dll",
51             "api-ms-win-core-winrt-string-l1-1-0.dll",
52         ]
54     if CONFIG["OS_ARCH"] == "WINNT" and CONFIG["ACCESSIBILITY"]:
55         LOCAL_INCLUDES += ["!/accessible/interfaces/gecko/"]
57     if CONFIG["OS_ARCH"] == "WINNT":
58         LOCAL_INCLUDES += [
59             "/widget/windows",
60             "/xpcom/base",
61         ]
62         RCINCLUDE = "/toolkit/library/xulrunner.rc"
64     # Show a breakdown of linker time. (Too verbose for local builds.)
65     if CONFIG["CC_TYPE"] == "clang-cl" and not CONFIG["DEVELOPER_OPTIONS"]:
66         LDFLAGS += ["-time"]
68     Libxul_defines()
70     if CONFIG["MOZ_NEEDS_LIBATOMIC"]:
71         OS_LIBS += ["atomic"]
73     # TouchBar-related classes are only available in the 10.12.2 SDK and later.
74     # We need to weak link these classes until we've upgraded our SDK to at
75     # least 10.12.2.
76     # We're also linking against libresolv to solve bug 1367932.
77     if CONFIG["OS_ARCH"] == "Darwin":
78         LDFLAGS += ["-Wl,-U,_OBJC_CLASS_$_NSTouchBar"]
79         LDFLAGS += ["-Wl,-U,_OBJC_CLASS_$_NSSharingServicePickerTouchBarItem"]
80         LDFLAGS += ["-Wl,-U,_OBJC_METACLASS_$_NSTouchBar"]
81         LDFLAGS += ["-Wl,-U,_OBJC_CLASS_$_NSCustomTouchBarItem"]
82         LDFLAGS += ["-Wl,-U,_OBJC_CLASS_$_NSPopoverTouchBarItem"]
83         LDFLAGS += ["-lresolv"]
85     if CONFIG["MOZ_DEBUG_SYMBOLS"] and CONFIG["CC_TYPE"] == "clang-cl":
86         LDFLAGS += ["-NATVIS:%s/toolkit/library/gecko.natvis" % TOPSRCDIR]
87     if CONFIG["RUSTC_NATVIS_LDFLAGS"]:
88         LDFLAGS += CONFIG["RUSTC_NATVIS_LDFLAGS"]
90     if CONFIG["OS_ARCH"] == "Linux" and CONFIG["OS_TARGET"] != "Android":
91         GeneratedFile(
92             "symverscript",
93             script="/build/gen_symverscript.py",
94             inputs=["../symverscript.in"],
95             flags=["xul%s" % CONFIG["MOZILLA_SYMBOLVERSION"]],
96         )
97         SYMBOLS_FILE = "!symverscript"
99     # Generate GDB pretty printer-autoload files only on Linux. OSX's GDB is
100     # too old to support Python pretty-printers; if this changes, we could
101     # make this 'ifdef __GNUC__'.
102     if CONFIG["OS_ARCH"] == "Linux":
103         # Create a GDB Python auto-load file alongside the libxul shared library
104         # in the build directory.
105         DEFINES["topsrcdir"] = TOPSRCDIR
106         OBJDIR_FILES.toolkit.library.build += ["../libxul.so-gdb.py"]
109 # The real libxul definition is in ./build/moz.build, but we define a
110 # xul library here such that # FINAL_LIBRARY = 'xul' refers to here, which
111 # is then linked to both build/libxul and gtest/libxul.
112 Library("xul")
114 STATIC_LIBRARY_NAME = "xul_s"
116 # Use a FINAL_LIBRARY for Libxul_defines to propagate from there. They wouldn't
117 # propagate from here.
118 FINAL_LIBRARY = "xul-real"
120 if CONFIG["OS_ARCH"] == "WINNT":
121     SOURCES += [
122         "nsDllMain.cpp",
123     ]
125 LOCAL_INCLUDES += [
126     "/config",
127     # need widget/windows for resource.h (included from widget.rc)
128     "/widget/windows",
131 if CONFIG["OS_ARCH"] == "WINNT" and CONFIG["CC_TYPE"] not in ("clang", "gcc"):
132     LOCAL_INCLUDES += [
133         "/xpcom/base",
134     ]
136 DIRS += [
137     "build",
138     "gtest",
141 if CONFIG["OS_ARCH"] == "WINNT":
142     DIRS += ["dummydll"]
144 # js needs to come after xul for now, because it is an archive and its content
145 # is discarded when it comes first.
146 USE_LIBS += [
147     "js",
150 USE_LIBS += [
151     "lgpllibs",
152     "nspr",
153     "nss",
154     "psshparser",
155     "sqlite",
156     "zlib",
159 if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
160     USE_LIBS += [
161         "mozgtk_stub",
162     ]
164 if CONFIG["MOZ_WAYLAND"]:
165     USE_LIBS += [
166         "mozwayland",
167     ]
169 if CONFIG["MOZ_JPROF"]:
170     USE_LIBS += [
171         "jprof",
172     ]
174 if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk" or CONFIG["MOZ_TREE_FREETYPE"]:
175     USE_LIBS += [
176         "freetype",
177     ]
179 if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
180     CXXFLAGS += CONFIG["TK_CFLAGS"]
182 if CONFIG["MOZ_WEBRTC"]:
183     if CONFIG["OS_TARGET"] == "WINNT":
184         OS_LIBS += [
185             "secur32",
186             "iphlpapi",
187             "strmiids",
188             "dmoguids",
189             "wmcodecdspuuid",
190             "amstrmid",
191             "msdmo",
192             "wininet",
193         ]
195 if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
196     OS_LIBS += [
197         "-framework OpenGL",
198         "-framework SystemConfiguration",
199         "-framework AVFoundation",
200         "-framework CoreMedia",
201         "-framework IOKit",
202         "-F%s" % CONFIG["MACOS_PRIVATE_FRAMEWORKS_DIR"],
203         "-framework CoreUI",
204         "-framework CoreSymbolication",
205         "cups",
206     ]
208 if CONFIG["MOZ_WMF"]:
209     OS_LIBS += [
210         "mfuuid",
211         "wmcodecdspuuid",
212         "strmiids",
213     ]
215 if CONFIG["OS_ARCH"] == "FreeBSD":
216     OS_LIBS += [
217         "util",
218     ]
220 if CONFIG["OS_ARCH"] == "WINNT":
221     OS_LIBS += [
222         "crypt32",
223         "shell32",
224         "ntdll",
225         "ole32",
226         "version",
227         "winspool",
228     ]
230 if CONFIG["OS_ARCH"] == "Linux" and CONFIG["OS_TARGET"] != "Android":
231     OS_LIBS += [
232         "rt",
233     ]
235 if CONFIG["MOZ_ANDROID_GOOGLE_VR"]:
236     OS_LIBS += [
237         "-L%s" % CONFIG["MOZ_ANDROID_GOOGLE_VR_LIBS"],
238         "-lgvr",
239     ]
241 OS_LIBS += CONFIG["MOZ_CAIRO_OSLIBS"]
242 OS_LIBS += CONFIG["MOZ_WEBRTC_X11_LIBS"]
244 if CONFIG["MOZ_SYSTEM_JPEG"]:
245     OS_LIBS += CONFIG["MOZ_JPEG_LIBS"]
247 if CONFIG["MOZ_SYSTEM_PNG"]:
248     OS_LIBS += CONFIG["MOZ_PNG_LIBS"]
250 if CONFIG["MOZ_SYSTEM_WEBP"]:
251     OS_LIBS += CONFIG["MOZ_WEBP_LIBS"]
253 if CONFIG["MOZ_SYSTEM_LIBEVENT"]:
254     OS_LIBS += CONFIG["MOZ_LIBEVENT_LIBS"]
256 if CONFIG["MOZ_SYSTEM_LIBVPX"]:
257     OS_LIBS += CONFIG["MOZ_LIBVPX_LIBS"]
259 if not CONFIG["MOZ_TREE_PIXMAN"]:
260     OS_LIBS += CONFIG["MOZ_PIXMAN_LIBS"]
262 if CONFIG["HAVE_CLOCK_MONOTONIC"]:
263     OS_LIBS += CONFIG["REALTIME_LIBS"]
265 OS_LIBS += CONFIG["ICONV_LIBS"]
267 if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
268     OS_LIBS += CONFIG["TK_LIBS"]
270 if CONFIG["OS_ARCH"] == "OpenBSD":
271     OS_LIBS += [
272         "sndio",
273     ]
275 if CONFIG["MOZ_ENABLE_DBUS"]:
276     OS_LIBS += CONFIG["MOZ_DBUS_GLIB_LIBS"]
278 if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
279     OS_LIBS += [l for l in CONFIG["TK_LIBS"] if l not in ("-lgtk-3", "-lgdk-3")]
280     OS_LIBS += CONFIG["XLDFLAGS"]
281     OS_LIBS += CONFIG["XLIBS"]
282     OS_LIBS += CONFIG["XEXT_LIBS"]
283     OS_LIBS += CONFIG["MOZ_PANGO_LIBS"]
284     OS_LIBS += CONFIG["XT_LIBS"]
285     OS_LIBS += [
286         "gthread-2.0",
287     ]
289 if CONFIG["MOZ_ENABLE_LIBPROXY"]:
290     OS_LIBS += CONFIG["MOZ_LIBPROXY_LIBS"]
292 if CONFIG["OS_ARCH"] == "FreeBSD":
293     OS_LIBS += [
294         "util",
295     ]
297 if CONFIG["OS_ARCH"] == "Darwin":
298     OS_LIBS += [
299         # Link to Metal as required by the Metal gfx-hal backend
300         "-weak_framework Metal",
301         "-weak_framework MediaPlayer",
302     ]
305 if CONFIG["OS_ARCH"] == "WINNT":
306     OS_LIBS += [
307         "shell32",
308         "ole32",
309         "version",
310         "winspool",
311         "comdlg32",
312         "imm32",
313         "msimg32",
314         "netapi32",
315         "shlwapi",
316         "ws2_32",
317         "dnsapi",
318         "dwmapi",
319         "iphlpapi",
320         "uxtheme",
321         "setupapi",
322         "secur32",
323         "sensorsapi",
324         "portabledeviceguids",
325         "wininet",
326         "wbemuuid",
327         "wintrust",
328         "wtsapi32",
329         "locationapi",
330         "sapi",
331         "dxguid",
332         "dhcpcsvc",
333         # gfx-rs supports D3D11 and D3D12, but we are not linking to them implicitly
334         # "d3d11", # should be explicitly linked by gfx-backend-d3d11
335         #'d3d12', # should be explicitly linked by d3d12-rs
336         "d3dcompiler",
337     ]
339     if CONFIG["CC_TYPE"] == "clang-cl":
340         OS_LIBS += [
341             "runtimeobject",
342         ]
344     if CONFIG["ACCESSIBILITY"]:
345         OS_LIBS += [
346             "oleacc",
347         ]
349     # Prevent winapi-rs from statically linking
350     LIBRARY_DEFINES["WINAPI_NO_BUNDLED_LIBRARIES"] = True
352 if CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
353     OS_LIBS += [
354         "usp10",
355         "oleaut32",
356     ]
358 # The buildid is refreshed on every (incremental) build. But we want to avoid
359 # rebuilding libxul every time, so instead of having a source file that
360 # #include's buildid.h, which would have a dependency on it, and that would
361 # thus trigger make to rebuild everything, we generate a source with the
362 # buildid hard coded in it. Then we make that source file depend on all the
363 # objects files that constitute libxul, so that if any of the files linked into
364 # libxul is rebuilt, we refresh the buildid and link it into libxul.
366 if CONFIG["COMPILE_ENVIRONMENT"]:
367     SOURCES += ["!buildid.cpp"]
368     if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
369         libxul_list = "XUL"
370     else:
371         libxul_list = "%sxul_%s" % (
372             CONFIG["DLL_PREFIX"],
373             CONFIG["DLL_SUFFIX"].lstrip(".").replace(".", "_"),
374         )
375     GeneratedFile(
376         "buildid.cpp", script="gen_buildid.py", inputs=["!build/%s.list" % libxul_list]
377     )