18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#
38c2ecf20Sopenharmony_ci# Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciPWD := $(shell pwd)
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciCHOST := $(shell gcc -dumpmachine)
88c2ecf20Sopenharmony_ciHOST_ARCH := $(firstword $(subst -, ,$(CHOST)))
98c2ecf20Sopenharmony_ciifneq (,$(ARCH))
108c2ecf20Sopenharmony_ciCBUILD := $(subst -gcc,,$(lastword $(subst /, ,$(firstword $(wildcard $(foreach bindir,$(subst :, ,$(PATH)),$(bindir)/$(ARCH)-*-gcc))))))
118c2ecf20Sopenharmony_ciifeq (,$(CBUILD))
128c2ecf20Sopenharmony_ci$(error The toolchain for $(ARCH) is not installed)
138c2ecf20Sopenharmony_ciendif
148c2ecf20Sopenharmony_cielse
158c2ecf20Sopenharmony_ciCBUILD := $(CHOST)
168c2ecf20Sopenharmony_ciARCH := $(firstword $(subst -, ,$(CBUILD)))
178c2ecf20Sopenharmony_ciendif
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci# Set these from the environment to override
208c2ecf20Sopenharmony_ciKERNEL_PATH ?= $(PWD)/../../../../..
218c2ecf20Sopenharmony_ciBUILD_PATH ?= $(PWD)/build/$(ARCH)
228c2ecf20Sopenharmony_ciDISTFILES_PATH ?= $(PWD)/distfiles
238c2ecf20Sopenharmony_ciNR_CPUS ?= 4
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciMIRROR := https://download.wireguard.com/qemu-test/distfiles/
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cidefault: qemu
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci# variable name, tarball project name, version, tarball extension, default URI base
308c2ecf20Sopenharmony_cidefine tar_download =
318c2ecf20Sopenharmony_ci$(1)_VERSION := $(3)
328c2ecf20Sopenharmony_ci$(1)_NAME := $(2)-$$($(1)_VERSION)
338c2ecf20Sopenharmony_ci$(1)_TAR := $(DISTFILES_PATH)/$$($(1)_NAME)$(4)
348c2ecf20Sopenharmony_ci$(1)_PATH := $(BUILD_PATH)/$$($(1)_NAME)
358c2ecf20Sopenharmony_ci$(call file_download,$$($(1)_NAME)$(4),$(5),$(6))
368c2ecf20Sopenharmony_ciendef
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cidefine file_download =
398c2ecf20Sopenharmony_ci$(DISTFILES_PATH)/$(1):
408c2ecf20Sopenharmony_ci	mkdir -p $(DISTFILES_PATH)
418c2ecf20Sopenharmony_ci	flock -x $$@.lock -c '[ -f $$@ ] && exit 0; wget -O $$@.tmp $(MIRROR)$(1) || wget -O $$@.tmp $(2)$(1) || rm -f $$@.tmp; [ -f $$@.tmp ] || exit 1; if echo "$(3)  $$@.tmp" | sha256sum -c -; then mv $$@.tmp $$@; else rm -f $$@.tmp; exit 71; fi'
428c2ecf20Sopenharmony_ciendef
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci$(eval $(call tar_download,MUSL,musl,1.2.0,.tar.gz,https://musl.libc.org/releases/,c6de7b191139142d3f9a7b5b702c9cae1b5ee6e7f57e582da9328629408fd4e8))
458c2ecf20Sopenharmony_ci$(eval $(call tar_download,IPERF,iperf,3.7,.tar.gz,https://downloads.es.net/pub/iperf/,d846040224317caf2f75c843d309a950a7db23f9b44b94688ccbe557d6d1710c))
468c2ecf20Sopenharmony_ci$(eval $(call tar_download,BASH,bash,5.0,.tar.gz,https://ftp.gnu.org/gnu/bash/,b4a80f2ac66170b2913efbfb9f2594f1f76c7b1afd11f799e22035d63077fb4d))
478c2ecf20Sopenharmony_ci$(eval $(call tar_download,IPROUTE2,iproute2,5.6.0,.tar.xz,https://www.kernel.org/pub/linux/utils/net/iproute2/,1b5b0e25ce6e23da7526ea1da044e814ad85ba761b10dd29c2b027c056b04692))
488c2ecf20Sopenharmony_ci$(eval $(call tar_download,IPTABLES,iptables,1.8.4,.tar.bz2,https://www.netfilter.org/projects/iptables/files/,993a3a5490a544c2cbf2ef15cf7e7ed21af1845baf228318d5c36ef8827e157c))
498c2ecf20Sopenharmony_ci$(eval $(call tar_download,NMAP,nmap,7.80,.tar.bz2,https://nmap.org/dist/,fcfa5a0e42099e12e4bf7a68ebe6fde05553383a682e816a7ec9256ab4773faa))
508c2ecf20Sopenharmony_ci$(eval $(call tar_download,IPUTILS,iputils,s20190709,.tar.gz,https://github.com/iputils/iputils/archive/s20190709.tar.gz/#,a15720dd741d7538dd2645f9f516d193636ae4300ff7dbc8bfca757bf166490a))
518c2ecf20Sopenharmony_ci$(eval $(call tar_download,WIREGUARD_TOOLS,wireguard-tools,1.0.20200206,.tar.xz,https://git.zx2c4.com/wireguard-tools/snapshot/,f5207248c6a3c3e3bfc9ab30b91c1897b00802ed861e1f9faaed873366078c64))
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciKERNEL_BUILD_PATH := $(BUILD_PATH)/kernel$(if $(findstring yes,$(DEBUG_KERNEL)),-debug)
548c2ecf20Sopenharmony_cirwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
558c2ecf20Sopenharmony_ciWIREGUARD_SOURCES := $(call rwildcard,$(KERNEL_PATH)/drivers/net/wireguard/,*)
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciexport CFLAGS ?= -O3 -pipe
588c2ecf20Sopenharmony_ciexport LDFLAGS ?=
598c2ecf20Sopenharmony_ciexport CPPFLAGS := -I$(BUILD_PATH)/include
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
628c2ecf20Sopenharmony_ciCROSS_COMPILE_FLAG := --host=$(CHOST)
638c2ecf20Sopenharmony_ciCFLAGS += -march=native
648c2ecf20Sopenharmony_ciSTRIP := strip
658c2ecf20Sopenharmony_cielse
668c2ecf20Sopenharmony_ci$(info Cross compilation: building for $(CBUILD) using $(CHOST))
678c2ecf20Sopenharmony_ciCROSS_COMPILE_FLAG := --build=$(CBUILD) --host=$(CHOST)
688c2ecf20Sopenharmony_ciexport CROSS_COMPILE=$(CBUILD)-
698c2ecf20Sopenharmony_ciSTRIP := $(CBUILD)-strip
708c2ecf20Sopenharmony_ciendif
718c2ecf20Sopenharmony_ciifeq ($(ARCH),aarch64)
728c2ecf20Sopenharmony_ciQEMU_ARCH := aarch64
738c2ecf20Sopenharmony_ciKERNEL_ARCH := arm64
748c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm64/boot/Image
758c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
768c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
778c2ecf20Sopenharmony_cielse
788c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu cortex-a53 -machine virt
798c2ecf20Sopenharmony_ciCFLAGS += -march=armv8-a -mtune=cortex-a53
808c2ecf20Sopenharmony_ciendif
818c2ecf20Sopenharmony_cielse ifeq ($(ARCH),aarch64_be)
828c2ecf20Sopenharmony_ciQEMU_ARCH := aarch64
838c2ecf20Sopenharmony_ciKERNEL_ARCH := arm64
848c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm64/boot/Image
858c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
868c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
878c2ecf20Sopenharmony_cielse
888c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu cortex-a53 -machine virt
898c2ecf20Sopenharmony_ciCFLAGS += -march=armv8-a -mtune=cortex-a53
908c2ecf20Sopenharmony_ciendif
918c2ecf20Sopenharmony_cielse ifeq ($(ARCH),arm)
928c2ecf20Sopenharmony_ciQEMU_ARCH := arm
938c2ecf20Sopenharmony_ciKERNEL_ARCH := arm
948c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm/boot/zImage
958c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
968c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
978c2ecf20Sopenharmony_cielse
988c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu cortex-a15 -machine virt
998c2ecf20Sopenharmony_ciCFLAGS += -march=armv7-a -mtune=cortex-a15 -mabi=aapcs-linux
1008c2ecf20Sopenharmony_ciendif
1018c2ecf20Sopenharmony_cielse ifeq ($(ARCH),armeb)
1028c2ecf20Sopenharmony_ciQEMU_ARCH := arm
1038c2ecf20Sopenharmony_ciKERNEL_ARCH := arm
1048c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm/boot/zImage
1058c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1068c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
1078c2ecf20Sopenharmony_cielse
1088c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu cortex-a15 -machine virt
1098c2ecf20Sopenharmony_ciCFLAGS += -march=armv7-a -mabi=aapcs-linux # We don't pass -mtune=cortex-a15 due to a compiler bug on big endian.
1108c2ecf20Sopenharmony_ciLDFLAGS += -Wl,--be8
1118c2ecf20Sopenharmony_ciendif
1128c2ecf20Sopenharmony_cielse ifeq ($(ARCH),x86_64)
1138c2ecf20Sopenharmony_ciQEMU_ARCH := x86_64
1148c2ecf20Sopenharmony_ciKERNEL_ARCH := x86_64
1158c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
1168c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1178c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine q35,accel=kvm
1188c2ecf20Sopenharmony_cielse
1198c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu Skylake-Server -machine q35
1208c2ecf20Sopenharmony_ciCFLAGS += -march=skylake-avx512
1218c2ecf20Sopenharmony_ciendif
1228c2ecf20Sopenharmony_cielse ifeq ($(ARCH),i686)
1238c2ecf20Sopenharmony_ciQEMU_ARCH := i386
1248c2ecf20Sopenharmony_ciKERNEL_ARCH := x86
1258c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
1268c2ecf20Sopenharmony_ciifeq ($(subst x86_64,i686,$(HOST_ARCH)),$(ARCH))
1278c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine q35,accel=kvm
1288c2ecf20Sopenharmony_cielse
1298c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu coreduo -machine q35
1308c2ecf20Sopenharmony_ciCFLAGS += -march=prescott
1318c2ecf20Sopenharmony_ciendif
1328c2ecf20Sopenharmony_cielse ifeq ($(ARCH),mips64)
1338c2ecf20Sopenharmony_ciQEMU_ARCH := mips64
1348c2ecf20Sopenharmony_ciKERNEL_ARCH := mips
1358c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
1368c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1378c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine malta,accel=kvm
1388c2ecf20Sopenharmony_ciCFLAGS += -EB
1398c2ecf20Sopenharmony_cielse
1408c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu MIPS64R2-generic -machine malta -smp 1
1418c2ecf20Sopenharmony_ciCFLAGS += -march=mips64r2 -EB
1428c2ecf20Sopenharmony_ciendif
1438c2ecf20Sopenharmony_cielse ifeq ($(ARCH),mips64el)
1448c2ecf20Sopenharmony_ciQEMU_ARCH := mips64el
1458c2ecf20Sopenharmony_ciKERNEL_ARCH := mips
1468c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
1478c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1488c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine malta,accel=kvm
1498c2ecf20Sopenharmony_ciCFLAGS += -EL
1508c2ecf20Sopenharmony_cielse
1518c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu MIPS64R2-generic -machine malta -smp 1
1528c2ecf20Sopenharmony_ciCFLAGS += -march=mips64r2 -EL
1538c2ecf20Sopenharmony_ciendif
1548c2ecf20Sopenharmony_cielse ifeq ($(ARCH),mips)
1558c2ecf20Sopenharmony_ciQEMU_ARCH := mips
1568c2ecf20Sopenharmony_ciKERNEL_ARCH := mips
1578c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
1588c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1598c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine malta,accel=kvm
1608c2ecf20Sopenharmony_ciCFLAGS += -EB
1618c2ecf20Sopenharmony_cielse
1628c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu 24Kf -machine malta -smp 1
1638c2ecf20Sopenharmony_ciCFLAGS += -march=mips32r2 -EB
1648c2ecf20Sopenharmony_ciendif
1658c2ecf20Sopenharmony_cielse ifeq ($(ARCH),mipsel)
1668c2ecf20Sopenharmony_ciQEMU_ARCH := mipsel
1678c2ecf20Sopenharmony_ciKERNEL_ARCH := mips
1688c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
1698c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1708c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host -machine malta,accel=kvm
1718c2ecf20Sopenharmony_ciCFLAGS += -EL
1728c2ecf20Sopenharmony_cielse
1738c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu 24Kf -machine malta -smp 1
1748c2ecf20Sopenharmony_ciCFLAGS += -march=mips32r2 -EL
1758c2ecf20Sopenharmony_ciendif
1768c2ecf20Sopenharmony_cielse ifeq ($(ARCH),powerpc64le)
1778c2ecf20Sopenharmony_ciQEMU_ARCH := ppc64
1788c2ecf20Sopenharmony_ciKERNEL_ARCH := powerpc
1798c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
1808c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1818c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host,accel=kvm -machine pseries
1828c2ecf20Sopenharmony_cielse
1838c2ecf20Sopenharmony_ciQEMU_MACHINE := -machine pseries
1848c2ecf20Sopenharmony_ciendif
1858c2ecf20Sopenharmony_ciCFLAGS += -mcpu=powerpc64le -mlong-double-64
1868c2ecf20Sopenharmony_cielse ifeq ($(ARCH),powerpc)
1878c2ecf20Sopenharmony_ciQEMU_ARCH := ppc
1888c2ecf20Sopenharmony_ciKERNEL_ARCH := powerpc
1898c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/powerpc/boot/uImage
1908c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
1918c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host,accel=kvm -machine ppce500
1928c2ecf20Sopenharmony_cielse
1938c2ecf20Sopenharmony_ciQEMU_MACHINE := -machine ppce500
1948c2ecf20Sopenharmony_ciendif
1958c2ecf20Sopenharmony_ciCFLAGS += -mcpu=powerpc -mlong-double-64 -msecure-plt
1968c2ecf20Sopenharmony_cielse ifeq ($(ARCH),m68k)
1978c2ecf20Sopenharmony_ciQEMU_ARCH := m68k
1988c2ecf20Sopenharmony_ciKERNEL_ARCH := m68k
1998c2ecf20Sopenharmony_ciKERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
2008c2ecf20Sopenharmony_ciKERNEL_CMDLINE := $(shell sed -n 's/CONFIG_CMDLINE=\(.*\)/\1/p' arch/m68k.config)
2018c2ecf20Sopenharmony_ciifeq ($(HOST_ARCH),$(ARCH))
2028c2ecf20Sopenharmony_ciQEMU_MACHINE := -cpu host,accel=kvm -machine q800 -smp 1 -append $(KERNEL_CMDLINE)
2038c2ecf20Sopenharmony_cielse
2048c2ecf20Sopenharmony_ciQEMU_MACHINE := -machine q800 -smp 1 -append $(KERNEL_CMDLINE)
2058c2ecf20Sopenharmony_ciendif
2068c2ecf20Sopenharmony_cielse
2078c2ecf20Sopenharmony_ci$(error I only build: x86_64, i686, arm, armeb, aarch64, aarch64_be, mips, mipsel, mips64, mips64el, powerpc64le, powerpc, m68k)
2088c2ecf20Sopenharmony_ciendif
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ciREAL_CC := $(CBUILD)-gcc
2118c2ecf20Sopenharmony_ciMUSL_CC := $(BUILD_PATH)/musl-gcc
2128c2ecf20Sopenharmony_ciexport CC := $(MUSL_CC)
2138c2ecf20Sopenharmony_ciUSERSPACE_DEPS := $(MUSL_CC) $(BUILD_PATH)/include/.installed $(BUILD_PATH)/include/linux/.installed
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_cibuild: $(KERNEL_BZIMAGE)
2168c2ecf20Sopenharmony_ciqemu: $(KERNEL_BZIMAGE)
2178c2ecf20Sopenharmony_ci	rm -f $(BUILD_PATH)/result
2188c2ecf20Sopenharmony_ci	timeout --foreground 20m qemu-system-$(QEMU_ARCH) \
2198c2ecf20Sopenharmony_ci		-nodefaults \
2208c2ecf20Sopenharmony_ci		-nographic \
2218c2ecf20Sopenharmony_ci		-smp $(NR_CPUS) \
2228c2ecf20Sopenharmony_ci		$(QEMU_MACHINE) \
2238c2ecf20Sopenharmony_ci		-m $$(grep -q CONFIG_DEBUG_KMEMLEAK=y $(KERNEL_BUILD_PATH)/.config && echo 1G || echo 256M) \
2248c2ecf20Sopenharmony_ci		-serial stdio \
2258c2ecf20Sopenharmony_ci		-serial file:$(BUILD_PATH)/result \
2268c2ecf20Sopenharmony_ci		-no-reboot \
2278c2ecf20Sopenharmony_ci		-monitor none \
2288c2ecf20Sopenharmony_ci		-kernel $<
2298c2ecf20Sopenharmony_ci	grep -Fq success $(BUILD_PATH)/result
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci$(BUILD_PATH)/init-cpio-spec.txt:
2328c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
2338c2ecf20Sopenharmony_ci	echo "file /init $(BUILD_PATH)/init 755 0 0" > $@
2348c2ecf20Sopenharmony_ci	echo "file /init.sh $(PWD)/../netns.sh 755 0 0" >> $@
2358c2ecf20Sopenharmony_ci	echo "dir /dev 755 0 0" >> $@
2368c2ecf20Sopenharmony_ci	echo "nod /dev/console 644 0 0 c 5 1" >> $@
2378c2ecf20Sopenharmony_ci	echo "dir /bin 755 0 0" >> $@
2388c2ecf20Sopenharmony_ci	echo "file /bin/iperf3 $(IPERF_PATH)/src/iperf3 755 0 0" >> $@
2398c2ecf20Sopenharmony_ci	echo "file /bin/wg $(WIREGUARD_TOOLS_PATH)/src/wg 755 0 0" >> $@
2408c2ecf20Sopenharmony_ci	echo "file /bin/bash $(BASH_PATH)/bash 755 0 0" >> $@
2418c2ecf20Sopenharmony_ci	echo "file /bin/ip $(IPROUTE2_PATH)/ip/ip 755 0 0" >> $@
2428c2ecf20Sopenharmony_ci	echo "file /bin/ss $(IPROUTE2_PATH)/misc/ss 755 0 0" >> $@
2438c2ecf20Sopenharmony_ci	echo "file /bin/ping $(IPUTILS_PATH)/ping 755 0 0" >> $@
2448c2ecf20Sopenharmony_ci	echo "file /bin/ncat $(NMAP_PATH)/ncat/ncat 755 0 0" >> $@
2458c2ecf20Sopenharmony_ci	echo "file /bin/xtables-legacy-multi $(IPTABLES_PATH)/iptables/xtables-legacy-multi 755 0 0" >> $@
2468c2ecf20Sopenharmony_ci	echo "slink /bin/iptables xtables-legacy-multi 777 0 0" >> $@
2478c2ecf20Sopenharmony_ci	echo "slink /bin/ping6 ping 777 0 0" >> $@
2488c2ecf20Sopenharmony_ci	echo "dir /lib 755 0 0" >> $@
2498c2ecf20Sopenharmony_ci	echo "file /lib/libc.so $(MUSL_PATH)/lib/libc.so 755 0 0" >> $@
2508c2ecf20Sopenharmony_ci	echo "slink /lib/ld-linux.so.1 libc.so 777 0 0" >> $@
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci$(KERNEL_BUILD_PATH)/.config: kernel.config arch/$(ARCH).config
2538c2ecf20Sopenharmony_ci	mkdir -p $(KERNEL_BUILD_PATH)
2548c2ecf20Sopenharmony_ci	cp kernel.config $(KERNEL_BUILD_PATH)/minimal.config
2558c2ecf20Sopenharmony_ci	printf 'CONFIG_NR_CPUS=$(NR_CPUS)\nCONFIG_INITRAMFS_SOURCE="$(BUILD_PATH)/init-cpio-spec.txt"\n' >> $(KERNEL_BUILD_PATH)/minimal.config
2568c2ecf20Sopenharmony_ci	cat arch/$(ARCH).config >> $(KERNEL_BUILD_PATH)/minimal.config
2578c2ecf20Sopenharmony_ci	$(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) allnoconfig
2588c2ecf20Sopenharmony_ci	cd $(KERNEL_BUILD_PATH) && ARCH=$(KERNEL_ARCH) $(KERNEL_PATH)/scripts/kconfig/merge_config.sh -n $(KERNEL_BUILD_PATH)/.config $(KERNEL_BUILD_PATH)/minimal.config
2598c2ecf20Sopenharmony_ci	$(if $(findstring yes,$(DEBUG_KERNEL)),cp debug.config $(KERNEL_BUILD_PATH) && cd $(KERNEL_BUILD_PATH) && ARCH=$(KERNEL_ARCH) $(KERNEL_PATH)/scripts/kconfig/merge_config.sh -n $(KERNEL_BUILD_PATH)/.config debug.config,)
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci$(KERNEL_BZIMAGE): $(KERNEL_BUILD_PATH)/.config $(BUILD_PATH)/init-cpio-spec.txt $(MUSL_PATH)/lib/libc.so $(IPERF_PATH)/src/iperf3 $(IPUTILS_PATH)/ping $(BASH_PATH)/bash $(IPROUTE2_PATH)/misc/ss $(IPROUTE2_PATH)/ip/ip $(IPTABLES_PATH)/iptables/xtables-legacy-multi $(NMAP_PATH)/ncat/ncat $(WIREGUARD_TOOLS_PATH)/src/wg $(BUILD_PATH)/init ../netns.sh $(WIREGUARD_SOURCES)
2628c2ecf20Sopenharmony_ci	$(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE)
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci$(BUILD_PATH)/include/linux/.installed: | $(KERNEL_BUILD_PATH)/.config
2658c2ecf20Sopenharmony_ci	$(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) INSTALL_HDR_PATH=$(BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) headers_install
2668c2ecf20Sopenharmony_ci	touch $@
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci$(MUSL_PATH)/lib/libc.so: $(MUSL_TAR)
2698c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
2708c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
2718c2ecf20Sopenharmony_ci	cd $(MUSL_PATH) && CC=$(REAL_CC) ./configure --prefix=/ --disable-static --build=$(CBUILD)
2728c2ecf20Sopenharmony_ci	$(MAKE) -C $(MUSL_PATH)
2738c2ecf20Sopenharmony_ci	$(STRIP) -s $@
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci$(BUILD_PATH)/include/.installed: $(MUSL_PATH)/lib/libc.so
2768c2ecf20Sopenharmony_ci	$(MAKE) -C $(MUSL_PATH) DESTDIR=$(BUILD_PATH) install-headers
2778c2ecf20Sopenharmony_ci	touch $@
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci$(MUSL_CC): $(MUSL_PATH)/lib/libc.so
2808c2ecf20Sopenharmony_ci	sh $(MUSL_PATH)/tools/musl-gcc.specs.sh $(BUILD_PATH)/include $(MUSL_PATH)/lib /lib/ld-linux.so.1 > $(BUILD_PATH)/musl-gcc.specs
2818c2ecf20Sopenharmony_ci	printf '#!/bin/sh\nexec "$(REAL_CC)" --specs="$(BUILD_PATH)/musl-gcc.specs" "$$@"\n' > $(BUILD_PATH)/musl-gcc
2828c2ecf20Sopenharmony_ci	chmod +x $(BUILD_PATH)/musl-gcc
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci$(IPERF_PATH)/.installed: $(IPERF_TAR)
2858c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
2868c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
2878c2ecf20Sopenharmony_ci	sed -i '1s/^/#include <stdint.h>/' $(IPERF_PATH)/src/cjson.h $(IPERF_PATH)/src/timer.h
2888c2ecf20Sopenharmony_ci	sed -i -r 's/-p?g//g' $(IPERF_PATH)/src/Makefile*
2898c2ecf20Sopenharmony_ci	touch $@
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci$(IPERF_PATH)/src/iperf3: | $(IPERF_PATH)/.installed $(USERSPACE_DEPS)
2928c2ecf20Sopenharmony_ci	cd $(IPERF_PATH) && CFLAGS="$(CFLAGS) -D_GNU_SOURCE" ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared --with-openssl=no
2938c2ecf20Sopenharmony_ci	$(MAKE) -C $(IPERF_PATH)
2948c2ecf20Sopenharmony_ci	$(STRIP) -s $@
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci$(WIREGUARD_TOOLS_PATH)/.installed: $(WIREGUARD_TOOLS_TAR)
2978c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
2988c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
2998c2ecf20Sopenharmony_ci	touch $@
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci$(WIREGUARD_TOOLS_PATH)/src/wg: | $(WIREGUARD_TOOLS_PATH)/.installed $(USERSPACE_DEPS)
3028c2ecf20Sopenharmony_ci	$(MAKE) -C $(WIREGUARD_TOOLS_PATH)/src wg
3038c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci$(BUILD_PATH)/init: init.c | $(USERSPACE_DEPS)
3068c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
3078c2ecf20Sopenharmony_ci	$(MUSL_CC) -o $@ $(CFLAGS) $(LDFLAGS) -std=gnu11 $<
3088c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci$(IPUTILS_PATH)/.installed: $(IPUTILS_TAR)
3118c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
3128c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
3138c2ecf20Sopenharmony_ci	touch $@
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci$(IPUTILS_PATH)/ping: | $(IPUTILS_PATH)/.installed $(USERSPACE_DEPS)
3168c2ecf20Sopenharmony_ci	sed -i /atexit/d $(IPUTILS_PATH)/ping.c
3178c2ecf20Sopenharmony_ci	cd $(IPUTILS_PATH) && $(CC) $(CFLAGS) -std=c99 -o $@ ping.c ping_common.c ping6_common.c iputils_common.c -D_GNU_SOURCE -D'IPUTILS_VERSION(f)=f' -lresolv $(LDFLAGS)
3188c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci$(BASH_PATH)/.installed: $(BASH_TAR)
3218c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
3228c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
3238c2ecf20Sopenharmony_ci	touch $@
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci$(BASH_PATH)/bash: | $(BASH_PATH)/.installed $(USERSPACE_DEPS)
3268c2ecf20Sopenharmony_ci	cd $(BASH_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --without-bash-malloc --disable-debugger --disable-help-builtin --disable-history --disable-multibyte --disable-progcomp --disable-readline --disable-mem-scramble
3278c2ecf20Sopenharmony_ci	$(MAKE) -C $(BASH_PATH)
3288c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci$(IPROUTE2_PATH)/.installed: $(IPROUTE2_TAR)
3318c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
3328c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
3338c2ecf20Sopenharmony_ci	printf 'CC:=$(CC)\nPKG_CONFIG:=pkg-config\nTC_CONFIG_XT:=n\nTC_CONFIG_ATM:=n\nTC_CONFIG_IPSET:=n\nIP_CONFIG_SETNS:=y\nHAVE_ELF:=n\nHAVE_MNL:=n\nHAVE_BERKELEY_DB:=n\nHAVE_LATEX:=n\nHAVE_PDFLATEX:=n\nCFLAGS+=-DHAVE_SETNS\n' > $(IPROUTE2_PATH)/config.mk
3348c2ecf20Sopenharmony_ci	printf 'lib: snapshot\n\t$$(MAKE) -C lib\nip/ip: lib\n\t$$(MAKE) -C ip ip\nmisc/ss: lib\n\t$$(MAKE) -C misc ss\n' >> $(IPROUTE2_PATH)/Makefile
3358c2ecf20Sopenharmony_ci	touch $@
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci$(IPROUTE2_PATH)/ip/ip: | $(IPROUTE2_PATH)/.installed $(USERSPACE_DEPS)
3388c2ecf20Sopenharmony_ci	$(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ ip/ip
3398c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci$(IPROUTE2_PATH)/misc/ss: | $(IPROUTE2_PATH)/.installed $(USERSPACE_DEPS)
3428c2ecf20Sopenharmony_ci	$(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ misc/ss
3438c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci$(IPTABLES_PATH)/.installed: $(IPTABLES_TAR)
3468c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
3478c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
3488c2ecf20Sopenharmony_ci	sed -i -e "/nfnetlink=[01]/s:=[01]:=0:" -e "/nfconntrack=[01]/s:=[01]:=0:" $(IPTABLES_PATH)/configure
3498c2ecf20Sopenharmony_ci	touch $@
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci$(IPTABLES_PATH)/iptables/xtables-legacy-multi: | $(IPTABLES_PATH)/.installed $(USERSPACE_DEPS)
3528c2ecf20Sopenharmony_ci	cd $(IPTABLES_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared --disable-nftables --disable-bpf-compiler --disable-nfsynproxy --disable-libipq --disable-connlabel --with-kernel=$(BUILD_PATH)/include
3538c2ecf20Sopenharmony_ci	$(MAKE) -C $(IPTABLES_PATH)
3548c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci$(NMAP_PATH)/.installed: $(NMAP_TAR)
3578c2ecf20Sopenharmony_ci	mkdir -p $(BUILD_PATH)
3588c2ecf20Sopenharmony_ci	flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
3598c2ecf20Sopenharmony_ci	touch $@
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci$(NMAP_PATH)/ncat/ncat: | $(NMAP_PATH)/.installed $(USERSPACE_DEPS)
3628c2ecf20Sopenharmony_ci	cd $(NMAP_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared --without-ndiff --without-zenmap --without-nping --with-libpcap=included --with-libpcre=included --with-libdnet=included --without-liblua --with-liblinear=included --without-nmap-update --without-openssl --with-pcap=linux --without-libssh
3638c2ecf20Sopenharmony_ci	$(MAKE) -C $(NMAP_PATH)/libpcap
3648c2ecf20Sopenharmony_ci	$(MAKE) -C $(NMAP_PATH)/ncat
3658c2ecf20Sopenharmony_ci	$(STRIP) -s $@
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ciclean:
3688c2ecf20Sopenharmony_ci	rm -rf $(BUILD_PATH)
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_cidistclean: clean
3718c2ecf20Sopenharmony_ci	rm -rf $(DISTFILES_PATH)
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cimenuconfig: $(KERNEL_BUILD_PATH)/.config
3748c2ecf20Sopenharmony_ci	$(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci.PHONY: qemu build clean distclean menuconfig
3778c2ecf20Sopenharmony_ci.DELETE_ON_ERROR:
378