[OpenWrt-Devel] [PATCH] Add option to read an alternative config file
Toan Pham
tpham3783 at gmail.com
Thu Mar 3 15:26:11 EST 2016
Presently, Openwrt reads default config filename ".config" or from
$(HOME)/.openwrt/defconfig if it exists. This patch will allow users to
specify an alternative config file (using relative or absolute path) from
the command line. ie)
make TARGET_CONFIG=/src/build/config/boardXYZ.config
This patch is introduced because in the future, i would like to be able to
treat OpenWrt SDK as a blackbox. Users can build multiple targets without
polluting the SDE environment by being able to specify an input config file
and an output target directory. For example:
make TARGET_CONFIG=/tmp/test.config TARGET_OUTPUT_DIR=/tmp/testboard
where, TARGET_OUTPUT_DIR would contain the output results like: bin,
build_dir, staging_dir
Another advantage of the above example is that it allows building on tmpfs,
which would sufficiently speed up build time.
Please review and comment! thanks!
Signed-off-by: Toan Pham <tpham3783 at gmail.com>
---
diff --git a/Makefile b/Makefile
index 8ba2bfc..452bef2 100644
--- a/Makefile
+++ b/Makefile
@@ -62,7 +62,7 @@ $(BUILD_DIR)/.prepared: Makefile
@mkdir -p $$(dirname $@)
@touch $@
-tmp/.prereq_packages: .config
+tmp/.prereq_packages: $(TARGET_CONFIG)
unset ERROR; \
for package in $(sort $(prereq-y) $(prereq-m)); do \
$(_SINGLE)$(NO_TRACE_MAKE) -s -r -C package/$$package prereq ||
ERROR=1; \
@@ -83,7 +83,7 @@ prereq: $(target/stamp-prereq) tmp/.prereq_packages
exit 1; \
fi
-prepare: .config $(tools/stamp-install) $(toolchain/stamp-install)
+prepare: $(TARGET_CONFIG) $(tools/stamp-install) $(toolchain/stamp-install)
world: prepare $(target/stamp-compile) $(package/stamp-compile)
$(package/stamp-install) $(target/stamp-install) FORCE
$(_SINGLE)$(SUBMAKE) -r package/index
diff --git a/include/kernel-build.mk b/include/kernel-build.mk
index a52c90d..f732d03 100644
--- a/include/kernel-build.mk
+++ b/include/kernel-build.mk
@@ -102,7 +102,7 @@ define BuildKernel
echo; \
) > $$@
- $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST)
$(TOPDIR)/.config
+ $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST)
$(TARGET_CONFIG)
$(Kernel/Configure)
touch $$@
diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index 406fd46..3cfcdb3 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -107,11 +107,11 @@ endef
define Kernel/Configure/Default
$(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
# copy CONFIG_KERNEL_* settings over to .config.target
- awk
'/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}'
$(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
+ awk
'/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}'
$(TARGET_CONFIG) >> $(LINUX_DIR)/.config.target
echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >>
$(LINUX_DIR)/.config.target
echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> $(LINUX_DIR)/.config.target
- $(SCRIPT_DIR)/metadata.pl kconfig $(TMP_DIR)/.packageinfo
$(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
+ $(SCRIPT_DIR)/metadata.pl kconfig $(TMP_DIR)/.packageinfo
$(TARGET_CONFIG) $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
$(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target
/dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config.set
$(call Kernel/SetNoInitramfs)
rm -rf $(KERNEL_BUILD_DIR)/modules
diff --git a/include/toplevel.mk b/include/toplevel.mk
index 9709302..2d45c9c 100644
--- a/include/toplevel.mk
+++ b/include/toplevel.mk
@@ -58,7 +58,7 @@ else
endif
ifeq ($(FORCE),)
- .config scripts/config/conf scripts/config/mconf:
staging_dir/host/.prereq-build
+ $(TARGET_CONFIG) scripts/config/conf scripts/config/mconf:
staging_dir/host/.prereq-build
endif
SCAN_COOKIE?=$(shell echo $$$$)
@@ -90,10 +90,10 @@ prepare-tmpinfo: FORCE
./scripts/metadata.pl package_subdirs tmp/.packageinfo >
tmp/.packagesubdirs || { rm -f tmp/.packagesubdirs; false; }
touch $(TOPDIR)/tmp/.build
-.config: ./scripts/config/conf $(if
$(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
- @+if [ \! -e .config ] || ! grep CONFIG_HAVE_DOT_CONFIG .config
>/dev/null; then \
- [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig
.config; \
- $(_SINGLE)$(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
+$(TARGET_CONFIG): ./scripts/config/conf $(if
$(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
+ @+if [ \! -e $(TARGET_CONFIG) ] || ! grep CONFIG_HAVE_DOT_CONFIG
$(TARGET_CONFIG) >/dev/null; then \
+ [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig
$(TARGET_CONFIG); \
+ $(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
fi
scripts/config/mconf:
@@ -105,15 +105,16 @@ scripts/config/conf:
@$(_SINGLE)$(SUBMAKE) -s -C scripts/config conf CC="$(HOSTCC_WRAPPER)"
config: scripts/config/conf prepare-tmpinfo FORCE
- $< Config.in
+ KCONFIG_CONFIG=$(TARGET_CONFIG) $< Config.in
config-clean: FORCE
$(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
defconfig: scripts/config/conf prepare-tmpinfo FORCE
- touch .config
- @if [ -e $(HOME)/.openwrt/defconfig ]; then cp
$(HOME)/.openwrt/defconfig .config; fi
- $< --defconfig=.config Config.in
+ touch $(TARGET_CONFIG)
+ @if [ -e $(HOME)/.openwrt/defconfig ]; then cp
$(HOME)/.openwrt/defconfig $(TARGET_CONFIG); fi
+ $< --defconfig=$(TARGET_CONFIG) Config.in
+ [ -f .config ] && mv .config $(TARGET_CONFIG)
confdefault-y=allyes
confdefault-m=allmod
@@ -121,15 +122,15 @@ confdefault-n=allno
confdefault:=$(confdefault-$(CONFDEFAULT))
oldconfig: scripts/config/conf prepare-tmpinfo FORCE
- $< --$(if $(confdefault),$(confdefault),old)config Config.in
+ KCONFIG_CONFIG=$(TARGET_CONFIG) $< --$(if
$(confdefault),$(confdefault),old)config Config.in
menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
- if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
+ if [ \! -e $(TARGET_CONFIG) -a -e $(HOME)/.openwrt/defconfig ]; then \
cp $(HOME)/.openwrt/defconfig .config; \
fi
- $< Config.in
+ KCONFIG_CONFIG=$(TARGET_CONFIG) $< Config.in
-prepare_kernel_conf: .config FORCE
+prepare_kernel_conf: $(TARGET_CONFIG) FORCE
ifeq ($(wildcard staging_dir/host/bin/quilt),)
prepare_kernel_conf:
@@ -142,7 +143,7 @@ kernel_oldconfig: prepare_kernel_conf
$(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
kernel_menuconfig: prepare_kernel_conf
- $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
+ $(MAKE) -C target/linux menuconfig
kernel_nconfig: prepare_kernel_conf
$(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
@@ -165,16 +166,16 @@ staging_dir/host/.prereq-build: include/
prereq-build.mk
printdb: FORCE
@$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
-download: .config FORCE
+download: $(TARGET_CONFIG) FORCE
@+$(SUBMAKE) tools/download
@+$(SUBMAKE) toolchain/download
@+$(SUBMAKE) package/download
@+$(SUBMAKE) target/download
-clean dirclean: .config
+clean dirclean: $(TARGET_CONFIG)
@+$(SUBMAKE) -r $@
-prereq:: prepare-tmpinfo .config
+prereq:: prepare-tmpinfo $(TARGET_CONFIG)
@+$(NO_TRACE_MAKE) -r -s $@
WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter
-j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
@@ -183,7 +184,7 @@ ifeq ($(SDK),1)
%::
@+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
- @./scripts/config/conf --defconfig=.config Config.in
+ @./scripts/config/conf --defconfig=$(TARGET_CONFIG) Config.in
@+$(ULIMIT_FIX) $(SUBMAKE) -r $@
else
@@ -191,9 +192,9 @@ else
%::
@+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
@( \
- cp .config tmp/.config; \
+ cp $(TARGET_CONFIG) tmp/.config; \
./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 \
+ if ./scripts/kconfig.pl '>' $(TARGET_CONFIG) tmp/.config | grep -q
CONFIG; then \
printf "$(_R)WARNING: your configuration is out of sync.
Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
fi \
)
@@ -232,7 +233,7 @@ distclean:
@$(_SINGLE)$(SUBMAKE) -C scripts/config clean
ifeq ($(findstring v,$(DEBUG)),)
- .SILENT: symlinkclean clean dirclean distclean config-clean download
help tmpinfo-clean .config scripts/config/mconf scripts/config/conf
menuconfig staging_dir/host/.prereq-build tmp/.prereq-package
prepare-tmpinfo
+ .SILENT: symlinkclean clean dirclean distclean config-clean download
help tmpinfo-clean $(TARGET_CONFIG) scripts/config/mconf
scripts/config/conf menuconfig staging_dir/host/.prereq-build
tmp/.prereq-package prepare-tmpinfo
endif
.PHONY: help FORCE
.NOTPARALLEL:
diff --git a/package/Makefile b/package/Makefile
index 1a78fde..acc2307 100644
--- a/package/Makefile
+++ b/package/Makefile
@@ -184,7 +184,8 @@ $(curdir)/preconfig:
$(curdir)/flags-install:= -j1
-$(eval $(call stampfile,$(curdir),package,prereq,.config))
+#$(eval $(call stampfile,$(curdir),package,prereq,.config))
+$(eval $(call stampfile,$(curdir),package,prereq,$(TARGET_CONFIG)))
$(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build))
$(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build))
$(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build))
diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile
index 6a55d56..c31b857 100644
--- a/package/utils/busybox/Makefile
+++ b/package/utils/busybox/Makefile
@@ -27,7 +27,7 @@ PKG_LICENSE_FILES:=LICENSE archival/libarchive/bz/LICENSE
include $(INCLUDE_DIR)/package.mk
ifeq ($(DUMP),)
- STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell $(SH_FUNC) grep
'^CONFIG_BUSYBOX_' $(TOPDIR)/.config | md5s)
+ STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell $(SH_FUNC) grep
'^CONFIG_BUSYBOX_' $(TARGET_CONFIG) | md5s)
endif
ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
@@ -62,7 +62,7 @@ export KCONFIG_NOTIMESTAMP=1
define Build/Configure
rm -f $(PKG_BUILD_DIR)/.configured*
- grep 'CONFIG_BUSYBOX_$(BUSYBOX_SYM)' $(TOPDIR)/.config | sed -e
"s,\\(# \)\\?CONFIG_BUSYBOX_$(BUSYBOX_SYM)_\\(.*\\),\\1CONFIG_\\2,g" >
$(PKG_BUILD_DIR)/.config
+ grep 'CONFIG_BUSYBOX_$(BUSYBOX_SYM)' $(TARGET_CONFIG) | sed -e "s,\\(#
\)\\?CONFIG_BUSYBOX_$(BUSYBOX_SYM)_\\(.*\\),\\1CONFIG_\\2,g" >
$(PKG_BUILD_DIR)/.config
yes 'n' | $(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CROSS_COMPILE="$(TARGET_CROSS)" \
diff --git a/rules.mk b/rules.mk
index 22807da..691b393 100644
--- a/rules.mk
+++ b/rules.mk
@@ -8,8 +8,16 @@
ifneq ($(__rules_inc),1)
__rules_inc=1
+TARGET_CONFIG?=$(TOPDIR)/.config
+
+ifneq ("$(wildcard $(TARGET_CONFIG))","")
+ override TARGET_CONFIG:=$(TARGET_CONFIG)
+else
+ override TARGET_CONFIG:=$(TOPDIR)/$(TARGET_CONFIG)
+endif
+
ifeq ($(DUMP),)
- -include $(TOPDIR)/.config
+ -include $(TARGET_CONFIG)
endif
include $(TOPDIR)/include/debug.mk
include $(TOPDIR)/include/verbose.mk
diff --git a/target/Makefile b/target/Makefile
index cb68454..c9c8e33 100644
--- a/target/Makefile
+++ b/target/Makefile
@@ -12,7 +12,7 @@ $(curdir)/builddirs-install:=linux $(if
$(CONFIG_SDK),sdk) $(if $(CONFIG_IB),ima
$(curdir)/imagebuilder/install:=$(curdir)/linux/install
-$(eval $(call stampfile,$(curdir),target,prereq,.config))
+$(eval $(call stampfile,$(curdir),target,prereq,$(TARGET_CONFIG)))
$(eval $(call stampfile,$(curdir),target,compile,$(TMP_DIR)/.build))
$(eval $(call stampfile,$(curdir),target,install,$(TMP_DIR)/.build))
diff --git a/target/linux/Makefile b/target/linux/Makefile
index f7bbdff..95cd417 100644
--- a/target/linux/Makefile
+++ b/target/linux/Makefile
@@ -10,4 +10,4 @@ include $(INCLUDE_DIR)/target.mk
export TARGET_BUILD=1
prereq clean download prepare compile install menuconfig nconfig oldconfig
update refresh: FORCE
- @+$(NO_TRACE_MAKE) -C $(BOARD) $@
+ @+$(NO_TRACE_MAKE) -C $(BOARD) $@
diff --git a/target/sdk/Makefile b/target/sdk/Makefile
index 857a6b7..7ef69db 100644
--- a/target/sdk/Makefile
+++ b/target/sdk/Makefile
@@ -92,11 +92,11 @@ $(BIN_DIR)/$(SDK_NAME).tar.bz2: clean
rm -rf \
$(SDK_BUILD_DIR)/target/linux/*/files* \
$(SDK_BUILD_DIR)/target/linux/*/patches*
- ./convert-config.pl $(TOPDIR)/.config >
$(SDK_BUILD_DIR)/Config-build.in
+ ./convert-config.pl $(TARGET_CONFIG) > $(SDK_BUILD_DIR)/Config-build.in
$(CP) -L \
$(TOPDIR)/LICENSE \
$(TOPDIR)/rules.mk \
- $(TOPDIR)/.config \
+ $(TARGET_CONFIG) \
./files/Config.in \
./files/Makefile \
./files/include/prepare.mk \
diff --git a/toolchain/Makefile b/toolchain/Makefile
index cd5399e..7479615 100644
--- a/toolchain/Makefile
+++ b/toolchain/Makefile
@@ -53,7 +53,7 @@ endif
ifndef DUMP_TARGET_DB
ifneq ($(ARCH),)
- $(TOOLCHAIN_DIR)/info.mk: .config
+ $(TOOLCHAIN_DIR)/info.mk: $(TARGET_CONFIG)
@for dir in $(TOOLCHAIN_DIR); do ( \
$(if $(QUIET),,set -x;) \
mkdir -p "$$dir"; \
@@ -68,7 +68,7 @@ endif
endif
# prerequisites for the individual targets
-$(curdir)/ := .config prereq
+$(curdir)/ := $(TARGET_CONFIG) prereq
$(curdir)//prepare = $(STAGING_DIR)/.prepared $(TOOLCHAIN_DIR)/info.mk
$(tools/stamp-install)
$(curdir)//compile = $(1)/prepare
$(curdir)//install = $(1)/compile
diff --git a/tools/Makefile b/tools/Makefile
index 187655e..64ebcbd 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -126,7 +126,7 @@ $(curdir)//prepare = $(STAGING_DIR)/.prepared
$(STAGING_DIR_HOST)/.prepared
$(curdir)//compile = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared
# prerequisites for the individual targets
-$(curdir)/ := .config prereq
+$(curdir)/ := $(TARGET_CONFIG) prereq
$(curdir)//install = $(1)/compile
tools_enabled = $(foreach tool,$(sort $(tools-y) $(tools-)),$(if $(filter
$(tool),$(tools-y)),y,n))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20160303/80a89cb5/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list