-
Notifications
You must be signed in to change notification settings - Fork 32
/
build.sh
executable file
·140 lines (127 loc) · 4.41 KB
/
build.sh
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
OUT="./out"
BUILD_DIR="./build/cmake"
EROFS_VERSION="v$(. scripts/get-version-number)"
cmake_build()
{
local TARGET=$1
local METHOD=$2
local ABI=$3
if [[ $METHOD == "Ninja" ]]; then
local BUILD_METHOD="-G Ninja"
echo ${CMAKE_CMD}
local MAKE_CMD="time -p ninja -C $OUT"
elif [[ $METHOD == "make" ]]; then
local MAKE_CMD="time -p make -C $OUT -j$(nproc)"
fi;
if [[ $TARGET == "Android" ]]; then
local ANDROID_PLATFORM=$4
cmake -S ${BUILD_DIR} -B $OUT ${BUILD_METHOD} \
-DNDK_CCACHE="ccache" \
-DCMAKE_BUILD_TYPE="Release" \
-DANDROID_PLATFORM="$ANDROID_PLATFORM" \
-DANDROID_ABI="$ABI" \
-DANDROID_STL="none" \
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
-DANDROID_USE_LEGACY_TOOLCHAIN_FILE="OFF" \
-DCMAKE_C_FLAGS="" \
-DCMAKE_CXX_FLAGS="" \
-DENABLE_FULL_LTO="ON" \
-DMAX_BLOCK_SIZE="4096"
elif [[ $TARGET == "Linux" ]]; then
local LINUX_PLATFORM=$4
local WSL="OFF"
[ "${LINUX_PLATFORM}" == "WSL" ] && WSL="ON"
if [[ ${ABI} == "x86_64" ]]; then
cmake -S ${BUILD_DIR} -B ${OUT} ${BUILD_METHOD} \
-DCMAKE_SYSTEM_NAME="Linux" \
-DCMAKE_SYSTEM_PROCESSOR="x86_64" \
-DCMAKE_BUILD_TYPE="Release" \
-DRUN_ON_WSL="${WSL}" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_C_COMPILER="${CUSTOM_CLANG_PATH}/bin/clang" \
-DCMAKE_CXX_COMPILER="${CUSTOM_CLANG_PATH}/bin/clang++" \
-DCMAKE_C_FLAGS="" \
-DCMAKE_CXX_FLAGS="" \
-DENABLE_FULL_LTO="ON" \
-DMAX_BLOCK_SIZE="4096"
elif [[ ${ABI} == "aarch64" ]]; then
cmake -S ${BUILD_DIR} -B ${OUT} ${BUILD_METHOD} \
-DCMAKE_SYSTEM_NAME="Linux" \
-DCMAKE_SYSTEM_PROCESSOR="aarch64" \
-DCMAKE_BUILD_TYPE="Release" \
-DRUN_ON_WSL="${WSL}" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_C_COMPILER="${CUSTOM_CLANG_PATH}/bin/clang" \
-DCMAKE_CXX_COMPILER="${CUSTOM_CLANG_PATH}/bin/clang++" \
-DCMAKE_SYSROOT="${AARCH64_GCC_PATH}/aarch64-linux-gnu/libc" \
-DCMAKE_C_COMPILER_TARGET="aarch64-linux-gnu" \
-DCMAKE_CXX_COMPILER_TARGET="aarch64-linux-gnu" \
-DCMAKE_C_FLAGS="--gcc-toolchain=${AARCH64_GCC_PATH}" \
-DCMAKE_CXX_FLAGS="--gcc-toolchain=${AARCH64_GCC_PATH}" \
-DENABLE_FULL_LTO="ON" \
-DMAX_BLOCK_SIZE="4096"
elif [[ ${ABI} == "loongarch64" ]]; then
cmake -S ${BUILD_DIR} -B ${OUT} ${BUILD_METHOD} \
-DCMAKE_SYSTEM_NAME="Linux" \
-DCMAKE_SYSTEM_PROCESSOR="loongarch64" \
-DCMAKE_BUILD_TYPE="Release" \
-DRUN_ON_WSL="${WSL}" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_C_COMPILER="${CUSTOM_CLANG_PATH}/bin/clang" \
-DCMAKE_CXX_COMPILER="${CUSTOM_CLANG_PATH}/bin/clang++" \
-DCMAKE_SYSROOT="${LOONGARCH64_GCC_PATH}/target" \
-DCMAKE_C_COMPILER_TARGET="loongarch64-linux-gnu" \
-DCMAKE_CXX_COMPILER_TARGET="loongarch64-linux-gnu" \
-DCMAKE_C_FLAGS="--gcc-toolchain=${LOONGARCH64_GCC_PATH}" \
-DCMAKE_CXX_FLAGS="--gcc-toolchain=${LOONGARCH64_GCC_PATH}" \
-DENABLE_FULL_LTO="OFF" \
-DMAX_BLOCK_SIZE="4096"
fi
fi
${MAKE_CMD}
}
build()
{
local TARGET=$1
local ABI=$2
local PLATFORM=$3
rm -r $OUT > /dev/null 2>&1
local NINJA=`which ninja`
if [[ -f $NINJA ]]; then
local METHOD="Ninja"
else
local METHOD="make"
fi
cmake_build "${TARGET}" "${METHOD}" "${ABI}" "${PLATFORM}"
[ "${PLATFORM}" == "WSL" ] && TARGET="WSL"
local BUILD="$OUT/erofs-tools"
local DUMP_BIN="$BUILD/dump.erofs"
local FSCK_BIN="$BUILD/fsck.erofs"
local FUSE_BIN="$BUILD/fuse.erofs"
local MKFS_BIN="$BUILD/mkfs.erofs"
local EXTRACT_BIN="$BUILD/extract.erofs"
local TARGE_DIR_NAME="erofs-utils-${EROFS_VERSION}-${TARGET}_${ABI}-$(TZ=UTC-8 date +%y%m%d%H%M)"
local TARGET_DIR_PATH="./target/${TARGET}_${ABI}/${TARGE_DIR_NAME}"
if [ -f "$DUMP_BIN" -a -f "$FSCK_BIN" -a -f "$FUSE_BIN" -a -f "$MKFS_BIN" -a -f "$EXTRACT_BIN" ]; then
echo "复制文件中..."
[[ ! -d "$TARGET_DIR_PATH" ]] && mkdir -p ${TARGET_DIR_PATH}
cp -af $BUILD/*.erofs ${TARGET_DIR_PATH}
touch -c -d "2009-01-01 00:00:00" ${TARGET_DIR_PATH}/*
echo "编译成功: ${TARGE_DIR_NAME}"
else
echo "error"
exit 1
fi
}
#build "Android" "arm64-v8a" "android-31"
#build "Android" "armeabi-v7a" "android-31"
#build "Android" "x86_64" "android-31"
#build "Android" "x86" "android-31"
build "Linux" "x86_64"
build "Linux" "x86_64" "WSL"
build "Linux" "aarch64"
build "Linux" "loongarch64"
exit 0