1 ###############################################################################
3 # by Rod Roark <rod@sunsetsystems.com> #
5 # Copyright (C) 2002 Rod Roark #
7 # See http://www.lfsmake.org/ for the most current standard version. #
9 # These Makefiles are made available under the terms of the Artistic License, #
10 # found at http://www.opensource.org/licenses/artistic-license.html. #
11 ###############################################################################
13 ###############################################################################
15 # IPFire.org - A linux based firewall #
16 # Copyright (C) 2007-2023 IPFire Team <info@ipfire.org> #
18 # This program is free software: you can redistribute it and/or modify #
19 # it under the terms of the GNU General Public License as published by #
20 # the Free Software Foundation, either version 3 of the License, or #
21 # (at your option) any later version. #
23 # This program is distributed in the hope that it will be useful, #
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
26 # GNU General Public License for more details. #
28 # You should have received a copy of the GNU General Public License #
29 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
31 ###############################################################################
33 # Cleanup environment from any variables
34 unexport BUILD_ARCH BUILD_PLATFORM BUILDTARGET CROSSTARGET TOOLCHAIN TOOLS_DIR
40 SPACE := $(EMPTY) $(EMPTY)
47 join-with = $(subst $(SPACE),$(1),$(strip $(2)))
49 PARALLELISM = $(shell echo $$( \
50 if [ -n "$(MAX_PARALLELISM)" ] && [ $(MAX_PARALLELISM) -lt 1 ]; then \
52 elif [ -n "$(MAX_PARALLELISM)" ] && [ $(MAX_PARALLELISM) -lt $(DEFAULT_PARALLELISM) ]; then \
53 echo $(MAX_PARALLELISM); \
55 echo $(DEFAULT_PARALLELISM); \
59 MAKETUNING = -j$(PARALLELISM)
61 ifeq "$(TOOLCHAIN)" "1"
70 --xattrs --xattrs-include='*'
77 # URLs that are common sources of downloads. If you're having trouble with
78 # a site you should change its URL to that of a suitable mirror site.
80 URL_IPFIRE = https://source.ipfire.org/source-2.x
81 URL_TOOLCHAIN = https://source.ipfire.org/toolchains
82 URL_SOURCE = git.ipfire.org:/pub/sources/source-2.x
84 # Don't change this; it will be overridden by other makefiles where necessary.
88 # For most packages tarballs are unpacked here and then deleted after
91 DIR_SRC = $(ROOT)/usr/src
93 # Files are downloaded into DIR_TMP and then moved to DIR_DL, to avoid
94 # messes with partially retrieved files. DIR_DL is where we will
95 # save all the files that are downloaded. DIR_INFO contains the
96 # file lists of installed packages.
98 DIR_DL = $(LFS_BASEDIR)/cache
99 DIR_CHK = $(LFS_BASEDIR)/cache/check
100 DIR_CONF = $(LFS_BASEDIR)/config
101 DIR_INFO = $(LFS_BASEDIR)/log
103 DIR_TMP_PAK = $(DIR_TMP)/package-$(PROG)
105 # Add the compiler location and version and specs to the ccache hash
106 CCACHE_COMPILERCHECK += $(shell gcc -dumpspecs 2>/dev/null | md5sum | cut -d ' ' -f1)
108 # We support EFI on x86_64 riscv64 and aarch64
109 ifeq "$(BUILD_ARCH)" "x86_64"
112 GRUB_ARCH = $(BUILD_ARCH)
115 ifeq "$(BUILD_ARCH)" "riscv64"
117 EFI_ARCH = $(BUILD_ARCH)
118 GRUB_ARCH = $(BUILD_ARCH)
121 ifeq "$(BUILD_ARCH)" "aarch64"
130 export GOPATH = $(HOME)/gopath
132 ifeq "$(BUILD_ARCH)" "x86_64"
136 ifeq "$(BUILD_ARCH)" "aarch64"
141 ifeq "$(BUILD_ARCH)" "riscv64"
142 RUST_ARCH = riscv64gc
144 RUST_ARCH = $(BUILD_ARCH)
147 RUST_PLATFORM = $(RUST_ARCH)-unknown-linux-gnu
149 CARGO_PATH = $(DIR_APP)/.cargo
150 CARGO_REGISTRY = /usr/share/cargo/registry
152 CRATE_NAME = $(patsubst rust-%,%,$(firstword $(MAKEFILE_LIST)))
154 CRATE_PATH = $(CARGO_REGISTRY)/$(CRATE_NAME)-$(CRATE_VER)
158 rustflags = [$(call join-with,$(COMMA)$(SPACE),$(foreach flag,$(RUSTFLAGS),"$(flag)"))]
162 CXXFLAGS = "$(CXXFLAGS)"
163 LDFLAGS = "$(LDFLAGS)"
170 [source.local-registry]
171 directory = "$(CARGO_REGISTRY)"
174 registry = "https://crates.io"
175 replace-with = "local-registry"
179 # Set to false if you want to skip the binary install step
183 CARGOPATH=$(CARGO_PATH) \
191 # Cargo dealocks on riscv64 when building on multiple cores at the same time
192 ifeq "$(BUILD_ARCH)" "riscv64"
195 CARGO_OPTIONS += $(MAKETUNING)
199 mkdir -p $(CARGO_PATH) && \
200 echo "$${CARGO_CONFIG}" > $(CARGO_PATH)/config && \
210 # Checks whether this crate has a right taregt
211 CARGO_TARGET_CHECK = $(CARGO) metadata --format-version 1 --no-deps | \
212 jq -e ".packages[].targets[].kind | any(. == \"$(1)\")" | grep -q "true"
215 mkdir -pv "$(CRATE_PATH)" && \
216 if $(call CARGO_TARGET_CHECK,lib) || $(call CARGO_TARGET_CHECK,rlib) || $(call CARGO_TARGET_CHECK,proc-macro); then \
218 '/^\\\[((.+\\\.)?((dev|build)-)?dependencies|features)/{f=1;next} /^\\\[/{f=0}; !f' \
219 < Cargo.toml > Cargo.toml.deps && \
220 $(CARGO) package -l | grep -wEv "Cargo.(lock|toml.orig)" \
221 | xargs -d "\n" cp -v --parents -a -t $(CRATE_PATH) && \
222 install -v -m 644 Cargo.toml.deps $(CRATE_PATH)/Cargo.toml && \
223 echo "{\"files\":{},\"package\":\"\"}" > $(CRATE_PATH)/.cargo-checksum.json; \
225 if $(CARGO_HAS_BIN) && $(call CARGO_TARGET_CHECK,bin); then \
226 $(CARGO) install $(CARGO_OPTIONS) --no-track --path .; \
230 ###############################################################################
231 # Common Macro Definitions
232 ###############################################################################
234 # For each package we create a list of files that it installed under
235 # log/<TARGET> name. Modified files are not identified
238 cd $(ROOT)/ && find -mount \
239 \( -path '.$(TOOLS_DIR)' -or -path './tmp' -or -path './usr/src' \
240 -or -path './run' -or -path './dev' -or -path './proc' \
241 -or -path './install' -or -path '.*/__pycache__' \) -prune -or -print | sort
244 # This is common starting logic for builds.
248 echo "====================================== Installing $(THISAPP) ..."
249 @echo "Install started; saving file list to $(DIR_SRC)/lsalr ..."
250 @if [ ! -f $(DIR_SRC)/lsalr ]; then $(FIND_FILES) > $(DIR_SRC)/lsalr; fi
251 # Fix installation on partial rebuild, so modules install where they should
252 # and not everytime on the last compiled kernel
253 if [ -f $(DIR_SRC)/linux-$(KVER) ]; then \
254 cd $(DIR_SRC)/linux-$(KVER) && \
255 sed -i -e 's+^EXTRAVERSION.*$$+EXTRAVERSION\ =\ $(word 4,$(subst ., .,$(KVER)))-ipfire$(KCFG)+' Makefile; \
260 echo "====================================== Installing $(THISAPP) ..."
264 # Common end-of-installation logic for Stage 2 and beyond.
268 @echo "Updating linker cache..."
269 @type -p ldconfig >/dev/null && ldconfig || :
270 @echo "Install done; saving file list to $(TARGET) ..."
271 @rm -rf $(GOPATH) /root/.cargo
272 @$(FIND_FILES) > $(DIR_SRC)/lsalrnew
273 @diff $(DIR_SRC)/lsalr $(DIR_SRC)/lsalrnew | grep '^> ' | sed 's/^> //' > $(TARGET)_diff
274 @mv -f $(DIR_SRC)/lsalrnew $(DIR_SRC)/lsalr
275 @sed -i -e 's+.\/++' $(TARGET)_diff
276 # compare roofile ( same name as lfs script) with the list of installed files
278 # - if the corresponding rootfile is not found, touch $(TARGET)_missing_rootfile
279 # - on a partial rebuild without a new file inside TARGET_diff, just touch TARGET
280 # $(TARGET)_diff : result of the diff
281 # ROOTFILE : reference of include/exclude files
282 # $(TARGET)_rootfile : ROOTFILE with KVER replacement
283 # $(TARGET) : log result with {commented|include|added} files
284 @if [ -s "$(TARGET)_diff" ]; then \
285 LFS_SCRIPT=$(firstword $(MAKEFILE_LIST))$(KCFG); \
286 echo $(LFS_SCRIPT); \
287 ROOTFILE=$$(find -L $(DIR_SRC)/config/rootfiles/{common,packages}/{$(BUILD_ARCH),} -maxdepth 1 -type f -name $$LFS_SCRIPT 2>/dev/null | head -1); \
288 if [ "$$ROOTFILE" = "" ]; then \
289 touch $(TARGET)_missing_rootfile; \
290 ROOTFILE=$(TARGET)_missing_rootfile ; \
291 echo "error $$LFS_SCRIPT not found in config/rootfiles"; \
293 sed -e "s/BUILDTARGET/$(BUILDTARGET)/g" -e "s/KVER/$(KVER)/g" -e "s/xxxMACHINExxx/$(BUILD_ARCH)/g" $$ROOTFILE > $(TARGET)_rootfile; \
294 while read -r line; do \
295 if grep -qG "^#$$line$$" $(TARGET)_rootfile; then echo "#$$line" >> $(TARGET); \
296 elif grep -qG "^$$line$$" $(TARGET)_rootfile ; then echo "$$line" >> $(TARGET); \
297 else echo "+$$line" >> $(TARGET); \
299 done < $(TARGET)_diff; \
300 grep -v "^#" $(TARGET)_rootfile | while read -r line; do \
301 if ! grep -qG "^$$line$$" $(TARGET)_diff ; then echo "-$$line" >> $(TARGET); \
304 rm -f $(TARGET)_rootfile; \
308 @rm -f $(TARGET)_diff
312 @echo "===================================== Install done for $(THISAPP)."
318 @echo -e "$(MESSAGE)Check: $($(notdir $@))"
319 wget -T 120 -t 1 --spider -nv -U "IPFireSourceGrabber/2.x" $($(notdir $@)) -O /dev/null
320 @touch $(DIR_CHK)/$(notdir $@)
324 @echo -e "$(MESSAGE)Download: $($(notdir $@))"
325 wget -T 60 -t 1 -nv -U "IPFireSourceGrabber/2.x" $($(notdir $@)) -O $(DIR_TMP)/$(notdir $@)
326 [ "$($(notdir $@)_BLAKE2)" = "$$(b2sum $(DIR_TMP)/$(notdir $@) | awk '{ print $$1 }')" ] # detect page not found answer
327 mv $(DIR_TMP)/$(notdir $@) $(DIR_DL)
331 # error mean file signature don't match the one in lfs script
332 [ "$($@_BLAKE2)" = "$$(b2sum $(DIR_DL)/$@ | awk '{ print $$1 }')" ] && echo "$@ checksum OK"
336 # Bringing the files to their right place.
337 @rm -rf $(DIR_TMP_PAK) && mkdir -p $(DIR_TMP_PAK)
338 if [ -e "/usr/src/src/paks/$(PROG)" ]; then \
339 cp -f /usr/src/src/paks/$(PROG)/{,un}install.sh /usr/src/src/paks/$(PROG)/update.sh \
342 cp -f /usr/src/src/paks/default/{,un}install.sh /usr/src/src/paks/default/update.sh \
345 for i in $(DIR_SRC)/config/rootfiles/packages/{$(BUILD_ARCH),}/$(PROG); do \
346 if [ -e "$${i}" ]; then \
347 cp -v $${i} $(DIR_TMP_PAK)/ROOTFILES; \
352 # Replace variables in rootfiles
353 sed -i $(DIR_TMP_PAK)/ROOTFILES \
354 -e 's/BUILDTARGET/$(BUILDTARGET)/g' \
355 -e 's/KVER/$(KVER)/g' \
356 -e 's/xxxMACHINExxx/$(BUILD_ARCH)/g'
358 # Replace variables in scripts
359 sed -i $(DIR_TMP_PAK)/install.sh \
360 -e 's/xxxKVERxxx/$(KVER)/g'
362 # Make scripts executable
363 chmod 754 $(DIR_TMP_PAK)/{{,un}install,update}.sh
366 rm -rf $(DIR_TMP_PAK)/root && mkdir -p $(DIR_TMP_PAK)/root
367 tar -c --exclude='#*' --exclude='proc/*' --exclude='dev/pts/*' --exclude='tmp/*' \
368 --exclude='__pycache__' \
369 -C / --files-from=$(DIR_TMP_PAK)/ROOTFILES | tar -x -C $(DIR_TMP_PAK)/root; \
370 exit $${PIPESTATUS[0]}
373 cd $(DIR_TMP_PAK)/root && tar cf - * | xz $(XZ_OPT) > $(DIR_TMP_PAK)/files.tar.xz
375 # Cleanup temporary files
376 rm -rf $(DIR_TMP_PAK)/root
378 # Remove any commented lines
379 sed -i $(DIR_TMP_PAK)/ROOTFILES -e "/^#/d"
382 cd $(DIR_TMP_PAK) && tar cf /install/packages/$(PROG)-$(VER)-$(PAK_VER).ipfire *
385 rm -rf $(DIR_TMP_PAK)
387 # Escape SUMMARY variable and create meta file
388 summaryEscaped=$$(sed 's/[&/\]/\\&/g' <<< "$(SUMMARY)"); \
390 -e "s/NAME/$(PROG)/g" \
391 -e "s/SUMMARY/$$summaryEscaped/g" \
392 -e "s/VER/$(VER)/g" \
393 -e "s/RELEASE/$(PAK_VER)/g" \
394 -e "s/DEPS/$(DEPS)/g" \
395 -e "s/SIZE/$$(stat --format=%s /install/packages/$(PROG)-$(VER)-$(PAK_VER).ipfire)/g" \
396 -e "s/SERVICES/$(SERVICES)/g" \
397 < /usr/src/src/pakfire/meta > /install/packages/meta-$(PROG)
400 define INSTALL_INITSCRIPT
401 install -m 754 -v $(DIR_SRC)/src/initscripts/packages/$(1) /etc/rc.d/init.d/$(1)
404 define INSTALL_INITSCRIPTS
405 for initscript in $(1); do \
406 $(call INSTALL_INITSCRIPT,$$initscript) || exit 1; \
410 ifeq "$(BUILD_ARCH)" "$(filter $(BUILD_ARCH),aarch64 riscv64)"
411 define UPDATE_AUTOMAKE
412 for i in $$(find $(DIR_APP) -name config.guess -o -name config.sub); do \
413 cp -vf /usr/share/automake*/$$(basename $${i}) $${i} || \
414 cp -vf $(TOOLS_DIR)/share/automake*/$$(basename $${i}) $${i}; \
420 $(call INSTALL_INITSCRIPT,hostapd)