build: use .ONESHELL
By using .ONESHELL and adding -e to .SHELLFLAGS, we can simplify complex shell commands (like manifest generation) and gain a simple way to pass multi-line environment variables into shell commands. The @ and + flags for recipe commands are moved to the top of each recipe.
This commit is contained in:
parent
47f1509e75
commit
a180bb8689
113
Makefile
113
Makefile
@ -4,6 +4,8 @@ LC_ALL:=C
|
|||||||
LANG:=C
|
LANG:=C
|
||||||
export LC_ALL LANG
|
export LC_ALL LANG
|
||||||
|
|
||||||
|
.SHELLFLAGS = -ec
|
||||||
|
|
||||||
# check for spaces & resolve possibly relative paths
|
# check for spaces & resolve possibly relative paths
|
||||||
define mkabspath
|
define mkabspath
|
||||||
ifneq (1,$(words [$($(1))]))
|
ifneq (1,$(words [$($(1))]))
|
||||||
@ -50,14 +52,16 @@ show-release:
|
|||||||
|
|
||||||
|
|
||||||
update: FORCE
|
update: FORCE
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update.sh
|
@
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/patch.sh
|
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update.sh
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/feeds.sh
|
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/patch.sh
|
||||||
|
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/feeds.sh
|
||||||
|
|
||||||
update-patches: FORCE
|
update-patches: FORCE
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update.sh
|
@
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update-patches.sh
|
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update.sh
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/patch.sh
|
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/update-patches.sh
|
||||||
|
GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/patch.sh
|
||||||
|
|
||||||
update-feeds: FORCE
|
update-feeds: FORCE
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/feeds.sh
|
@GLUON_SITEDIR='$(GLUON_SITEDIR)' scripts/feeds.sh
|
||||||
@ -89,19 +93,34 @@ GLUON_CONFIG_VARS := \
|
|||||||
SUBTARGET='$(SUBTARGET)'
|
SUBTARGET='$(SUBTARGET)'
|
||||||
|
|
||||||
|
|
||||||
CheckTarget := [ '$(BOARD)' ] \
|
define CheckTarget
|
||||||
|| (echo 'Please set GLUON_TARGET to a valid target. Gluon supports the following targets:'; $(foreach target,$(GLUON_TARGETS),echo ' * $(target)';) false)
|
if [ -z '$(BOARD)' ]; then
|
||||||
|
echo 'Please set GLUON_TARGET to a valid target. Gluon supports the following targets:'
|
||||||
|
for target in $(GLUON_TARGETS); do
|
||||||
|
echo " * $$target"
|
||||||
|
done
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
endef
|
||||||
|
|
||||||
CheckExternal := test -d openwrt || (echo 'You don'"'"'t seem to have obtained the external repositories needed by Gluon; please call `make update` first!'; false)
|
define CheckExternal
|
||||||
|
if [ ! -d openwrt ]; then
|
||||||
|
echo "You don't seem to have obtained the external repositories needed by Gluon; please call \`make update\` first!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
endef
|
||||||
|
|
||||||
define CheckSite
|
define CheckSite
|
||||||
@GLUON_SITEDIR='$(GLUON_SITEDIR)' GLUON_SITE_CONFIG='$(1).conf' $(LUA) -e 'assert(dofile("scripts/site_config.lua")(os.getenv("GLUON_SITE_CONFIG")))' \
|
if ! GLUON_SITEDIR='$(GLUON_SITEDIR)' GLUON_SITE_CONFIG='$(1).conf' $(LUA) -e 'assert(dofile("scripts/site_config.lua")(os.getenv("GLUON_SITE_CONFIG")))'; then
|
||||||
|| (echo 'Your site configuration ($(1).conf) did not pass validation.'; false)
|
echo 'Your site configuration ($(1).conf) did not pass validation
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
endef
|
endef
|
||||||
|
|
||||||
list-targets: FORCE
|
list-targets: FORCE
|
||||||
@$(foreach target,$(GLUON_TARGETS),echo '$(target)';)
|
@for target in $(GLUON_TARGETS); do
|
||||||
|
echo "$$target"
|
||||||
|
done
|
||||||
|
|
||||||
lint: lint-lua lint-sh
|
lint: lint-lua lint-sh
|
||||||
|
|
||||||
@ -140,61 +159,71 @@ $(eval $(call merge_lists,GLUON_CLASS_PACKAGES_tiny,$(GLUON_FEATURE_PACKAGES_tin
|
|||||||
LUA := openwrt/staging_dir/hostpkg/bin/lua
|
LUA := openwrt/staging_dir/hostpkg/bin/lua
|
||||||
|
|
||||||
$(LUA):
|
$(LUA):
|
||||||
@$(CheckExternal)
|
+@
|
||||||
|
|
||||||
+@[ -e openwrt/.config ] || $(OPENWRTMAKE) defconfig
|
$(CheckExternal)
|
||||||
+@$(OPENWRTMAKE) tools/install
|
|
||||||
+@$(OPENWRTMAKE) package/lua/host/compile
|
[ -e openwrt/.config ] || $(OPENWRTMAKE) defconfig
|
||||||
|
$(OPENWRTMAKE) tools/install
|
||||||
|
$(OPENWRTMAKE) package/lua/host/compile
|
||||||
|
|
||||||
|
|
||||||
config: $(LUA) FORCE
|
config: $(LUA) FORCE
|
||||||
@$(CheckExternal)
|
+@
|
||||||
@$(CheckTarget)
|
|
||||||
$(foreach conf,site $(patsubst $(GLUON_SITEDIR)/%.conf,%,$(wildcard $(GLUON_SITEDIR)/domains/*.conf)),$(call CheckSite,$(conf)))
|
|
||||||
|
|
||||||
@$(GLUON_CONFIG_VARS) \
|
$(CheckExternal)
|
||||||
|
$(CheckTarget)
|
||||||
|
$(foreach conf,site $(patsubst $(GLUON_SITEDIR)/%.conf,%,$(wildcard $(GLUON_SITEDIR)/domains/*.conf)),\
|
||||||
|
$(call CheckSite,$(conf)); \
|
||||||
|
)
|
||||||
|
|
||||||
|
$(GLUON_CONFIG_VARS) \
|
||||||
$(LUA) scripts/target_config.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)' \
|
$(LUA) scripts/target_config.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)' \
|
||||||
> openwrt/.config
|
> openwrt/.config
|
||||||
+@$(OPENWRTMAKE) defconfig
|
$(OPENWRTMAKE) defconfig
|
||||||
|
|
||||||
@$(GLUON_CONFIG_VARS) \
|
$(GLUON_CONFIG_VARS) \
|
||||||
$(LUA) scripts/target_config_check.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)'
|
$(LUA) scripts/target_config_check.lua '$(GLUON_TARGET)' '$(GLUON_DEFAULT_PACKAGES)' '$(GLUON_CLASS_PACKAGES_standard)' '$(GLUON_CLASS_PACKAGES_tiny)'
|
||||||
|
|
||||||
|
|
||||||
all: config
|
all: config
|
||||||
@$(GLUON_CONFIG_VARS) \
|
+@
|
||||||
|
$(GLUON_CONFIG_VARS) \
|
||||||
$(LUA) scripts/clean_output.lua
|
$(LUA) scripts/clean_output.lua
|
||||||
+@$(OPENWRTMAKE)
|
$(OPENWRTMAKE)
|
||||||
@$(GLUON_CONFIG_VARS) \
|
$(GLUON_CONFIG_VARS) \
|
||||||
$(LUA) scripts/copy_output.lua '$(GLUON_TARGET)'
|
$(LUA) scripts/copy_output.lua '$(GLUON_TARGET)'
|
||||||
|
|
||||||
clean download: config
|
clean download: config
|
||||||
+@$(OPENWRTMAKE) $@
|
+@$(OPENWRTMAKE) $@
|
||||||
|
|
||||||
dirclean: FORCE
|
dirclean: FORCE
|
||||||
+@[ -e openwrt/.config ] || $(OPENWRTMAKE) defconfig
|
+@
|
||||||
+@$(OPENWRTMAKE) dirclean
|
[ -e openwrt/.config ] || $(OPENWRTMAKE) defconfig
|
||||||
@rm -rf $(GLUON_TMPDIR) $(GLUON_OUTPUTDIR)
|
$(OPENWRTMAKE) dirclean
|
||||||
|
rm -rf $(GLUON_TMPDIR) $(GLUON_OUTPUTDIR)
|
||||||
|
|
||||||
manifest: $(LUA) FORCE
|
manifest: $(LUA) FORCE
|
||||||
@[ '$(GLUON_BRANCH)' ] || (echo 'Please set GLUON_BRANCH to create a manifest.'; false)
|
@
|
||||||
@echo '$(GLUON_PRIORITY)' | grep -qE '^([0-9]*\.)?[0-9]+$$' || (echo 'Please specify a numeric value for GLUON_PRIORITY to create a manifest.'; false)
|
[ '$(GLUON_BRANCH)' ] || (echo 'Please set GLUON_BRANCH to create a manifest.'; false)
|
||||||
@$(CheckExternal)
|
echo '$(GLUON_PRIORITY)' | grep -qE '^([0-9]*\.)?[0-9]+$$' || (echo 'Please specify a numeric value for GLUON_PRIORITY to create a manifest.'; false)
|
||||||
|
$(CheckExternal)
|
||||||
|
|
||||||
@( \
|
(
|
||||||
echo 'BRANCH=$(GLUON_BRANCH)' && \
|
echo 'BRANCH=$(GLUON_BRANCH)'
|
||||||
echo "DATE=$$($(LUA) scripts/rfc3339date.lua)" && \
|
echo "DATE=$$($(LUA) scripts/rfc3339date.lua)"
|
||||||
echo 'PRIORITY=$(GLUON_PRIORITY)' && \
|
echo 'PRIORITY=$(GLUON_PRIORITY)'
|
||||||
echo && \
|
echo
|
||||||
$(foreach GLUON_TARGET,$(GLUON_TARGETS), \
|
for target in $(GLUON_TARGETS); do
|
||||||
GLUON_SITEDIR='$(GLUON_SITEDIR)' $(LUA) scripts/generate_manifest.lua '$(GLUON_TARGET)' && \
|
GLUON_SITEDIR='$(GLUON_SITEDIR)' $(LUA) scripts/generate_manifest.lua "$$target"
|
||||||
) : \
|
done
|
||||||
) > 'tmp/$(GLUON_BRANCH).manifest.tmp'
|
) > 'tmp/$(GLUON_BRANCH).manifest.tmp'
|
||||||
|
|
||||||
@mkdir -p '$(GLUON_IMAGEDIR)/sysupgrade'
|
mkdir -p '$(GLUON_IMAGEDIR)/sysupgrade'
|
||||||
@mv 'tmp/$(GLUON_BRANCH).manifest.tmp' '$(GLUON_IMAGEDIR)/sysupgrade/$(GLUON_BRANCH).manifest'
|
mv 'tmp/$(GLUON_BRANCH).manifest.tmp' '$(GLUON_IMAGEDIR)/sysupgrade/$(GLUON_BRANCH).manifest'
|
||||||
|
|
||||||
FORCE: ;
|
FORCE: ;
|
||||||
|
|
||||||
.PHONY: FORCE
|
.PHONY: FORCE
|
||||||
.NOTPARALLEL:
|
.NOTPARALLEL:
|
||||||
|
.ONESHELL:
|
||||||
|
Loading…
Reference in New Issue
Block a user