Rules.mak 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. STRIP_FLAGS ?= -x -R .note -R .comment
  58. # Select the compiler needed to build binaries for your development system
  59. HOSTCC = gcc
  60. BUILD_CFLAGS = -Os
  61. #---------------------------------------------------------
  62. # Nothing beyond this point should ever be touched by mere
  63. # mortals. Unless you hang out with the gods, you should
  64. # probably leave all this stuff alone.
  65. # strip quotes
  66. qstrip = $(strip $(subst ",,$(1)))
  67. #"))
  68. TARGET_ARCH:=$(call qstrip,$(TARGET_ARCH))
  69. ifeq ($(TARGET_ARCH),)
  70. ARCH ?= $(shell uname -m | $(SED) -e s/i.86/i386/ \
  71. -e s/sun.*/sparc/ -e s/sparc.*/sparc/ \
  72. -e s/arm.*/arm/ -e s/sa110/arm/ \
  73. -e s/nds32.*/nds32/ \
  74. -e s/sh.*/sh/ \
  75. -e s/s390x/s390/ -e s/parisc.*/hppa/ \
  76. -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
  77. -e s/xtensa.*/xtensa/ )
  78. else
  79. ARCH = $(TARGET_ARCH)
  80. endif
  81. export ARCH
  82. # Make certain these contain a final "/", but no "//"s.
  83. scrub_path = $(strip $(subst //,/, $(subst ,/, $(call qstrip,$(1)))))
  84. TARGET_SUBARCH := $(call qstrip,$(TARGET_SUBARCH))
  85. RUNTIME_PREFIX := $(call scrub_path,$(RUNTIME_PREFIX))
  86. DEVEL_PREFIX := $(call scrub_path,$(DEVEL_PREFIX))
  87. MULTILIB_DIR := $(call scrub_path,$(MULTILIB_DIR))
  88. KERNEL_HEADERS := $(call scrub_path,$(KERNEL_HEADERS))
  89. export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS MULTILIB_DIR
  90. # Make sure DESTDIR and PREFIX can be used to install
  91. # PREFIX is a uClibcism while DESTDIR is a common GNUism
  92. ifndef PREFIX
  93. PREFIX = $(DESTDIR)
  94. endif
  95. comma:=,
  96. space:= #
  97. ifeq ($(CROSS_COMPILE),)
  98. CROSS_COMPILE=$(call qstrip,$(CROSS_COMPILER_PREFIX))
  99. endif
  100. # A nifty macro to make testing gcc features easier
  101. check_gcc=$(shell \
  102. if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
  103. then echo "$(1)"; else echo "$(2)"; fi)
  104. check_as=$(shell \
  105. if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
  106. then echo "-Wa,$(1)"; fi)
  107. check_ld=$(shell \
  108. 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; \
  109. then echo "$(1)"; fi)
  110. # Use variable indirection here so that we can have variable
  111. # names with fun chars in them like equal signs
  112. define check-tool-var
  113. ifeq ($(filter $(clean_targets) CLEAN_%,$(MAKECMDGOALS)),)
  114. _v = $(2)_$(3)
  115. ifndef $$(_v)
  116. $$(_v) := $$(call $(1),$(subst %, ,$(3)))
  117. export $$(_v)
  118. endif
  119. endif
  120. endef
  121. # Usage: check-gcc-var,<flag>
  122. # Check the C compiler to see if it supports <flag>.
  123. # Export the variable CFLAG_<flag> if it does.
  124. define check-gcc-var
  125. $(call check-tool-var,check_gcc,CFLAG,$(1))
  126. endef
  127. # Usage: check-as-var,<flag>
  128. # Check the assembler to see if it supports <flag>. Export the
  129. # variable ASFLAG_<flag> if it does (for invoking the assembler),
  130. # as well CFLAG_-Wa<flag> (for invoking the compiler driver).
  131. define check-as-var
  132. $(call check-tool-var,check_as,ASFLAG,$(1))
  133. _v = CFLAG_-Wa$(1)
  134. export $$(_v) = $$(if $$(ASFLAG_$(1)),-Wa$$(comma)$$(ASFLAG_$(1)))
  135. endef
  136. # Usage: check-ld-var,<flag>
  137. # Check the linker to see if it supports <flag>. Export the
  138. # variable LDFLAG_<flag> if it does (for invoking the linker),
  139. # as well CFLAG_-Wl<flag> (for invoking the compiler driver).
  140. define check-ld-var
  141. $(call check-tool-var,check_ld,LDFLAG,$(1))
  142. _v = CFLAG_-Wl$(1)
  143. export $$(_v) = $$(if $$(LDFLAG_$(1)),-Wl$$(comma)$$(LDFLAG_$(1)))
  144. endef
  145. # Usage: cache-output-var,<variable>,<shell command>
  146. # Execute <shell command> and cache the output in <variable>.
  147. define cache-output-var
  148. ifndef $(1)
  149. $(1) := $$(shell $(2))
  150. export $(1)
  151. endif
  152. endef
  153. ARFLAGS:=cr
  154. ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
  155. CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
  156. endif
  157. ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
  158. LDFLAGS += $(call qstrip,$(UCLIBC_EXTRA_LDFLAGS))
  159. endif