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 \
35 # Strip quotes and then whitespaces
36 qstrip=$(strip $(subst ",,$(1)))
39 # Variables for use in Make constructs
42 space:=$(empty) $(empty)
44 # $(shell find . -name *_defconfig |sed 's/.*\///')
45 # Pull in the user's configuration file
46 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
50 # Override BR2_DL_DIR if shell variable defined
51 ifneq ($(BUILDROOT_DL_DIR),)
52 BR2_DL_DIR:=$(BUILDROOT_DL_DIR)
55 # To put more focus on warnings, be less verbose as default
56 # Use 'make V=1' to see the full commands
58 ifeq ("$(origin V)", "command line")
66 ifeq ($(KBUILD_VERBOSE),1)
77 # we want bash as shell
78 SHELL:=$(shell if [ -x "$$BASH" ]; then echo $$BASH; \
79 else if [ -x /bin/bash ]; then echo /bin/bash; \
82 # kconfig uses CONFIG_SHELL
83 CONFIG_SHELL:=$(SHELL)
85 export SHELL CONFIG_SHELL quiet Q KBUILD_VERBOSE VERBOSE
115 HOSTAR:=$(shell which $(HOSTAR) || type -p $(HOSTAR) || echo ar)
116 HOSTAS:=$(shell which $(HOSTAS) || type -p $(HOSTAS) || echo as)
117 HOSTCC:=$(shell which $(HOSTCC) || type -p $(HOSTCC) || echo gcc)
118 HOSTCXX:=$(shell which $(HOSTCXX) || type -p $(HOSTCXX) || echo g++)
119 HOSTFC:=$(shell which $(HOSTLD) || type -p $(HOSTLD) || echo || which g77 || type -p g77 || echo gfortran)
120 HOSTCPP:=$(shell which $(HOSTCPP) || type -p $(HOSTCPP) || echo cpp)
121 HOSTLD:=$(shell which $(HOSTLD) || type -p $(HOSTLD) || echo ld)
122 HOSTLN:=$(shell which $(HOSTLN) || type -p $(HOSTLN) || echo ln)
123 HOSTNM:=$(shell which $(HOSTNM) || type -p $(HOSTNM) || echo nm)
125 ifndef CFLAGS_FOR_BUILD
126 CFLAGS_FOR_BUILD:=-g -O2
128 ifndef CXXFLAGS_FOR_BUILD
129 CXXFLAGS_FOR_BUILD:=-g -O2
131 ifndef FCFLAGS_FOR_BUILD
132 FCFLAGS_FOR_BUILD:=-g -O2
134 export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTFC HOSTLD
137 ifeq ($(BR2_HAVE_DOT_CONFIG),y)
140 # Usage: cflags-y+=$(call cc-option, -march=winchip-c6, -march=i586)
141 # sets -march=winchip-c6 if supported else falls back to -march=i586
142 # without checking the latter.
143 cc-option=$(shell if $(TARGET_CC) $(TARGET_CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
144 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
146 #############################################################
148 # Hide troublesome environment variables from sub processes
150 #############################################################
151 unexport CROSS_COMPILE
154 #############################################################
156 # Setup the proper filename extensions for the host
158 ##############################################################
159 ifneq ($(findstring linux,$(BR2_GNU_BUILD_SUFFIX)),)
164 ifneq ($(findstring apple,$(BR2_GNU_BUILD_SUFFIX)),)
169 ifneq ($(findstring cygwin,$(BR2_GNU_BUILD_SUFFIX)),)
173 HOST_LOADLIBES="-lcurses -lintl"
174 export HOST_LOADLIBES
176 ifneq ($(findstring mingw,$(BR2_GNU_BUILD_SUFFIX)),)
182 # The preferred type of libs we build for the target
183 ifeq ($(BR2_PREFER_STATIC_LIB),y)
185 #PREFERRED_LIB_FLAGS:=--disable-shared --enable-static
188 #PREFERRED_LIB_FLAGS:=--disable-static --enable-shared
190 PREFERRED_LIB_FLAGS:=--enable-static --enable-shared
192 ##############################################################
194 # The list of stuff to build for the target toolchain
195 # along with the packages to build for the target.
197 ##############################################################
198 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
199 BASE_TARGETS:=uclibc-configured binutils cross_compiler uclibc-target-utils kernel-headers
205 # Strip off the annoying quoting
206 ARCH:=$(call qstrip,$(BR2_ARCH))
207 ifeq ($(ARCH),xtensa)
208 ARCH:=$(ARCH)_$(call qstrip,$(BR2_xtensa_core_name))
210 WGET:=$(call qstrip,$(BR2_WGET)) $(SPIDER) $(QUIET)
211 SVN_CO:=$(call qstrip,$(BR2_SVN_CO)) $(QUIET)
212 SVN_UP:=$(call qstrip,$(BR2_SVN_UP)) $(QUIET)
213 BZR_CO:=$(call qstrip,$(BR2_BZR_CO)) $(QUIET)
214 BZR_UP:=$(call qstrip,$(BR2_BZR_UP)) $(QUIET)
215 GIT:=$(call qstrip,$(BR2_GIT)) $(QUIET)
216 ZCAT:=$(call qstrip,$(BR2_ZCAT))
217 BZCAT:=$(call qstrip,$(BR2_BZCAT))
218 TAR_OPTIONS=$(call qstrip,$(BR2_TAR_OPTIONS)) -xf
220 ifneq ("$(origin O)", "command line")
223 # other packages might also support Linux-style out of tree builds
224 # with the O=<dir> syntax (E.G. Busybox does). As make automatically
225 # forwards command line variable definitions those packages get very
226 # confused. Fix this by telling make to not do so
230 BASE_DIR := $(shell mkdir -p $(O) && cd $(O) && pwd)
231 $(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
233 TOPDIR_PREFIX:=$(call qstrip,$(BR2_TOPDIR_PREFIX))_
234 TOPDIR_SUFFIX:=_$(call qstrip,$(BR2_TOPDIR_SUFFIX))
235 ifeq ($(TOPDIR_PREFIX),_)
238 ifeq ($(TOPDIR_SUFFIX),_)
242 DL_DIR=$(call qstrip,$(BR2_DL_DIR))
244 DL_DIR:=$(BASE_DIR)/dl
247 BUILD_DIR:=$(BASE_DIR)/$(TOPDIR_PREFIX)build_$(ARCH)$(ARCH_FPU_SUFFIX)$(TOPDIR_SUFFIX)
249 GNU_TARGET_SUFFIX:=-$(call qstrip,$(BR2_GNU_TARGET_SUFFIX))
251 STAGING_DIR:=$(call qstrip,$(BR2_STAGING_DIR))
253 # packages compiled for the host goes here
254 HOST_DIR:=$(BUILD_DIR)/host_dir
256 # stamp (dependency) files go here
257 STAMP_DIR:=$(BUILD_DIR)/stamps
259 BINARIES_DIR:=$(BASE_DIR)/binaries/
260 TARGET_DIR:=$(BUILD_DIR)/target_dir
262 # define values for prepatched source trees for toolchains
263 VENDOR_SITE:=$(call qstrip,$(BR2_VENDOR_SITE))
264 VENDOR_SUFFIX:=$(call qstrip,$(BR2_VENDOR_SUFFIX))
265 VENDOR_BINUTILS_RELEASE:=$(call qstrip,$(BR2_VENDOR_BINUTILS_RELEASE))
266 VENDOR_GCC_RELEASE:=$(call qstrip,$(BR2_VENDOR_GCC_RELEASE))
267 VENDOR_UCLIBC_RELEASE:=$(call qstrip,$(BR2_VENDOR_UCLIBC_RELEASE))
268 VENDOR_GDB_RELEASE:=$(call qstrip,$(BR2_VENDOR_GDB_RELEASE))
269 VENDOR_PATCH_DIR:=$(call qstrip,$(BR2_VENDOR_PATCH_DIR))
271 BR2_DEPENDS_DIR=$(BUILD_DIR)/buildroot-config
273 include toolchain/Makefile.in
274 include package/Makefile.in
276 #############################################################
278 # You should probably leave this stuff alone unless you know
279 # what you are doing.
281 #############################################################
285 # In this section, we need .config
288 # We also need the various per-package makefiles, which also add
289 # each selected package to TARGETS if that package was selected
290 # in the .config file.
291 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
292 # avoid pulling in external toolchain which is broken for toplvl parallel builds
294 include toolchain/dependencies/dependencies.mk
295 include toolchain/binutils/binutils.mk
296 include toolchain/ccache/ccache.mk
297 include toolchain/elf2flt/elf2flt.mk
298 include toolchain/gcc/gcc-uclibc-3.x.mk
299 include toolchain/gcc/gcc-uclibc-4.x.mk
300 include toolchain/gdb/gdb.mk
301 include toolchain/kernel-headers/kernel-headers.mk
302 include toolchain/mklibs/mklibs.mk
303 include toolchain/sstrip/sstrip.mk
304 include toolchain/uClibc/uclibc.mk
306 include toolchain/*/*.mk
309 ifeq ($(BR2_PACKAGE_LINUX),y)
310 TARGETS+=linux26-modules
313 include package/*/*.mk
315 TARGETS+=target-finalize
317 ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
318 TARGETS+=target-purgelocales
321 # target stuff is last so it can override anything else
322 include target/Makefile.in
324 TARGETS+=erase-fakeroots
326 TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
327 TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS) $(BASE_TARGETS))
328 TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))
329 TARGETS_ALL:=$(patsubst %,__real_tgt_%,$(TARGETS))
330 # all targets depend on the crosscompiler and it's prerequisites
331 $(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) %
333 $(BR2_DEPENDS_DIR): .config
336 cp -dpRf $(CONFIG)/buildroot-config $@
338 dirs: $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
339 $(HOST_DIR) $(BR2_DEPENDS_DIR) $(BINARIES_DIR) $(STAMP_DIR)
341 $(BASE_TARGETS): dirs
343 world: dependencies dirs $(BASE_TARGETS) $(TARGETS_ALL)
346 .PHONY: all world dirs clean dirclean distclean source \
347 $(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
348 $(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) \
349 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
350 $(HOST_DIR) $(BR2_DEPENDS_DIR) $(BINARIES_DIR) $(STAMP_DIR)
352 #############################################################
354 # staging and target directories do NOT list these as
355 # dependencies anywhere else
357 #############################################################
358 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR):
362 @mkdir -p $(STAGING_DIR)/bin
363 @mkdir -p $(STAGING_DIR)/lib
364 ifeq ($(BR2_TOOLCHAIN_SYSROOT),y)
365 @mkdir -p $(STAGING_DIR)/usr/lib
367 ifneq ($(BR2_TOOLCHAIN_EXTERNAL),y)
368 @ln -snf . $(STAGING_DIR)/usr
369 @mkdir -p $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)
370 @ln -snf ../lib $(STAGING_DIR)/usr/lib
371 @ln -snf ../lib $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
374 @mkdir -p $(STAGING_DIR)/usr/include
377 mkdir -p $(TARGET_DIR)
378 if ! [ -d "$(TARGET_DIR)/bin" ]; then \
379 if [ -d "$(TARGET_SKELETON)" ]; then \
380 cp -fa $(TARGET_SKELETON)/* $(TARGET_DIR)/; \
382 if [ -d "$(TARGET_SKELETON_PATCH)" ]; then \
383 toolchain/patch-kernel.sh $(TARGET_DIR) $(TARGET_SKELETON_PATCH)/ \*patch\*; \
385 touch $(STAGING_DIR)/.fakeroot.00000; \
387 -find $(TARGET_DIR) -type d -name CVS -print0 -o -name .svn -print0 | xargs -0 rm -rf
388 -find $(TARGET_DIR) -type f -name .empty -print0 | xargs -0 rm -rf
391 $(TARGET_DIR): $(BUILD_DIR)/.root
394 rm -f $(BUILD_DIR)/.fakeroot*
397 ifeq ($(BR2_HAVE_DEVFILES),y)
398 ( scripts/copy.sh $(STAGING_DIR) $(TARGET_DIR) )
400 rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/lib/pkgconfig
401 find $(TARGET_DIR)/lib \( -name '*.a' -o -name '*.la' \) -print0 | xargs -0 rm -f
402 find $(TARGET_DIR)/usr/lib \( -name '*.a' -o -name '*.la' \) -print0 | xargs -0 rm -f
404 ifneq ($(BR2_HAVE_MANPAGES),y)
405 rm -rf $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/man
407 ifneq ($(BR2_HAVE_INFOPAGES),y)
408 rm -rf $(TARGET_DIR)/usr/info $(TARGET_DIR)/usr/share/info
410 find $(TARGET_DIR) -type f -perm +111 | xargs $(STRIPCMD) 2>/dev/null || true
411 $(TARGET_LDCONFIG) -r $(TARGET_DIR) 2>/dev/null
413 ifneq ($(BR2_ROOTFS_POST_BUILD_SCRIPT),"")
414 $(BR2_ROOTFS_POST_BUILD_SCRIPT) $(TARGET_DIR)
417 ifeq ($(BR2_ENABLE_LOCALE_PURGE),y)
418 LOCALE_WHITELIST=$(BUILD_DIR)/locales.nopurge
419 LOCALE_NOPURGE=$(call qstrip,$(BR2_ENABLE_LOCALE_WHITELIST))
422 rm -f $(LOCALE_WHITELIST)
423 for i in $(LOCALE_NOPURGE); do echo $$i >> $(LOCALE_WHITELIST); done
425 for dir in $(wildcard $(addprefix $(TARGET_DIR),/usr/share/locale /usr/share/X11/locale /usr/man /usr/share/man)); \
427 for lang in $$(cd $$dir; ls .|grep -v man); \
429 grep -qx $$lang $(LOCALE_WHITELIST) || rm -rf $$dir/$$lang; \
434 source: $(TARGETS_SOURCE) $(HOST_SOURCE)
437 $(MAKE) SPIDER=--spider source
440 @$(MAKE) -Bs BR2_WGET=$(TOPDIR)/toolchain/wget-show-external-deps.sh \
441 SPIDER=--spider source
443 #############################################################
445 # Cleanup and misc junk
447 #############################################################
448 clean: $(TARGETS_CLEAN)
449 rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) $(BUILD_DIR)/.root $(STAMP_DIR)
451 dirclean: $(TARGETS_DIRCLEAN)
452 rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) $(BUILD_DIR)/.root $(STAMP_DIR)
455 ifeq ($(DL_DIR),$(BASE_DIR)/dl)
458 rm -rf $(TOOL_BUILD_DIR) $(BUILD_DIR) $(BUILD_DIR) $(BINARIES_DIR) \
460 $(MAKE) -C $(CONFIG) clean
463 rm -rf $(BUILD_DIR) $(BUILD_DIR) $(BINARIES_DIR)
466 rm -f buildroot.tar.bz2; \
467 tar -cvf buildroot.tar buildroot; \
468 bzip2 -9 buildroot.tar; \
471 else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
476 # ---------------------------------------------------------------------------
478 HOSTCFLAGS=$(CFLAGS_FOR_BUILD)
482 @mkdir -p $(CONFIG)/buildroot-config
483 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf
484 -@if [ ! -f .config ]; then \
485 cp $(CONFIG_DEFCONFIG) .config; \
489 @mkdir -p $(CONFIG)/buildroot-config
490 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) mconf
491 -@if [ ! -f .config ]; then \
492 cp $(CONFIG_DEFCONFIG) .config; \
496 @mkdir -p $(CONFIG)/buildroot-config
497 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) qconf
498 -@if [ ! -f .config ]; then \
499 cp $(CONFIG_DEFCONFIG) .config; \
502 xconfig: $(CONFIG)/qconf
503 @mkdir -p $(CONFIG)/buildroot-config
504 @if ! KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
505 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
506 $(CONFIG)/qconf $(CONFIG_CONFIG_IN); then \
507 test -f .config.cmd || rm -f .config; \
510 menuconfig: $(CONFIG)/mconf
511 @mkdir -p $(CONFIG)/buildroot-config
512 @if ! KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
513 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
514 $(CONFIG)/mconf $(CONFIG_CONFIG_IN); then \
515 test -f .config.cmd || rm -f .config; \
518 config: $(CONFIG)/conf
519 @mkdir -p $(CONFIG)/buildroot-config
520 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
521 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
522 $(CONFIG)/conf $(CONFIG_CONFIG_IN)
524 oldconfig: $(CONFIG)/conf
525 @mkdir -p $(CONFIG)/buildroot-config
526 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
527 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
528 $(CONFIG)/conf -o $(CONFIG_CONFIG_IN)
530 randconfig: $(CONFIG)/conf
531 @mkdir -p $(CONFIG)/buildroot-config
532 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
533 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
534 $(CONFIG)/conf -r $(CONFIG_CONFIG_IN)
536 allyesconfig: $(CONFIG)/conf
537 cat $(CONFIG_DEFCONFIG) > .config
538 @mkdir -p $(CONFIG)/buildroot-config
539 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
540 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
541 $(CONFIG)/conf -y $(CONFIG_CONFIG_IN)
542 #sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
544 allnoconfig: $(CONFIG)/conf
545 @mkdir -p $(CONFIG)/buildroot-config
546 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
547 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
548 $(CONFIG)/conf -n $(CONFIG_CONFIG_IN)
550 defconfig: $(CONFIG)/conf
551 @mkdir -p $(CONFIG)/buildroot-config
552 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
553 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
554 $(CONFIG)/conf -d $(CONFIG_CONFIG_IN)
556 # check if download URLs are outdated
557 source-check: allyesconfig
558 $(MAKE) _source-check
560 #############################################################
562 # Cleanup and misc junk
564 #############################################################
566 rm -f .config .config.old .config.cmd .tmpconfig.h .lognr.*
567 -$(MAKE) -C $(CONFIG) clean
573 endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
576 rm -f $(BUILD_DIR)/tgt-config.cache
578 %_defconfig: $(CONFIG)/conf
579 cp $(shell find ./target/ -name $@) .config
582 configured: dirs host-sed kernel-headers uclibc-config busybox-config linux26-config
584 prepatch: gcc-patched binutils-patched gdb-patched uclibc-patched
586 cross: $(BASE_TARGETS)
590 @echo ' clean - delete temporary files created by build'
591 @echo ' distclean - delete all non-source files (including .config)'
594 @echo ' all - make world'
596 @echo 'Configuration:'
597 @echo ' menuconfig - interactive curses-based configurator'
598 @echo ' xconfig - interactive Qt-based configurator'
599 @echo ' oldconfig - resolve any unresolved symbols in .config'
600 @echo ' configured - make {uclibc/busybox/linux26}-config'
601 @echo ' saveconfig - save current configuration under local/<project>'
602 @echo ' getconfig - restore saved configuration from local/<project>'
604 @echo 'Miscellaneous:'
605 @echo ' source - download all sources needed for offline-build'
606 @echo ' source-check - check all packages for valid download URLs'
607 @echo ' external-deps - list external packages used'
608 @echo ' flush - flush configuration cache'
610 @echo 'See docs/README and docs/buildroot.html for further details'
614 OUT=buildroot-$$(grep -A2 BR2_VERSION $(CONFIG_CONFIG_IN)|grep default|cut -f2 -d\"); \
615 rm -rf ../$$OUT*; cp -al . ../$$OUT; cd ..; \
616 tar cfz $$OUT.tar.gz --exclude .svn --exclude .git --exclude \*~ $$OUT; \
619 .PHONY: dummy subdirs release distclean clean config oldconfig \
620 menuconfig xconfig tags check test depend defconfig help