1 # Makefile for buildroot2
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #--------------------------------------------------------------
22 # Just run 'make menuconfig', configure stuff, then run 'make'.
23 # You shouldn't need to mess with anything beyond this point...
24 #--------------------------------------------------------------
26 CONFIG_CONFIG_IN=Config.in
27 CONFIG_DEFCONFIG=.defconfig
29 DATE:=$(shell date +%Y%m%d)
31 noconfig_targets:=menuconfig xconfig config oldconfig randconfig \
32 defconfig allyesconfig allnoconfig release tags \
36 # Use shell variables, if defined
37 ifneq ($(BUILDROOT_LOCAL),)
38 BR2_LOCAL:=$(BUILDROOT_LOCAL)
40 BR2_LOCAL:=$(TOPDIR)/local
43 # Strip quotes and then whitespaces
44 qstrip=$(strip $(subst ",,$(1)))
47 # Variables for use in Make constructs
50 space:=$(empty) $(empty)
52 # $(shell find . -name *_defconfig |sed 's/.*\///')
53 # Pull in the user's configuration file
54 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
56 # if "make BOARD=xyz" command
60 -include $(BR2_LOCAL)/$(BOARD)/$(BOARD).config
64 # Override BR2_DL_DIR if shell variable defined
65 ifneq ($(BUILDROOT_DL_DIR),)
66 BR2_DL_DIR:=$(BUILDROOT_DL_DIR)
70 # To put more focus on warnings, be less verbose as default
71 # Use 'make V=1' to see the full commands
73 ifeq ("$(origin V)", "command line")
81 ifeq ($(KBUILD_VERBOSE),1)
92 # we want bash as shell
93 SHELL:=$(shell if [ -x "$$BASH" ]; then echo $$BASH; \
94 else if [ -x /bin/bash ]; then echo /bin/bash; \
97 # kconfig uses CONFIG_SHELL
98 CONFIG_SHELL:=$(SHELL)
100 export SHELL CONFIG_SHELL quiet Q KBUILD_VERBOSE VERBOSE
130 HOSTAR:=$(shell which $(HOSTAR) || type -p $(HOSTAR) || echo ar)
131 HOSTAS:=$(shell which $(HOSTAS) || type -p $(HOSTAS) || echo as)
132 HOSTCC:=$(shell which $(HOSTCC) || type -p $(HOSTCC) || echo gcc)
133 HOSTCXX:=$(shell which $(HOSTCXX) || type -p $(HOSTCXX) || echo g++)
134 HOSTFC:=$(shell which $(HOSTLD) || type -p $(HOSTLD) || echo || which g77 || type -p g77 || echo gfortran)
135 HOSTCPP:=$(shell which $(HOSTCPP) || type -p $(HOSTCPP) || echo cpp)
136 HOSTLD:=$(shell which $(HOSTLD) || type -p $(HOSTLD) || echo ld)
137 HOSTLN:=$(shell which $(HOSTLN) || type -p $(HOSTLN) || echo ln)
138 HOSTNM:=$(shell which $(HOSTNM) || type -p $(HOSTNM) || echo nm)
140 ifndef CFLAGS_FOR_BUILD
141 CFLAGS_FOR_BUILD:=-g -O2
143 ifndef CXXFLAGS_FOR_BUILD
144 CXXFLAGS_FOR_BUILD:=-g -O2
146 ifndef FCFLAGS_FOR_BUILD
147 FCFLAGS_FOR_BUILD:=-g -O2
149 export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTFC HOSTLD
152 ifeq ($(BR2_HAVE_DOT_CONFIG),y)
155 # Usage: cflags-y+=$(call cc-option, -march=winchip-c6, -march=i586)
156 # sets -march=winchip-c6 if supported else falls back to -march=i586
157 # without checking the latter.
158 cc-option=$(shell if $(TARGET_CC) $(TARGET_CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
159 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
161 #############################################################
163 # Hide troublesome environment variables from sub processes
165 #############################################################
166 unexport CROSS_COMPILE
169 #############################################################
171 # Setup the proper filename extensions for the host
173 ##############################################################
174 ifneq ($(findstring linux,$(BR2_GNU_BUILD_SUFFIX)),)
179 ifneq ($(findstring apple,$(BR2_GNU_BUILD_SUFFIX)),)
184 ifneq ($(findstring cygwin,$(BR2_GNU_BUILD_SUFFIX)),)
188 HOST_LOADLIBES="-lcurses -lintl"
189 export HOST_LOADLIBES
191 ifneq ($(findstring mingw,$(BR2_GNU_BUILD_SUFFIX)),)
197 # The preferred type of libs we build for the target
198 ifeq ($(BR2_PREFER_STATIC_LIB),y)
200 #PREFERRED_LIB_FLAGS:=--disable-shared --enable-static
203 #PREFERRED_LIB_FLAGS:=--disable-static --enable-shared
205 PREFERRED_LIB_FLAGS:=--enable-static --enable-shared
207 ##############################################################
209 # The list of stuff to build for the target toolchain
210 # along with the packages to build for the target.
212 ##############################################################
213 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
214 BASE_TARGETS:=uclibc-configured binutils cross_compiler uclibc-target-utils kernel-headers
221 include project/Makefile.in
223 BR2_DEPENDS_DIR=$(PROJECT_BUILD_DIR)/buildroot-config
225 include toolchain/Makefile.in
226 include package/Makefile.in
228 #############################################################
230 # You should probably leave this stuff alone unless you know
231 # what you are doing.
233 #############################################################
237 # In this section, we need .config
242 # We also need the various per-package makefiles, which also add
243 # each selected package to TARGETS if that package was selected
244 # in the .config file.
245 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
246 # avoid pulling in external toolchain which is broken for toplvl parallel builds
248 include toolchain/dependencies/dependencies.mk
249 include toolchain/binutils/binutils.mk
250 include toolchain/ccache/ccache.mk
251 include toolchain/elf2flt/elf2flt.mk
252 include toolchain/gcc/gcc-uclibc-3.x.mk
253 include toolchain/gcc/gcc-uclibc-4.x.mk
254 include toolchain/gdb/gdb.mk
255 include toolchain/kernel-headers/kernel-headers.mk
256 include toolchain/mklibs/mklibs.mk
257 include toolchain/sstrip/sstrip.mk
258 include toolchain/uClibc/uclibc.mk
260 include toolchain/*/*.mk
263 ifeq ($(BR2_PACKAGE_LINUX),y)
264 TARGETS+=linux26-modules
267 include package/*/*.mk
269 TARGETS+=target-finalize
271 ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
272 TARGETS+=target-purgelocales
275 # target stuff is last so it can override anything else
276 include target/Makefile.in
278 TARGETS+=erase-fakeroots
280 TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
281 TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS) $(BASE_TARGETS))
282 TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))
283 TARGETS_ALL:=$(patsubst %,__real_tgt_%,$(TARGETS))
284 # all targets depend on the crosscompiler and it's prerequisites
285 $(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) %
287 $(BR2_DEPENDS_DIR): .config
290 cp -dpRf $(CONFIG)/buildroot-config $@
292 dirs: $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
293 $(HOST_DIR) $(BR2_DEPENDS_DIR) $(BINARIES_DIR) $(PROJECT_BUILD_DIR) \
294 $(PROJECT_BUILD_DIR)/autotools-stamps $(STAMP_DIR)
296 $(BASE_TARGETS): dirs
298 world: dependencies dirs target-host-info $(BASE_TARGETS) $(TARGETS_ALL)
301 .PHONY: all world dirs clean dirclean distclean source \
302 $(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
303 $(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) \
304 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
305 $(HOST_DIR) $(BR2_DEPENDS_DIR) $(BINARIES_DIR) $(PROJECT_BUILD_DIR) \
306 $(PROJECT_BUILD_DIR)/autotools-stamps $(STAMP_DIR)
308 #############################################################
310 # staging and target directories do NOT list these as
311 # dependencies anywhere else
313 #############################################################
314 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(HOST_DIR) $(PROJECT_BUILD_DIR) \
315 $(PROJECT_BUILD_DIR)/autotools-stamps $(BINARIES_DIR) $(STAMP_DIR):
319 @mkdir -p $(STAGING_DIR)/bin
320 @mkdir -p $(STAGING_DIR)/lib
321 ifeq ($(BR2_TOOLCHAIN_SYSROOT),y)
322 @mkdir -p $(STAGING_DIR)/usr/lib
324 ifneq ($(BR2_TOOLCHAIN_EXTERNAL),y)
325 @ln -snf . $(STAGING_DIR)/usr
326 @mkdir -p $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)
327 @ln -snf ../lib $(STAGING_DIR)/usr/lib
328 @ln -snf ../lib $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
331 @mkdir -p $(STAGING_DIR)/usr/include
333 $(PROJECT_BUILD_DIR)/.root:
334 mkdir -p $(TARGET_DIR)
335 if ! [ -d "$(TARGET_DIR)/bin" ]; then \
336 if [ -d "$(TARGET_SKELETON)" ]; then \
337 cp -fa $(TARGET_SKELETON)/* $(TARGET_DIR)/; \
339 if [ -d "$(TARGET_SKELETON_PATCH)" ]; then \
340 toolchain/patch-kernel.sh $(TARGET_DIR) $(TARGET_SKELETON_PATCH)/ \*patch\*; \
342 touch $(STAGING_DIR)/.fakeroot.00000; \
344 -find $(TARGET_DIR) -type d -name CVS -print0 -o -name .svn -print0 | xargs -0 rm -rf
345 -find $(TARGET_DIR) -type f -name .empty -print0 | xargs -0 rm -rf
348 $(TARGET_DIR): $(PROJECT_BUILD_DIR)/.root
351 rm -f $(PROJECT_BUILD_DIR)/.fakeroot*
354 ifeq ($(BR2_HAVE_DEVFILES),y)
355 ( scripts/copy.sh $(STAGING_DIR) $(TARGET_DIR) )
357 rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/lib/pkgconfig
358 find $(TARGET_DIR)/lib \( -name '*.a' -o -name '*.la' \) -print0 | xargs -0 rm -f
359 find $(TARGET_DIR)/usr/lib \( -name '*.a' -o -name '*.la' \) -print0 | xargs -0 rm -f
361 ifneq ($(BR2_HAVE_MANPAGES),y)
362 rm -rf $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/man
364 ifneq ($(BR2_HAVE_INFOPAGES),y)
365 rm -rf $(TARGET_DIR)/usr/info $(TARGET_DIR)/usr/share/info
367 find $(TARGET_DIR) -type f -perm +111 | xargs $(STRIPCMD) 2>/dev/null || true
368 $(TARGET_LDCONFIG) -r $(TARGET_DIR) 2>/dev/null
370 ifneq ($(BR2_ROOTFS_POST_BUILD_SCRIPT),"")
371 $(BR2_ROOTFS_POST_BUILD_SCRIPT) $(TARGET_DIR)
374 ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
375 LOCALE_WHITELIST=$(PROJECT_BUILD_DIR)/locales.nopurge
376 LOCALE_NOPURGE=$(strip $(subst ",,$(BR2_ENABLE_LOCALE_WHITELIST)))
380 rm -f $(LOCALE_WHITELIST)
381 for i in $(LOCALE_NOPURGE); do echo $$i >> $(LOCALE_WHITELIST); done
383 for dir in $(wildcard $(addprefix $(TARGET_DIR),/usr/share/locale /usr/share/X11/locale /usr/man /usr/share/man)); \
385 for lang in $$(cd $$dir; ls .|grep -v man); \
387 grep -qx $$lang $(LOCALE_WHITELIST) || rm -rf $$dir/$$lang; \
392 source: $(TARGETS_SOURCE) $(HOST_SOURCE)
395 $(MAKE) SPIDER=--spider source
398 @$(MAKE) -Bs BR2_WGET=$(TOPDIR)/toolchain/wget-show-external-deps.sh \
399 SPIDER=--spider source
401 #############################################################
403 # Cleanup and misc junk
405 #############################################################
406 clean: $(TARGETS_CLEAN)
407 rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) $(PROJECT_BUILD_DIR)/.root $(PROJECT_BUILD_DIR)/autotools-stamps $(STAMP_DIR)
409 dirclean: $(TARGETS_DIRCLEAN)
410 rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) $(PROJECT_BUILD_DIR)/.root $(PROJECT_BUILD_DIR)/autotools-stamps $(STAMP_DIR)
413 ifeq ($(DL_DIR),$(BASE_DIR)/dl)
416 rm -rf $(TOOL_BUILD_DIR) $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR) \
418 $(MAKE) -C $(CONFIG) clean
421 rm -rf $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR)
424 rm -f buildroot.tar.bz2; \
425 tar -cvf buildroot.tar buildroot; \
426 bzip2 -9 buildroot.tar; \
429 else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
434 # ---------------------------------------------------------------------------
436 HOSTCFLAGS=$(CFLAGS_FOR_BUILD)
440 @mkdir -p $(CONFIG)/buildroot-config
441 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf
442 -@if [ ! -f .config ]; then \
443 cp $(CONFIG_DEFCONFIG) .config; \
447 @mkdir -p $(CONFIG)/buildroot-config
448 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) mconf
449 -@if [ ! -f .config ]; then \
450 cp $(CONFIG_DEFCONFIG) .config; \
454 @mkdir -p $(CONFIG)/buildroot-config
455 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) qconf
456 -@if [ ! -f .config ]; then \
457 cp $(CONFIG_DEFCONFIG) .config; \
460 xconfig: $(CONFIG)/qconf
461 @mkdir -p $(CONFIG)/buildroot-config
462 @if ! KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
463 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
464 $(CONFIG)/qconf $(CONFIG_CONFIG_IN); then \
465 test -f .config.cmd || rm -f .config; \
468 menuconfig: $(CONFIG)/mconf
469 @mkdir -p $(CONFIG)/buildroot-config
470 @if ! KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
471 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
472 $(CONFIG)/mconf $(CONFIG_CONFIG_IN); then \
473 test -f .config.cmd || rm -f .config; \
476 config: $(CONFIG)/conf
477 @mkdir -p $(CONFIG)/buildroot-config
478 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
479 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
480 $(CONFIG)/conf $(CONFIG_CONFIG_IN)
482 oldconfig: $(CONFIG)/conf
483 @mkdir -p $(CONFIG)/buildroot-config
484 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
485 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
486 $(CONFIG)/conf -o $(CONFIG_CONFIG_IN)
488 randconfig: $(CONFIG)/conf
489 @mkdir -p $(CONFIG)/buildroot-config
490 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
491 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
492 $(CONFIG)/conf -r $(CONFIG_CONFIG_IN)
494 allyesconfig: $(CONFIG)/conf
495 cat $(CONFIG_DEFCONFIG) > .config
496 @mkdir -p $(CONFIG)/buildroot-config
497 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
498 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
499 $(CONFIG)/conf -y $(CONFIG_CONFIG_IN)
500 #sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
502 allnoconfig: $(CONFIG)/conf
503 @mkdir -p $(CONFIG)/buildroot-config
504 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
505 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
506 $(CONFIG)/conf -n $(CONFIG_CONFIG_IN)
508 defconfig: $(CONFIG)/conf
509 @mkdir -p $(CONFIG)/buildroot-config
510 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
511 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
512 $(CONFIG)/conf -d $(CONFIG_CONFIG_IN)
514 # check if download URLs are outdated
515 source-check: allyesconfig
516 $(MAKE) _source-check
518 #############################################################
520 # Cleanup and misc junk
522 #############################################################
524 rm -f .config .config.old .config.cmd .tmpconfig.h .lognr.*
525 -$(MAKE) -C $(CONFIG) clean
531 endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
534 rm -f $(PROJECT_BUILD_DIR)/tgt-config.cache
536 %_defconfig: $(CONFIG)/conf
537 cp $(shell find ./target/ -name $@) .config
541 cp .config $(BOARD_PATH)/$(PROJECT)_defconfig
543 configured: dirs host-sed kernel-headers uclibc-config busybox-config linux26-config
545 prepatch: gcc-patched binutils-patched gdb-patched uclibc-patched
548 @echo "0" > .lognr.$(PROJECT)
550 log: .lognr.$(PROJECT)
551 @expr `cat .lognr.$(PROJECT)` + 1 > .lognr.$(PROJECT)
552 @echo Creating $(PROJECT)-`cat .lognr.$(PROJECT)`.log
553 @$(MAKE) > $(PROJECT)-`cat .lognr.$(PROJECT)`.log 2>&1
556 cross: $(BASE_TARGETS)
560 @echo ' clean - delete temporary files created by build'
561 @echo ' distclean - delete all non-source files (including .config)'
564 @echo ' all - make world'
566 @echo 'Configuration:'
567 @echo ' menuconfig - interactive curses-based configurator'
568 @echo ' xconfig - interactive Qt-based configurator'
569 @echo ' oldconfig - resolve any unresolved symbols in .config'
570 @echo ' configured - make {uclibc/busybox/linux26}-config'
571 @echo ' saveconfig - save current configuration under local/<project>'
572 @echo ' getconfig - restore saved configuration from local/<project>'
574 @echo 'Miscellaneous:'
575 @echo ' source - download all sources needed for offline-build'
576 @echo ' source-check - check all packages for valid download URLs'
577 @echo ' external-deps - list external packages used'
578 @echo ' flush - flush configuration cache'
580 @echo 'See docs/README and docs/buildroot.html for further details'
584 OUT=buildroot-$$(grep -A2 BR2_VERSION $(CONFIG_CONFIG_IN)|grep default|cut -f2 -d\"); \
585 rm -rf ../$$OUT*; cp -al . ../$$OUT; cd ..; \
586 tar cfz $$OUT.tar.gz --exclude .svn --exclude .git --exclude \*~ $$OUT; \
589 .PHONY: dummy subdirs release distclean clean config oldconfig \
590 menuconfig xconfig tags check test depend defconfig help