-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmake_munge.sh
executable file
·138 lines (115 loc) · 3.65 KB
/
make_munge.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
#!/bin/bash
#
# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: BSD-2-Clause
#
set -e
usage() {
cat <<EOF 1>&2
USAGE: make_munge.sh [-h|-o <dir>|-p <dir>] [git-ref]
-o Output directory
-p Path to the repo collection
-a Generate AST
-h Print help
git-ref Use this seL4 ref, default HEAD
EOF
}
fail() {
echo $1 >&2
exit 1
}
# Defaults
SEL4REF=HEAD
OUT_DIR=.
# Script directory
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
# If no path given, assume local checkout
REPO_DIR="${SCRIPT_DIR}/../.."
# Argument parsing
while getopts ":hao:p:" opts
do
case $opts in
h)
usage
exit 0
;;
o)
OUT_DIR=${OPTARG}
if [ ! -d "${OUT_DIR}" ]
then
fail "-o: ${OUT_DIR} is not a directory (cwd: $(pwd))"
fi
;;
a) BUILD_AST=true
;;
p) REPO_DIR="${OPTARG}"
if ! [ -d "${REPO_DIR}" ]
then
fail "-p: ${REPO_DIR} is not a directory (cwd: $(pwd))"
fi
;;
*)
fail "Invalid option: -${OPTARG}"
esac
done
shift $((OPTIND - 1))
[ $# -gt 0 ] && SEL4REF_RAW=$1 && shift
[ $# -gt 0 ] && echo >&2 "Ignoring arguments: $*"
# Find the l4v/ base folder
: ${L4V_DIR:=$(cd "${REPO_DIR}/l4v" && pwd)}
[ -d "${L4V_DIR}" ] || fail "Couldn't find l4v; tried ${L4V_DIR}"
# Find the c-parser directory
: ${CPARSER_DIR:=$(cd "${L4V_DIR}/tools/c-parser" && pwd)}
[ -d "${CPARSER_DIR}" ] || fail "Couldn't find c-parser; tried ${CPARSER_DIR}"
# Find the seL4/ base folder
: ${SEL4_DIR:=$(cd "${REPO_DIR}/seL4" && pwd)}
[ -d "${SEL4_DIR}" ] || fail "Couldn't find seL4; tried ${SEL4_DIR}"
# Create temporary directory to work in
MUN_TMP=$(mktemp --tmpdir -d munge-seL4.XXXXXXXX) || \
fail "Error creating temporary directory"
trap "rm -rf ${MUN_TMP}" EXIT
mkdir -p "${MUN_TMP}"
# Defaults
export L4V_ARCH=${L4V_ARCH:="ARM"}
# Useful refs
CKERNEL_DIR=${L4V_DIR}/spec/cspec/c
CKERNEL_REL=build/${L4V_ARCH}/kernel_all.c_pp
CKERNEL=${CKERNEL_DIR}/${CKERNEL_REL}
NAMES_FILE=${MUN_TMP}/ckernel_names.txt
AST_FILE=${MUN_TMP}/ckernel_ast.txt
SEL4_CLONE=${MUN_TMP}/sel4-clone
: ${CPARSER_FLAGS:="--underscore_idents"}
# Clone seL4 repo into temporary folder
git clone -q -n "${SEL4_DIR}" "${SEL4_CLONE}" || \
fail "Error cloning seL4 repo from \n ${SEL4_DIR}"
# Getting correct reference
if [ -n "${SEL4REF_RAW}" ]
then
SEL4REF=$(git -C "${SEL4_DIR}" rev-parse --short "${SEL4REF_RAW}") || \
fail "Error retrieving reference ${SEL4REF_RAW} on local seL4 repo"
fi
# Checking out the reference
git -C "${SEL4_CLONE}" checkout -q "${SEL4REF}" || \
fail "Error checking out reference in temporary repo"
# Save the current kernel_all.c_pp
if [ -f "${CKERNEL}" ]
then
mv "${CKERNEL}" "${CKERNEL}.orig"
# move back kernel_all.c_pp
trap 'mv "${CKERNEL}.orig" "${CKERNEL}"' EXIT
fi
# build kernel_all.c_pp
make -C "${CKERNEL_DIR}" "SOURCE_ROOT=${SEL4_CLONE}" "${CKERNEL_REL}"
# does the c-parser exist?
CPARSER_EXE_REL=standalone-parser/${L4V_ARCH}/c-parser
CPARSER_EXE=${CPARSER_DIR}/${CPARSER_EXE_REL}
[ -x "${CPARSER_EXE}" ] || (echo "Building c-parser..." ; make -C "${CPARSER_DIR}" "cparser_tools")
# build name munge file
"${CPARSER_EXE}" "${CPARSER_FLAGS}" "--munge_info_fname=${NAMES_FILE}" "${CKERNEL}"
# build ast
[ -z ${BUILD_AST+x} ] || "${CPARSER_EXE}" "${CPARSER_FLAGS}" --ast "${CKERNEL}" >"${AST_FILE}"
mv "${CKERNEL}" "${OUT_DIR}/kernel_all.txt"
# copy generated results to OUT_DIR
cp "${NAMES_FILE}" "${OUT_DIR}/ckernel_names.txt"
[ -z ${BUILD_AST+x} ] || cp "${AST_FILE}" "${OUT_DIR}/ckernel_ast.txt"