-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
168 lines (133 loc) · 3.92 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
#
# Copyright (C) 2019 Vincent Wiemann <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0
#
export BUILD_TOPDIR=$(PWD)
export STAGING_DIR=$(BUILD_TOPDIR)/tmp
export MAKECMD=make --silent ARCH=mips CROSS_COMPILE=mipsel-openwrt-linux-musl-
export PATH:=$(BUILD_TOPDIR)/toolchain/bin/:$(PATH)
SHELL = bash
HOSTARCH := $(shell uname -m | \
sed -e s/i.86/x86_32/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ \
-e s/sa110/arm/ \
-e s/powerpc/ppc/ \
-e s/macppc/ppc/)
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
sed -e 's/\(cygwin\).*/cygwin/')
ifneq ($(HOSTOS), darwin)
ifneq ($(HOSTOS), linux)
$(error Error! Unsupported host operating system/arch: "$(HOSTOS)-$(HOSTARCH)")
endif
endif
export HOSTOS
export HOSTARCH
export STAGING_DIR = $(BUILD_TOPDIR)/tmp
export SOURCE_DIR = $(BUILD_TOPDIR)/u-boot
export BIN_DIR = $(BUILD_TOPDIR)/bin
export SUB_MAKE_CMD = $(MAKE) --silent --no-print-directory \
ARCH=mips V=1 SHELL=$(SHELL)
ifndef CROSS_COMPILE
CROSS_COMPILE = mipsel-openwrt-linux-musl-
endif
export CROSS_COMPILE
# =======================
# CUSTOM HELPER FUNCTIONS
# =======================
define echo_green
echo -e "\e[92m$(1)\e[0m"
endef
define echo_red
echo -e "\e[91m$(1)\e[0m"
endef
define echo_blue
echo -e "\e[96m$(1)\e[0m"
endef
# $(1): size
define img_size
$(if $(IMG_SIZE),$(strip $(IMG_SIZE)),$(strip $(1)))
endef
define git_branch
$(shell git symbolic-ref --short -q HEAD 2>/dev/null || echo "unknown")
endef
define git_hash
$(shell git rev-parse --short=8 -q HEAD 2>/dev/null || echo "unknown")
endef
define git_branch_hash
git_$(call git_branch)-$(call git_hash)
endef
# $(1): file extension
define img_name
tp-u-boot__$@__$(shell date +"%Y%m%d")__$(call git_branch_hash)
endef
define md5_sum
$(call echo_green,Calculating MD5 sum for the final image...)
md5sum $(BIN_DIR)/$(call img_name,bin) | \
awk '{print $$1}' | \
tr -d '\n' > $(BIN_DIR)/$(call img_name).md5
echo ' *'$(call img_name,bin) >> $(BIN_DIR)/$(call img_name,md5)
endef
# $(1): size
define padded_img
$(call echo_green,Preparing $(1) KB image padded with 0xFF...)
tr "\000" "\377" < /dev/zero | dd ibs=1k count=$(1) \
of=$(BIN_DIR)/$(call img_name,bin) 2> /dev/null
endef
define final_img
$(call echo_green,Preparing final image...)
dd if=$(BIN_DIR)/temp.bin of=$(BIN_DIR)/$(call img_name,bin) \
conv=notrunc 2> /dev/null
rm -f $(BIN_DIR)/temp.bin
endef
# $(1): path to image
# $(2): size limit in KB
define size_chk
$(call echo_green,Checking size of the image...)
if [ `wc -c < $(1)` -gt $$(($(2) * 1024)) ]; then \
echo; \
$(call echo_red, ======================); \
$(call echo_red, IMAGE SIZE IS TOO BIG!); \
$(call echo_red, ======================); \
echo; \
rm -f $(1); \
exit 1; \
fi;
endef
# $(1): filename of image to copy
# $(2): image size limit (check if set)
define copy_img
echo;
$(call echo_green,Copying compiled image...)
cp $(SOURCE_DIR)/$(strip $(1)).bin $(BIN_DIR)/temp.bin
$(if $(2),$(call size_chk,$(BIN_DIR)/temp.bin,$(2)))
endef
# $(1): size limit in KB
# $(2): other parameters passed to subdir make
define build
args="IMG_SIZE=$$((1024*$(call img_size,$(1)))) \
TP_BOARD_FILE=$(strip $(2))"; \
cd $(SOURCE_DIR) && \
$(SUB_MAKE_CMD) $$args && \
$(SUB_MAKE_CMD) all $$args
$(call final_img)
$(call md5_sum)
echo;
$(call echo_green,DONE!)
$(call echo_green,Image 'bin/$(call img_name,bin)' is ready!)
endef
# ===========================================
# TARGETS IN ALPHABETICAL ORDER, SHARED FIRST
# ===========================================
tp-link_archer_c50_v4:
@$(call build,128,tp_archer_c50_v4)
# =============
# CLEAN TARGETS
# =============
clean:
@cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) distclean
clean_all: clean
@$(call echo_green,Removing all binary images...)
@rm -f $(BIN_DIR)/*.bin
@rm -f $(BIN_DIR)/*.md5