Rules.mak 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. # Rules.make for uClibc
  2. #
  3. # Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
  4. #
  5. # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. #
  7. # make nano-doc
  8. # FOO = bar -- recursively expanded variable. Value is remebered verbatim.
  9. # If it contains references to other variables, these references
  10. # are expanded whenever this variable is _substituted_.
  11. # FOO := bar -- simply expanded variable. Right hand is expanded when
  12. # the variable is _defined_. Therefore faster than =.
  13. # FOO ?= bar -- set a value only if it is not already set
  14. # (behaves as =, not :=).
  15. # FOO += bar -- append; if FOO is not defined, acts like = (not :=).
  16. # check for proper make version
  17. ifneq ($(findstring x3.7,x$(MAKE_VERSION)),)
  18. $(error Your make is too old $(MAKE_VERSION). Go get at least 3.80)
  19. endif
  20. #-----------------------------------------------------------
  21. # This file contains rules which are shared between multiple
  22. # Makefiles. All normal configuration options live in the
  23. # file named ".config". Don't mess with this file unless
  24. # you know what you are doing.
  25. #-----------------------------------------------------------
  26. # If you are running a cross compiler, you will want to set
  27. # 'CROSS_COMPILE' to something more interesting ... Target
  28. # architecture is determined by asking the CC compiler what
  29. # arch it compiles things for, so unless your compiler is
  30. # broken, you should not need to specify TARGET_ARCH.
  31. #
  32. # Most people will set this stuff on the command line, i.e.
  33. # make CROSS_COMPILE=arm-linux-
  34. # will build uClibc for 'arm'.
  35. # CROSS is still supported for backward compatibily only
  36. CROSS_COMPILE ?= $(CROSS)
  37. CC = $(CROSS_COMPILE)gcc
  38. AR = $(CROSS_COMPILE)ar
  39. LD = $(CROSS_COMPILE)ld
  40. NM = $(CROSS_COMPILE)nm
  41. OBJDUMP = $(CROSS_COMPILE)objdump
  42. STRIPTOOL = $(CROSS_COMPILE)strip
  43. INSTALL = install
  44. LN = ln
  45. RM = rm -f
  46. TAR = tar
  47. SED = sed
  48. AWK = awk
  49. STRIP_FLAGS ?= -x -R .note -R .comment
  50. ## unused? if yes, remove after 0.9.31
  51. ## UNIFDEF := $(top_builddir)extra/scripts/unifdef
  52. # Select the compiler needed to build binaries for your development system
  53. HOSTCC = gcc
  54. BUILD_CFLAGS = -Os -Wall
  55. #---------------------------------------------------------
  56. # Nothing beyond this point should ever be touched by mere
  57. # mortals. Unless you hang out with the gods, you should
  58. # probably leave all this stuff alone.
  59. # strip quotes
  60. qstrip = $(strip $(subst ",,$(1)))
  61. #"))
  62. # Pull in the user's uClibc configuration
  63. ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
  64. -include $(top_builddir).config
  65. endif
  66. TARGET_ARCH:=$(call qstrip,$(TARGET_ARCH))
  67. ifeq ($(TARGET_ARCH),)
  68. ARCH ?= $(shell uname -m | $(SED) -e s/i.86/i386/ \
  69. -e s/sun.*/sparc/ -e s/sparc.*/sparc/ \
  70. -e s/arm.*/arm/ -e s/sa110/arm/ \
  71. -e s/sh.*/sh/ \
  72. -e s/s390x/s390/ -e s/parisc.*/hppa/ \
  73. -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
  74. -e s/xtensa.*/xtensa/ )
  75. else
  76. ARCH = $(TARGET_ARCH)
  77. endif
  78. export ARCH
  79. # Make certain these contain a final "/", but no "//"s.
  80. TARGET_SUBARCH:=$(call qstrip,$(TARGET_SUBARCH))
  81. RUNTIME_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(call qstrip,$(RUNTIME_PREFIX)))))
  82. DEVEL_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(call qstrip,$(DEVEL_PREFIX)))))
  83. MULTILIB_DIR:=$(strip $(subst //,/, $(subst ,/, $(call qstrip,$(MULTILIB_DIR)))))
  84. KERNEL_HEADERS:=$(strip $(subst //,/, $(subst ,/, $(call qstrip,$(KERNEL_HEADERS)))))
  85. export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS MULTILIB_DIR
  86. # Now config hard core
  87. MAJOR_VERSION := 0
  88. MINOR_VERSION := 9
  89. SUBLEVEL := 34
  90. EXTRAVERSION :=-git
  91. VERSION := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
  92. ABI_VERSION := $(MAJOR_VERSION)
  93. ifneq ($(EXTRAVERSION),)
  94. VERSION := $(VERSION)$(EXTRAVERSION)
  95. endif
  96. # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
  97. LC_ALL := C
  98. export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION ABI_VERSION LC_ALL
  99. LIBC := libc
  100. SHARED_LIBNAME := $(LIBC).so.$(ABI_VERSION)
  101. UBACKTRACE_DSO := libubacktrace.a #so.$(ABI_VERSION)
  102. ifneq ($(findstring $(TARGET_ARCH) , hppa64 ia64 mips64 powerpc64 s390x sparc64 x86_64 ),)
  103. UCLIBC_LDSO_NAME := ld64-uClibc
  104. ARCH_NATIVE_BIT := 64
  105. else
  106. UCLIBC_LDSO_NAME := ld-uClibc
  107. ARCH_NATIVE_BIT := 32
  108. endif
  109. UCLIBC_LDSO := $(UCLIBC_LDSO_NAME).so.$(ABI_VERSION)
  110. NONSHARED_LIBNAME := uclibc_nonshared.a
  111. libc := $(top_builddir)lib/$(SHARED_LIBNAME)
  112. libc.depend := $(top_builddir)lib/$(SHARED_LIBNAME:.$(ABI_VERSION)=)
  113. ifneq ($(ARCH_HAS_NO_SHARED),y)
  114. libdl.depend := $(top_builddir)lib/libdl.so
  115. endif
  116. ifneq ($(HAS_NO_THREADS),y)
  117. libpthread.depend := $(top_builddir)lib/libpthread.so
  118. endif
  119. ifeq ($(UCLIBC_HAS_BACKTRACE),y)
  120. libubacktrace.depend := $(top_builddir)lib/libubacktrace.a
  121. endif
  122. interp := $(top_builddir)lib/interp.os
  123. ldso := $(top_builddir)lib/$(UCLIBC_LDSO)
  124. headers_dep := $(top_builddir)include/bits/sysnum.h
  125. sub_headers := $(headers_dep)
  126. #LIBS :=$(interp) -L$(top_builddir)lib -lc
  127. LIBS := $(interp) -L$(top_builddir)lib $(libc:.$(ABI_VERSION)=)
  128. # Make sure DESTDIR and PREFIX can be used to install
  129. # PREFIX is a uClibcism while DESTDIR is a common GNUism
  130. ifndef PREFIX
  131. PREFIX = $(DESTDIR)
  132. endif
  133. ifneq ($(HAVE_SHARED),y)
  134. libc :=
  135. interp :=
  136. ldso :=
  137. endif
  138. comma:=,
  139. space:= #
  140. ifeq ($(CROSS_COMPILE),)
  141. CROSS_COMPILE=$(call qstrip,$(CROSS_COMPILER_PREFIX))
  142. endif
  143. # A nifty macro to make testing gcc features easier
  144. check_gcc=$(shell \
  145. if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
  146. then echo "$(1)"; else echo "$(2)"; fi)
  147. check_as=$(shell \
  148. if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
  149. then echo "-Wa,$(1)"; fi)
  150. check_ld=$(shell \
  151. if $(LD) $(1) -o /dev/null -b binary /dev/null > /dev/null 2>&1; \
  152. then echo "$(1)"; fi)
  153. # Use variable indirection here so that we can have variable
  154. # names with fun chars in them like equal signs
  155. define check-tool-var
  156. ifeq ($(filter $(clean_targets) CLEAN_%,$(MAKECMDGOALS)),)
  157. _v = $(2)_$(3)
  158. ifndef $$(_v)
  159. $$(_v) := $$(call $(1),$(subst %, ,$(3)))
  160. export $$(_v)
  161. endif
  162. endif
  163. endef
  164. # Usage: check-gcc-var,<flag>
  165. # Check the C compiler to see if it supports <flag>.
  166. # Export the variable CFLAG_<flag> if it does.
  167. define check-gcc-var
  168. $(call check-tool-var,check_gcc,CFLAG,$(1))
  169. endef
  170. # Usage: check-as-var,<flag>
  171. # Check the assembler to see if it supports <flag>. Export the
  172. # variable ASFLAG_<flag> if it does (for invoking the assembler),
  173. # as well CFLAG_-Wa<flag> (for invoking the compiler driver).
  174. define check-as-var
  175. $(call check-tool-var,check_as,ASFLAG,$(1))
  176. _v = CFLAG_-Wa$(1)
  177. export $$(_v) = $$(if $$(ASFLAG_$(1)),-Wa$$(comma)$$(ASFLAG_$(1)))
  178. endef
  179. # Usage: check-ld-var,<flag>
  180. # Check the linker to see if it supports <flag>. Export the
  181. # variable LDFLAG_<flag> if it does (for invoking the linker),
  182. # as well CFLAG_-Wl<flag> (for invoking the compiler driver).
  183. define check-ld-var
  184. $(call check-tool-var,check_ld,LDFLAG,$(1))
  185. _v = CFLAG_-Wl$(1)
  186. export $$(_v) = $$(if $$(LDFLAG_$(1)),-Wl$$(comma)$$(LDFLAG_$(1)))
  187. endef
  188. # Usage: cache-output-var,<variable>,<shell command>
  189. # Execute <shell command> and cache the output in <variable>.
  190. define cache-output-var
  191. ifndef $(1)
  192. $(1) := $$(shell $(2))
  193. export $(1)
  194. endif
  195. endef
  196. ARFLAGS:=cr
  197. # Flags in OPTIMIZATION are used only for non-debug builds
  198. OPTIMIZATION:=
  199. # Use '-Os' optimization if available, else use -O2, allow Config to override
  200. $(eval $(call check-gcc-var,-Os))
  201. ifneq ($(CFLAG_-Os),)
  202. OPTIMIZATION += $(CFLAG_-Os)
  203. else
  204. $(eval $(call check-gcc-var,-O2))
  205. OPTIMIZATION += $(CFLAG_-O2)
  206. endif
  207. # Use the gcc 3.4 -funit-at-a-time optimization when available
  208. $(eval $(call check-gcc-var,-funit-at-a-time))
  209. OPTIMIZATION += $(CFLAG_-funit-at-a-time)
  210. # shrinks code by about 0.1%
  211. $(eval $(call check-gcc-var,-fmerge-all-constants))
  212. $(eval $(call check-gcc-var,-fstrict-aliasing))
  213. OPTIMIZATION += $(CFLAG_-fmerge-all-constants) $(CFLAG_-fstrict-aliasing)
  214. $(eval $(call cache-output-var,GCC_VER,$(CC) -dumpversion))
  215. GCC_VER := $(subst ., ,$(GCC_VER))
  216. GCC_MAJOR_VER ?= $(word 1,$(GCC_VER))
  217. #GCC_MINOR_VER ?= $(word 2,$(GCC_VER))
  218. ifeq ($(GCC_MAJOR_VER),4)
  219. # shrinks code, results are from 4.0.2
  220. # 0.36%
  221. $(eval $(call check-gcc-var,-fno-tree-loop-optimize))
  222. OPTIMIZATION += $(CFLAG_-fno-tree-loop-optimize)
  223. # 0.34%
  224. $(eval $(call check-gcc-var,-fno-tree-dominator-opts))
  225. OPTIMIZATION += $(CFLAG_-fno-tree-dominator-opts)
  226. # 0.1%
  227. $(eval $(call check-gcc-var,-fno-strength-reduce))
  228. OPTIMIZATION += $(CFLAG_-fno-strength-reduce)
  229. endif
  230. # CPU_CFLAGS-y contain options which are not warnings,
  231. # not include or library paths, and not optimizations.
  232. # Why -funsigned-char: I hunted a bug related to incorrect
  233. # sign extension of 'char' type for 10 hours straight. Not fun.
  234. CPU_CFLAGS-y := -funsigned-char -fno-builtin
  235. $(eval $(call check-gcc-var,-fno-asm))
  236. CPU_CFLAGS-y += $(CFLAG_-fno-asm)
  237. LDADD_LIBFLOAT=
  238. ifeq ($(UCLIBC_HAS_SOFT_FLOAT),y)
  239. # If -msoft-float isn't supported, we want an error anyway.
  240. # Hmm... might need to revisit this for arm since it has 2 different
  241. # soft float encodings.
  242. ifneq ($(TARGET_ARCH),nios)
  243. ifneq ($(TARGET_ARCH),nios2)
  244. ifneq ($(TARGET_ARCH),sh)
  245. ifneq ($(TARGET_ARCH),c6x)
  246. CPU_CFLAGS-y += -msoft-float
  247. endif
  248. endif
  249. endif
  250. endif
  251. ifeq ($(TARGET_ARCH),arm)
  252. # No longer needed with current toolchains, but leave it here for now.
  253. # If anyone is actually still using gcc 2.95 (say), they can uncomment it.
  254. # LDADD_LIBFLOAT=-lfloat
  255. endif
  256. endif
  257. $(eval $(call check-gcc-var,-std=gnu99))
  258. CPU_CFLAGS-y += $(CFLAG_-std=gnu99)
  259. CPU_CFLAGS-$(UCLIBC_FORMAT_SHARED_FLAT) += -mid-shared-library
  260. CPU_CFLAGS-$(UCLIBC_FORMAT_FLAT_SEP_DATA) += -msep-data
  261. CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN) += -Wl,-EL
  262. CPU_LDFLAGS-$(ARCH_BIG_ENDIAN) += -Wl,-EB
  263. PICFLAG-y := -fPIC
  264. PICFLAG-$(UCLIBC_FORMAT_FDPIC_ELF) := -mfdpic
  265. PICFLAG-$(UCLIBC_FORMAT_DSBT_ELF) := -mdsbt -fpic
  266. PICFLAG := $(PICFLAG-y)
  267. PIEFLAG_NAME:=-fPIE
  268. # Some nice CPU specific optimizations
  269. ifeq ($(TARGET_ARCH),i386)
  270. $(eval $(call check-gcc-var,-fomit-frame-pointer))
  271. OPTIMIZATION += $(CFLAG_-fomit-frame-pointer)
  272. ifeq ($(CONFIG_386)$(CONFIG_486)$(CONFIG_586)$(CONFIG_586MMX),y)
  273. # Non-SSE capable processor.
  274. # NB: this may make SSE insns segfault!
  275. # -O1 -march=pentium3, -Os -msse etc are known to be affected.
  276. # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13685
  277. # -m32 is needed if host is 64-bit
  278. OPTIMIZATION+=$(call check_gcc,-m32 -mpreferred-stack-boundary=2,)
  279. else
  280. $(eval $(call check-gcc-var,-mpreferred-stack-boundary=4))
  281. OPTIMIZATION += $(CFLAG_-mpreferred-stack-boundary=4)
  282. endif
  283. # Choice of alignment (please document why!)
  284. # -falign-labels: in-line labels
  285. # (reachable by normal code flow, aligning will insert nops
  286. # which will be executed - may even make things slower)
  287. # -falign-jumps: reachable only by a jump
  288. # Generic: no alignment at all (smallest code)
  289. GCC_FALIGN=$(call check_gcc,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,-malign-jumps=1 -malign-loops=1)
  290. ifeq ($(CONFIG_K7),y)
  291. # Align functions to four bytes, use default for jumps and loops (why?)
  292. GCC_FALIGN=$(call check_gcc,-falign-functions=4 -falign-labels=1,-malign-functions=4)
  293. endif
  294. ifeq ($(CONFIG_CRUSOE),y)
  295. # Use compiler's default for functions, jumps and loops (why?)
  296. GCC_FALIGN=$(call check_gcc,-falign-functions=0 -falign-labels=1,-malign-functions=0)
  297. endif
  298. ifeq ($(CONFIG_CYRIXIII),y)
  299. # Use compiler's default for functions, jumps and loops (why?)
  300. GCC_FALIGN=$(call check_gcc,-falign-functions=0 -falign-labels=1,-malign-functions=0)
  301. endif
  302. OPTIMIZATION+=$(GCC_FALIGN)
  303. # Putting each function and data object into its own section
  304. # allows for kbytes of less text if users link against static uclibc
  305. # using ld --gc-sections.
  306. # ld 2.18 can't do that (yet?) for shared libraries, so we itself
  307. # do not use --gc-sections at shared lib link time.
  308. # However, in combination with sections being sorted by alignment
  309. # it does result in much reduced padding:
  310. # text data bss dec hex
  311. # 235319 1472 5992 242783 3b45f old.so
  312. # 234104 1472 5980 241556 3af94 new.so
  313. # Without -ffunction-sections, all functions will get aligned
  314. # to 4 byte boundary by as/ld. This is arguably a bug in as.
  315. # It specifies 4 byte align for .text even if not told to do so:
  316. # Idx Name Size VMA LMA File off Algn
  317. # 0 .text xxxxxxxx 00000000 00000000 xxxxxxxx 2**2 <===!
  318. CPU_CFLAGS-y += $(CFLAG_-ffunction-sections) $(CFLAG_-fdata-sections)
  319. CPU_LDFLAGS-y += $(CFLAG_-Wl--sort-common)
  320. $(eval $(call check-ld-var,--sort-section=alignment))
  321. CPU_LDFLAGS-y += $(CFLAG_-Wl--sort-section=alignment)
  322. CPU_LDFLAGS-y+=-m32
  323. CPU_CFLAGS-y+=-m32
  324. CPU_CFLAGS-$(CONFIG_386)+=-march=i386
  325. CPU_CFLAGS-$(CONFIG_486)+=-march=i486
  326. CPU_CFLAGS-$(CONFIG_ELAN)+=-march=i486
  327. CPU_CFLAGS-$(CONFIG_586)+=-march=i586
  328. CPU_CFLAGS-$(CONFIG_586MMX)+=$(call check_gcc,-march=pentium-mmx,-march=i586)
  329. CPU_CFLAGS-$(CONFIG_686)+=-march=i686
  330. CPU_CFLAGS-$(CONFIG_PENTIUMII)+=$(call check_gcc,-march=pentium2,-march=i686)
  331. CPU_CFLAGS-$(CONFIG_PENTIUMIII)+=$(call check_gcc,-march=pentium3,-march=i686)
  332. CPU_CFLAGS-$(CONFIG_PENTIUM4)+=$(call check_gcc,-march=pentium4,-march=i686)
  333. CPU_CFLAGS-$(CONFIG_K6)+=$(call check_gcc,-march=k6,-march=i586)
  334. CPU_CFLAGS-$(CONFIG_K7)+=$(call check_gcc,-march=athlon,-march=i686)
  335. CPU_CFLAGS-$(CONFIG_CRUSOE)+=-march=i686
  336. CPU_CFLAGS-$(CONFIG_WINCHIPC6)+=$(call check_gcc,-march=winchip-c6,-march=i586)
  337. CPU_CFLAGS-$(CONFIG_WINCHIP2)+=$(call check_gcc,-march=winchip2,-march=i586)
  338. CPU_CFLAGS-$(CONFIG_CYRIXIII)+=$(call check_gcc,-march=c3,-march=i486)
  339. CPU_CFLAGS-$(CONFIG_NEHEMIAH)+=$(call check_gcc,-march=c3-2,-march=i686)
  340. endif
  341. ifeq ($(TARGET_ARCH),sparc)
  342. CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
  343. CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
  344. CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
  345. CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
  346. endif
  347. ifeq ($(TARGET_ARCH),arm)
  348. CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
  349. CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
  350. CPU_CFLAGS-$(COMPILE_IN_THUMB_MODE)+=-mthumb
  351. endif
  352. ifeq ($(TARGET_ARCH),mips)
  353. OPTIMIZATION+=-mno-split-addresses
  354. CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1
  355. CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2
  356. CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3
  357. CPU_CFLAGS-$(CONFIG_MIPS_ISA_4)+=-mips4 -mtune=mips4
  358. CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32
  359. CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32R2)+=-march=mips32r2 -mtune=mips32r2
  360. CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32
  361. ifeq ($(strip $(ARCH_BIG_ENDIAN)),y)
  362. CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64btsmip
  363. CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32btsmip
  364. endif
  365. ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y)
  366. CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64ltsmip
  367. CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32ltsmip
  368. endif
  369. CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64
  370. CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32
  371. CPU_CFLAGS-$(CONFIG_MIPS_N32_ABI)+=-mabi=n32
  372. endif
  373. ifeq ($(TARGET_ARCH),nios)
  374. OPTIMIZATION+=-funaligned-struct-hack
  375. CPU_LDFLAGS-y+=-Wl,-m32
  376. CPU_CFLAGS-y+=-Wl,-m32
  377. endif
  378. ifeq ($(TARGET_ARCH),sh)
  379. $(eval $(call check-gcc-var,-mprefergot))
  380. OPTIMIZATION += $(CFLAG_-mprefergot)
  381. CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
  382. CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
  383. CPU_CFLAGS-$(CONFIG_SH2)+=-m2
  384. CPU_CFLAGS-$(CONFIG_SH3)+=-m3
  385. ifeq ($(UCLIBC_HAS_FPU),y)
  386. CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
  387. CPU_CFLAGS-$(CONFIG_SH4)+=-m4
  388. else
  389. CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
  390. CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
  391. endif
  392. endif
  393. ifeq ($(TARGET_ARCH),sh64)
  394. CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
  395. CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
  396. CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
  397. endif
  398. ifeq ($(TARGET_ARCH),h8300)
  399. SYMBOL_PREFIX=_
  400. CPU_LDFLAGS-$(CONFIG_H8300H)+= -Wl,-ms8300h
  401. CPU_LDFLAGS-$(CONFIG_H8S) += -Wl,-ms8300s
  402. CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32
  403. CPU_CFLAGS-$(CONFIG_H8S) += -ms -mint32
  404. endif
  405. ifeq ($(TARGET_ARCH),i960)
  406. OPTIMIZATION+=-mh -mint32 #-fsigned-char
  407. endif
  408. ifeq ($(TARGET_ARCH),e1)
  409. OPTIMIZATION+=-mgnu-param
  410. endif
  411. ifeq ($(TARGET_ARCH),cris)
  412. CPU_LDFLAGS-$(CONFIG_CRIS)+=-Wl,-mcrislinux
  413. CPU_LDFLAGS-$(CONFIG_CRISV32)+=-Wl,-mcrislinux
  414. CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
  415. PICFLAG:=-fpic
  416. PIEFLAG_NAME:=-fpie
  417. endif
  418. ifeq ($(TARGET_ARCH),m68k)
  419. # -fPIC is only supported for 68020 and above. It is not supported
  420. # for 68000, 68010, or Coldfire.
  421. PICFLAG:=-fpic
  422. PIEFLAG_NAME:=-fpie
  423. endif
  424. ifeq ($(TARGET_ARCH),powerpc)
  425. # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
  426. # enough. Therefore use -fpic which will reduce code size and generates
  427. # faster code.
  428. PICFLAG:=-fpic
  429. PIEFLAG_NAME:=-fpie
  430. PPC_HAS_REL16:=$(shell echo -e "\t.text\n\taddis 11,30,_GLOBAL_OFFSET_TABLE_-.@ha" | $(CC) -c -x assembler -o /dev/null - 2> /dev/null && echo -n y || echo -n n)
  431. CPU_CFLAGS-$(PPC_HAS_REL16)+= -DHAVE_ASM_PPC_REL16
  432. CPU_CFLAGS-$(CONFIG_E500) += "-D__NO_MATH_INLINES"
  433. endif
  434. ifeq ($(TARGET_ARCH),bfin)
  435. SYMBOL_PREFIX=_
  436. ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
  437. CPU_CFLAGS-y:=-mfdpic
  438. CPU_LDFLAGS-y += -Wl,-melf32bfinfd
  439. PICFLAG:=-fpic
  440. PIEFLAG_NAME:=-fpie
  441. endif
  442. ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
  443. PICFLAG := -mleaf-id-shared-library
  444. endif
  445. endif
  446. ifeq ($(TARGET_ARCH),frv)
  447. CPU_LDFLAGS-$(CONFIG_FRV)+=-Wl,-melf32frvfd
  448. # Using -pie causes the program to have an interpreter, which is
  449. # forbidden, so we must make do with -shared. Unfortunately,
  450. # -shared by itself would get us global function descriptors
  451. # and calls through PLTs, dynamic resolution of symbols, etc,
  452. # which would break as well, but -Bsymbolic comes to the rescue.
  453. export LDPIEFLAG:=-shared -Wl,-Bsymbolic
  454. UCLIBC_LDSO=ld.so.1
  455. endif
  456. ifeq ($(strip $(TARGET_ARCH)),avr32)
  457. CPU_CFLAGS-$(CONFIG_AVR32_AP7) += -march=ap
  458. CPU_CFLAGS-$(CONFIG_LINKRELAX) += -mrelax
  459. CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
  460. endif
  461. ifeq ($(TARGET_ARCH),i960)
  462. SYMBOL_PREFIX=_
  463. endif
  464. ifeq ($(TARGET_ARCH),v850)
  465. SYMBOL_PREFIX=_
  466. endif
  467. ifeq ($(TARGET_ARCH),c6x)
  468. PIEFLAG:=
  469. CPU_CFLAGS-$(CONFIG_TMS320C64X) += -march=c64x
  470. CPU_CFLAGS-$(CONFIG_TMS320C64XPLUS) += -march=c64x+
  471. CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
  472. CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
  473. CPU_LDFLAGS-y += $(CPU_CFLAGS)
  474. endif
  475. $(eval $(call check-gcc-var,$(PIEFLAG_NAME)))
  476. PIEFLAG := $(CFLAG_$(PIEFLAG_NAME))
  477. ifeq ($(PIEFLAG),)
  478. PIEFLAG := $(PICFLAG)
  479. endif
  480. # We need to keep track of both the CC PIE flag (above) as
  481. # well as the LD PIE flag (below) because we can't rely on
  482. # gcc passing -pie if we used -fPIE. We need to directly use -pie
  483. # instead of -Wl,-pie as gcc picks up the wrong startfile/endfile
  484. $(eval $(call cache-output-var,LDPIEFLAG,$(LD) --help 2>/dev/null | grep -q -- -pie && echo "-pie"))
  485. # Check for --as-needed support in linker
  486. ifndef LD_FLAG_ASNEEDED
  487. _LD_FLAG_ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -- --as-needed)
  488. ifneq ($(_LD_FLAG_ASNEEDED),)
  489. export LD_FLAG_ASNEEDED:=--as-needed
  490. endif
  491. endif
  492. ifndef LD_FLAG_NO_ASNEEDED
  493. ifdef LD_FLAG_ASNEEDED
  494. export LD_FLAG_NO_ASNEEDED:=--no-as-needed
  495. endif
  496. endif
  497. ifndef CC_FLAG_ASNEEDED
  498. ifdef LD_FLAG_ASNEEDED
  499. export CC_FLAG_ASNEEDED:=-Wl,$(LD_FLAG_ASNEEDED)
  500. endif
  501. endif
  502. ifndef CC_FLAG_NO_ASNEEDED
  503. ifdef LD_FLAG_NO_ASNEEDED
  504. export CC_FLAG_NO_ASNEEDED:=-Wl,$(LD_FLAG_NO_ASNEEDED)
  505. endif
  506. endif
  507. link.asneeded = $(if $(findstring yy,$(CC_FLAG_ASNEEDED)$(CC_FLAG_NO_ASNEEDED)),$(CC_FLAG_ASNEEDED) $(1) $(CC_FLAG_NO_ASNEEDED))
  508. # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
  509. ifndef ASNEEDED
  510. export ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UCLIBC_LDSO) )" || echo "$(UCLIBC_LDSO)")
  511. # Only used in installed libc.so linker script
  512. ifeq ($(UCLIBC_HAS_BACKTRACE),y)
  513. export UBACKTRACE_ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- --as-needed && \
  514. echo "GROUP ( AS_NEEDED ( $(UBACKTRACE_DSO) ) )" || \
  515. echo "GROUP ( $(UBACKTRACE_DSO) )")
  516. else
  517. export UBACKTRACE_ASNEEDED:=""
  518. endif
  519. endif
  520. # Add a bunch of extra pedantic annoyingly strict checks
  521. WARNING_FLAGS = -Wstrict-prototypes -Wstrict-aliasing
  522. ifeq ($(EXTRA_WARNINGS),y)
  523. WARNING_FLAGS += \
  524. -Wformat=2 \
  525. -Wmissing-noreturn \
  526. -Wmissing-format-attribute \
  527. -Wmissing-prototypes \
  528. -Wmissing-declarations \
  529. -Wnested-externs \
  530. -Wnonnull \
  531. -Wold-style-declaration \
  532. -Wold-style-definition \
  533. -Wshadow \
  534. -Wundef
  535. # Works only w/ gcc-3.4 and up, can't be checked for gcc-3.x w/ check_gcc()
  536. WARNING_FLAGS-gcc-4 += -Wdeclaration-after-statement
  537. endif
  538. WARNING_FLAGS += $(WARNING_FLAGS-gcc-$(GCC_MAJOR_VER))
  539. $(foreach w,$(WARNING_FLAGS),$(eval $(call check-gcc-var,$(w))))
  540. XWARNINGS = $(call qstrip,$(WARNINGS)) $(foreach w,$(WARNING_FLAGS),$(CFLAG_$(w)))
  541. CPU_CFLAGS=$(call qstrip,$(CPU_CFLAGS-y))
  542. # Save the tested flag in a single variable and force it to be
  543. # evaluated just once. Then use that computed value.
  544. $(eval $(call check-gcc-var,-fno-stack-protector))
  545. SSP_DISABLE_FLAGS ?= $(CFLAG_-fno-stack-protector)
  546. ifeq ($(UCLIBC_BUILD_SSP),y)
  547. $(eval $(call check-gcc-var,-fno-stack-protector-all))
  548. $(eval $(call check-gcc-var,-fstack-protector))
  549. $(eval $(call check-gcc-var,-fstack-protector-all))
  550. SSP_CFLAGS := $(CFLAG_-fno-stack-protector-all)
  551. SSP_CFLAGS += $(CFLAG_-fstack-protector)
  552. SSP_ALL_CFLAGS ?= $(CFLAG_-fstack-protector-all)
  553. else
  554. SSP_CFLAGS := $(SSP_DISABLE_FLAGS)
  555. endif
  556. $(eval $(call check-gcc-var,-nostdlib))
  557. # Collect all CFLAGS components
  558. CFLAGS := $(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
  559. -nostdinc -I$(top_builddir)include \
  560. -I$(top_srcdir)include -include libc-symbols.h \
  561. -I$(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH) \
  562. -I$(top_srcdir)libc/sysdeps/linux \
  563. -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) \
  564. -I$(top_srcdir)ldso/include -I.
  565. ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
  566. CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
  567. endif
  568. # We need this to be checked within libc-symbols.h
  569. ifneq ($(HAVE_SHARED),y)
  570. CFLAGS += -DSTATIC
  571. endif
  572. $(eval $(call check-ld-var,--warn-once))
  573. $(eval $(call check-ld-var,--sort-common))
  574. $(eval $(call check-ld-var,--discard-all))
  575. LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared \
  576. -Wl,--warn-common $(CFLAG_-Wl--warn-once) -Wl,-z,combreloc
  577. # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok
  578. #$(eval $(call check-ld-var,--gc-sections))
  579. #LDFLAGS_NOSTRIP += $(LDFLAG_--gc-sections)
  580. $(eval $(call check-gcc-var,-fdata-sections))
  581. $(eval $(call check-gcc-var,-ffunction-sections))
  582. ifeq ($(UCLIBC_BUILD_RELRO),y)
  583. LDFLAGS_NOSTRIP+=-Wl,-z,relro
  584. endif
  585. ifeq ($(UCLIBC_BUILD_NOW),y)
  586. LDFLAGS_NOSTRIP+=-Wl,-z,now
  587. endif
  588. ifeq ($(LDSO_GNU_HASH_SUPPORT),y)
  589. # Be sure that binutils support it
  590. $(eval $(call check-ld-var,--hash-style=gnu))
  591. ifeq ($(LDFLAG_--hash-style=gnu),)
  592. ifneq ($(filter-out $(clean_targets) CLEAN_% install_headers headers-y,$(MAKECMDGOALS)),)
  593. $(error Your binutils do not support --hash-style option, while you want to use it)
  594. endif
  595. else
  596. LDFLAGS_NOSTRIP += $(CFLAG_-Wl--hash-style=gnu)
  597. endif
  598. endif
  599. LDFLAGS:=$(LDFLAGS_NOSTRIP) -Wl,-z,defs
  600. ifeq ($(DODEBUG),y)
  601. CFLAGS += -O0 -g3 -DDEBUG
  602. else
  603. CFLAGS += $(OPTIMIZATION)
  604. endif
  605. ifeq ($(DOSTRIP),y)
  606. LDFLAGS += -Wl,-s
  607. else
  608. STRIPTOOL := true -Stripping_disabled
  609. endif
  610. ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
  611. CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
  612. endif
  613. ifeq ($(DOMULTI),y)
  614. # we try to compile all sources at once into an object (IMA), but
  615. # gcc-3.3.x does not support it
  616. # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
  617. # gcc-4.0.x supports it, supports the --combine flag, but does not need it
  618. # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
  619. ifeq ($(GCC_MAJOR_VER),3)
  620. DOMULTI:=n
  621. else
  622. $(eval $(call check-gcc-var,--combine))
  623. CFLAGS += $(CFLAG_--combine)
  624. endif
  625. else
  626. DOMULTI:=n
  627. endif
  628. ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
  629. LDFLAGS += $(call qstrip,$(UCLIBC_EXTRA_LDFLAGS))
  630. endif
  631. ifeq ($(UCLIBC_HAS_THREADS),y)
  632. ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
  633. PTNAME := nptl
  634. CFLAGS += -DHAVE_FORCED_UNWIND
  635. else
  636. ifeq ($(LINUXTHREADS_OLD),y)
  637. PTNAME := linuxthreads.old
  638. else
  639. PTNAME := linuxthreads
  640. endif
  641. endif
  642. PTDIR := libpthread/$(PTNAME)
  643. # set up system dependencies include dirs (NOTE: order matters!)
  644. ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
  645. PTINC:= -I$(top_builddir)$(PTDIR) \
  646. -I$(top_srcdir)$(PTDIR) \
  647. $(if $(TARGET_ARCH),-I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/$(TARGET_SUBARCH)) \
  648. -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
  649. -I$(top_builddir)$(PTDIR)/sysdeps/$(TARGET_ARCH) \
  650. -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH) \
  651. -I$(top_builddir)$(PTDIR)/sysdeps/unix/sysv/linux \
  652. -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux \
  653. -I$(top_srcdir)$(PTDIR)/sysdeps/pthread \
  654. -I$(top_srcdir)$(PTDIR)/sysdeps/pthread/bits \
  655. -I$(top_srcdir)$(PTDIR)/sysdeps/generic
  656. #
  657. # Test for TLS if NPTL support was selected.
  658. #
  659. GCC_HAS_TLS=$(shell \
  660. echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
  661. ifneq ($(GCC_HAS_TLS),)
  662. gcc_tls_test_fail:
  663. @echo "####";
  664. @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
  665. @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
  666. @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
  667. @echo "#### about this problem.";
  668. @echo "####";
  669. @echo "#### Exiting...";
  670. @echo "####";
  671. @exit 1;
  672. endif
  673. else
  674. PTINC := \
  675. -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
  676. -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH) \
  677. -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux \
  678. -I$(top_srcdir)$(PTDIR)/sysdeps/pthread \
  679. -I$(top_srcdir)$(PTDIR) \
  680. -I$(top_srcdir)libpthread
  681. endif
  682. CFLAGS+=$(PTINC)
  683. else
  684. PTNAME :=
  685. PTINC :=
  686. endif
  687. CFLAGS += -I$(top_srcdir)libc/sysdeps/linux/common
  688. #CFLAGS += -iwithprefix include-fixed -iwithprefix include
  689. $(eval $(call cache-output-var,CC_IPREFIX,$(CC) -print-file-name=include))
  690. CC_INC := -isystem $(dir $(CC_IPREFIX))include-fixed -isystem $(CC_IPREFIX)
  691. CFLAGS += $(CC_INC)
  692. CFLAGS += -I$(KERNEL_HEADERS)
  693. ifneq ($(DOASSERTS),y)
  694. CFLAGS+=-DNDEBUG
  695. endif
  696. ifeq ($(SYMBOL_PREFIX),_)
  697. CFLAGS+=-D__UCLIBC_UNDERSCORES__
  698. endif
  699. # Keep the check_as from being needlessly executed
  700. ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
  701. $(eval $(call check-as-var,--noexecstack))
  702. endif
  703. ASFLAGS = $(ASFLAG_--noexecstack)
  704. LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
  705. $(eval $(call cache-output-var,LIBGCC,$(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name))
  706. LIBGCC_DIR:=$(dir $(LIBGCC))
  707. # moved from libpthread/linuxthreads
  708. ifeq ($(UCLIBC_CTOR_DTOR),y)
  709. SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
  710. SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
  711. endif
  712. LOCAL_INSTALL_PATH := install_dir