Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: improve check for TARGET #841

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ FW_TARGET_DIR=$(FW_DIR)/firmwares/$(MAINTARGET)-$(SUBTARGET)
VERSION_FILE=$(FW_TARGET_DIR)/VERSION.txt
UMASK=umask 022

# test for existing $TARGET-config or abort
ifeq ($(wildcard $(FW_DIR)/configs/$(TARGET).config),)
$(error config for $(TARGET) not defined)
endif
define newline


endef

VALID_TARGETS=$(sort $(notdir $(basename $(wildcard $(FW_DIR)/profiles/*.profiles))))

define listtargets
$(error $(1) TARGET defined ! $(newline) \
$(addprefix $(newline) * ,$(VALID_TARGETS)) \
$(newline)Please specify one from the list above via 'TARGET' environment or in config.mk)
endef

# if any of the following files have been changed: clean up openwrt dir
DEPS=$(TARGET_CONFIG) modules patches $(wildcard patches/*)
Expand All @@ -31,6 +39,15 @@ FW_REVISION=$(shell $(REVISION))

default: firmwares

test-target:
# test for existing $TARGET-config or abort
ifeq ($(TARGET),)
$(call listtargets,No)
endif
ifeq ($(wildcard $(FW_DIR)/configs/$(TARGET).config),)
$(call listtargets,Invalid)
endif

## Gluon - Begin
# compatibility to Gluon.buildsystem
# * setup required makros and variables
Expand Down Expand Up @@ -115,7 +132,7 @@ $(OPENWRT_DIR)/files: $(FW_DIR)/embedded-files
ln -s $(FW_DIR)/embedded-files $(OPENWRT_DIR)/files

# openwrt config
$(OPENWRT_DIR)/.config: .stamp-feeds-updated $(TARGET_CONFIG) .stamp-build_rev $(OPENWRT_DIR)/dl
$(OPENWRT_DIR)/.config: test-target .stamp-feeds-updated $(TARGET_CONFIG) .stamp-build_rev $(OPENWRT_DIR)/dl
cat $(TARGET_CONFIG) >$(OPENWRT_DIR)/.config
# always replace CONFIG_VERSION_CODE by FW_REVISION
sed -i "/^CONFIG_VERSION_CODE=/c\CONFIG_VERSION_CODE=\"$(FW_REVISION)\"" $(OPENWRT_DIR)/.config
Expand All @@ -124,12 +141,12 @@ $(OPENWRT_DIR)/.config: .stamp-feeds-updated $(TARGET_CONFIG) .stamp-build_rev $

# prepare openwrt working copy
prepare: stamp-clean-prepared .stamp-prepared
.stamp-prepared: .stamp-feeds-updated $(OPENWRT_DIR)/.config $(OPENWRT_DIR)/files
.stamp-prepared: test-target .stamp-feeds-updated $(OPENWRT_DIR)/.config $(OPENWRT_DIR)/files
touch $@

# compile
compile: stamp-clean-compiled .stamp-compiled
.stamp-compiled: .stamp-prepared openwrt-clean-bin
.stamp-compiled: test-target .stamp-prepared openwrt-clean-bin
$(UMASK); \
$(MAKE) -C $(OPENWRT_DIR) $(MAKE_ARGS)
touch $@
Expand All @@ -139,7 +156,7 @@ compile: stamp-clean-compiled .stamp-compiled
# * packages directory
# * firmware-images are already in place (target images)
firmwares: stamp-clean-firmwares .stamp-firmwares
.stamp-firmwares: .stamp-images $(VERSION_FILE) .stamp-initrd
.stamp-firmwares: test-target .stamp-images $(VERSION_FILE) .stamp-initrd
# copy imagebuilder, sdk and toolchain (if existing)
# remove old versions
rm -f $(FW_TARGET_DIR)/*.tar.xz
Expand All @@ -156,7 +173,7 @@ firmwares: stamp-clean-firmwares .stamp-firmwares
touch $@

initrd: .stamp-initrd
.stamp-initrd: .stamp-compiled
.stamp-initrd: test-target .stamp-compiled
$(eval TARGET_BINDIR := $(OPENWRT_DIR)/bin/targets/$(MAINTARGET)/$(SUBTARGET))
$(eval INITRD_DIR := $(FW_TARGET_DIR)/initrd)
[ -d $(INITRD_DIR) ] || mkdir -p $(INITRD_DIR)
Expand Down Expand Up @@ -193,10 +210,10 @@ images: .stamp-images
# gets created during build, in this case a
# prerequirement is a build OpenWRT
ifeq ($(origin IB_FILE),command line)
.stamp-images: .FORCE
.stamp-images: test-target .FORCE
$(info IB_FILE explicitly defined; using it for building firmware-images)
else
.stamp-images: .stamp-compiled
.stamp-images: test-target .stamp-compiled
$(info IB_FILE not defined; assuming called from inside regular build)
$(eval IB_FILE := $(shell ls -tr $(OPENWRT_DIR)/bin/targets/$(MAINTARGET)/$(SUBTARGET)/*-imagebuilder-*.tar.xz | tail -n1))
endif
Expand All @@ -212,7 +229,7 @@ endif
for file in `find $(RELPATH) -name "freifunk-berlin-*-$(MAINTARGET)-$(SUBTARGET)-*.bin"` ; do mv $$file $${file/$(MAINTARGET)-$(SUBTARGET)-/}; done
touch $@

setup-sdk: .stamp-patched
setup-sdk: test-target .stamp-patched
@if [ -z "$(SDK_FILE)" ]; then \
echo Error: Please provide SDK-FILE by using "make SDK_FILE=<filename>"; \
exit 1; \
Expand Down Expand Up @@ -251,7 +268,7 @@ stamp-clean:

clean: stamp-clean .stamp-openwrt-cleaned

.PHONY: openwrt-clean openwrt-clean-bin patch feeds-update prepare compile firmwares stamp-clean clean setup-sdk
.PHONY: openwrt-clean openwrt-clean-bin test-target patch feeds-update prepare compile firmwares stamp-clean clean setup-sdk
.NOTPARALLEL:
.FORCE:
.SUFFIXES:
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# default parameters for Makefile
SHELL:=$(shell which bash)
TARGET=ar71xx-generic
#TARGET=ar71xx-generic
PACKAGES_LIST_DEFAULT=notunnel tunnel-berlin-tunneldigger manual
MAKE_ARGS=