forked from freifunk-berlin/firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (127 loc) · 5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
include config.mk
# get main- and subtarget name from TARGET
MAINTARGET=$(word 1, $(subst _, ,$(TARGET)))
SUBTARGET=$(word 2, $(subst _, ,$(TARGET)))
# set dir and file names
FW_DIR=$(shell pwd)
OPENWRT_DIR=$(FW_DIR)/openwrt
TARGET_CONFIG=$(FW_DIR)/configs/$(TARGET).config
IB_BUILD_DIR=$(FW_DIR)/imagebuilder_tmp
FW_TARGET_DIR=$(FW_DIR)/firmwares/$(TARGET)
UMASK=umask 022
# if any of the following files have been changed: clean up openwrt dir
DEPS=$(TARGET_CONFIG) feeds.conf patches $(wildcard patches/*)
# profiles to be built (router models)
PROFILES=$(shell cat $(FW_DIR)/profiles/$(TARGET).profiles)
default: firmwares
# clone openwrt
$(OPENWRT_DIR):
git clone $(OPENWRT_SRC) $(OPENWRT_DIR)
# clean up openwrt working copy
openwrt-clean: stamp-clean-openwrt-cleaned .stamp-openwrt-cleaned
.stamp-openwrt-cleaned: config.mk | $(OPENWRT_DIR)
cd $(OPENWRT_DIR); \
./scripts/feeds clean && \
git clean -dff && git fetch && git reset --hard HEAD && \
rm -rf bin .config feeds.conf build_dir/target-*
touch $@
# update openwrt and checkout specified commit
openwrt-update: stamp-clean-openwrt-updated .stamp-openwrt-updated
.stamp-openwrt-updated: .stamp-openwrt-cleaned
cd $(OPENWRT_DIR); git checkout --detach $(OPENWRT_COMMIT)
touch $@
# patches require updated openwrt working copy
$(OPENWRT_DIR)/patches: | .stamp-openwrt-updated
ln -s $(FW_DIR)/patches $(OPENWRT_DIR)
# feeds
$(OPENWRT_DIR)/feeds.conf: .stamp-openwrt-updated
cp $(FW_DIR)/feeds.conf $(OPENWRT_DIR)/feeds.conf
# update feeds
feeds-update: stamp-clean-feeds-updated .stamp-feeds-updated
.stamp-feeds-updated: $(OPENWRT_DIR)/feeds.conf
+cd $(OPENWRT_DIR); \
./scripts/feeds uninstall -a && \
./scripts/feeds update && \
./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
touch $@
# patch openwrt working copy
patch: stamp-clean-patched .stamp-patched
.stamp-patched: .stamp-pre-patch
cd $(OPENWRT_DIR); quilt push -a
touch $@
# openwrt config
$(OPENWRT_DIR)/.config: .stamp-feeds-updated $(TARGET_CONFIG)
cp $(TARGET_CONFIG) $(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
touch $@
# compile
compile: stamp-clean-compiled .stamp-compiled
.stamp-compiled: .stamp-prepared
$(UMASK); \
$(MAKE) -C $(OPENWRT_DIR) $(MAKE_ARGS)
touch $@
# fill firmwares-directory with:
# * firmwares built with imagebuilder
# * imagebuilder file
# * packages directory
firmwares: stamp-clean-firmwares .stamp-firmwares
.stamp-firmwares: .stamp-compiled
rm -rf $(IB_BUILD_DIR)
mkdir -p $(IB_BUILD_DIR)
$(eval TOOLCHAIN_PATH := $(shell printf "%s:" $(OPENWRT_DIR)/staging_dir/toolchain-*/bin))
$(eval IB_FILE := $(shell ls $(OPENWRT_DIR)/bin/$(MAINTARGET)/OpenWrt-ImageBuilder-$(TARGET)*.tar.bz2))
$(eval IB_DIR := $(shell basename $(IB_FILE) .tar.bz2))
cd $(IB_BUILD_DIR); tar xf $(IB_FILE)
export PATH=$(PATH):$(TOOLCHAIN_PATH); \
PACKAGES_PATH="$(FW_DIR)/packages"; \
for PROFILE in $(PROFILES); do \
for PACKAGES_FILE in $(PACKAGES_LIST_DEFAULT); do \
CUSTOM_POSTINST_PARAM=""; \
if [[ $$PROFILE =~ ":" ]]; then \
SUFFIX="$$(echo $$PROFILE | cut -d':' -f 2)"; \
PACKAGES_SUFFIXED="$${PACKAGES_FILE}_$${SUFFIX}"; \
if [[ -f "$$PACKAGES_PATH/$$PACKAGES_SUFFIXED.txt" ]]; then \
PACKAGES_FILE="$$PACKAGES_SUFFIXED"; \
PROFILE=$$(echo $$PROFILE | cut -d':' -f 1); \
fi; \
fi; \
if [[ -f "$$PACKAGES_PATH/$$PACKAGES_FILE.sh" ]]; then \
CUSTOM_POSTINST_PARAM="CUSTOM_POSTINST_SCRIPT=$$PACKAGES_PATH/$$PACKAGES_FILE.sh"; \
fi; \
PACKAGES_FILE_ABS="$$PACKAGES_PATH/$$PACKAGES_FILE.txt"; \
PACKAGES_LIST=$$(grep -v '^\#' $$PACKAGES_FILE_ABS | tr -t '\n' ' '); \
$(UMASK);\
echo -e "\n *** Building Kathleen image file for profile $${PROFILE} with packages list from $${PACKAGES_FILE}.\n"; \
$(MAKE) -C $(IB_BUILD_DIR)/$(IB_DIR) image PROFILE="$$PROFILE" PACKAGES="$$PACKAGES_LIST" BIN_DIR="$(IB_BUILD_DIR)/$(IB_DIR)/bin/$$PACKAGES_FILE" $$CUSTOM_POSTINST_PARAM || exit 1; \
done; \
done
mkdir -p $(FW_TARGET_DIR)
# copy different firmwares (like vpn, minimal) including imagebuilder
for DIR_ABS in $(IB_BUILD_DIR)/$(IB_DIR)/bin/*; do \
TARGET_DIR=$(FW_TARGET_DIR)/$$(basename $$DIR_ABS); \
rm -rf $$TARGET_DIR; \
mv $$DIR_ABS $$TARGET_DIR; \
done;
# copy imagebuilder, sdk and toolchain (if existing)
cp -a $(OPENWRT_DIR)/bin/$(MAINTARGET)/OpenWrt-*.tar.bz2 $(FW_TARGET_DIR)/
# copy packages
PACKAGES_DIR="$(FW_TARGET_DIR)/packages"; \
rm -rf $$PACKAGES_DIR; \
cp -a $(OPENWRT_DIR)/bin/$(MAINTARGET)/packages $$PACKAGES_DIR
rm -rf $(IB_BUILD_DIR)
touch $@
stamp-clean-%:
rm -f .stamp-$*
stamp-clean:
rm -f .stamp-*
clean: stamp-clean .stamp-openwrt-cleaned
.PHONY: openwrt-clean openwrt-update patch feeds-update prepare compile firmwares stamp-clean clean
.NOTPARALLEL: