target/sdk: use .config instead of unconditionally enabling all build dirs
[openwrt.git] / include / toplevel.mk
index 4bbc58e..10b8104 100644 (file)
@@ -1,14 +1,16 @@
 # Makefile for OpenWrt
 #
-# Copyright (C) 2007-2011 OpenWrt.org
+# Copyright (C) 2007-2012 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
 #
 
-RELEASE:=Attitude Adjustment
+RELEASE:=Barrier Breaker
 PREP_MK= OPENWRT_BUILD= QUIET=0
 
+export IS_TTY=$(shell tty -s && echo 1 || echo 0)
+
 include $(TOPDIR)/include/verbose.mk
 
 ifeq ($(SDK),1)
@@ -22,7 +24,6 @@ OPENWRTVERSION:=$(RELEASE)$(if $(REVISION), ($(REVISION)))
 export RELEASE
 export REVISION
 export OPENWRTVERSION
-export IS_TTY=$(shell tty -s && echo 1 || echo 0)
 export LD_LIBRARY_PATH:=$(subst ::,:,$(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):)$(STAGING_DIR_HOST)/lib)
 export DYLD_LIBRARY_PATH:=$(subst ::,:,$(if $(DYLD_LIBRARY_PATH),$(DYLD_LIBRARY_PATH):)$(STAGING_DIR_HOST)/lib)
 export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
@@ -42,6 +43,13 @@ unexport LPATH
 # make sure that a predefined CFLAGS variable does not disturb packages
 export CFLAGS=
 
+ifneq ($(shell $(HOSTCC) 2>&1 | grep clang),)
+  export HOSTCC_REAL?=$(HOSTCC)
+  export HOSTCC_WRAPPER:=$(TOPDIR)/scripts/clang-gcc-wrapper
+else
+  export HOSTCC_WRAPPER:=$(HOSTCC)
+endif
+
 ifeq ($(FORCE),)
   .config scripts/config/conf scripts/config/mconf: tmp/.prereq-build
 endif
@@ -51,6 +59,8 @@ export SCAN_COOKIE
 
 SUBMAKE:=umask 022; $(SUBMAKE)
 
+ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024;
+
 prepare-mk: FORCE ;
 
 prepare-tmpinfo: FORCE
@@ -71,12 +81,12 @@ prepare-tmpinfo: FORCE
        fi
 
 scripts/config/mconf:
-       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config all CC="$(HOSTCC)"
+       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config all CC="$(HOSTCC_WRAPPER)"
 
 $(eval $(call rdep,scripts/config,scripts/config/mconf))
 
 scripts/config/conf:
-       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config conf CC="$(HOSTCC)"
+       @$(_SINGLE)$(SUBMAKE) -s -C scripts/config conf CC="$(HOSTCC_WRAPPER)"
 
 config: scripts/config/conf prepare-tmpinfo FORCE
        $< Config.in
@@ -86,10 +96,16 @@ config-clean: FORCE
 
 defconfig: scripts/config/conf prepare-tmpinfo FORCE
        touch .config
-       $< -D .config Config.in
+       @if [ -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
+       $< --defconfig=.config Config.in
+
+confdefault-y=allyes
+confdefault-m=allmod
+confdefault-n=allno
+confdefault:=$(confdefault-$(CONFDEFAULT))
 
 oldconfig: scripts/config/conf prepare-tmpinfo FORCE
-       $< -$(if $(CONFDEFAULT),$(CONFDEFAULT),o) Config.in
+       $< --$(if $(confdefault),$(confdefault),old)config Config.in
 
 menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
        if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
@@ -140,16 +156,27 @@ prereq:: prepare-tmpinfo .config
        @+$(MAKE) -r -s tmp/.prereq-build $(PREP_MK)
        @+$(NO_TRACE_MAKE) -r -s $@
 
+ifeq ($(SDK),1)
+
+%::
+       @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
+       @./scripts/config/conf --defconfig=.config Config.in
+       @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
+
+else
+
 %::
        @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
        @( \
                cp .config tmp/.config; \
-               ./scripts/config/conf -tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
+               ./scripts/config/conf --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
                if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
-                       echo "WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!"; \
+                       printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
                fi \
        )
-       @+$(SUBMAKE) -r $@
+       @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
+
+endif
 
 help:
        cat README