3
0

Rules.mak 7.0 KB

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