Linux.mk 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. CC ?= gcc
  6. CCC ?= g++
  7. RANLIB ?= ranlib
  8. include $(CORE_DEPTH)/coreconf/UNIX.mk
  9. #
  10. # The default implementation strategy for Linux is now pthreads
  11. #
  12. ifneq ($(OS_TARGET),Android)
  13. USE_PTHREADS = 1
  14. endif
  15. ifeq ($(USE_PTHREADS),1)
  16. IMPL_STRATEGY = _PTH
  17. endif
  18. DEFAULT_COMPILER = gcc
  19. DEFINES += -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -DSQL_MEASURE_USE_TEMP_DIR
  20. ifeq ($(OS_TARGET),Android)
  21. ifndef ANDROID_NDK
  22. $(error Must set ANDROID_NDK to the path to the android NDK first)
  23. endif
  24. ifndef ANDROID_TOOLCHAIN_VERSION
  25. $(error Must set ANDROID_TOOLCHAIN_VERSION to the requested version number)
  26. endif
  27. ANDROID_PREFIX=$(OS_TEST)-linux-androideabi
  28. ANDROID_TARGET=$(ANDROID_PREFIX)-$(ANDROID_TOOLCHAIN_VERSION)
  29. # should autodetect which linux we are on, currently android only
  30. # supports linux-x86 prebuilts
  31. ANDROID_TOOLCHAIN=$(ANDROID_NDK)/toolchains/$(ANDROID_TARGET)/prebuilt/linux-x86
  32. ANDROID_SYSROOT=$(ANDROID_NDK)/platforms/android-$(OS_TARGET_RELEASE)/arch-$(OS_TEST)
  33. ANDROID_CC=$(ANDROID_TOOLCHAIN)/bin/$(ANDROID_PREFIX)-gcc
  34. ANDROID_CCC=$(ANDROID_TOOLCHAIN)/bin/$(ANDROID_PREFIX)-g++
  35. NSS_DISABLE_GTESTS=1
  36. # internal tools need to be built with the native compiler
  37. ifndef INTERNAL_TOOLS
  38. CC = $(ANDROID_CC) --sysroot=$(ANDROID_SYSROOT)
  39. CCC = $(ANDROID_CCC) --sysroot=$(ANDROID_SYSROOT)
  40. DEFAULT_COMPILER=$(ANDROID_PREFIX)-gcc
  41. ARCHFLAG = --sysroot=$(ANDROID_SYSROOT)
  42. DEFINES += -DNO_SYSINFO -DNO_FORK_CHECK -DANDROID
  43. CROSS_COMPILE = 1
  44. endif
  45. endif
  46. ifeq (,$(filter-out ppc64 ppc64le,$(OS_TEST)))
  47. CPU_ARCH = ppc
  48. ifeq ($(USE_64),1)
  49. ARCHFLAG = -m64
  50. endif
  51. else
  52. ifeq ($(OS_TEST),alpha)
  53. OS_REL_CFLAGS = -D_ALPHA_
  54. CPU_ARCH = alpha
  55. else
  56. ifeq ($(OS_TEST),x86_64)
  57. ifeq ($(USE_64),1)
  58. CPU_ARCH = x86_64
  59. ARCHFLAG = -m64
  60. else
  61. ifeq ($(USE_X32),1)
  62. CPU_ARCH = x86_64
  63. ARCHFLAG = -mx32
  64. 64BIT_TAG = _x32
  65. else
  66. OS_REL_CFLAGS = -Di386
  67. CPU_ARCH = x86
  68. ARCHFLAG = -m32
  69. endif
  70. endif
  71. else
  72. ifeq ($(OS_TEST),sparc64)
  73. CPU_ARCH = sparc
  74. else
  75. ifeq (,$(filter-out arm% sa110,$(OS_TEST)))
  76. CPU_ARCH = arm
  77. else
  78. ifeq (,$(filter-out parisc%,$(OS_TEST)))
  79. CPU_ARCH = hppa
  80. else
  81. ifeq (,$(filter-out i%86,$(OS_TEST)))
  82. OS_REL_CFLAGS = -Di386
  83. CPU_ARCH = x86
  84. else
  85. ifeq ($(OS_TEST),sh4a)
  86. CPU_ARCH = sh4
  87. else
  88. # $(OS_TEST) == m68k, ppc, ia64, sparc, s390, s390x, mips, sh3, sh4
  89. CPU_ARCH = $(OS_TEST)
  90. endif
  91. endif
  92. endif
  93. endif
  94. endif
  95. endif
  96. endif
  97. endif
  98. ifneq ($(OS_TARGET),Android)
  99. LIBC_TAG = _glibc
  100. endif
  101. ifdef BUILD_OPT
  102. ifeq (11,$(ALLOW_OPT_CODE_SIZE)$(OPT_CODE_SIZE))
  103. OPTIMIZER = -Os
  104. else
  105. OPTIMIZER = -O2
  106. endif
  107. ifdef MOZ_DEBUG_SYMBOLS
  108. ifdef MOZ_DEBUG_FLAGS
  109. OPTIMIZER += $(MOZ_DEBUG_FLAGS)
  110. else
  111. OPTIMIZER += -gdwarf-2
  112. endif
  113. endif
  114. endif
  115. ifndef COMPILER_TAG
  116. COMPILER_TAG := _$(CC_NAME)
  117. endif
  118. ifeq ($(USE_PTHREADS),1)
  119. OS_PTHREAD = -lpthread
  120. endif
  121. OS_CFLAGS = $(DSO_CFLAGS) $(OS_REL_CFLAGS) $(ARCHFLAG) -pipe -ffunction-sections -fdata-sections -DHAVE_STRERROR
  122. ifeq ($(KERNEL),Linux)
  123. OS_CFLAGS += -DLINUX -Dlinux
  124. endif
  125. OS_LIBS = $(OS_PTHREAD) -ldl -lc
  126. ifeq ($(OS_TARGET),Android)
  127. OS_LIBS += -llog
  128. endif
  129. ifdef USE_PTHREADS
  130. DEFINES += -D_REENTRANT
  131. endif
  132. DSO_CFLAGS = -fPIC
  133. DSO_LDOPTS = -shared $(ARCHFLAG) -Wl,--gc-sections
  134. # The linker on Red Hat Linux 7.2 and RHEL 2.1 (GNU ld version 2.11.90.0.8)
  135. # incorrectly reports undefined references in the libraries we link with, so
  136. # we don't use -z defs there.
  137. # Also, -z defs conflicts with Address Sanitizer, which emits relocations
  138. # against the libsanitizer runtime built into the main executable.
  139. ZDEFS_FLAG = -Wl,-z,defs
  140. DSO_LDOPTS += $(if $(findstring 2.11.90.0.8,$(shell ld -v)),,$(ZDEFS_FLAG))
  141. LDFLAGS += $(ARCHFLAG) -z noexecstack
  142. # On Maemo, we need to use the -rpath-link flag for even the standard system
  143. # library directories.
  144. ifdef _SBOX_DIR
  145. LDFLAGS += -Wl,-rpath-link,/usr/lib:/lib
  146. endif
  147. G++INCLUDES = -I/usr/include/g++
  148. #
  149. # Always set CPU_TAG on Linux.
  150. #
  151. CPU_TAG = _$(CPU_ARCH)
  152. #
  153. # On Linux 2.6 or later, build libfreebl3.so with no NSPR and libnssutil3.so
  154. # dependencies by default. Set FREEBL_NO_DEPEND to 0 in the environment to
  155. # override this.
  156. #
  157. ifneq ($(OS_TARGET),Android)
  158. ifeq (2.6,$(firstword $(sort 2.6 $(OS_RELEASE))))
  159. ifndef FREEBL_NO_DEPEND
  160. FREEBL_NO_DEPEND = 1
  161. FREEBL_LOWHASH = 1
  162. endif
  163. endif
  164. endif
  165. USE_SYSTEM_ZLIB = 1
  166. ZLIB_LIBS = -lz
  167. # The -rpath '$$ORIGIN' linker option instructs this library to search for its
  168. # dependencies in the same directory where it resides.
  169. ifeq ($(BUILD_SUN_PKG), 1)
  170. ifeq ($(USE_64), 1)
  171. RPATH = -Wl,-rpath,'$$ORIGIN:/opt/sun/private/lib64:/opt/sun/private/lib'
  172. else
  173. RPATH = -Wl,-rpath,'$$ORIGIN:/opt/sun/private/lib'
  174. endif
  175. endif
  176. MKSHLIB = $(CC) $(DSO_LDOPTS) -Wl,-soname -Wl,$(@:$(OBJDIR)/%.so=%.so) $(RPATH)
  177. ifdef MAPFILE
  178. MKSHLIB += -Wl,--version-script,$(MAPFILE)
  179. endif
  180. PROCESS_MAP_FILE = grep -v ';-' $< | \
  181. sed -e 's,;+,,' -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,;,' > $@
  182. ifeq ($(OS_RELEASE),2.4)
  183. DEFINES += -DNO_FORK_CHECK
  184. endif
  185. ifdef USE_GCOV
  186. OS_CFLAGS += --coverage
  187. LDFLAGS += --coverage
  188. DSO_LDOPTS += --coverage
  189. endif