]> Git Repo - buildroot-mgba.git/blob - Makefile
Build $(PROJECT_BUILD_DIR)/autotools-stamps with normal Makefile rules
[buildroot-mgba.git] / Makefile
1 # Makefile for buildroot2
2 #
3 # Copyright (C) 1999-2005 by Erik Andersen <[email protected]>
4 #
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.
9 #
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.
14 #
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
18 #
19
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 +%Y%m%d)
29
30 noconfig_targets:=menuconfig config oldconfig randconfig \
31         defconfig allyesconfig allnoconfig release tags \
32         source-check help
33
34
35 # Use shell variables, if defined
36 ifneq ($(BUILDROOT_LOCAL),)
37 BR2_LOCAL:=$(BUILDROOT_LOCAL)
38 else
39 BR2_LOCAL:=$(TOPDIR)/local
40 endif
41
42 # $(shell find . -name *_defconfig |sed 's/.*\///')
43 # Pull in the user's configuration file
44 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
45 ifeq ($(BOARD),)
46 # if "make BOARD=xyz" command
47 -include .config
48 else
49 # if "make" command
50 -include $(BR2_LOCAL)/$(BOARD)/$(BOARD).config
51 endif
52 endif
53
54 # Override BR2_DL_DIR if shell variable defined
55 ifneq ($(BUILDROOT_DL_DIR),)
56 BR2_DL_DIR:=$(BUILDROOT_DL_DIR)
57 endif
58 LOCAL:=$(BR2_LOCAL)
59
60 # To put more focus on warnings, be less verbose as default
61 # Use 'make V=1' to see the full commands
62 ifdef V
63   ifeq ("$(origin V)", "command line")
64     KBUILD_VERBOSE=$(V)
65   endif
66 endif
67 ifndef KBUILD_VERBOSE
68   KBUILD_VERBOSE=0
69 endif
70
71 ifeq ($(KBUILD_VERBOSE),1)
72   quiet=
73   Q=
74 ifndef VERBOSE
75   VERBOSE=1
76 endif
77 else
78   quiet=quiet_
79   Q=@
80 endif
81
82 CONFIG_SHELL:=$(shell if [ -x "$$BASH" ]; then echo $$BASH; \
83         else if [ -x /bin/bash ]; then echo /bin/bash; \
84         else echo sh; fi; fi)
85
86 export CONFIG_SHELL quiet Q KBUILD_VERBOSE VERBOSE
87
88 ifndef HOSTAR
89 HOSTAR:=ar
90 endif
91 ifndef HOSTAS
92 HOSTAS:=as
93 endif
94 ifndef HOSTCC
95 HOSTCC:=gcc
96 else
97 endif
98 ifndef HOSTCXX
99 HOSTCXX:=g++
100 endif
101 ifndef HOSTFC
102 HOSTFC:=gfortran
103 endif
104 ifndef HOSTCPP
105 HOSTCPP:=cpp
106 endif
107 ifndef HOSTLD
108 HOSTLD:=ld
109 endif
110 ifndef HOSTLN
111 HOSTLN:=ln
112 endif
113 ifndef HOSTNM
114 HOSTNM:=nm
115 endif
116 HOSTAR:=$(shell $(CONFIG_SHELL) -c "which $(HOSTAR)" || type -p $(HOSTAR) || echo ar)
117 HOSTAS:=$(shell $(CONFIG_SHELL) -c "which $(HOSTAS)" || type -p $(HOSTAS) || echo as)
118 HOSTCC:=$(shell $(CONFIG_SHELL) -c "which $(HOSTCC)" || type -p $(HOSTCC) || echo gcc)
119 HOSTCXX:=$(shell $(CONFIG_SHELL) -c "which $(HOSTCXX)" || type -p $(HOSTCXX) || echo g++)
120 HOSTFC:=$(shell $(CONFIG_SHELL) -c "which $(HOSTLD)" || type -p $(HOSTLD) || echo || which g77 || type -p g77 || echo gfortran)
121 HOSTCPP:=$(shell $(CONFIG_SHELL) -c "which $(HOSTCPP)" || type -p $(HOSTCPP) || echo cpp)
122 HOSTLD:=$(shell $(CONFIG_SHELL) -c "which $(HOSTLD)" || type -p $(HOSTLD) || echo ld)
123 HOSTLN:=$(shell $(CONFIG_SHELL) -c "which $(HOSTLN)" || type -p $(HOSTLN) || echo ln)
124 HOSTNM:=$(shell $(CONFIG_SHELL) -c "which $(HOSTNM)" || type -p $(HOSTNM) || echo nm)
125 # ignore version in staging_dir
126 HOST_GLIB_BIN:=`dirname $(shell $(CONFIG_SHELL) -c "(which -a glib-genmarshal; echo /usr/bin/glib-genmarshal)|grep -v $(BR2_STAGING_DIR)|head -n 1")`
127 HOST_GLIB:=$(shell $(CONFIG_SHELL) -c "dirname $(HOST_GLIB_BIN)" || echo /usr)
128
129
130 ifndef CFLAGS_FOR_BUILD
131 CFLAGS_FOR_BUILD:=-g -O2
132 endif
133 ifndef CXXFLAGS_FOR_BUILD
134 CXXFLAGS_FOR_BUILD:=-g -O2
135 endif
136 ifndef FCFLAGS_FOR_BUILD
137 FCFLAGS_FOR_BUILD:=-g -O2
138 endif
139 export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTFC HOSTLD
140
141
142 ifeq ($(BR2_HAVE_DOT_CONFIG),y)
143
144 # cc-option
145 # Usage: cflags-y+=$(call cc-option, -march=winchip-c6, -march=i586)
146 # sets -march=winchip-c6 if supported else falls back to -march=i586
147 # without checking the latter.
148 cc-option=$(shell if $(TARGET_CC) $(TARGET_CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
149         > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
150
151 #############################################################
152 #
153 # Hide troublesome environment variables from sub processes
154 #
155 #############################################################
156 unexport CROSS_COMPILE
157 unexport ARCH
158
159 #############################################################
160 #
161 # Setup the proper filename extensions for the host
162 #
163 ##############################################################
164 ifneq ($(findstring linux,$(BR2_GNU_BUILD_SUFFIX)),)
165 HOST_EXEEXT:=
166 HOST_LIBEXT:=.a
167 HOST_SHREXT:=.so
168 endif
169 ifneq ($(findstring apple,$(BR2_GNU_BUILD_SUFFIX)),)
170 HOST_EXEEXT:=
171 HOST_LIBEXT:=.a
172 HOST_SHREXT:=.dylib
173 endif
174 ifneq ($(findstring cygwin,$(BR2_GNU_BUILD_SUFFIX)),)
175 HOST_EXEEXT:=.exe
176 HOST_LIBEXT:=.lib
177 HOST_SHREXT:=.dll
178 HOST_LOADLIBES="-lcurses -lintl"
179 export HOST_LOADLIBES
180 endif
181 ifneq ($(findstring mingw,$(BR2_GNU_BUILD_SUFFIX)),)
182 HOST_EXEEXT:=.exe
183 HOST_LIBEXT:=.lib
184 HOST_SHREXT:=.dll
185 endif
186
187 # The preferred type of libs we build for the target
188 ifeq ($(BR2_PREFER_STATIC_LIB),y)
189 LIBTGTEXT=.a
190 #PREFERRED_LIB_FLAGS:=--disable-shared --enable-static
191 else
192 LIBTGTEXT=.so
193 #PREFERRED_LIB_FLAGS:=--disable-static --enable-shared
194 endif
195 PREFERRED_LIB_FLAGS:=--enable-static --enable-shared
196
197 ##############################################################
198 #
199 # The list of stuff to build for the target toolchain
200 # along with the packages to build for the target.
201 #
202 ##############################################################
203 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
204 BASE_TARGETS:=uclibc-configured binutils cross_compiler uclibc-target-utils kernel-headers
205 else
206 BASE_TARGETS:=uclibc
207 endif
208 TARGETS:=
209
210 # setup our pathes
211 include project/Makefile.in
212
213 BR2_DEPENDS_DIR=$(PROJECT_BUILD_DIR)/buildroot-config
214
215 include toolchain/Makefile.in
216 include package/Makefile.in
217
218 #############################################################
219 #
220 # You should probably leave this stuff alone unless you know
221 # what you are doing.
222 #
223 #############################################################
224
225 all: world
226
227 # In this section, we need .config
228 include .config.cmd
229
230 include project/*.mk
231
232 # We also need the various per-package makefiles, which also add
233 # each selected package to TARGETS if that package was selected
234 # in the .config file.
235 ifeq ($(BR2_TOOLCHAIN_SOURCE),y)
236 # avoid pulling in external toolchain which is broken for toplvl parallel builds
237 # Explicit ordering:
238 include toolchain/dependencies/dependencies.mk
239 include toolchain/binutils/binutils.mk
240 include toolchain/ccache/ccache.mk
241 include toolchain/elf2flt/elf2flt.mk
242 include toolchain/gcc/gcc-uclibc-3.x.mk
243 include toolchain/gcc/gcc-uclibc-4.x.mk
244 include toolchain/gdb/gdb.mk
245 include toolchain/kernel-headers/kernel-headers.mk
246 include toolchain/mklibs/mklibs.mk
247 include toolchain/sstrip/sstrip.mk
248 include toolchain/uClibc/uclibc.mk
249 else
250 include toolchain/*/*.mk
251 endif
252
253 ifeq ($(BR2_PACKAGE_LINUX),y)
254 TARGETS+=linux26-modules
255 endif
256
257 include package/*/*.mk
258
259 TARGETS+=target-devfiles
260
261 # target stuff is last so it can override anything else
262 include target/Makefile.in
263
264 TARGETS+=erase-fakeroots
265
266 TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
267 TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS) $(BASE_TARGETS))
268 TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))
269 TARGETS_ALL:=$(patsubst %,__real_tgt_%,$(TARGETS))
270 # all targets depend on the crosscompiler and it's prerequisites
271 $(TARGETS_ALL): __real_tgt_%: $(BASE_TARGETS) %
272
273 $(BR2_DEPENDS_DIR): .config
274         rm -rf $@
275         mkdir -p $(@D)
276         cp -dpRf $(CONFIG)/buildroot-config $@
277
278 dirs: $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
279         $(BR2_DEPENDS_DIR) $(BINARIES_DIR) $(PROJECT_BUILD_DIR) \
280         $(PROJECT_BUILD_DIR)/autotools-stamps
281
282 $(BASE_TARGETS): dirs
283
284 world: dependencies dirs target-host-info $(BASE_TARGETS) $(TARGETS_ALL)
285
286
287 .PHONY: all world dirs clean dirclean distclean source \
288         $(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
289         $(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) \
290         $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
291         $(BR2_DEPENDS_DIR) $(BINARIES_DIR) $(PROJECT_BUILD_DIR) \
292         $(PROJECT_BUILD_DIR)/autotools-stamps
293
294 #############################################################
295 #
296 # staging and target directories do NOT list these as
297 # dependencies anywhere else
298 #
299 #############################################################
300 $(DL_DIR) $(TOOL_BUILD_DIR) $(BUILD_DIR) $(PROJECT_BUILD_DIR) \
301         $(PROJECT_BUILD_DIR)/autotools-stamps $(BINARIES_DIR):
302         @mkdir -p $@
303
304 $(STAGING_DIR):
305         @mkdir -p $(STAGING_DIR)/bin
306         @mkdir -p $(STAGING_DIR)/lib
307 ifeq ($(BR2_TOOLCHAIN_SYSROOT),y)
308         @mkdir -p $(STAGING_DIR)/usr/lib
309 else
310 ifneq ($(BR2_TOOLCHAIN_EXTERNAL),y)
311         @ln -snf . $(STAGING_DIR)/usr
312         @mkdir -p $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)
313         @ln -snf ../lib $(STAGING_DIR)/usr/lib
314         @ln -snf ../lib $(STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)/lib
315 endif
316 endif
317         @mkdir -p $(STAGING_DIR)/usr/include
318
319 $(PROJECT_BUILD_DIR)/.root:
320         mkdir -p $(TARGET_DIR)
321         if ! [ -d "$(TARGET_DIR)/bin" ]; then \
322                 if [ -d "$(TARGET_SKELETON)" ]; then \
323                         cp -fa $(TARGET_SKELETON)/* $(TARGET_DIR)/; \
324                 fi; \
325                 touch $(STAGING_DIR)/.fakeroot.00000; \
326         fi
327         -find $(TARGET_DIR) -type d -name CVS -o -name .svn | xargs rm -rf
328         -find $(TARGET_DIR) -type f -name .empty | xargs rm -rf 
329         touch $@
330
331 $(TARGET_DIR): $(PROJECT_BUILD_DIR)/.root
332
333 erase-fakeroots:
334         rm -f $(PROJECT_BUILD_DIR)/.fakeroot*
335
336 target-devfiles:
337 ifeq ($(BR2_HAVE_DEVFILES),y)
338         ( scripts/copy.sh $(STAGING_DIR) $(TARGET_DIR) )
339 else
340         rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/lib/pkgconfig
341         find $(TARGET_DIR)/usr/lib -name '*.a' -delete
342         find $(TARGET_DIR)/lib -name '*.a' -delete
343         find $(TARGET_DIR)/usr/lib -name '*.la' -delete
344         find $(TARGET_DIR)/lib -name '*.la' -delete
345 endif
346
347 source: $(TARGETS_SOURCE) $(HOST_SOURCE)
348
349 _source-check:
350         $(MAKE) SPIDER=--spider source
351
352 external-deps:
353         @$(MAKE) -Bs BR2_WGET=$(TOPDIR)/toolchain/wget-show-external-deps.sh \
354                 SPIDER=--spider source
355
356 #############################################################
357 #
358 # Cleanup and misc junk
359 #
360 #############################################################
361 clean: $(TARGETS_CLEAN)
362         rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) $(PROJECT_BUILD_DIR)/.root $(PROJECT_BUILD_DIR)/autotools-stamps
363
364 dirclean: $(TARGETS_DIRCLEAN)
365         rm -rf $(STAGING_DIR) $(TARGET_DIR) $(IMAGE) $(PROJECT_BUILD_DIR)/.root $(PROJECT_BUILD_DIR)/autotools-stamps
366
367 distclean:
368 ifeq ($(DL_DIR),$(BASE_DIR)/dl)
369         rm -rf $(DL_DIR)
370 endif
371         rm -rf $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR) \
372         $(LINUX_KERNEL) $(BASE_DIR)/include \
373                 .config.cmd
374         $(MAKE) -C $(CONFIG) clean
375
376 sourceball:
377         rm -rf $(BUILD_DIR) $(PROJECT_BUILD_DIR) $(BINARIES_DIR)
378         set -e; \
379         cd ..; \
380         rm -f buildroot.tar.bz2; \
381         tar -cvf buildroot.tar buildroot; \
382         bzip2 -9 buildroot.tar; \
383
384
385 else # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
386
387 all: menuconfig
388
389 # configuration
390 # ---------------------------------------------------------------------------
391
392 HOSTCFLAGS=$(CFLAGS_FOR_BUILD)
393 export HOSTCFLAGS
394
395 $(CONFIG)/conf:
396         @mkdir -p $(CONFIG)/buildroot-config
397         $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf
398         -@if [ ! -f .config ]; then \
399                 cp $(CONFIG_DEFCONFIG) .config; \
400         fi
401 $(CONFIG)/mconf:
402         @mkdir -p $(CONFIG)/buildroot-config
403         $(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf mconf
404         -@if [ ! -f .config ]; then \
405                 cp $(CONFIG_DEFCONFIG) .config; \
406         fi
407
408 menuconfig: $(CONFIG)/mconf
409         @mkdir -p $(CONFIG)/buildroot-config
410         @if ! KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
411                 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
412                 $(CONFIG)/mconf $(CONFIG_CONFIG_IN); then \
413                 test -f .config.cmd || rm -f .config; \
414         fi
415
416 config: $(CONFIG)/conf
417         @mkdir -p $(CONFIG)/buildroot-config
418         @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
419                 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
420                 $(CONFIG)/conf $(CONFIG_CONFIG_IN)
421
422 oldconfig: $(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 -o $(CONFIG_CONFIG_IN)
427
428 randconfig: $(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 -r $(CONFIG_CONFIG_IN)
433
434 allyesconfig: $(CONFIG)/conf
435         cat $(CONFIG_DEFCONFIG) > .config
436         @mkdir -p $(CONFIG)/buildroot-config
437         @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
438                 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
439                 $(CONFIG)/conf -y $(CONFIG_CONFIG_IN)
440         #sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
441
442 allnoconfig: $(CONFIG)/conf
443         @mkdir -p $(CONFIG)/buildroot-config
444         @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
445                 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
446                 $(CONFIG)/conf -n $(CONFIG_CONFIG_IN)
447
448 defconfig: $(CONFIG)/conf
449         @mkdir -p $(CONFIG)/buildroot-config
450         @KCONFIG_AUTOCONFIG=$(CONFIG)/buildroot-config/auto.conf \
451                 KCONFIG_AUTOHEADER=$(CONFIG)/buildroot-config/autoconf.h \
452                 $(CONFIG)/conf -d $(CONFIG_CONFIG_IN)
453
454 # check if download URLs are outdated
455 source-check: allyesconfig
456         $(MAKE) _source-check
457
458 #############################################################
459 #
460 # Cleanup and misc junk
461 #
462 #############################################################
463 clean:
464         rm -f .config .config.old .config.cmd .tmpconfig.h .lognr.*
465         -$(MAKE) -C $(CONFIG) clean
466
467 distclean: clean
468         rm -rf sources/*
469
470 endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
471
472 %_defconfig: $(CONFIG)/conf
473         cp $(shell find ./target/ -name $@) .config
474         -@$(MAKE) oldconfig
475
476 update:
477         cp .config $(BOARD_PATH)/$(BOARD_NAME)_defconfig
478
479 configured: dirs host-sed kernel-headers uclibc-config busybox-config linux26-config
480
481 prepatch:       gcc-patched binutils-patched gdb-patched uclibc-patched
482
483 .lognr.$(PROJECT):
484         @echo "0" > .lognr.$(PROJECT)
485
486 log:    .lognr.$(PROJECT)
487         @expr `cat .lognr.$(PROJECT)` + 1 > .lognr.$(PROJECT)   
488         @echo Creating $(PROJECT)-`cat .lognr.$(PROJECT)`.log
489         @$(MAKE) > $(PROJECT)-`cat .lognr.$(PROJECT)`.log 2>&1
490
491
492 cross: $(BASE_TARGETS)
493
494 help:
495         @echo 'Cleaning:'
496         @echo '  clean                  - delete temporary files created by build'
497         @echo '  distclean              - delete all non-source files (including .config)'
498         @echo
499         @echo 'Build:'
500         @echo '  all                    - make world'
501         @echo
502         @echo 'Configuration:'
503         @echo '  menuconfig             - interactive curses-based configurator'
504         @echo '  oldconfig              - resolve any unresolved symbols in .config'
505         @echo
506         @echo 'Miscellaneous:'
507         @echo '  source                 - download all sources needed for offline-build'
508         @echo '  source-check           - check all packages for valid download URLs'
509         @echo '  external-deps          - list external packages used'
510         @echo
511         @echo 'See docs/README and docs/buildroot.html for further details'
512         @echo
513
514 .PHONY: dummy subdirs release distclean clean config oldconfig \
515         menuconfig tags check test depend defconfig help
516
This page took 0.063346 seconds and 4 git commands to generate.