forked from libremesh/lime-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
249 lines (202 loc) · 8.2 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# LibreMesh firmware generator (http://libre-mesh.org)
#
# Copyright (C) 2011-2012 libre-mesh.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contributors: Pau Escrich <[email protected]>, Simó Albert i Beltran, Agustí Moll,
# Gui Iribarren <[email protected]>
J ?= 1
V ?= 0
T =
MAKE_SRC = -j$(J) V=$(V)
include config.mk
include targets.mk
PROFILE ?= ath-qmp-tiny-node
TIMESTAMP = $(shell date +%Y%m%d_%H%M)
#Checking if developer mode is enabled and if target is defined before
$(eval $(if $(DEV),LIME_GIT=$(LIME_GIT_RW),LIME_GIT=$(LIME_GIT_RO)))
$(eval $(if $(DEV),$(info Developer mode enabled),))
#Define TARGET_CONFIGS and TARGET
$(eval $(if $(TARGET_MASTER),TARGET_CONFIGS=$(TARGET_MASTER),TARGET_CONFIGS=$(T)))
$(eval $(if $(TARGET),,TARGET=$(T)))
#Define BUILD_PATH based on TBUILD (defined in targets.mk)
BUILD_PATH=$(BUILD_DIR)/$(TBUILD)
#Getting output image paths
IMAGE_PATH = $(IMAGE)
SIMAGE_PATH = $(SYSUPGRADE)
CONFIG = $(BUILD_PATH)/.config
KCONFIG = $(BUILD_PATH)/target/linux/$(ARCH)/config-*
.PHONY: checkout update clean config menuconfig kernel_menuconfig list_targets build clean_lime_pkg
define build_src
$(eval BRANCH_GIT=$(shell git --git-dir=$(BUILD_DIR)/$(LIME_PKG_DIR)/.git branch|grep ^*|cut -d " " -f 2))
$(eval REV_GIT=$(shell git --git-dir=$(BUILD_DIR)/$(LIME_PKG_DIR)/.git --no-pager log -n 1 --oneline|cut -d " " -f 1))
make -C $(BUILD_PATH) $(MAKE_SRC) BRANCH_GIT=$(BRANCH_GIT) REV_GIT=$(REV_GIT)
endef
define copy_feeds_file
$(if $(1),$(eval FEEDS_DIR=$(1)),$(eval FEEDS_DIR=$(TBUILD)))
$(if $(FEEDS_DIR),,$(call target_error))
cp -f feeds.conf $(BUILD_DIR)/$(FEEDS_DIR)
sed -i -e "s|PATH|`pwd`/$(BUILD_DIR)|" $(BUILD_DIR)/$(FEEDS_DIR)/feeds.conf || true
endef
define checkout_src
$(OWRT_SCM) $(BUILD_PATH)
mkdir -p dl
mkdir -p files
ln -fs ../../dl $(BUILD_PATH)/dl
ln -fs ../../files $(BUILD_PATH)/files
rm -rf $(BUILD_PATH)/feeds/
$(call copy_feeds_file,$(TBUILD))
endef
define copy_config
@echo "Using profile $(PROFILE)"
cp -f $(CONFIG_DIR)/$(PROFILE) $(CONFIG) || echo "WARNING: Config file not found!"
[ -f $(CONFIG_DIR)/targets/$(TARGET) ] && cat $(CONFIG_DIR)/targets/$(TARGET) >> $(CONFIG) || true
cd $(BUILD_PATH) && make defconfig
endef
define copy_config_obsolete
@echo "Syncronizing new configuration"
cp -f $(CONFIG_DIR)/$(TARGET_CONFIGS)/config $(CONFIG) || echo "WARNING: Config file not found!"
cd $(BUILD_PATH) && ./scripts/diffconfig.sh > .config.tmp
cp -f $(BUILD_PATH)/.config.tmp $(BUILD_PATH)/.config
make -C $(BUILD_PATH) defconfig
[ -f $(CONFIG_DIR)/$(TARGET_CONFIGS)/kernel_config ] && cat $(CONFIG_DIR)/$(TARGET_CONFIGS)/kernel_config >> $(CONFIG) || true
endef
define copy_myconfig
@echo "Syncronizing configuration from previous one"
@cp -f $(MY_CONFIGS)/$(TARGET_CONFIGS)/config $(CONFIG) || echo "WARNING: Config file not found in $(MY_CONFIGS)!"
make -C $(BUILD_PATH) defconfig
@[ -f $(MY_CONFIGS)/$(TARGET_CONFIGS)/kernel_config ] && cat $(MY_CONFIGS)/$(TARGET_CONFIGS)/kernel_config >> $(CONFIG) || true
endef
define update_feeds
@echo "Updating feed $(1)"
./$(BUILD_DIR)/$(1)/scripts/feeds update -a
./$(BUILD_DIR)/$(1)/scripts/feeds install -a
endef
define menuconfig_owrt
make -C $(BUILD_PATH) menuconfig
mkdir -p $(MY_CONFIGS)/$(TARGET)
( cd $(BUILD_PATH) && ./scripts/diffconfig.sh ) > $(MY_CONFIGS)/$(TARGET)/config
endef
define kmenuconfig_owrt
make -C $(BUILD_PATH) kernel_menuconfig
mkdir -p $(MY_CONFIGS)/$(TARGET)
cp -f $(KCONFIG) $(MY_CONFIGS)/$(TARGET)/kernel_config
endef
define pre_build
$(foreach SCRIPT, $(wildcard $(SCRIPTS_DIR)/*.script), $(shell $(SCRIPT) PRE_BUILD $(TBUILD) $(TARGET)) )
endef
define post_build
$(eval LIME_GIT_BRANCH_CLEAN=$(shell echo $(LIME_GIT_BRANCH) | tr [:punct:] _))
$(eval IM_NAME=$(NAME)-$(COMMUNITY)_$(LIME_GIT_BRANCH_CLEAN)-factory-$(TIMESTAMP).bin)
$(eval SIM_NAME=$(NAME)-$(COMMUNITY)_$(LIME_GIT_BRANCH_CLEAN)-sysupgrade-$(TIMESTAMP).bin)
$(eval COMP=$(shell ls $(BUILD_PATH)/$(IMAGE_PATH) 2>/dev/null | grep -c \\.gz))
@mkdir -p $(IMAGES)
@[ $(COMP) -eq 1 ] && gunzip $(BUILD_PATH)/$(IMAGE_PATH) -c > $(IMAGES)/$(IM_NAME) || true
@[ $(COMP) -ne 1 -a -f $(BUILD_PATH)/$(IMAGE_PATH) ] && cp -f $(BUILD_PATH)/$(IMAGE_PATH) $(IMAGES)/$(IM_NAME) || true
@[ $(COMP) -eq 1 -a -n "$(SYSUPGRADE)" ] && gunzip $(BUILD_PATH)/$(SIMAGE_PATH) -c > $(IMAGES)/$(SIM_NAME) || true
@[ $(COMP) -ne 1 -a -n "$(SYSUPGRADE)" ] && cp -f $(BUILD_PATH)/$(SIMAGE_PATH) $(IMAGES)/$(SIM_NAME) || true
@[ -f $(IMAGES)/$(IM_NAME) ] || echo No output image configured in targets.mk
@[ -n "$(OUTDIR)" ] && [ ! -e $(IMAGES)/$(TARGET) ] && ln -s ../$(BUILD_PATH)/$(OUTDIR) $(IMAGES)/$(TARGET) || true
@echo $(IM_NAME)
$(if $(SYSUPGRADE),@echo $(SIM_NAME))
$(foreach SCRIPT, $(wildcard $(SCRIPTS_DIR)/*.script), $(shell $(SCRIPT) POST_BUILD $(TBUILD) $(TARGET)) )
@echo "LiMe firmware compiled, you can find output files in $(IMAGES) directory."
endef
define clean_all
rm -rf $(BUILD_DIR)/*
rm -f .checkout_*
rm -f $(IMAGES)/*
endef
define clean_target
rm -rf $(BUILD_PATH) || true
rm -f .checkout_$(TBUILD) || true
rm -rf $(BUILD_DIR)/packages.$(TARGET) || true
endef
define clean_pkg
echo "Cleaning package $1"
make $1/clean
endef
define target_error
@echo "You must specify target using T=target (i.e. 'make T=ar71xx build')"
@echo "To see available targets run: make list_targets"
@exit 1
endef
define get_git_local_revision
git rev-parse origin/$1
endef
define get_git_remote_revision
git ls-remote origin $1 | awk 'NR==1{print $$1}'
endef
define update_all
@echo Updating LiMe repository
(cd $(BUILD_DIR)/$(LIME_PKG_DIR) && git pull && git checkout $(LIME_GIT_BRANCH) && git pull origin $(LIME_GIT_BRANCH))
@echo Updating feeds config files
$(foreach dir,$(TBUILD_LIST),$(if $(wildcard $(BUILD_DIR)/$(dir)),$(call copy_feeds_file,$(dir))))
@echo Updating feeds
$(foreach dir,$(TBUILD_LIST),$(if $(wildcard $(BUILD_DIR)/$(dir)),$(call update_feeds,$(dir))))
endef
all: build
.checkout_lime_pkg:
@[ "$(DEV)" == "1" ] && echo "Using developer enviroment" || true
git clone $(LIME_GIT) $(BUILD_DIR)/$(LIME_PKG_DIR)
cd $(BUILD_DIR)/$(LIME_PKG_DIR); git checkout $(LIME_GIT_BRANCH); cd ..
@touch $@
.checkout_owrt:
$(if $(TBUILD),,$(call target_error))
$(if $(wildcard .checkout_$(TBUILD)),,$(call checkout_src))
@touch $@
checkout: .checkout_lime_pkg .checkout_owrt
$(if $(TARGET),,$(call target_error))
$(if $(UPDATE),$(call update_all),)
$(if $(wildcard .checkout_$(TBUILD)),,$(call update_feeds,$(TBUILD)))
$(if $(wildcard .checkout_$(TBUILD)),,$(call copy_config))
@touch .checkout_$(TBUILD)
sync_config:
$(if $(TARGET),,$(call target_error))
$(if $(wildcard $(MY_CONFIGS)/$(TARGET_CONFIGS)), $(call copy_myconfig),$(call copy_config))
update: .checkout_lime_pkg
$(if $(TBUILD),,$(call target_error))
cd $(BUILD_DIR)/$(LIME_PKG_DIR) && git pull
$(call copy_feeds_file)
update_all: .checkout_lime_pkg
$(call update_all)
update_feeds: update
$(call update_feeds,$(TBUILD))
menuconfig: checkout sync_config
$(call menuconfig_owrt)
kernel_menuconfig: checkout sync_config
$(call kmenuconfig_owrt)
clean:
$(if $(TARGET),$(call clean_target),$(call clean_all))
post_build: checkout
$(call post_build)
pre_build: checkout
$(call pre_build)
list_targets:
$(info $(HW_AVAILABLE))
@exit 0
config:
@select HW in $(HW_AVAILABLE); do break; done; echo $$HW > .config.tmp;
mv .config.tmp .config
help:
cat README.md | more || true
build: checkout sync_config
$(call pre_build)
$(if $(TARGET),$(call build_src))
$(call post_build)
is_up_to_date:
@(cd $(BUILD_DIR)/$(LIME_PKG_DIR) && \
test "$$($(call get_git_local_revision,$(LIME_GIT_BRANCH)))" == "$$($(call get_git_remote_revision,$(LIME_GIT_BRANCH)))";\
echo $$?)