Rules.mak 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # Rules.mak 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. clean_targets := clean realclean distclean \
  26. objclean-y headers_clean-y CLEAN_utils
  27. noconfig_targets := menuconfig config nconfig \
  28. oldaskconfig silentoldconfig oldconfig allnoconfig allyesconfig \
  29. alldefconfig randconfig defconfig savedefconfig listnewconfig \
  30. olddefconfig \
  31. xconfig gconfig update-po-config mconf qconf gconf nconf conf \
  32. release dist tags help
  33. #-----------------------------------------------------------
  34. # If you are running a cross compiler, you will want to set
  35. # 'CROSS_COMPILE' to something more interesting ... Target
  36. # architecture is determined by asking the CC compiler what
  37. # arch it compiles things for, so unless your compiler is
  38. # broken, you should not need to specify TARGET_ARCH.
  39. #
  40. # Most people will set this stuff on the command line, i.e.
  41. # make CROSS_COMPILE=arm-linux-
  42. # will build uClibc for 'arm'.
  43. # CROSS is still supported for backward compatibily only
  44. CROSS_COMPILE ?= $(CROSS)
  45. CC = $(CROSS_COMPILE)gcc
  46. AR = $(CROSS_COMPILE)ar
  47. LD = $(CROSS_COMPILE)ld
  48. NM = $(CROSS_COMPILE)nm
  49. OBJDUMP = $(CROSS_COMPILE)objdump
  50. STRIPTOOL = $(CROSS_COMPILE)strip
  51. INSTALL = install
  52. LN = ln
  53. RM = rm -f
  54. TAR = tar
  55. SED = sed
  56. AWK = awk
  57. DESTDIR ?=
  58. STRIP_FLAGS ?= -x -R .note -R .comment
  59. # Select the compiler needed to build binaries for your development system
  60. HOSTCC = gcc
  61. BUILD_CFLAGS = -Os
  62. #---------------------------------------------------------
  63. # Nothing beyond this point should ever be touched by mere
  64. # mortals. Unless you hang out with the gods, you should
  65. # probably leave all this stuff alone.
  66. # strip quotes
  67. qstrip = $(strip $(subst ",,$(1)))
  68. #"))
  69. TARGET_ARCH:=$(call qstrip,$(TARGET_ARCH))
  70. ifeq ($(TARGET_ARCH),)
  71. ARCH ?= $(shell uname -m | $(SED) -e s/i.86/i386/ \
  72. -e s/sun.*/sparc/ -e s/sparc.*/sparc/ \
  73. -e s/arm.*/arm/ -e s/sa110/arm/ \
  74. -e s/nds32.*/nds32/ \
  75. -e s/sh.*/sh/ \
  76. -e s/s390x/s390/ -e s/parisc.*/hppa/ \
  77. -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
  78. -e s/xtensa.*/xtensa/ )
  79. else
  80. ARCH = $(TARGET_ARCH)
  81. endif
  82. export ARCH
  83. # Make certain these contain a final "/", but no "//"s.
  84. scrub_path = $(strip $(subst //,/, $(subst ,/, $(call qstrip,$(1)))))
  85. TARGET_SUBARCH := $(call qstrip,$(TARGET_SUBARCH))
  86. RUNTIME_PREFIX := $(call scrub_path,$(RUNTIME_PREFIX))
  87. DEVEL_PREFIX := $(call scrub_path,$(DEVEL_PREFIX))
  88. MULTILIB_DIR := $(call scrub_path,$(MULTILIB_DIR))
  89. KERNEL_HEADERS := $(call scrub_path,$(KERNEL_HEADERS))
  90. export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS MULTILIB_DIR
  91. # Make sure DESTDIR and PREFIX can be used to install
  92. # PREFIX is a uClibcism while DESTDIR is a common GNUism
  93. ifndef PREFIX
  94. PREFIX = $(DESTDIR)
  95. endif
  96. comma:=,
  97. space:= #
  98. ifeq ($(CROSS_COMPILE),)
  99. CROSS_COMPILE=$(call qstrip,$(CROSS_COMPILER_PREFIX))
  100. endif
  101. # A nifty macro to make testing gcc features easier
  102. check_gcc=$(shell \
  103. if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
  104. then echo "$(1)"; else echo "$(2)"; fi)
  105. check_as=$(shell \
  106. if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
  107. then echo "-Wa,$(1)"; fi)
  108. check_ld=$(shell \
  109. if $(CC) $(LDFLAG-fuse-ld) $(CFLAG_-Wl--no-warn-mismatch) -Wl,$(1) $(CFLAG_-nostdlib) -o /dev/null -Wl,-b,binary /dev/null > /dev/null 2>&1; \
  110. then echo "$(1)"; fi)
  111. # Use variable indirection here so that we can have variable
  112. # names with fun chars in them like equal signs
  113. define check-tool-var
  114. ifeq ($(filter $(clean_targets) CLEAN_%,$(MAKECMDGOALS)),)
  115. _v = $(2)_$(3)
  116. ifndef $$(_v)
  117. $$(_v) := $$(call $(1),$(subst %, ,$(3)))
  118. export $$(_v)
  119. endif
  120. endif
  121. endef
  122. # Usage: check-gcc-var,<flag>
  123. # Check the C compiler to see if it supports <flag>.
  124. # Export the variable CFLAG_<flag> if it does.
  125. define check-gcc-var
  126. $(call check-tool-var,check_gcc,CFLAG,$(1))
  127. endef
  128. # Usage: check-as-var,<flag>
  129. # Check the assembler to see if it supports <flag>. Export the
  130. # variable ASFLAG_<flag> if it does (for invoking the assembler),
  131. # as well CFLAG_-Wa<flag> (for invoking the compiler driver).
  132. define check-as-var
  133. $(call check-tool-var,check_as,ASFLAG,$(1))
  134. _v = CFLAG_-Wa$(1)
  135. export $$(_v) = $$(if $$(ASFLAG_$(1)),-Wa$$(comma)$$(ASFLAG_$(1)))
  136. endef
  137. # Usage: check-ld-var,<flag>
  138. # Check the linker to see if it supports <flag>. Export the
  139. # variable LDFLAG_<flag> if it does (for invoking the linker),
  140. # as well CFLAG_-Wl<flag> (for invoking the compiler driver).
  141. define check-ld-var
  142. $(call check-tool-var,check_ld,LDFLAG,$(1))
  143. _v = CFLAG_-Wl$(1)
  144. export $$(_v) = $$(if $$(LDFLAG_$(1)),-Wl$$(comma)$$(LDFLAG_$(1)))
  145. endef
  146. # Usage: cache-output-var,<variable>,<shell command>
  147. # Execute <shell command> and cache the output in <variable>.
  148. define cache-output-var
  149. ifndef $(1)
  150. $(1) := $$(shell $(2))
  151. export $(1)
  152. endif
  153. endef
  154. ARFLAGS:=cr
  155. ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
  156. CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
  157. endif
  158. ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
  159. LDFLAGS += $(call qstrip,$(UCLIBC_EXTRA_LDFLAGS))
  160. endif