Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. # Makefile for busybox
  2. #
  3. # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  4. #
  5. # Licensed under GPLv2, see the file LICENSE in this tarball for details.
  6. #
  7. #--------------------------------------------------------------
  8. # You shouldn't need to mess with anything beyond this point...
  9. #--------------------------------------------------------------
  10. noconfig_targets := menuconfig config oldconfig randconfig \
  11. defconfig allyesconfig allnoconfig allbareconfig \
  12. clean distclean help \
  13. release tags
  14. # the toplevel sourcedir
  15. ifndef top_srcdir
  16. top_srcdir=$(CURDIR)
  17. endif
  18. # toplevel directory of the object-tree
  19. ifndef top_builddir
  20. top_builddir=$(CURDIR)
  21. endif
  22. export srctree=$(top_srcdir)
  23. vpath %/Config.in $(srctree)
  24. DIRS:=applets archival archival/libunarchive coreutils console-tools \
  25. debianutils editors findutils init miscutils modutils networking \
  26. networking/libiproute networking/udhcp procps loginutils shell \
  27. sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
  28. SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
  29. # That's our default target when none is given on the command line
  30. .PHONY: _all
  31. _all:
  32. CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
  33. ifeq ($(KBUILD_SRC),)
  34. ifdef O
  35. ifeq ("$(origin O)", "command line")
  36. KBUILD_OUTPUT := $(O)
  37. top_builddir := $(O)
  38. endif
  39. else
  40. # If no alternate output-dir was specified, we build in cwd
  41. # We are using KBUILD_OUTPUT nevertheless to make sure that we create
  42. # Rules.mak and the toplevel Makefile, in case they don't exist.
  43. KBUILD_OUTPUT := $(top_builddir)
  44. endif
  45. ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
  46. # pull in OS specific commands like cp, mkdir, etc. early
  47. -include $(top_srcdir)/Rules.mak
  48. endif
  49. # All object directories.
  50. OBJ_DIRS := $(DIRS)
  51. all_tree := $(patsubst %,$(top_builddir)/%,$(OBJ_DIRS) scripts scripts/config include)
  52. all_tree: $(all_tree)
  53. $(all_tree):
  54. @mkdir -p "$@"
  55. ifneq ($(KBUILD_OUTPUT),)
  56. # Invoke a second make in the output directory, passing relevant variables
  57. # Check that the output directory actually exists
  58. saved-output := $(KBUILD_OUTPUT)
  59. KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
  60. $(if $(wildcard $(KBUILD_OUTPUT)),, \
  61. $(error output directory "$(saved-output)" does not exist))
  62. .PHONY: $(MAKECMDGOALS)
  63. $(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile all_tree
  64. $(Q)$(MAKE) -C $(KBUILD_OUTPUT) \
  65. top_srcdir=$(top_srcdir) \
  66. top_builddir=$(top_builddir) \
  67. KBUILD_SRC=$(top_srcdir) \
  68. -f $(CURDIR)/Makefile $@
  69. $(KBUILD_OUTPUT)/Rules.mak:
  70. @echo > $@
  71. @echo top_srcdir=$(top_srcdir) >> $@
  72. @echo top_builddir=$(KBUILD_OUTPUT) >> $@
  73. @echo include $(top_srcdir)/Rules.mak >> $@
  74. $(KBUILD_OUTPUT)/Makefile:
  75. @echo > $@
  76. @echo top_srcdir=$(top_srcdir) >> $@
  77. @echo top_builddir=$(KBUILD_OUTPUT) >> $@
  78. @echo KBUILD_SRC='$$(top_srcdir)' >> $@
  79. @echo include '$$(KBUILD_SRC)'/Makefile >> $@
  80. # Leave processing to above invocation of make
  81. skip-makefile := 1
  82. endif # ifneq ($(KBUILD_OUTPUT),)
  83. endif # ifeq ($(KBUILD_SRC),)
  84. ifeq ($(skip-makefile),)
  85. # We only need a copy of the Makefile for the config targets and reuse
  86. # the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
  87. scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile
  88. cp $< $@
  89. _all: all
  90. help:
  91. @echo 'Cleaning:'
  92. @echo ' clean - delete temporary files created by build'
  93. @echo ' distclean - delete all non-source files (including .config)'
  94. @echo
  95. @echo 'Build:'
  96. @echo ' all - Executable and documentation'
  97. @echo ' busybox - the swiss-army executable'
  98. @echo ' doc - docs/BusyBox.{txt,html,1}'
  99. @echo
  100. @echo 'Configuration:'
  101. @echo ' allnoconfig - disable all symbols in .config'
  102. @echo ' allyesconfig - enable all symbols in .config (see defconfig)'
  103. @echo ' allbareconfig - enable all applets without any sub-features'
  104. @echo ' config - text based configurator (of last resort)'
  105. @echo ' defconfig - set .config to largest generic configuration'
  106. @echo ' menuconfig - interactive curses-based configurator'
  107. @echo ' oldconfig - resolve any unresolved symbols in .config'
  108. @echo
  109. @echo 'Installation:'
  110. @echo ' install - install busybox into $(PREFIX)'
  111. @echo ' uninstall'
  112. @echo
  113. @echo 'Development:'
  114. @echo ' check - run the test suite for all applets'
  115. @echo ' randconfig - generate a random configuration'
  116. @echo ' release - create a distribution tarball'
  117. @echo ' sizes - show size of all enabled busybox symbols'
  118. @echo
  119. include $(top_srcdir)/Rules.mak
  120. ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
  121. # Default target if none was requested explicitly
  122. all: menuconfig
  123. # warn if no configuration exists and we are asked to build a non-config target
  124. .config:
  125. @echo ""
  126. @echo "No $(top_builddir)/$@ found!"
  127. @echo "Please refer to 'make help', section Configuration."
  128. @echo ""
  129. @exit 1
  130. # configuration
  131. # ---------------------------------------------------------------------------
  132. scripts/config/conf: scripts/config/Makefile
  133. $(Q)$(MAKE) -C scripts/config conf
  134. -@if [ ! -f .config ] ; then \
  135. touch .config; \
  136. fi
  137. scripts/config/mconf: scripts/config/Makefile
  138. $(Q)$(MAKE) -C scripts/config ncurses conf mconf
  139. -@if [ ! -f .config ] ; then \
  140. touch .config; \
  141. fi
  142. menuconfig: scripts/config/mconf
  143. @[ -f .config ] || make $(MAKEFLAGS) defconfig
  144. @./scripts/config/mconf $(CONFIG_CONFIG_IN)
  145. config: scripts/config/conf
  146. @./scripts/config/conf $(CONFIG_CONFIG_IN)
  147. oldconfig: scripts/config/conf
  148. @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
  149. randconfig: scripts/config/conf
  150. @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
  151. allyesconfig: scripts/config/conf
  152. @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
  153. @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
  154. @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
  155. allnoconfig: scripts/config/conf
  156. @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
  157. # defconfig is allyesconfig minus any features that are specialized enough
  158. # or cause enough behavior change that the user really should switch them on
  159. # manually if that's what they want. Sort of "maximum sane config".
  160. defconfig: scripts/config/conf
  161. @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
  162. @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG.*|STATIC|SELINUX|BUILD_(AT_ONCE|LIBBUSYBOX)|FEATURE_(DEVFS|FULL_LIBBUSYBOX|SHARED_BUSYBOX|MTAB_SUPPORT|CLEAN_UP|UDHCP_DEBUG)|INSTALL_NO_USR))=.*/# \1 is not set/" .config
  163. @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
  164. allbareconfig: scripts/config/conf
  165. @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
  166. @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG|STATIC|SELINUX|DEVFSD|NC_GAPING_SECURITY_HOLE|BUILD_AT_ONCE)).*/# \1 is not set/" .config
  167. @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
  168. @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
  169. @yes n | ./scripts/config/conf -o $(CONFIG_CONFIG_IN)
  170. else # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
  171. all: busybox busybox.links doc
  172. # In this section, we need .config
  173. -include $(top_builddir)/.config.cmd
  174. include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
  175. endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
  176. -include $(top_builddir)/.config
  177. -include $(top_builddir)/.depend
  178. ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
  179. libraries-y:=
  180. # Which parts of the internal libs are requested?
  181. # Per default we only want what was actually selected.
  182. # -a denotes all while -y denotes the selected ones.
  183. ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
  184. LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
  185. LIBRARY_SRC :=$(LIBRARY_SRC-a)
  186. else # CONFIG_FEATURE_FULL_LIBBUSYBOX
  187. LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
  188. LIBRARY_SRC :=$(LIBRARY_SRC-y)
  189. endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
  190. APPLET_SRC:=$(APPLET_SRC-y)
  191. APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
  192. else # CONFIG_BUILD_AT_ONCE
  193. # no --combine, build archives out of the individual .o
  194. # This was the old way the binary was built.
  195. libbusybox-obj:=archival/libunarchive/libunarchive.a \
  196. networking/libiproute/libiproute.a \
  197. libpwdgrp/libpwdgrp.a \
  198. coreutils/libcoreutils/libcoreutils.a \
  199. libbb/libbb.a
  200. libbusybox-obj:=$(patsubst %,$(top_builddir)/%,$(libbusybox-obj))
  201. ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
  202. # linking against libbusybox, so don't build the .a already contained in the .so
  203. libraries-y:=$(filter-out $(libbusybox-obj),$(libraries-y))
  204. endif # CONFIG_FEATURE_SHARED_BUSYBOX
  205. endif # CONFIG_BUILD_AT_ONCE
  206. ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
  207. LD_LIBBUSYBOX:=libbusybox.so
  208. LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
  209. DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
  210. $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
  211. $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
  212. endif # CONFIG_BUILD_LIBBUSYBOX
  213. ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
  214. ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
  215. # --combine but not linking against libbusybox, so compile all
  216. BUSYBOX_SRC := $(LIBRARY_SRC)
  217. BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
  218. endif # !CONFIG_FEATURE_SHARED_BUSYBOX
  219. $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
  220. else # CONFIG_BUILD_AT_ONCE
  221. $(LIBBUSYBOX_SONAME): $(libbusybox-obj)
  222. endif # CONFIG_BUILD_AT_ONCE
  223. ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
  224. LDBUSYBOX:=-L$(top_builddir) -lbusybox
  225. endif
  226. ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
  227. $(LIBBUSYBOX_SONAME):
  228. ifndef MAJOR_VERSION
  229. $(error MAJOR_VERSION needed for $@ is not defined)
  230. endif
  231. $(do_link) $(LIB_CFLAGS) $(CFLAGS_COMBINE) \
  232. -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
  233. -Wl,-z,combreloc $(LIB_LDFLAGS) \
  234. -o $(@) \
  235. -Wl,--start-group -Wl,--whole-archive \
  236. $(LIBRARY_DEFINE) $(^) \
  237. -Wl,--no-whole-archive -Wl,--end-group
  238. @rm -f $(DO_INSTALL_LIBS)
  239. @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
  240. $(do_strip)
  241. endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
  242. busybox_unstripped: .depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(libraries-y)
  243. $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
  244. -o $@ -Wl,--start-group \
  245. $(APPLETS_DEFINE) $(APPLET_SRC) \
  246. $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) $(libraries-y) \
  247. $(LDBUSYBOX) $(LIBRARIES) \
  248. -Wl,--end-group
  249. busybox: busybox_unstripped
  250. $(Q)cp busybox_unstripped busybox
  251. $(do_strip)
  252. busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
  253. $(Q)-$(SHELL) $^ >$@
  254. install: $(top_srcdir)/applets/install.sh busybox busybox.links
  255. $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
  256. $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
  257. ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
  258. @echo
  259. @echo
  260. @echo --------------------------------------------------
  261. @echo You will probably need to make your busybox binary
  262. @echo setuid root to ensure all configured applets will
  263. @echo work properly.
  264. @echo --------------------------------------------------
  265. @echo
  266. endif
  267. uninstall: busybox.links
  268. rm -f $(PREFIX)/bin/busybox
  269. for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
  270. ifneq ($(strip $(DO_INSTALL_LIBS)),n)
  271. for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
  272. rm -f $(PREFIX)$$i; \
  273. done
  274. endif
  275. # see if we are in verbose mode
  276. KBUILD_VERBOSE :=
  277. ifdef V
  278. ifeq ("$(origin V)", "command line")
  279. KBUILD_VERBOSE := $(V)
  280. endif
  281. endif
  282. ifneq ($(strip $(KBUILD_VERBOSE)),)
  283. CHECK_VERBOSE := -v
  284. # ARFLAGS+=v
  285. endif
  286. check test: busybox
  287. bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
  288. $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
  289. sizes: busybox_unstripped
  290. $(NM) --size-sort $(<)
  291. # Documentation Targets
  292. doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
  293. docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod $(top_srcdir)/docs/autodocifier.pl
  294. $(disp_doc)
  295. $(Q)-mkdir -p docs
  296. $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
  297. $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
  298. cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
  299. docs/BusyBox.txt: docs/busybox.pod
  300. $(disp_doc)
  301. $(Q)-mkdir -p docs
  302. $(Q)-pod2text $< > $@
  303. docs/BusyBox.1: docs/busybox.pod
  304. $(disp_doc)
  305. $(Q)-mkdir -p docs
  306. $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
  307. $< > $@
  308. docs/BusyBox.html: docs/busybox.net/BusyBox.html
  309. $(disp_doc)
  310. $(Q)-mkdir -p docs
  311. $(Q)-rm -f docs/BusyBox.html
  312. $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
  313. docs/busybox.net/BusyBox.html: docs/busybox.pod
  314. $(Q)-mkdir -p docs/busybox.net
  315. $(Q)-pod2html --noindex $< > \
  316. docs/busybox.net/BusyBox.html
  317. $(Q)-rm -f pod2htm*
  318. # The nifty new dependency stuff
  319. scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
  320. $(Q)$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
  321. DEP_INCLUDES := include/bb_config.h
  322. ifeq ($(strip $(CONFIG_BBCONFIG)),y)
  323. DEP_INCLUDES += include/bbconfigopts.h
  324. include/bbconfigopts.h: .config
  325. $(disp_gen)
  326. $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
  327. endif
  328. depend dep: .depend
  329. .depend: scripts/bb_mkdep $(DEP_INCLUDES)
  330. $(disp_gen)
  331. $(Q)rm -f .depend
  332. $(Q)mkdir -p include/config
  333. $(Q)scripts/bb_mkdep -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
  334. $(Q)mv $@.tmp $@
  335. include/bb_config.h: .config
  336. @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
  337. $(MAKE) -C scripts/config conf; \
  338. fi;
  339. @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
  340. clean:
  341. - $(MAKE) -C scripts/config $@
  342. - rm -f docs/busybox.dvi docs/busybox.ps \
  343. docs/busybox.pod docs/busybox.net/busybox.html \
  344. docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
  345. docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
  346. docs/busybox.net/BusyBox.html busybox.links \
  347. libbusybox.so* \
  348. .config.old busybox busybox_unstripped
  349. - rm -r -f _install testsuite/links
  350. - find . -name .\*.flags -o -name \*.o -o -name \*.om \
  351. -o -name \*.os -o -name \*.osm -o -name \*.a | xargs rm -f
  352. distclean: clean
  353. - rm -f scripts/bb_mkdep
  354. - rm -r -f include/config $(DEP_INCLUDES)
  355. - find . -name .depend'*' | xargs rm -f
  356. rm -f .config .config.old .config.cmd
  357. release: distclean #doc
  358. cd ..; \
  359. rm -r -f $(PROG)-$(VERSION); \
  360. cp -a busybox $(PROG)-$(VERSION); \
  361. \
  362. find $(PROG)-$(VERSION)/ -type d \
  363. -name .svn \
  364. -print \
  365. -exec rm -r -f {} \; ; \
  366. \
  367. find $(PROG)-$(VERSION)/ -type f \
  368. -name .\#* \
  369. -print \
  370. -exec rm -f {} \; ; \
  371. \
  372. tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
  373. tags:
  374. ctags -R .
  375. endif # ifeq ($(skip-makefile),)
  376. .PHONY: dummy subdirs release distclean clean config oldconfig \
  377. menuconfig tags check test depend dep buildtree