Skip to content

Commit

Permalink
Makefile: implement PR #714
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenRoederer committed Oct 14, 2019
1 parent 21fe2d2 commit ddae353
Showing 1 changed file with 82 additions and 14 deletions.
96 changes: 82 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ REVISION=git describe --always
FW_DIR=$(shell pwd)
OPENWRT_DIR=$(FW_DIR)/openwrt
TARGET_CONFIG=$(FW_DIR)/configs/common.config $(FW_DIR)/configs/$(MAINTARGET)-$(SUBTARGET).config
TARGET_CONFIG_AUTOBUILD=$(FW_DIR)/configs/common-autobuild.config
FW_TARGET_DIR=$(FW_DIR)/firmwares/$(MAINTARGET)-$(SUBTARGET)
VERSION_FILE=$(FW_TARGET_DIR)/VERSION.txt
UMASK=umask 022
Expand All @@ -32,13 +33,21 @@ $(error config for $(TARGET) not defined)
endif

# if any of the following files have been changed: clean up openwrt dir
DEPS=$(TARGET_CONFIG) feeds.conf patches $(wildcard patches/*)
DEPS=$(TARGET_CONFIG) feeds.conf patches $(wildcard patches/openwrt/*) $(wildcard patches/packages/*/*)

# profiles to be built (router models)
PROFILES=$(shell cat $(FW_DIR)/profiles/$(MAINTARGET)-$(SUBTARGET).profiles)

FW_REVISION=$(shell $(REVISION))

