build: process variable exports from toplevel.mk only once (fixed)
authorFelix Fietkau <nbd@nbd.name>
Tue, 6 Oct 2020 10:37:51 +0000 (12:37 +0200)
committerZoltan HERPAI <wigyori@uid0.hu>
Mon, 21 Dec 2020 09:17:39 +0000 (10:17 +0100)
These run a lot of expensive shell calls, so redundant calls should be
avoided

Signed-off-by: Felix Fietkau <nbd@nbd.name>
include/toplevel-vars.mk [new file with mode: 0644]
include/toplevel.mk

diff --git a/include/toplevel-vars.mk b/include/toplevel-vars.mk
new file mode 100644 (file)
index 0000000..a77456c
--- /dev/null
@@ -0,0 +1,52 @@
+export OPENWRT_VARS=1
+
+ifeq ($(SDK),1)
+  include $(TOPDIR)/include/version.mk
+else
+  REVISION:=$(shell $(TOPDIR)/scripts/getver.sh)
+  SOURCE_DATE_EPOCH:=$(shell $(TOPDIR)/scripts/get_source_date_epoch.sh)
+endif
+
+HOSTCC ?= $(CC)
+export REVISION
+export SOURCE_DATE_EPOCH
+export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
+export GIT_ASKPASS:=/bin/true
+export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
+export GNU_HOST_NAME:=$(shell $(TOPDIR)/scripts/config.guess)
+export HOST_OS:=$(shell uname)
+export HOST_ARCH:=$(shell uname -m)
+
+# prevent perforce from messing with the patch utility
+unexport P4PORT P4USER P4CONFIG P4CLIENT
+
+# prevent user defaults for quilt from interfering
+unexport QUILT_PATCHES QUILT_PATCH_OPTS
+
+unexport C_INCLUDE_PATH CROSS_COMPILE ARCH
+
+# prevent distro default LPATH from interfering
+unexport LPATH
+
+# make sure that a predefined CFLAGS variable does not disturb packages
+export CFLAGS=
+export LDFLAGS=
+
+empty:=
+space:= $(empty) $(empty)
+path:=$(subst :,$(space),$(PATH))
+path:=$(filter-out .%,$(path))
+path:=$(subst $(space),:,$(path))
+export PATH:=$(path)
+
+unexport TAR_OPTIONS
+
+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
+
+SCAN_COOKIE?=$(shell echo $$$$)
+export SCAN_COOKIE
index 4003b4824182bf7d3f4243e68c3d4da806d4fc76..4df9ec46ca04defd2cb6a388071d3bc3e7f823e9 100644 (file)
@@ -12,67 +12,20 @@ export IS_TTY=$(shell tty -s && echo 1 || echo 0)
 
 include $(TOPDIR)/include/verbose.mk
 
-ifeq ($(SDK),1)
-  include $(TOPDIR)/include/version.mk
-else
-  REVISION:=$(shell $(TOPDIR)/scripts/getver.sh)
-  SOURCE_DATE_EPOCH:=$(shell $(TOPDIR)/scripts/get_source_date_epoch.sh)
-endif
+ifeq ($(OPENWRT_VARS),)
+  include $(TOPDIR)/include/toplevel-vars.mk
 
-HOSTCC ?= $(CC)
-export REVISION
-export SOURCE_DATE_EPOCH
-export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
-export GIT_ASKPASS:=/bin/true
-export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
-export GNU_HOST_NAME:=$(shell $(TOPDIR)/scripts/config.guess)
-export HOST_OS:=$(shell uname)
-export HOST_ARCH:=$(shell uname -m)
-
-ifeq ($(HOST_OS),Darwin)
-  ifneq ($(filter /Applications/Xcode.app/% /Library/Developer/%,$(MAKE)),)
-    $(error Please use a newer version of GNU make. The version shipped by Apple is not supported)
+  ifeq ($(HOST_OS),Darwin)
+    ifneq ($(filter /Applications/Xcode.app/% /Library/Developer/%,$(MAKE)),)
+      $(error Please use a newer version of GNU make. The version shipped by Apple is not supported)
+    endif
   endif
 endif
 
-# prevent perforce from messing with the patch utility
-unexport P4PORT P4USER P4CONFIG P4CLIENT
-
-# prevent user defaults for quilt from interfering
-unexport QUILT_PATCHES QUILT_PATCH_OPTS
-
-unexport C_INCLUDE_PATH CROSS_COMPILE ARCH
-
-# prevent distro default LPATH from interfering
-unexport LPATH
-
-# make sure that a predefined CFLAGS variable does not disturb packages
-export CFLAGS=
-export LDFLAGS=
-
-empty:=
-space:= $(empty) $(empty)
-path:=$(subst :,$(space),$(PATH))
-path:=$(filter-out .%,$(path))
-path:=$(subst $(space),:,$(path))
-export PATH:=$(path)
-
-unexport TAR_OPTIONS
-
-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: staging_dir/host/.prereq-build
 endif
 
-SCAN_COOKIE?=$(shell echo $$$$)
-export SCAN_COOKIE
-
 SUBMAKE:=umask 022; $(SUBMAKE)
 
 ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024;