do not rebuild everything if V= changes
[buildroot.git] / Makefile
blob721b6c59b5f5450ad50381fb0bdc097da70b27df
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 BR2_LIBC_NAME:=$(strip ",,$(BR2_LIBC_NAME))
189 ##############################################################
191 # The list of stuff to build for the target toolchain
192 # along with the packages to build for the target.
194 ##############################################################
195 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
196 BASE_TARGETS:=libc-configured binutils cross_compiler libc_target
197 else
198 BASE_TARGETS:=libc
199 endif
200 TARGETS:=
202 # setup our paths
203 include project/Makefile.in
205 BR2_DEPENDS_DIR=$(PROJECT_BUILD_DIR)/buildroot-config
207 include toolchain/Makefile.in
208 include package/Makefile.in
210 #############################################################
212 # You should probably leave this stuff alone unless you know
213 # what you are doing.
215 #############################################################
217 all: world
219 # In this section, we need .config
220 include .config.cmd
222 include project/*.mk
224 # We also need the various per-package makefiles, which also add
225 # each selected package to TARGETS if that package was selected
226 # in the .config file.
227 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
228 # avoid pulling in external toolchain which is broken for toplvl parallel builds
229 # Explicit ordering:
230 include toolchain/dependencies/dependencies.mk
231 include toolchain/binutils/binutils.mk
232 include toolchain/ccache/ccache.mk
233 include toolchain/elf2flt/elf2flt.mk
234 ifeq ($(BR2_LIBC_FLAVOUR_uclibc),y)
235 include toolchain/gcc/gcc-uclibc-3.x.mk
236 include toolchain/gcc/gcc-uclibc-4.x.mk
237 else
238 include toolchain/gcc/gcc-$(BR2_LIBC_NAME).mk
239 endif
240 include toolchain/gdb/gdb.mk
241 include toolchain/kernel-headers/kernel-headers.mk
242 include toolchain/mklibs/mklibs.mk
243 include toolchain/sstrip/sstrip.mk
244 ifeq ($(BR2_LIBC_FLAVOUR_uclibc),y)
245 include toolchain/uClibc/uclibc.mk
246 else
247 include toolchain/$(BR2_LIBC_NAME)/$(BR2_LIBC_NAME).mk
248 endif
249 else
250 include toolchain/*/*.mk
251 endif
253 ifeq ($(BR2_PACKAGE_LINUX),y)
254 TARGETS+=linux26-modules
255 endif
257 include package/*/*.mk
259 # target stuff is last so it can override anything else
260 include target/Makefile.in
262 TARGETS+=erase-fakeroots
264 TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
265 TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS) $(BASE_TARGETS))
266 TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))
267 TARGETS_ALL:=$(patsubst %,__real_tgt_%,$(TARGETS))
268 # all targets depend on the crosscompiler and it's prerequisites
269 $(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) % libtool_cluebait
271 $(BR2_DEPENDS_DIR): .config
272 rm -rf $(BR2_DEPENDS_DIR)
273 $(INSTALL) -d $(@D)
274 cp -dpRf $(CONFIG)/buildroot-config $(BR2_DEPENDS_DIR)
275 touch $@/.done
277 dirs: $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
278 $(BR2_DEPENDS_DIR) \
279 $(BINARIES_DIR) $(PROJECT_BUILD_DIR)
281 $(BASE_TARGETS): | dirs
283 world: $(dependencies) dirs target-host-info $(BASE_TARGETS) $(TARGETS_ALL)
286 .PHONY: all world dirs clean dirclean distclean source \
287 $(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
288 $(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) \
289 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
290 $(BR2_DEPENDS_DIR) \
291 $(BINARIES_DIR) $(PROJECT_BUILD_DIR) libtool_cluebait
293 # libtool currently does not play nice with cross-compiling
294 libtool_cluebait:
295 $(Q)find $(STAGING_DIR)/lib* -name "*.la" -exec rm -f {} \;
296 $(Q)find $(STAGING_DIR)/usr/lib* -name "*.la" -exec rm -f {} \;
298 #############################################################
300 # staging and target directories do NOT list these as
301 # dependencies anywhere else
303 #############################################################
304 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) \
305 $(PROJECT_BUILD_DIR) $(BINARIES_DIR):
306 @mkdir -p $@
308 $(STAGING_DIR):
309 @mkdir -p $(STAGING_DIR)/bin
310 @mkdir -p $(STAGING_DIR)/lib
311 ifeq ($(BR2_TOOLCHAIN_SYSROOT),y)
312 @mkdir -p $(STAGING_DIR)/usr/lib
313 else
314 @if test ! -L $(STAGING_DIR)/usr && test -d $(STAGING_DIR)/usr; then \
315 echo "You seem to be coming from a toolchain with sysroot support."; \
316 echo "Reconfiguring without wiping your rootfs will not work, sorry.";\
317 echo "Please 'rm -rf $(STAGING_DIR)'"; \
318 echo "Then run 'make' again."; \
319 echo ""; \
320 exit 1; \
322 ln -snf . $(STAGING_DIR)/usr
323 @mkdir -p $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)
324 ln -snf ../lib $(STAGING_DIR)/usr/lib
325 ln -snf ../lib $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
326 endif
327 @mkdir -p $(STAGING_DIR)/usr/include
329 $(PROJECT_BUILD_DIR)/.root:
330 mkdir -p $(TARGET_DIR)
331 if ! [ -d "$(TARGET_DIR)/bin" ]; then \
332 if [ -d "$(TARGET_SKELETON)" ]; then \
333 cp -fa $(TARGET_SKELETON)/* $(TARGET_DIR)/; \
334 fi; \
335 touch $(STAGING_DIR)/.fakeroot.00000; \
337 -find $(TARGET_DIR) -type d -name CVS | xargs rm -rf
338 -find $(TARGET_DIR) -type d -name .svn | xargs rm -rf
339 -find $(TARGET_DIR) -type d -name .gitignore | xargs rm -rf
340 touch $@
342 $(TARGET_DIR): $(PROJECT_BUILD_DIR)/.root
344 erase-fakeroots:
345 rm -f $(PROJECT_BUILD_DIR)/.fakeroot*
347 source: $(TARGETS_SOURCE) $(HOST_SOURCE)
349 _source-check:
350 $(MAKE) SPIDER=--spider source
352 #############################################################
354 # Cleanup and misc junk
356 #############################################################
357 clean: $(TARGETS_CLEAN)
358 rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) \
359 $(BR2_UCLIBC_CONFIG_FOR_BUILDROOT) $(dependencies) \
360 $(PROJECT_BUILD_DIR)/.root $(PROJECT_BUILD_DIR)/autotools-stamps
362 dirclean: $(TARGETS_DIRCLEAN) clean
364 distclean:
365 ifeq ($(DL_DIR),$(BASE_DIR)/dl)
366 rm -rf $(DL_DIR)
367 endif
368 rm -rf $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR) \
369 $(LINUX_KERNEL) $(IMAGE) $(BASE_DIR)/include \
370 .config* .auto.deps $(dependencies) \
371 $(BR2_UCLIBC_CONFIG_FOR_BUILDROOT)
372 $(MAKE) -C $(CONFIG) clean distclean
374 sourceball:
375 rm -rf $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR)
376 set -e; \
377 cd ..; \
378 rm -f buildroot.tar.bz2; \
379 tar -cvf buildroot.tar buildroot; \
380 bzip2 -9 buildroot.tar; \
383 else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
385 all: menuconfig
387 # configuration
388 # ---------------------------------------------------------------------------
390 HOSTCFLAGS=$(CFLAGS_FOR_BUILD)
391 export HOSTCFLAGS
393 $(CONFIG)/conf:
394 @mkdir -p $(CONFIG)/buildroot-config
395 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf
396 -@if [ ! -f .config ]; then \
397 cp $(CONFIG_DEFCONFIG) .config; \
399 $(CONFIG)/mconf:
400 @mkdir -p $(CONFIG)/buildroot-config
401 $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf mconf
402 -@if [ ! -f .config ]; then \
403 cp $(CONFIG_DEFCONFIG) .config; \
406 menuconfig: $(CONFIG)/mconf
407 @mkdir -p $(CONFIG)/buildroot-config
408 @if ! KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
409 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
410 $(CONFIG)/mconf $(CONFIG_CONFIG_IN); then \
411 test -f .config.cmd || rm -f .config; \
414 config: $(CONFIG)/conf
415 @mkdir -p $(CONFIG)/buildroot-config
416 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
417 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
418 $(CONFIG)/conf $(CONFIG_CONFIG_IN)
420 oldconfig: $(CONFIG)/conf
421 @mkdir -p $(CONFIG)/buildroot-config
422 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
423 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
424 $(CONFIG)/conf -o $(CONFIG_CONFIG_IN)
426 silentoldconfig: $(CONFIG)/conf
427 @mkdir -p $(CONFIG)/buildroot-config
428 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
429 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
430 $(CONFIG)/conf -s $(CONFIG_CONFIG_IN)
432 randconfig: $(CONFIG)/conf
433 @mkdir -p $(CONFIG)/buildroot-config
434 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
435 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
436 $(CONFIG)/conf -r $(CONFIG_CONFIG_IN)
438 allyesconfig: $(CONFIG)/conf
439 cat $(CONFIG_DEFCONFIG) > .config
440 @mkdir -p $(CONFIG)/buildroot-config
441 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
442 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
443 $(CONFIG)/conf -y $(CONFIG_CONFIG_IN)
444 #sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
446 allnoconfig: $(CONFIG)/conf
447 @mkdir -p $(CONFIG)/buildroot-config
448 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
449 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
450 $(CONFIG)/conf -n $(CONFIG_CONFIG_IN)
452 defconfig: $(CONFIG)/conf
453 @mkdir -p $(CONFIG)/buildroot-config
454 @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
455 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
456 $(CONFIG)/conf -d $(CONFIG_CONFIG_IN)
458 # check if download URLs are outdated
459 source-check: allyesconfig
460 $(MAKE) _source-check
462 #############################################################
464 # Cleanup and misc junk
466 #############################################################
467 clean:
468 rm -f .config .config.old .config.cmd .tmpconfig.h
469 -$(MAKE) -C $(CONFIG) clean
471 distclean: clean
472 rm -rf sources/*
474 endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
476 %_defconfig: $(CONFIG)/conf
477 cp $(shell find ./target/ -name $@) .config
478 -@$(MAKE) oldconfig
480 configured: dirs host-sed kernel-headers libc-config busybox-config linux26-config
482 cross: $(BASE_TARGETS)
484 help:
485 @echo 'Cleaning:'
486 @echo ' clean - delete temporary files created by build'
487 @echo ' distclean - delete all non-source files (including .config)'
488 @echo
489 @echo 'Build:'
490 @echo ' all - make world'
491 @echo
492 @echo 'Configuration:'
493 @echo ' menuconfig - interactive curses-based configurator'
494 @echo ' oldconfig - resolve any unresolved symbols in .config'
495 @echo ' silentoldconfig - silently resolve any unresolved symbols in .config'
496 @echo
497 @echo 'Miscellaneous:'
498 @echo ' source - download all sources needed for offline-build'
499 @echo ' source-check - check all packages for valid download URLs'
500 @echo
501 @echo 'See docs/README and docs/buildroot.html for further details'
502 @echo
504 .PHONY: dummy subdirs release distclean clean config oldconfig \
505 menuconfig tags check test depend defconfig help