Rules.mak 22 KB

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