Rules.mak 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. # Rules.make for busybox
  2. #
  3. # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
  4. #
  5. # Licensed under GPLv2, see the file LICENSE in this tarball for details.
  6. #
  7. # Pull in the user's busybox configuration
  8. ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
  9. -include $(top_builddir)/.config
  10. endif
  11. #--------------------------------------------------------
  12. PROG := busybox
  13. MAJOR_VERSION :=1
  14. MINOR_VERSION :=1
  15. SUBLEVEL_VERSION:=4
  16. EXTRAVERSION :=-pre0
  17. VERSION :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
  18. BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
  19. #--------------------------------------------------------
  20. # With a modern GNU make(1) (highly recommended, that's what all the
  21. # developers use), all of the following configuration values can be
  22. # overridden at the command line. For example:
  23. # make CROSS=powerpc-linux- top_srcdir="$HOME/busybox" PREFIX=/mnt/app
  24. #--------------------------------------------------------
  25. # If you are running a cross compiler, you will want to set 'CROSS'
  26. # to something more interesting... Target architecture is determined
  27. # by asking the CC compiler what arch it compiles things for, so unless
  28. # your compiler is broken, you should not need to specify TARGET_ARCH
  29. CROSS =$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
  30. CC = $(CROSS)gcc
  31. AR = $(CROSS)ar
  32. AS = $(CROSS)as
  33. LD = $(CROSS)ld
  34. NM = $(CROSS)nm
  35. STRIP = $(CROSS)strip
  36. CPP = $(CC) -E
  37. SED ?= sed
  38. # What OS are you compiling busybox for? This allows you to include
  39. # OS specific things, syscall overrides, etc.
  40. TARGET_OS=linux
  41. # Select the compiler needed to build binaries for your development system
  42. HOSTCC = gcc
  43. HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
  44. # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
  45. LC_ALL:= C
  46. # If you want to add some simple compiler switches (like -march=i686),
  47. # especially from the command line, use this instead of CFLAGS directly.
  48. # For optimization overrides, it's better still to set OPTIMIZATION.
  49. CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
  50. # To compile vs some other alternative libc, you may need to use/adjust
  51. # the following lines to meet your needs...
  52. #
  53. # If you are using Red Hat 6.x with the compatible RPMs (for developing under
  54. # Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
  55. # using the compatible RPMs (compat-*) at http://www.redhat.com !
  56. #LIBCDIR:=/usr/i386-glibc20-linux
  57. #
  58. # For other libraries, you are on your own. But these may (or may not) help...
  59. #LDFLAGS+=-nostdlib
  60. #LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
  61. #CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR) -funsigned-char
  62. #GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
  63. WARNINGS=-Wall -Wstrict-prototypes -Wshadow
  64. CFLAGS+=-I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
  65. ARFLAGS=cru
  66. # gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest
  67. # get the CC MAJOR/MINOR version
  68. CC_MAJOR:=$(shell printf "%02d" $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1))
  69. CC_MINOR:=$(shell printf "%02d" $(shell echo __GNUC_MINOR__ | $(CC) -E -xc - | tail -n 1))
  70. #--------------------------------------------------------
  71. export VERSION BUILDTIME HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
  72. ifeq ($(strip $(TARGET_ARCH)),)
  73. TARGET_ARCH:=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
  74. -e 's/i.86/i386/' \
  75. -e 's/sparc.*/sparc/' \
  76. -e 's/arm.*/arm/g' \
  77. -e 's/m68k.*/m68k/' \
  78. -e 's/ppc/powerpc/g' \
  79. -e 's/v850.*/v850/g' \
  80. -e 's/sh[234]/sh/' \
  81. -e 's/mips-.*/mips/' \
  82. -e 's/mipsel-.*/mipsel/' \
  83. -e 's/cris.*/cris/' \
  84. )
  85. endif
  86. # A nifty macro to make testing gcc features easier
  87. check_gcc=$(shell \
  88. if [ "$(1)" != "" ]; then \
  89. if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
  90. then echo "$(1)"; else echo "$(2)"; fi \
  91. fi)
  92. # A not very robust macro to check for available ld flags
  93. check_ld=$(shell \
  94. if [ "x$(1)" != "x" ]; then \
  95. $(LD) --help | grep -q "\$(1)" && echo "-Wl,$(1)" ; \
  96. fi)
  97. CFLAGS+=$(call check_gcc,-funsigned-char,)
  98. CFLAGS+=$(call check_gcc,-mmax-stack-frame=256,)
  99. #--------------------------------------------------------
  100. # Arch specific compiler optimization stuff should go here.
  101. # Unless you want to override the defaults, do not set anything
  102. # for OPTIMIZATION...
  103. # use '-Os' optimization if available, else use -O2
  104. OPTIMIZATION:=$(call check_gcc,-Os,-O2)
  105. ifeq ($(CONFIG_BUILD_AT_ONCE),y)
  106. # gcc 2.95 exits with 0 for "unrecognized option"
  107. ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 3 ] ; echo $$?)),0)
  108. CFLAGS_COMBINE:=$(call check_gcc,--combine,)
  109. endif
  110. OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
  111. # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795
  112. #PROG_CFLAGS+=$(call check_gcc,-fwhole-program,)
  113. endif # CONFIG_BUILD_AT_ONCE
  114. LIB_LDFLAGS:=$(call check_ld,--enable-new-dtags,)
  115. #LIB_LDFLAGS+=$(call check_ld,--reduce-memory-overheads,)
  116. #LIB_LDFLAGS+=$(call check_ld,--as-needed,)
  117. #LIB_LDFLAGS+=$(call check_ld,--warn-shared-textrel,)
  118. # Some nice architecture specific optimizations
  119. ifeq ($(strip $(TARGET_ARCH)),arm)
  120. OPTIMIZATION+=-fstrict-aliasing
  121. endif
  122. ifeq ($(strip $(TARGET_ARCH)),i386)
  123. OPTIMIZATION+=$(call check_gcc,-march=i386,)
  124. # gcc-4.0 and older seem to benefit from these
  125. #ifneq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
  126. OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
  127. OPTIMIZATION+=$(call check_gcc,-falign-functions=1 -falign-jumps=1 -falign-loops=1,\
  128. -malign-functions=0 -malign-jumps=0 -malign-loops=0)
  129. #endif # gcc-4.0 and older
  130. # gcc-4.1 and beyond seem to benefit from these
  131. ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
  132. # turn off flags which hurt -Os
  133. OPTIMIZATION+=$(call check_gcc,-fno-tree-loop-optimize,)
  134. OPTIMIZATION+=$(call check_gcc,-fno-tree-dominator-opts,)
  135. OPTIMIZATION+=$(call check_gcc,-fno-strength-reduce,)
  136. OPTIMIZATION+=$(call check_gcc,-fno-branch-count-reg,)
  137. endif # gcc-4.1 and beyond
  138. endif
  139. OPTIMIZATIONS:=$(OPTIMIZATION) $(call check_gcc,-fomit-frame-pointer,)
  140. #
  141. #--------------------------------------------------------
  142. # If you're going to do a lot of builds with a non-vanilla configuration,
  143. # it makes sense to adjust parameters above, so you can type "make"
  144. # by itself, instead of following it by the same half-dozen overrides
  145. # every time. The stuff below, on the other hand, is probably less
  146. # prone to casual user adjustment.
  147. #
  148. ifeq ($(strip $(CONFIG_LFS)),y)
  149. # For large file summit support
  150. CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
  151. endif
  152. ifeq ($(strip $(CONFIG_DMALLOC)),y)
  153. # For testing mem leaks with dmalloc
  154. CFLAGS+=-DDMALLOC
  155. LIBRARIES:=-ldmalloc
  156. else
  157. ifeq ($(strip $(CONFIG_EFENCE)),y)
  158. LIBRARIES:=-lefence
  159. endif
  160. endif
  161. ifeq ($(strip $(CONFIG_DEBUG)),y)
  162. CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE
  163. LDFLAGS += $(call check_ld,--warn-common,)
  164. else
  165. CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
  166. LDFLAGS += $(call check_ld,--warn-common,)
  167. LDFLAGS += $(call check_ld,--sort-common,)
  168. endif
  169. STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
  170. ifeq ($(strip $(CONFIG_STATIC)),y)
  171. PROG_CFLAGS += $(call check_gcc,-static,)
  172. endif
  173. CFLAGS_SHARED += $(call check_gcc,-shared,)
  174. LIB_CFLAGS+=$(CFLAGS_SHARED)
  175. ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
  176. CFLAGS_PIC:= $(call check_gcc,-fPIC,)
  177. LIB_CFLAGS+=$(CFLAGS_PIC)
  178. endif
  179. ifeq ($(strip $(CONFIG_SELINUX)),y)
  180. LIBRARIES += -lselinux
  181. endif
  182. ifeq ($(strip $(PREFIX)),)
  183. PREFIX:=`pwd`/_install
  184. endif
  185. # Additional complications due to support for pristine source dir.
  186. # Include files in the build directory should take precedence over
  187. # the copy in top_srcdir, both during the compilation phase and the
  188. # shell script that finds the list of object files.
  189. # Work in progress by <ldoolitt@recycle.lbl.gov>.
  190. OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
  191. CFLAGS += $(CROSS_CFLAGS)
  192. ifdef BB_INIT_SCRIPT
  193. CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
  194. endif
  195. # Put user-supplied flags at the end, where they
  196. # have a chance of winning.
  197. CFLAGS += $(CFLAGS_EXTRA)
  198. #------------------------------------------------------------
  199. # Installation options
  200. ifeq ($(strip $(CONFIG_INSTALL_APPLET_HARDLINKS)),y)
  201. INSTALL_OPTS=--hardlinks
  202. endif
  203. ifeq ($(strip $(CONFIG_INSTALL_APPLET_SYMLINKS)),y)
  204. INSTALL_OPTS=--symlinks
  205. endif
  206. ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
  207. INSTALL_OPTS=
  208. endif
  209. #------------------------------------------------------------
  210. # Make the output nice and tight
  211. MAKEFLAGS += --no-print-directory
  212. export MAKE_IS_SILENT=n
  213. ifneq ($(findstring s,$(MAKEFLAGS)),)
  214. export MAKE_IS_SILENT=y
  215. SECHO := @-false
  216. DISP := sil
  217. Q := @
  218. else
  219. ifneq ($(V)$(VERBOSE),)
  220. SECHO := @-false
  221. DISP := ver
  222. Q :=
  223. else
  224. SECHO := @echo
  225. DISP := pur
  226. Q := @
  227. endif
  228. endif
  229. show_objs = $(subst $(top_builddir)/,,$(subst ../,,$@))
  230. pur_disp_compile.c = echo " "CC $(show_objs)
  231. pur_disp_compile.h = echo " "HOSTCC $(show_objs)
  232. pur_disp_strip = echo " "STRIP $(show_objs)
  233. pur_disp_link = echo " "LINK $(show_objs)
  234. pur_disp_ar = echo " "AR $(ARFLAGS) $(show_objs)
  235. sil_disp_compile.c = true
  236. sil_disp_compile.h = true
  237. sil_disp_strip = true
  238. sil_disp_link = true
  239. sil_disp_ar = true
  240. ver_disp_compile.c = echo $(cmd_compile.c)
  241. ver_disp_compile.h = echo $(cmd_compile.h)
  242. ver_disp_strip = echo $(cmd_strip)
  243. ver_disp_link = echo $(cmd_link)
  244. ver_disp_ar = echo $(cmd_ar)
  245. disp_compile.c = $($(DISP)_disp_compile.c)
  246. disp_compile.h = $($(DISP)_disp_compile.h)
  247. disp_strip = $($(DISP)_disp_strip)
  248. disp_link = $($(DISP)_disp_link)
  249. disp_ar = $($(DISP)_disp_ar)
  250. disp_gen = $(SECHO) " "GEN $@ ; true
  251. disp_doc = $(SECHO) " "DOC $(subst docs/,,$@) ; true
  252. cmd_compile.c = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
  253. cmd_compile.h = $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
  254. cmd_strip = $(STRIPCMD) $@
  255. cmd_link = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS)
  256. cmd_ar = $(AR) $(ARFLAGS) $@ $^
  257. compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
  258. compile.h = @$(disp_compile.h) ; $(cmd_compile.h)
  259. do_strip = @$(disp_strip) ; $(cmd_strip)
  260. do_link = @$(disp_link) ; $(cmd_link)
  261. do_ar = @$(disp_ar) ; $(cmd_ar)
  262. .PHONY: dummy