Merge branch 'master' of git://repo.or.cz/buildroot
[buildroot.git] / Makefile
blob178f601ca774e1046473cb6e32c71c7753e66a29
1 # Makefile for buildroot2
3 # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
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.
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.
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
20 #--------------------------------------------------------------
21 # Just run 'make menuconfig', configure stuff, then run 'make'.
22 # You shouldn't need to mess with anything beyond this point...
23 #--------------------------------------------------------------
24 TOPDIR=./
25 CONFIG_CONFIG_IN=Config.in
26 CONFIG_DEFCONFIG=.defconfig
27 CONFIG=package/config
28 DATE:=$(shell date -u +%Y%m%d)
30 noconfig_targets:=menuconfig config oldconfig randconfig \
31 defconfig allyesconfig allnoconfig release tags \
32 silentoldconfig source-check help
34 # $(shell find . -name *_defconfig |sed 's/.*\///')
36 # Pull in the user's configuration file
37 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
38 ifeq ($(BOARD),)
39 -include $(TOPDIR).config
40 else
41 -include $(TOPDIR)/local/$(BOARD)/$(BOARD).config
42 endif
43 endif
45 ifneq ($(BUILDROOT_DL_DIR),)
46 BR2_DL_DIR:=$(BUILDROOT_DL_DIR)
47 endif
48 ifneq ($(BUILDROOT_LOCAL),)
49 LOCAL:=$(BUILDROOT_LOCAL)
50 else
51 LOCAL:=local
52 endif
54 # To put more focus on warnings, be less verbose as default
55 # Use 'make V=1' to see the full commands
56 ifdef V
57 ifeq ("$(origin V)", "command line")
58 KBUILD_VERBOSE=$(V)
59 endif
60 endif
61 ifndef KBUILD_VERBOSE
62 KBUILD_VERBOSE=0
63 endif
65 ifeq ($(KBUILD_VERBOSE),1)
66 quiet=
68 ifndef VERBOSE
69 VERBOSE=1
70 endif
71 else
72 quiet=quiet_
73 Q=@
74 endif
76 CONFIG_SHELL:=$(shell if [ -x "$$BASH" ]; then echo $$BASH; \
77 else if [ -x /bin/bash ]; then echo /bin/bash; \
78 else echo sh; fi; fi)
80 export CONFIG_SHELL quiet Q KBUILD_VERBOSE VERBOSE
82 ifndef HOSTAR
83 HOSTAR:=ar
84 endif
85 ifndef HOSTAS
86 HOSTAS:=as
87 endif
88 ifndef HOSTCC
89 HOSTCC:=gcc
90 else
91 endif
92 ifndef HOSTCXX
93 HOSTCXX:=g++
94 endif
95 ifndef HOSTFC
96 HOSTFC:=gfortran
97 endif
98 ifndef HOSTCPP
99 HOSTCPP:=cpp
100 endif
101 ifndef HOSTLD
102 HOSTLD:=ld
103 endif
104 ifndef HOSTLN
105 HOSTLN:=ln
106 endif
107 ifndef HOSTNM
108 HOSTNM:=nm
109 endif
110 HOSTAR:=$(shell $(CONFIG_SHELL) -c "which $(HOSTAR)" || type -p $(HOSTAR) || echo ar)
111 HOSTAS:=$(shell $(CONFIG_SHELL) -c "which $(HOSTAS)" || type -p $(HOSTAS) || echo as)
112 HOSTCC:=$(shell $(CONFIG_SHELL) -c "which $(HOSTCC)" || type -p $(HOSTCC) || echo gcc)
113 HOSTCXX:=$(shell $(CONFIG_SHELL) -c "which $(HOSTCXX)" || type -p $(HOSTCXX) || echo g++)
114 HOSTFC:=$(shell $(CONFIG_SHELL) -c "which $(HOSTFC)" || type -p $(HOSTFC) || echo || which g77 || type -p g77 || echo gfortran)
115 HOSTCPP:=$(shell $(CONFIG_SHELL) -c "which $(HOSTCPP)" || type -p $(HOSTCPP) || echo cpp)
116 HOSTLD:=$(shell $(CONFIG_SHELL) -c "which $(HOSTLD)" || type -p $(HOSTLD) || echo ld)
117 HOSTLN:=$(shell $(CONFIG_SHELL) -c "which $(HOSTLN)" || type -p $(HOSTLN) || echo ln)
118 HOSTNM:=$(shell $(CONFIG_SHELL) -c "which $(HOSTNM)" || type -p $(HOSTNM) || echo nm)
119 ifndef CFLAGS_FOR_BUILD
120 CFLAGS_FOR_BUILD:=-g -O2
121 endif
122 ifndef CXXFLAGS_FOR_BUILD
123 CXXFLAGS_FOR_BUILD:=-g -O2
124 endif
125 ifndef FCFLAGS_FOR_BUILD
126 FCFLAGS_FOR_BUILD:=-g -O2
127 endif
128 export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTFC HOSTLD
131 ifeq ($(BR2_HAVE_DOT_CONFIG),y)
133 # cc-option
134 # Usage: cflags-y+=$(call cc-option, -march=winchip-c6, -march=i586)
135 # sets -march=winchip-c6 if supported else falls back to -march=i586
136 # without checking the latter.
137 cc-option=$(shell if $(TARGET_CC) $(TARGET_CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
138 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
140 #############################################################
142 # Hide troublesome environment variables from sub processes
144 #############################################################
145 unexport CROSS_COMPILE
146 unexport ARCH
148 #############################################################
150 # Setup the proper filename extensions for the host
152 ##############################################################
153 ifneq ($(findstring linux,$(BR2_GNU_BUILD_SUFFIX)),)
154 HOST_EXEEXT:=
155 HOST_LIBEXT:=.a
156 HOST_SHREXT:=.so
157 endif
158 ifneq ($(findstring apple,$(BR2_GNU_BUILD_SUFFIX)),)
159 HOST_EXEEXT:=
160 HOST_LIBEXT:=.a
161 HOST_SHREXT:=.dylib
162 endif
163 ifneq ($(findstring cygwin,$(BR2_GNU_BUILD_SUFFIX)),)
164 HOST_EXEEXT:=.exe
165 HOST_LIBEXT:=.lib
166 HOST_SHREXT:=.dll
167 HOST_LOADLIBES="-lcurses -lintl"
168 export HOST_LOADLIBES
169 endif
170 ifneq ($(findstring mingw,$(BR2_GNU_BUILD_SUFFIX)),)
171 HOST_EXEEXT:=.exe
172 HOST_LIBEXT:=.lib
173 HOST_SHREXT:=.dll
174 endif
176 # The preferred type of libs we build for the target
177 ifeq ($(BR2_PREFER_STATIC_LIB),y)
178 LIBTGTEXT=.a
179 #PREFERRED_LIB_FLAGS:=--disable-shared --enable-static
180 else
181 LIBTGTEXT=.so
182 #PREFERRED_LIB_FLAGS:=--disable-static --enable-shared
183 endif
184 PREFERRED_LIB_FLAGS:=--enable-static --enable-shared
186 ##############################################################
188 # The list of stuff to build for the target toolchain
189 # along with the packages to build for the target.
191 ##############################################################
192 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
193 BASE_TARGETS:=uclibc-configured binutils cross_compiler uclibc-target-utils
194 else
195 BASE_TARGETS:=uclibc
196 endif
197 TARGETS:=
199 # setup our paths
200 include project/Makefile.in
202 BR2_DEPENDS_DIR=$(PROJECT_BUILD_DIR)/buildroot-config
204 include toolchain/Makefile.in
205 include package/Makefile.in
207 #############################################################
209 # You should probably leave this stuff alone unless you know
210 # what you are doing.
212 #############################################################
214 all: world
216 # In this section, we need .config
217 include .config.cmd
219 include project/*.mk
221 # We also need the various per-package makefiles, which also add
222 # each selected package to TARGETS if that package was selected
223 # in the .config file.
224 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
225 # avoid pulling in external toolchain which is broken for toplvl parallel builds
226 # Explicit ordering:
227 include toolchain/dependencies/dependencies.mk
228 include toolchain/binutils/binutils.mk
229 include toolchain/ccache/ccache.mk
230 include toolchain/elf2flt/elf2flt.mk
231 include toolchain/gcc/gcc-uclibc-3.x.mk
232 include toolchain/gcc/gcc-uclibc-4.x.mk
233 include toolchain/gdb/gdb.mk
234 include toolchain/kernel-headers/kernel-headers.mk
235 include toolchain/mklibs/mklibs.mk
236 include toolchain/sstrip/sstrip.mk
237 include toolchain/uClibc/uclibc.mk
238 else
239 include toolchain/*/*.mk
240 endif
242 ifeq ($(BR2_PACKAGE_LINUX),y)
243 TARGETS+=linux26-modules
244 endif
246 include package/*/*.mk
248 # target stuff is last so it can override anything else
249 include target/Makefile.in
251 TARGETS+=erase-fakeroots
253 TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
254 TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS) $(BASE_TARGETS))
255 TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))
256 TARGETS_ALL:=$(patsubst %,__real_tgt_%,$(TARGETS))
257 # all targets depend on the crosscompiler and it's prerequisites
258 $(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) % libtool_cluebait
261 BR2_UCLIBC_CONFIG_FOR_BUILDROOT=$(BASE_DIR)/.buildroot.uclibc_config
262 $(BR2_UCLIBC_CONFIG_FOR_BUILDROOT): $(dependencies) $(UCLIBC_DIR)/.config
263 # Create BR2__UCLIBC_SYM=val
264 cat $(UCLIBC_DIR)/.config > $(BR2_UCLIBC_CONFIG_FOR_BUILDROOT)
265 $(SED) '/#/d' -e '/^$$/d' -e 's,\([^=]*\)=\(.*\),BR2__UCLIBC_\1=\2,g' \
266 $(BR2_UCLIBC_CONFIG_FOR_BUILDROOT)
267 touch -c $@
269 ifeq ($(BR2__UCLIBC_HAVE_DOT_CONFIG),)
270 ifeq ($(filter uclibc-menuconfig,$(MAKECMDGOALS)),)
271 ifneq ($(wildcard $(UCLIBC_CONFIG_FILE)),)
272 ifeq ($(findstring host-,$(MAKECMDGOALS)),)
273 include $(BR2_UCLIBC_CONFIG_FOR_BUILDROOT)
274 endif
275 endif
276 endif
277 endif
279 $(BR2_DEPENDS_DIR): .config
280 rm -rf $(BR2_DEPENDS_DIR)
281 $(INSTALL) -d $(@D)
282 cp -dpRf $(CONFIG)/buildroot-config $(BR2_DEPENDS_DIR)
283 touch $@/.done
285 dirs: $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
286 $(BR2_DEPENDS_DIR) \
287 $(BINARIES_DIR) $(PROJECT_BUILD_DIR)
289 $(BASE_TARGETS): dirs
291 world: $(dependencies) dirs target-host-info $(BASE_TARGETS) $(TARGETS_ALL)
294 .PHONY: all world dirs clean dirclean distclean source \
295 $(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
296 $(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) \
297 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
298 $(BR2_DEPENDS_DIR) \
299 $(BINARIES_DIR) $(PROJECT_BUILD_DIR) libtool_cluebait
301 # libtool currently does not play nice with cross-compiling
302 libtool_cluebait:
303 $(Q)find $(STAGING_DIR)/lib* -name "*.la" -exec rm -f {} \;
304 $(Q)find $(STAGING_DIR)/usr/lib* -name "*.la" -exec rm -f {} \;
306 #############################################################
308 # staging and target directories do NOT list these as
309 # dependencies anywhere else
311 #############################################################
312 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) \
313 $(PROJECT_BUILD_DIR) $(BINARIES_DIR):
314 @mkdir -p $@
316 $(STAGING_DIR):
317 @mkdir -p $(STAGING_DIR)/bin
318 @mkdir -p $(STAGING_DIR)/lib
319 ifeq ($(BR2_TOOLCHAIN_SYSROOT),y)
320 @mkdir -p $(STAGING_DIR)/usr/lib
321 else
322 @if test ! -L $(STAGING_DIR)/usr && test -d $(STAGING_DIR)/usr; then \
323 echo "You seem to be coming from a toolchain with sysroot support."; \
324 echo "Reconfiguring without wiping your rootfs will not work, sorry.";\
325 echo "Please 'rm -rf $(STAGING_DIR)'"; \
326 echo "Then run 'make' again."; \
327 echo ""; \
328 exit 1; \
330 ln -snf . $(STAGING_DIR)/usr
331 @mkdir -p $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)
332 ln -snf ../lib $(STAGING_DIR)/usr/lib
333 ln -snf ../lib $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
334 endif
335 @mkdir -p $(STAGING_DIR)/usr/include
337 $(PROJECT_BUILD_DIR)/.root:
338 mkdir -p $(TARGET_DIR)
339 if ! [ -d "$(TARGET_DIR)/bin" ]; then \
340 if [ -d "$(TARGET_SKELETON)" ]; then \
341 cp -fa $(TARGET_SKELETON)/* $(TARGET_DIR)/; \
342 fi; \
343 touch $(STAGING_DIR)/.fakeroot.00000; \
345 -find $(TARGET_DIR) -type d -name CVS | xargs rm -rf
346 -find $(TARGET_DIR) -type d -name .svn | xargs rm -rf
347 -find $(TARGET_DIR) -type d -name .gitignore | xargs rm -rf
348 touch $@
350 $(TARGET_DIR): $(PROJECT_BUILD_DIR)/.root
352 erase-fakeroots:
353 rm -f $(PROJECT_BUILD_DIR)/.fakeroot*
355 source: $(TARGETS_SOURCE) $(HOST_SOURCE)
357 _source-check:
358 $(MAKE) SPIDER=--spider source
360 #############################################################
362 # Cleanup and misc junk
364 #############################################################
365 clean: $(TARGETS_CLEAN)
366 rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) \
367 $(PROJECT_BUILD_DIR)/.root $(PROJECT_BUILD_DIR)/autotools-stamps
369 dirclean: $(TARGETS_DIRCLEAN)
370 rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) \
371 $(PROJECT_BUILD_DIR)/.root $(PROJECT_BUILD_DIR)/autotools-stamps
373 distclean:
374 ifeq ($(DL_DIR),$(BASE_DIR)/dl)
375 rm -rf $(DL_DIR)
376 endif
377 rm -rf $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR) \
378 $(LINUX_KERNEL) $(IMAGE) $(BASE_DIR)/include \
379 .config* .auto.deps
380 $(MAKE) -C $(CONFIG) clean distclean
382 sourceball:
383 rm -rf $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR)
384 set -e; \
385 cd ..; \
386 rm -f buildroot.tar.bz2; \
387 tar -cvf buildroot.tar buildroot; \
388 bzip2 -9 buildroot.tar; \
391 else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
393 all: menuconfig
395 # configuration
396 # ---------------------------------------------------------------------------
398 HOSTCFLAGS=$(CFLAGS_FOR_BUILD)
399 export HOSTCFLAGS
401 $(CONFIG)/conf:
402 @mkdir -p $(CONFIG)/buildroot-config
403 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf
404 -@if [ ! -f .config ]; then \
405 cp $(CONFIG_DEFCONFIG) .config; \
407 $(CONFIG)/mconf:
408 @mkdir -p $(CONFIG)/buildroot-config
409 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf mconf
410 -@if [ ! -f .config ]; then \
411 cp $(CONFIG_DEFCONFIG) .config; \
414 menuconfig: $(CONFIG)/mconf
415 @mkdir -p $(CONFIG)/buildroot-config
416 @if ! KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
417 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
418 $(CONFIG)/mconf $(CONFIG_CONFIG_IN); then \
419 test -f .config.cmd || rm -f .config; \
422 config: $(CONFIG)/conf
423 @mkdir -p $(CONFIG)/buildroot-config
424 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
425 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
426 $(CONFIG)/conf $(CONFIG_CONFIG_IN)
428 oldconfig: $(CONFIG)/conf
429 @mkdir -p $(CONFIG)/buildroot-config
430 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
431 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
432 $(CONFIG)/conf -o $(CONFIG_CONFIG_IN)
434 silentoldconfig: $(CONFIG)/conf
435 @mkdir -p $(CONFIG)/buildroot-config
436 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
437 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
438 $(CONFIG)/conf -s $(CONFIG_CONFIG_IN)
440 randconfig: $(CONFIG)/conf
441 @mkdir -p $(CONFIG)/buildroot-config
442 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
443 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
444 $(CONFIG)/conf -r $(CONFIG_CONFIG_IN)
446 allyesconfig: $(CONFIG)/conf
447 cat $(CONFIG_DEFCONFIG) > .config
448 @mkdir -p $(CONFIG)/buildroot-config
449 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
450 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
451 $(CONFIG)/conf -y $(CONFIG_CONFIG_IN)
452 #sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
454 allnoconfig: $(CONFIG)/conf
455 @mkdir -p $(CONFIG)/buildroot-config
456 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
457 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
458 $(CONFIG)/conf -n $(CONFIG_CONFIG_IN)
460 defconfig: $(CONFIG)/conf
461 @mkdir -p $(CONFIG)/buildroot-config
462 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
463 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
464 $(CONFIG)/conf -d $(CONFIG_CONFIG_IN)
466 # check if download URLs are outdated
467 source-check: allyesconfig
468 $(MAKE) _source-check
470 #############################################################
472 # Cleanup and misc junk
474 #############################################################
475 clean:
476 rm -f .config .config.old .config.cmd .tmpconfig.h
477 -$(MAKE) -C $(CONFIG) clean
479 distclean: clean
480 rm -rf sources/*
482 endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
484 %_defconfig: $(CONFIG)/conf
485 cp $(shell find ./target/ -name $@) .config
486 -@$(MAKE) oldconfig
488 configured: dirs host-sed kernel-headers uclibc-config busybox-config linux26-config
490 cross: $(BASE_TARGETS)
492 help:
493 @echo 'Cleaning:'
494 @echo ' clean - delete temporary files created by build'
495 @echo ' distclean - delete all non-source files (including .config)'
496 @echo
497 @echo 'Build:'
498 @echo ' all - make world'
499 @echo
500 @echo 'Configuration:'
501 @echo ' menuconfig - interactive curses-based configurator'
502 @echo ' oldconfig - resolve any unresolved symbols in .config'
503 @echo ' silentoldconfig - silently resolve any unresolved symbols in .config'
504 @echo
505 @echo 'Miscellaneous:'
506 @echo ' source - download all sources needed for offline-build'
507 @echo ' source-check - check all packages for valid download URLs'
508 @echo
509 @echo 'See docs/README and docs/buildroot.html for further details'
510 @echo
512 .PHONY: dummy subdirs release distclean clean config oldconfig \
513 menuconfig tags check test depend defconfig help