-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
159 lines (123 loc) · 5.51 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
# Kernel and Firmware version to use when building Phonebo.Cx Kernel. This
# should be provided by the isobuild Makefile, but defaults are here for
# testing
KERNELVER ?= 6.6.39
KERNELREL ?= 1
KFIRMWARE ?= 20240610
KMAJOR=$(word 1,$(subst ., ,$(KERNELVER)))
KMINOR=$(word 2,$(subst ., ,$(KERNELVER)))
KREV=$(word 3,$(subst ., ,$(KERNELVER)))
BUILDER="Honest Rob <[email protected]>"
ORIG=src/linux-$(KERNELVER).tar.xz
FORIG=src/linux-firmware-$(KFIRMWARE).tar.gz
DEST=kernel/linux-$(KERNELVER)
FDEST=kernel/linux-firmware-$(KFIRMWARE)
DIR=$(shell pwd)
SHELL=/bin/bash
export KERNELREV DEST DIR
.PHONY: all clean distclean setup modules deb patch unpatch sgm-dahdi firmware test
DPKG_FLAGS=-Zgzip
export DPKG_FLAGS
DESTDEB=kernel/linux-image-$(KERNELVER)-$(KERNELREL)_$(KERNELVER)-$(KERNELREL)_amd64.deb
# PhoneBo.cx git repo, sgm branch.
DAHDI_SRC=src/dahdi-linux
test: $(DESTDEB)
# If this fails, the kernel did not build Dahdi or our USB device
@dpkg-deb --contents $< | grep ua32xx.ko && echo ua32xx.ko found
@dpkg-deb --contents $< | grep dahdi.ko && echo dahdi.ko found
clean:
[ -d $(DIR)/kernel ] && cd $(DIR)/kernel && rm -rf * || :
distclean: clean
rm -rf $(DEST) $(FDEST) $(DAHDI_SRC)
firmware: $(FORIG)
mkdir -p $(FDEST) && \
tar -C $(FDEST) --strip-components=1 -xf $(FORIG)
setup: /usr/bin/ccache /usr/bin/gcc $(DEST)/.config patch
@if ! grep -q DAHDI $(DEST)/.config; then echo ".config has no DAHDI lines"; exit 1; fi
/usr/bin/ccache:
apt-get -y install ccache
.PHONY: packages
packages /usr/bin/gcc:
apt-get -y install build-essential flex bison libelf-dev libssl-dev bc debhelper libelf-dev:native libssl-dev:native
deb: $(DESTDEB)
modules:
cd $(DEST) && make -j$(shell nproc) CC="ccache gcc" $@
$(DESTDEB): setup
cd $(DEST) && make -j$(shell nproc) CC="ccache gcc" LOCALVERSION="-$(KERNELREL)" KDEB_PKGVERSION="$(KERNELVER)-$(KERNELREL)" EMAIL=$(BUILDER) DPKG_FLAGS=$(DPKG_FLAGS) bindeb-pkg
SCONFIG=configs/defconfig-$(KMAJOR)
$(DEST)/.config: $(DEST)/Makefile sgm-dahdi $(DEST)/arch/x86/configs/pbx_defconfig patch
cd $(DEST) && make pbx_defconfig
touch $(DEST)/.config
$(DEST)/arch/x86/configs/pbx_defconfig: $(SCONFIG)
cp -p $< $@
$(DEST)/Makefile: $(ORIG)
mkdir -p $(DEST) && \
tar -C $(DEST) --strip-components=1 -xf $(ORIG) && \
touch $@
patch: $(DEST)/.patched
$(DEST)/.patched: $(DEST)/.config
@cd $(DEST); \
for x in $(wildcard $(DIR)/patches/*.patch); do \
echo Applying patch $$(basename $$x); \
patch -p0 < $$x; \
done; \
for x in $(wildcard $(DIR)/patches/*.sh); do \
echo Running patch script $$(basename $$x); \
$$x -i; \
done
@touch $@
unpatch:
@[ -d $(DEST) ] && cd $(DEST) && \
for x in $(wildcard $(DIR)/patches/*.patch); do \
echo Removing patch $$(basename $$x); \
patch -R -N -r/dev/null -p0 < $$x || :; \
done && \
for x in $(wildcard $(DIR)/patches/*.sh); do \
echo Running patch uninstall $$(basename $$x); \
$$x -u; \
done && \
rm -f .patched || :
src/linux-6%.xz:
@mkdir -p src
@wget https://cdn.kernel.org/pub/linux/kernel/v6.x/$(@F) -O $@
src/linux-5%.xz:
@mkdir -p src
@wget https://cdn.kernel.org/pub/linux/kernel/v5.x/$(@F) -O $@
src/linux-firmware-%.tar.gz:
@mkdir -p src
wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/snapshot/$(@F) -O $@
sgm-dahdi: $(DAHDI_SRC) $(DEST)/drivers/dahdi $(DAHDI_SRC)/include/dahdi/version.h $(DEST)/include/dahdi $(DEST)/include/uapi/dahdi dmpatched
dmpatched: $(DEST)/drivers/.Makefile_patched $(DEST)/drivers/.KConf_patched
$(DEST)/drivers/.Makefile_patched:
@sed -i -e '/linux\/dahdi/d' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/dahdi_config.h:CONFIG_HDLC' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/dahdi_config.h:CONFIG_HDLC_MODULE' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/dahdi_config.h:CONFIG_PPP' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/dahdi_config.h:CONFIG_PPP_MODULE' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/dahdi_config.h:CONFIG_DAHDI_CORE_TIMER' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/kernel.h:CONFIG_DAHDI_NET' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/kernel.h:CONFIG_DAHDI_PPP' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/kernel.h:CONFIG_DAHDI_ECHOCAN_PROCESS_TX' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/kernel.h:CONFIG_DAHDI_MIRROR' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/kernel.h:CONFIG_CALC_XLAW' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/kernel.h:CONFIG_DAHDI_WATCHDOG' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/kernel.h:CONFIG_PROC_FS' \
-e '/^config_leak_ignores=/a include/uapi/dahdi/user.h:CONFIG_DAHDI_MIRROR' \
$(DEST)/scripts/headers_install.sh && \
sed -i -e '/dahdi/d' -e '/endmenu/i source "drivers/dahdi/Kconfig"' $(DEST)/drivers/Kconfig && \
sed -i -e '/dahdi/d' $(DEST)/drivers/Makefile && \
echo 'obj-$$(CONFIG_DAHDI) += dahdi/' >> $(DEST)/drivers/Makefile
touch $@
$(DAHDI_SRC):
cd src && git clone -b sgm https://github.com/phonebocx/dahdi-linux.git
$(DAHDI_SRC)/include/dahdi/version.h:
cd $(DAHDI_SRC) && make include/dahdi/version.h
# '---help---' is no longer the delimter for help. It's now 'help'. Fix it.
$(DEST)/drivers/.KConf_patched: $(DEST)/drivers/dahdi/xpp/.KConf_patched $(DEST)/drivers/dahdi/.KConf_patched
$(DEST)/drivers/dahdi/xpp/.KConf_patched $(DEST)/drivers/dahdi/.KConf_patched: $(DEST)/drivers/dahdi
@sed -i 's/---help---/help/g' $(@D)/Kconfig
@touch $@
$(DEST)/drivers/dahdi:
rsync -av --delete $(DAHDI_SRC)/drivers/dahdi/ $@
$(DEST)/include/dahdi $(DEST)/include/uapi/dahdi:
mkdir -p $@ && cp $(DAHDI_SRC)/include/dahdi/*.h $@