-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmake.sh
executable file
·136 lines (112 loc) · 2.96 KB
/
make.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
#!/bin/bash
# check for ecosconfig
command -v ecosconfig >/dev/null 2>&1 || { echo >&2 "FATAL: ecosconfig is not installed in the system. Put it in /usr/local/bin or an equivalent location."; exit 1; }
function get_option {
VALUE=`echo $1 | sed 's/[-a-zA-Z0-9]*=//'`
}
function ecc_get_value {
RET=$(grep $1 -A 10 "$ECC" | grep -v '#' | grep '_value' | head -1 | awk '{$1=""; print $0}' | sed 's/\"//g')
# if this value is not set, take the default one
if [[ -z "$RET" ]]; then
RET=$(grep $1 -A 10 "$ECC" | grep 'Default' | head -1 | awk '{$1=$2=$3=""; print $0}' | sed 's/\"//g')
fi
echo $RET
}
function usage {
echo "Usage: `basename $0` --config=<config-name> (--output-filename=<filename>|--tests|--rebuild)"
echo " Use a config with FILES='' to just generate a kernel"
}
TESTS=false
REBUILD=false
for i in "$@"
do
get_option $i
case $i in
-c=*|--config=*)
CONFIG="$VALUE"
;;
-o=*|--output-filename=*)
OUTPUT_FILENAME="$VALUE"
;;
-t|--tests)
TESTS=true
;;
-r|--rebuild)
REBUILD=true
;;
*)
echo "FATAL: You have provided an unknown option: $i."
usage
exit 1
esac
done
if [[ -z "$CONFIG" ]]
then
FIRST_FILE=`ls *.config | head -1`
if [[ -e "$FIRST_FILE" ]]
then
CONFIG="${FIRST_FILE%.*}"
fi
fi
if [[ -z "$CONFIG" ]]
then
echo "FATAL: No config file provided."
usage
exit 1
fi
CONFIG_FILE=$CONFIG.config
if [[ ! -e "$CONFIG_FILE" ]]
then
echo "FATAL: The config file \"$CONFIG_FILE\" does not exist."
exit 1
fi
echo "Using file: $CONFIG_FILE"
TPATH_FILE=$CONFIG.tpath
if [[ -e "$TPATH_FILE" ]]
then
# include the toolchain path file, if it exits
export PATH="`cat $TPATH_FILE`:$PATH"
fi
# include config file to set appropriate variables
. ./$CONFIG_FILE
ECOS_REPOSITORY=$(readlink -f $ECOS_REPOSITORY)
ECC=$(readlink -f $ECC)
if [[ -z "$ECOS_REPOSITORY" ]] || [[ -z "$ECC" ]]
then
echo "FATAL: The variables \"ECOS_REPOSITORY\" AND \"ECC\" have not been set properly."
exit 1
fi
GCC=$(ecc_get_value CYGBLD_GLOBAL_COMMAND_PREFIX)-gcc
CFLAGS=$(ecc_get_value CYGBLD_GLOBAL_CFLAGS)
# check for compiler
command -v $GCC >/dev/null 2>&1 || { echo >&2 "FATAL: The required compiler ($GCC) does not exist in your PATH. Did you forget an appropriate $CONFIG.tpath file?"; exit 1; }
mkdir -p "$CONFIG"\_build
if "$REBUILD" ; then
rm -rf "$CONFIG"\_build/*
fi
cd "$CONFIG"\_build
KPATH=`pwd`
ecosconfig --config=$ECC tree
if "$TESTS"; then
make tests
exit
else
make
fi
cd ..
if [[ ! -z "$FILES" ]]
then
if [[ -z "$OUTPUT_FILENAME" ]] ; then
OUTPUT_FILENAME="$CONFIG"
fi
echo "Compiling eCos application..."
OK=0
$GCC -Wno-psabi -g -I./ -g -I${KPATH}/install/include ${FILES} \
-L${KPATH}/install/lib -Ttarget.ld ${CFLAGS} ${ADD_OPT} -nostdlib -o $OUTPUT_FILENAME && OK=1
if [ $OK -eq 0 ]
then
echo -e "\e[1;91mCOMPILATION ERROR\e[21;39m!"
else
echo -e "\e[1;32mCOMPILATION SUCCESSFUL\e[21;39m!"
fi
fi