forked from DanEngelbrecht/longtail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_helper.sh
executable file
·133 lines (114 loc) · 4.83 KB
/
build_helper.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
#!/bin/bash
set -e
export BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/"
export SOURCE_FOLDER=$1
. ${BASE_DIR}arch_helper.sh
if [ "$2" = "build-third-party" ] || [ "$3" = "build-third-party" ] || [ "$4" = "build-third-party" ] ; then
BUILD_THIRD_PARTY="build-third-party"
else
BUILD_THIRD_PARTY=""
fi
if [ "$2" = "release" ] || [ "$3" = "release" ] || [ "$4" = "release" ] ; then
RELEASE_MODE="release"
else
RELEASE_MODE="debug"
fi
if [ "$2" = "run" ] || [ "$3" = "run" ] || [ "$4" = "run" ] ; then
RUN="run"
else
RUN=""
fi
export BASE_CXXFLAGS="-Wno-sign-conversion -Wno-missing-prototypes -Wno-cast-align -Wno-unused-function -Wno-deprecated-register -Wno-deprecated -Wno-c++98-compat-pedantic -Wno-unused-parameter -Wno-unused-template -Wno-zero-as-null-pointer-constant -Wno-old-style-cast -Wno-global-constructors -Wno-padded"
. ${SOURCE_FOLDER}build_options.sh
OUTPUT_FOLDER="${BASE_DIR}build/${PLATFORM}/${TARGET}/${RELEASE_MODE}"
if [ ! -d ${OUTPUT_FOLDER} ]
then
mkdir -p ${OUTPUT_FOLDER}
fi
THIRD_PARTY_OUTPUT_FOLDER="${OUTPUT_FOLDER}/third-party"
if [ ! -d ${THIRD_PARTY_OUTPUT_FOLDER} ]
then
mkdir -p ${THIRD_PARTY_OUTPUT_FOLDER}
fi
THIRD_PARTY_LIB="${TARGET}-third-party.a"
# -pedantic
# -Wno-atomic-implicit-seq-cst
# -Wno-extra-semi-stmt
# -Wno-implicit-int-conversion
if [ "$RELEASE_MODE" = "release" ]; then
export OPT=-O3
#DISASSEMBLY='-S -masm=intel'
export ASAN=""
export ARCH="-m64 -maes -mssse3 -msse4.1"
export CXXFLAGS="$BASE_CXXFLAGS $CXXFLAGS"
else
export OPT="-g"
export ASAN="-fsanitize=address -fno-omit-frame-pointer"
BASE_CXXFLAGS="$BASE_CXXFLAGS" # -Wall -Weverything"
export ARCH="-m64 -maes -mssse3 -msse4.1"
export CXXFLAGS="$BASE_CXXFLAGS $CXXFLAGS_DEBUG"
fi
if [ $TARGET_TYPE == "SHAREDLIB" ] || [ $TARGET_TYPE == "STATICLIB" ]; then
# Keep third-party lib separate from other builds
# Disable ASAN since it would force user of .so to enable ASAN
export THIRD_PARTY_LIB="lib${THIRD_PARTY_LIB}"
export ASAN=""
export OPT="$OPT -fPIC -fvisibility=hidden"
fi
if [ ! -f "${THIRD_PARTY_OUTPUT_FOLDER}/${THIRD_PARTY_LIB}" ]; then
BUILD_THIRD_PARTY="build-third-party"
fi
if [ "$BUILD_THIRD_PARTY" = "build-third-party" ]; then
echo "Compiling third party dependencies to library" $THIRD_PARTY_LIB
cd ${THIRD_PARTY_OUTPUT_FOLDER}
rm -rf ${THIRD_PARTY_OUTPUT_FOLDER}/*.o
clang++ -c $OPT $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $THIRDPARTY_SRC
if [ -n "$THIRDPARTY_SRC_SSE42" ]; then
clang++ -c $OPT -msse4.2 $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $THIRDPARTY_SRC_SSE42
fi
if [ -n "$THIRDPARTY_SRC_AVX2" ]; then
clang++ -c $OPT -mavx2 $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $THIRDPARTY_SRC_AVX2
fi
if [ -n "$THIRDPARTY_SRC_AVX512" ]; then
clang++ -c $OPT -mavx512vl -mavx512f $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $THIRDPARTY_SRC_AVX512
fi
if [ -n "$ZSTD_THIRDPARTY_GCC_SRC" ]; then
clang++ -c $OPT $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $ZSTD_THIRDPARTY_GCC_SRC
fi
ar rc ${THIRD_PARTY_OUTPUT_FOLDER}/$THIRD_PARTY_LIB *.o
cd $BASE_DIR
fi
if [ $TARGET_TYPE == "EXECUTABLE" ]; then
echo Building ${OUTPUT_FOLDER}/${TARGET}
clang++ -o ${OUTPUT_FOLDER}/${TARGET} $OPT $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $SRC $MAIN_SRC ${THIRD_PARTY_OUTPUT_FOLDER}/$THIRD_PARTY_LIB
fi
if [ $TARGET_TYPE == "SHAREDLIB" ]; then
echo Building ${OUTPUT_FOLDER}/${TARGET}.so
clang++ -shared -o ${OUTPUT_FOLDER}/${TARGET}.so $OPT $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $SRC $MAIN_SRC ${THIRD_PARTY_OUTPUT_FOLDER}/$THIRD_PARTY_LIB
fi
if [ $TARGET_TYPE == "STATICLIB" ]; then
echo Building ${OUTPUT_FOLDER}.a
mkdir -p ${BASE_DIR}build/static-lib-$RELEASE_MODE
cd ${BASE_DIR}build/static-lib-$RELEASE_MODE
rm -rf ${BASE_DIR}build/static-lib-$RELEASE_MODE/*.o
clang++ -c $OPT $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $SRC $MAIN_SRC
ar rc ${OUTPUT_FOLDER}.a *.o ${THIRD_PARTY_OUTPUT_FOLDER}/$THIRD_PARTY_LIB
cd ..
fi
if [ $TARGET_TYPE == "EXECUTABLE" ] && [ "$RUN" = "run" ]; then
pushd ${SOURCE_FOLDER}
${OUTPUT_FOLDER}/${TARGET}
popd
fi
#if [ "$TARGET_MODE" = "lib" ]; then
# mkdir -p ${BASE_DIR}build/lib-$RELEASE_MODE
# rm -rf ${BASE_DIR}build/lib-$RELEASE_MODE/*.o
# cd ${BASE_DIR}build/lib-$RELEASE_MODE
# clang++ -c $OPT $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $SRC $MAIN_SRC
# echo ${BASE_DIR}build/$TARGET
# ar rc ${BASE_DIR}build/$TARGET *.o ${BASE_DIR}build/third-party-$RELEASE_MODE/*.o
# cd $BASE_DIR
#else
# echo Building $OUTPUT
# clang++ -o ${BASE_DIR}build/$OUTPUT $OPT $DISASSEMBLY $ARCH -std=c++11 $CXXFLAGS $ASAN -Isrc $SRC $MAIN_SRC ${BASE_DIR}build/third-party-$RELEASE_MODE/$THIRD_PARTY_LIB
#fi