-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
148 lines (113 loc) · 4.77 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
#
# Builds Openwrt images for ar71xx & ipq806x targets used at Scale
# Assumes all dependency tools are already installed
#
include include/*.mk
# Export all variables by default
.EXPORT_ALL_VARIABLES:
SHELL = /usr/bin/env bash
# WNDR by default
TARGET ?= ar71xx
BUILD_DIR ?= build
# Set to configure -j (defaults to nproc)
JOBS ?= $(shell nproc)
BUILD_SECRETS ?= ../facts/secrets/$(TARGET)-openwrt-example.yaml
KEYPATH ?= ../facts/keys/
# bins
GOMPLATE := $(shell command -v gomplate 2> /dev/null)
CURL := $(shell command -v curl 2> /dev/null)
OPENWRT_VER ?= 9062e5faaedc03823ee419fe34de1de73f48babc
# If bumping opkg it needs to be a commit that exists in the fork
# https://github.com/sarcasticadmin/opkgs
OPENWRT_PKG_VERSION ?= b18cf76d0f31fa12877f7b8e83596d27d89f0020
SHORT_VER = $(shell echo $(OPENWRT_VER) | cut -c 1-7)
IMAGEBUILDER = source-$(TARGET)-$(SHORT_VER)
TAR_EXT = .tar.gz
TMPL_SRC_DIR = files
TMPL_OUT_DIR = $(BUILD_DIR)/$(IMAGEBUILDER)/files
ifndef CURL
$(error "curl is not available please install it")
endif
# TODO: Fix this after getting feedback from upstream opkgs
# https://github.com/openwrt/packages/issues/20184
define FEEDS_CONF_DEFAULT
src-git packages https://github.com/sarcasticadmin/opkgs.git^$(OPENWRT_PKG_VERSION)
endef
PHONY: download-image extract templates clean clean-templates
download-image: $(BUILD_DIR)/$(OPENWRT_VER)$(TAR_EXT)
extract: $(BUILD_DIR)/$(IMAGEBUILDER)
$(BUILD_DIR)/$(OPENWRT_VER)$(TAR_EXT): | $(BUILD_DIR)
curl -L -o $(BUILD_DIR)/$(OPENWRT_VER)$(TAR_EXT) https://github.com/openwrt/openwrt/archive/$(OPENWRT_VER)$(TAR_EXT)
$(BUILD_DIR)/$(IMAGEBUILDER): $(BUILD_DIR)/$(OPENWRT_VER)$(TAR_EXT)
@cd $(BUILD_DIR) && \
mkdir -p $(IMAGEBUILDER) && \
tar -zxmf $(OPENWRT_VER)$(TAR_EXT) -C $(IMAGEBUILDER) --strip-components 1
$(BUILD_DIR)/$(IMAGEBUILDER)/feeds.conf.default: extract
@cd $(BUILD_DIR)/$(IMAGEBUILDER) \
&& echo "$$FEEDS_CONF_DEFAULT" > feeds.conf.default
feeds: $(BUILD_DIR)/$(IMAGEBUILDER)/feeds.conf.default
$(BUILD_DIR)/$(IMAGEBUILDER)/.config: feeds
@cd $(BUILD_DIR)/$(IMAGEBUILDER) \
&& ./scripts/feeds update -a \
&& ./scripts/feeds install -a \
&& cat ../../configs/$(TARGET)-generic.config > .config \
&& cat ../../configs/common.config >> .config \
&& make defconfig
diffconfig:
@cd $(BUILD_DIR)/$(IMAGEBUILDER) && ./scripts/diffconfig.sh > .diffconfig
commonconfig: diffconfig
ifneq ($(TARGET), x86)
$(error "common config can only be generated from x86")
endif
cat ./$(BUILD_DIR)/$(IMAGEBUILDER)/.diffconfig | grep -v CONFIG_TARGET > ./configs/common.config
targetconfig: diffconfig
comm -23 <(sort ./$(BUILD_DIR)/$(IMAGEBUILDER)/.diffconfig) <(sort ./configs/common.config) > ./configs/$(TARGET)-generic.config
config: $(BUILD_DIR)/$(IMAGEBUILDER)/.config
menuconfig:
@cd $(BUILD_DIR)/$(IMAGEBUILDER) && $(MAKE) menuconfig
build-img: $(BUILD_DIR)/$(IMAGEBUILDER)/.config
@cd $(BUILD_DIR)/$(IMAGEBUILDER) \
&& echo SCALE_VER=$(shell git rev-parse HEAD) > $(TMPL_SRC_DIR)/etc/scale-release \
&& echo OPENWRT_VER=$(OPENWRT_VER) >> $(TMPL_SRC_DIR)/etc/scale-release \
&& $(MAKE) download \
&& $(MAKE) V=s -j $(JOBS)
# Common way to package up the build artifacts due to the various limits of
# some CI tools
package:
mkdir -p $(BUILD_DIR)/artifacts
# TODO: Look into striping path to only be from targets/ onward
tar zcvf $(BUILD_DIR)/artifacts/$(TARGET)-$(SHORT_VER)-artifacts.tar.gz \
-C $(BUILD_DIR)/$(IMAGEBUILDER)/bin/targets/* ./
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
clean-all:
rm -rf $(BUILD_DIR)
clean:
rm -rf $(BUILD_DIR)/$(IMAGEBUILDER)
clean-config:
rm -f ./$(BUILD_DIR)/$(IMAGEBUILDER)/.config
rm -f ./$(BUILD_DIR)/$(IMAGEBUILDER)/.diffconfig
clean-templates:
rm -rf $(BUILD_DIR)/$(IMAGEBUILDER)/files
templates: $(TMPL_OUT_DIR)
$(TMPL_OUT_DIR): $(TMPL_SRC_DIR) $(BUILD_SECRETS) | $(BUILD_DIR)/$(IMAGEBUILDER)
ifndef GOMPLATE
$(error "gomplate is not available please install it")
endif
$(GOMPLATE) -d openwrt=$(BUILD_SECRETS) -d keys_dir=$(KEYPATH) --input-dir=$(TMPL_SRC_DIR) --output-dir=$(TMPL_OUT_DIR)
# Check that TARGET specific dir exists
ifneq ($(wildcard $(TMPL_SRC_DIR)-$(TARGET)/.),)
$(GOMPLATE) -d openwrt=$(BUILD_SECRETS) -d keys_dir=$(KEYPATH) --input-dir=$(TMPL_SRC_DIR)-$(TARGET) --output-dir=$(TMPL_OUT_DIR)
endif
# TODO: should do this automatically for .sh file types
chmod 750 $(TMPL_OUT_DIR)/root/bin/config-version.sh
chmod 750 $(TMPL_OUT_DIR)/root/bin/wifi-details.sh
chmod 750 $(TMPL_OUT_DIR)/root/bin/apinger-pop.sh
chmod 755 $(TMPL_OUT_DIR)/root
chmod 700 $(TMPL_OUT_DIR)/root/.ssh
chmod 640 $(TMPL_OUT_DIR)/root/.ssh/authorized_keys
@cd $(TMPL_OUT_DIR)/etc/config && ln -s network.0 network && ln -s wireless.0 wireless
@cd $(TMPL_OUT_DIR)/etc && ln -s /tmp/resolv.conf.d/resolv.conf.auto resolv.conf
touch $(TMPL_OUT_DIR)
bump:
bash scripts/openwrt_bump.sh