Rules.mak 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # Rules.make for busybox
  2. #
  3. # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. #--------------------------------------------------------
  20. PROG := busybox
  21. VERSION := 1.00
  22. BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
  23. #--------------------------------------------------------
  24. # With a modern GNU make(1) (highly recommended, that's what all the
  25. # developers use), all of the following configuration values can be
  26. # overridden at the command line. For example:
  27. # make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
  28. #--------------------------------------------------------
  29. # If you are running a cross compiler, you will want to set 'CROSS'
  30. # to something more interesting... Target architecture is determined
  31. # by asking the CC compiler what arch it compiles things for, so unless
  32. # your compiler is broken, you should not need to specify TARGET_ARCH
  33. CROSS =$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
  34. CC = $(CROSS)gcc
  35. AR = $(CROSS)ar
  36. AS = $(CROSS)as
  37. LD = $(CROSS)ld
  38. NM = $(CROSS)nm
  39. STRIP = $(CROSS)strip
  40. CPP = $(CC) -E
  41. # MAKEFILES = $(top_builddir)/.config
  42. # What OS are you compiling busybox for? This allows you to include
  43. # OS specific things, syscall overrides, etc.
  44. TARGET_OS=linux
  45. # Select the compiler needed to build binaries for your development system
  46. HOSTCC = gcc
  47. HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
  48. # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
  49. LC_ALL:= C
  50. # If you want to add some simple compiler switches (like -march=i686),
  51. # especially from the command line, use this instead of CFLAGS directly.
  52. # For optimization overrides, it's better still to set OPTIMIZATION.
  53. CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
  54. # If you have a "pristine" source directory, point BB_SRC_DIR to it.
  55. # Experimental and incomplete; tell the mailing list
  56. # <busybox@busybox.net> if you do or don't like it so far.
  57. BB_SRC_DIR=
  58. # To compile vs some other alternative libc, you may need to use/adjust
  59. # the following lines to meet your needs...
  60. #
  61. # If you are using Red Hat 6.x with the compatible RPMs (for developing under
  62. # Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
  63. # using the compatible RPMs (compat-*) at http://www.redhat.com !
  64. #LIBCDIR:=/usr/i386-glibc20-linux
  65. #
  66. # For other libraries, you are on your own. But these may (or may not) help...
  67. #LDFLAGS+=-nostdlib
  68. #LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
  69. #CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
  70. #GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
  71. WARNINGS=-Wall -Wstrict-prototypes -Wshadow
  72. CFLAGS=-I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
  73. ARFLAGS=-r
  74. #--------------------------------------------------------
  75. export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
  76. ifeq ($(strip $(TARGET_ARCH)),)
  77. TARGET_ARCH=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
  78. -e 's/i.86/i386/' \
  79. -e 's/sparc.*/sparc/' \
  80. -e 's/arm.*/arm/g' \
  81. -e 's/m68k.*/m68k/' \
  82. -e 's/ppc/powerpc/g' \
  83. -e 's/v850.*/v850/g' \
  84. -e 's/sh[234]/sh/' \
  85. -e 's/mips-.*/mips/' \
  86. -e 's/mipsel-.*/mipsel/' \
  87. -e 's/cris.*/cris/' \
  88. )
  89. endif
  90. # Pull in the user's busybox configuration
  91. ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
  92. -include $(top_builddir)/.config
  93. endif
  94. # A nifty macro to make testing gcc features easier
  95. check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
  96. then echo "$(1)"; else echo "$(2)"; fi)
  97. #--------------------------------------------------------
  98. # Arch specific compiler optimization stuff should go here.
  99. # Unless you want to override the defaults, do not set anything
  100. # for OPTIMIZATION...
  101. # use '-Os' optimization if available, else use -O2
  102. OPTIMIZATION=
  103. OPTIMIZATION=${call check_gcc,-Os,-O2}
  104. # Some nice architecture specific optimizations
  105. ifeq ($(strip $(TARGET_ARCH)),arm)
  106. OPTIMIZATION+=-fstrict-aliasing
  107. endif
  108. ifeq ($(strip $(TARGET_ARCH)),i386)
  109. OPTIMIZATION+=$(call check_gcc,-march=i386,)
  110. OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
  111. OPTIMIZATION+=$(call check_gcc,-falign-functions=0 -falign-jumps=0 -falign-loops=0,\
  112. -malign-functions=0 -malign-jumps=0 -malign-loops=0)
  113. endif
  114. OPTIMIZATIONS=$(OPTIMIZATION) -fomit-frame-pointer
  115. #
  116. #--------------------------------------------------------
  117. # If you're going to do a lot of builds with a non-vanilla configuration,
  118. # it makes sense to adjust parameters above, so you can type "make"
  119. # by itself, instead of following it by the same half-dozen overrides
  120. # every time. The stuff below, on the other hand, is probably less
  121. # prone to casual user adjustment.
  122. #
  123. ifeq ($(strip $(CONFIG_LFS)),y)
  124. # For large file summit support
  125. CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
  126. endif
  127. ifeq ($(strip $(CONFIG_DMALLOC)),y)
  128. # For testing mem leaks with dmalloc
  129. CFLAGS+=-DDMALLOC
  130. LIBRARIES:=-ldmalloc
  131. else
  132. ifeq ($(strip $(CONFIG_EFENCE)),y)
  133. LIBRARIES:=-lefence
  134. endif
  135. endif
  136. ifeq ($(strip $(CONFIG_DEBUG)),y)
  137. CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE
  138. LDFLAGS +=-Wl,-warn-common
  139. STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
  140. else
  141. CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
  142. LDFLAGS += -s -Wl,-warn-common
  143. STRIPCMD:=$(STRIP) --remove-section=.note --remove-section=.comment
  144. endif
  145. ifeq ($(strip $(CONFIG_STATIC)),y)
  146. LDFLAGS += --static
  147. endif
  148. ifeq ($(strip $(PREFIX)),)
  149. PREFIX:=`pwd`/_install
  150. endif
  151. # Additional complications due to support for pristine source dir.
  152. # Include files in the build directory should take precedence over
  153. # the copy in BB_SRC_DIR, both during the compilation phase and the
  154. # shell script that finds the list of object files.
  155. # Work in progress by <ldoolitt@recycle.lbl.gov>.
  156. #
  157. ifneq ($(strip $(BB_SRC_DIR)),)
  158. VPATH:=$(BB_SRC_DIR)
  159. endif
  160. OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
  161. CFLAGS += $(CROSS_CFLAGS)
  162. ifdef BB_INIT_SCRIPT
  163. CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
  164. endif
  165. # Put user-supplied flags at the end, where they
  166. # have a chance of winning.
  167. CFLAGS += $(CFLAGS_EXTRA)
  168. .PHONY: dummy
  169. .EXPORT_ALL_VARIABLES: