xref: /OK3568_Linux_fs/device/rockchip/common/scripts/mk-kbuild.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2
3case "$(uname -m)" in
4	armv7l) KERNEL_ARCH=armhf ;;
5	aarch64) KERNEL_ARCH=aarch64 ;;
6	*)
7		echo -e "\e[35mThis script is not for $(uname -m)\e[0m"
8		exit 1
9		;;
10esac
11
12set -a
13
14if [ ! -d debian/ ]; then
15	echo -e "\e[35m"
16	echo "debian/ is not exists!"
17	echo "Please download it from:"
18	echo "https://salsa.debian.org/kernel-team/linux"
19	echo "Tag:"
20	echo "4.4/4.19: debian/4.19.282-1"
21	echo "5.10: debian/5.10.179-1"
22	echo -e "\e[0m"
23	exit 1
24fi
25
26env -u ABINAME -u ARCH -u FEATURESET -u FLAVOUR -u VERSION -u LOCALVERSION >/dev/null
27
28KERNAL_ARCH=${1:-$KERNAL_ARCH}
29KVER3=$(grep -A 2 "^VERSION = " Makefile | cut -d' ' -f 3 | paste -sd'.')
30KVER2=$(grep -A 1 "^VERSION = " Makefile | cut -d' ' -f 3 | paste -sd'.')
31GVER=$(git log --oneline -1 | cut -d' ' -f1)
32
33DISTRIBUTION_OFFICIAL_BUILD=1
34DISTRIBUTOR="Rockchip"
35DISTRIBUTION_VERSION="$KVER3"
36KBUILD_BUILD_TIMESTAMP="$(date +%Y_%m_%d)"
37KBUILD_BUILD_VERSION_TIMESTAMP="Debian $KBUILD_BUILD_TIMESTAMP - Rockchip ($GVER)"
38KBUILD_BUILD_USER="Rockchip"
39KBUILD_BUILD_HOST="Rockchip"
40
41DEB_CFLAGS_SET="-static"
42DEB_CPPFLAGS_SET="-static"
43DEB_LDFLAGS_SET="-static"
44
45CUR_DIR="$PWD"
46OUT_DIR="$CUR_DIR/output"
47BUILD_DIR="$OUT_DIR/build"
48DESTDIR="$OUT_DIR/linux-kbuild"
49
50make_subdir()
51{
52	SUBDIR=$1
53	shift
54
55	mkdir -p "$BUILD_DIR/$SUBDIR"
56	make -j8 -s KCFLAGS="-fdebug-prefix-map=$PWD/=" \
57		-C "$BUILD_DIR/$SUBDIR" \
58		-f "$CUR_DIR/debian/rules.d/$SUBDIR/Makefile" \
59		top_srcdir="$CUR_DIR" top_rulesdir="$CUR_DIR/debian/rules.d" \
60		OUTDIR=$SUBDIR VERSION=$KVER2 KERNEL_ARCH=$KERNEL_ARCH \
61		KBUILD_HOSTCFLAGS="-static" KBUILD_HOSTLDFLAGS="-static -lz" \
62		HOSTCC="gcc -static" HOSTLD="ld -static" $@
63}
64
65echo
66echo "Packing linux-kbuild into $DESTDIR ..."
67echo
68
69sed -i 's/\(-lcrypto$\)/\1 -ldl -lpthread/' debian/rules.d/scripts/Makefile
70
71if [ "$KVER2" = 4.4 ]; then
72	sed -i -e '/_shipped/,$d' \
73		-e '$a\\n%.c: %.c_shipped\n	cat $< > $@' \
74		-e '$a\\n%.h: %.h_shipped\n	cat $< > $@' \
75		debian/rules.d/Makefile.inc
76
77	sed -i -e '/lex.c:/,$d' \
78		-e 's/kconf_id.c/zconf.hash.c/' \
79		debian/rules.d/scripts/kconfig/Makefile
80
81	sed -i -e '/parse.tab.c:/,$d' \
82		-e 's/keywords.c/keywords.hash.c/' \
83		debian/rules.d/scripts/genksyms/Makefile
84
85	sed -i '/bin2c/d' debian/rules.d/scripts/Makefile
86	sed -i 's/\(.*fixdep\)\(.*\)/\1 bin2c\2/' \
87		debian/rules.d/scripts/basic/Makefile
88
89	sed -i '/autoconf.h/d' scripts/mod/modpost.c
90
91	make_subdir scripts
92	make_subdir scripts install
93else # 4.19/5.10
94	make_subdir scripts
95	make_subdir tools/objtool
96	make_subdir scripts install
97	make_subdir tools/objtool install
98fi
99