ifneq ($(wildcard $(OPENWRT_DIR)/*),)
#FEEDS=$(shell [ -e $(OPENWRT_DIR)/scripts/feeds ] && (cd $(OPENWRT_DIR); ./scripts/feeds list -n) )
#FEEDS=cd $(OPENWRT_DIR); ./scripts/feeds list -n
FEEDS=$(shell cd $(OPENWRT_DIR); ./scripts/feeds list -n)
#PATCH_FEEDS_TARGET = $(addprefix patch-feed-, $(FEEDS))
#UNPATCH_FEEDS_TARGET = $(addprefix unpatch-feed-, $(FEEDS))
endif

default: firmwares

# clone openwrt
Expand Down Expand Up @@ -67,30 +76,68 @@ openwrt-update: stamp-clean-openwrt-updated .stamp-openwrt-updated

# patches require updated openwrt working copy
$(OPENWRT_DIR)/patches: | .stamp-openwrt-updated
ln -s $(FW_DIR)/patches $@
ln -s $(FW_DIR)/patches/openwrt $@

# patches require updated openwrt working copy
$(OPENWRT_DIR)/feeds/%/patches: .stamp-feeds-updated
[ -d $(FW_DIR)/patches/packages/$* ] || mkdir $(FW_DIR)/patches/packages/$*
[ -d $@ ] || ln -s $(FW_DIR)/patches/packages/$* $@

# feeds
$(OPENWRT_DIR)/feeds.conf: .stamp-openwrt-updated feeds.conf
cp $(FW_DIR)/feeds.conf $@
$(OPENWRT_DIR)/feeds.conf: feeds.conf | .stamp-openwrt-updated
$(info $(shell cp $(FW_DIR)/feeds.conf $@; echo file copied))
$(info updating FEEDS variable, as the feeds.conf has changed)
# cd $(OPENWRT_DIR); ./scripts/feeds list -n >$(FW_DIR)/.tmp_feeds
# $(eval FEEDS=$(shell cat $(FW_DIR)/.tmp_feeds))
$(eval FEEDS=$(shell cd $(OPENWRT_DIR); ./scripts/feeds list -n >$(FW_DIR)/.tmp_feeds; cat $(FW_DIR)/.tmp_feeds))
$(info new FEEDS $(FEEDS))
rm $(FW_DIR)/.tmp_feeds

# update feeds
feeds-update: stamp-clean-feeds-updated .stamp-feeds-updated
.stamp-feeds-updated: $(OPENWRT_DIR)/feeds.conf unpatch
cd $(OPENWRT_DIR); ./scripts/feeds uninstall -a
$(UMASK); cd $(OPENWRT_DIR); ./scripts/feeds update
.stamp-feeds-updated: | $(OPENWRT_DIR)/feeds.conf $(addprefix .stamp-feed-update-,$(FEEDS))
$(info FEEDS is: $(FEEDS))
make $(addprefix .stamp-feed-update-,$(FEEDS))
#cd $(OPENWRT_DIR); ./scripts/feeds uninstall -a
#$(UMASK); cd $(OPENWRT_DIR); ./scripts/feeds update $*
touch $@

.stamp-feed-update-%: $(OPENWRT_DIR)/feeds.conf
#cd $(OPENWRT_DIR); ./scripts/feeds uninstall -a
$(UMASK); cd $(OPENWRT_DIR); ./scripts/feeds update $*
touch $@

.stamp-packages-install: .stamp-patch-openwrt .stamp-patch-feeds .stamp-feeds-updated
cd $(OPENWRT_DIR); ./scripts/feeds install -a
touch $@

# prepare patch
pre-patch: stamp-clean-pre-patch .stamp-pre-patch
.stamp-pre-patch: .stamp-feeds-updated $(wildcard $(FW_DIR)/patches/*) | $(OPENWRT_DIR)/patches
.stamp-pre-patch:
# # ensure that an (empty) patches-directory per feed exists
# $(foreach feed,$(FEEDS),$(shell [ -d $(FW_DIR)/patches/packages/$(feed) ] || mkdir $(FW_DIR)/patches/packages/$(feed)))
touch $@

# patch openwrt working copy
patch: stamp-clean-patched .stamp-patched
.stamp-patched: .stamp-pre-patch
cd $(OPENWRT_DIR); quilt push -a
.stamp-patched: .stamp-patch-openwrt .stamp-patch-feeds
touch $@

.stamp-patch-openwrt: .stamp-pre-patch $(wildcard $(FW_DIR)/patches/openwrt/*) | $(OPENWRT_DIR)/patches
cd $(OPENWRT_DIR); quilt push -a || [ $$? = 2 ] && true
rm -rf $(OPENWRT_DIR)/tmp
#$(UMASK); cd $(OPENWRT_DIR); ./scripts/feeds update
#$(UMASK); cd $(OPENWRT_DIR); ./scripts/feeds install -a
touch $@

.stamp-patch-feeds: .stamp-pre-patch .stamp-feeds-updated .stamp-patch-openwrt $(addprefix .stamp-patch-feed-,$(FEEDS))
$(info patching all feeds: $(FEEDS))
make $(addprefix .stamp-patch-feed-,$(FEEDS))
touch $@

.stamp-patch-feed-%: .stamp-patch-openwrt .stamp-feed-update-% $(wildcard patches/packages/%/*) | $(OPENWRT_DIR)/feeds/%/patches
$(info this is $@)
if [ -f $(OPENWRT_DIR)/feeds/$*/patches/series ]; then cd $(OPENWRT_DIR)/feeds/$*; quilt push -a || [ $$? = 2 ] && true; fi
touch $@

.stamp-build_rev: .FORCE
Expand All @@ -115,16 +162,20 @@ $(OPENWRT_DIR)/files: $(FW_DIR)/embedded-files
ln -s $(FW_DIR)/embedded-files $(OPENWRT_DIR)/files

# openwrt config
$(OPENWRT_DIR)/.config: .stamp-patched $(TARGET_CONFIG) .stamp-build_rev $(OPENWRT_DIR)/dl
$(OPENWRT_DIR)/.config: .stamp-packages-install $(TARGET_CONFIG) $(TARGET_CONFIG_AUTOBUILD) .stamp-build_rev $(OPENWRT_DIR)/dl
ifdef IS_BUILDBOT
cat $(TARGET_CONFIG) $(TARGET_CONFIG_AUTOBUILD) >$(OPENWRT_DIR)/.config
else
cat $(TARGET_CONFIG) >$(OPENWRT_DIR)/.config
endif
# always replace CONFIG_VERSION_CODE by FW_REVISION
sed -i "/^CONFIG_VERSION_CODE=/c\CONFIG_VERSION_CODE=\"$(FW_REVISION)\"" $(OPENWRT_DIR)/.config
$(UMASK); \
$(MAKE) -C $(OPENWRT_DIR) defconfig

# prepare openwrt working copy
prepare: stamp-clean-prepared .stamp-prepared
.stamp-prepared: .stamp-patched $(OPENWRT_DIR)/.config $(OPENWRT_DIR)/files
.stamp-prepared: .stamp-patched $(OPENWRT_DIR)/.config $(OPENWRT_DIR)/files .stamp-packages-install
touch $@

# compile
Expand Down Expand Up @@ -231,15 +282,32 @@ stamp-clean-%:
stamp-clean:
rm -f .stamp-*

unpatch: unpatch-openwrt unpatch-feeds
rm -f .stamp-patched

# unpatch needs "patches/" in openwrt
unpatch: $(OPENWRT_DIR)/patches
unpatch-openwrt:
ifneq ($(wildcard $(OPENWRT_DIR)/.pc),)
# RC = 2 of quilt --> nothing to be done
cd $(OPENWRT_DIR); quilt pop -a -f || [ $$? = 2 ] && true
rm -rf $(OPENWRT_DIR)/tmp
rm -f .stamp-patched
endif
rm -f .stamp-patch-openwrt

unpatch-feeds: $(OPENWRT_DIR)/feeds.conf $(addprefix unpatch-feed-,$(FEEDS))
$(info unpatching all feeds: $(FEEDS))
rm -f .stamp-patch-feeds

unpatch-feed-%: $(OPENWRT_DIR)/feeds/%
$(info this is $@)
[ ! -d $(OPENWRT_DIR)/feeds/$*/.pc ] || \
(cd $(OPENWRT_DIR)/feeds/$*; quilt pop -a -f || [ $$? = 2 ] && true)
rm .stamp-patch-feed-$*


clean: stamp-clean .stamp-openwrt-cleaned

.PHONY: openwrt-clean openwrt-clean-bin openwrt-update patch feeds-update prepare compile firmwares stamp-clean clean
.NOTPARALLEL:
.FORCE:
.SUFFIXES:

0 comments on commit ddae353

Please sign in to comment.