-
Notifications
You must be signed in to change notification settings - Fork 0
/
link
executable file
·62 lines (50 loc) · 1.26 KB
/
link
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
#! /bin/bash
#====================================================
# file: link.sh
#----------------------------------------------------
# - link a secure module to an outside test / attack
# By
#====================================================
Usage="link.sh module.o partner.c"
Outfold="out/"
# script input
if [[ $# -lt 2 ]];then
echo $Usage
exit 1
fi
module=$1
partner=$2
insecure=""
if [[ $# -gt 2 ]];then
insecure=$3
fi
#==== format : format errors ====
function format
{
echo "------------------------------------------------------"
echo "$1 failed"
echo "------------------------------------------------------"
cat $2
}
#==== toplevel ====
# compile the partner
pfilen=$(basename "$partner" 2> /dev/null)
pbase="${pfilen%.*}"
pobj=${Outfold}/${pbase}.o
tempp=/tmp/${pbase}.tmp
gcc $partner -I./lib/ -I./out/ -Werror -Wfatal-errors -std=c99 $insecure -g -c -o $pobj > $tempp 2>&1
if [[ $? -ne 0 ]];then
format "Compiling $partner !" $tempp
exit 3
fi
# link with the module
filename=$(basename "$module" 2> /dev/null)
base="${filename%.*}"
outputb="${Outfold}/${base}.bin"
temp=/tmp/${base}.tmp
gcc $module $pobj -o $outputb > $temp 2>&1
if [[ $? -ne 0 ]];then
format "Linking $module $partner" $temp
exit 3
fi
exit 0