-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.sh
executable file
·188 lines (144 loc) · 3.23 KB
/
config.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
##
## Shell script for creating configuration include files.
##
## Authors:
## Marco Guazzone, <[email protected]>
##
##TODO:
## * we need to check if c++ (or other compiler??) is present
dtnow=$(date +'%F %T (%Z)')
logfile="$0.log"
basedir=$1
CC=${CC:=cc}
CXX=${CXX:=c++}
## Declares user-related variables
USR_CPPFLAGS=
USR_CFLAGS=
USR_CXXFLAGS=
USR_LDFLAGS=
## Format a date
function dcs_format_date()
{
echo $(date +'%F %T (%Z)')
}
## Initialize log file
function dcs_log_init()
{
> $logfile
}
## Log an error to the log-file.
function dcs_log_error()
{
date=$(dcs_format_date)
echo "ERROR ($date)>> $1" >> $logfile
}
## Log an error to the log-file.
function dcs_log_info()
{
date=$(dcs_format_date)
echo "INFO ($date)>> $1" >> $logfile
}
## Log an error to the log-file.
function dcs_log_warn()
{
date=$(dcs_format_date)
echo "WARNING ($date)>> $1" >> $logfile
}
## Check if your system has the Boost libraries installed
function dcs_check_boost()
{
src_temp_file=`mktemp tmp.XXXXXXXXXX`
out_temp_file=`mktemp tmp.XXXXXXXXXX`
cat > $src_temp_file <<EOT
#include <boost/version.hpp>
int main(int argc, char* argv[])
{
return 0;
}
EOT
compile_test=(`$CXX $CXXFLAGS -x 'c++' -o $out_temp_file $src_temp_file 2>&1 >/dev/null`)
ret=$?
rm -f $out_temp_file $src_temp_file
if [ $ret == 0 ]; then
echo -n "yes"
else
echo -n "no"
fi
}
## Script starts here
dcs_log_init
dcs_log_info "Starting configuration maker..."
## Control variables
have_boost_bool=
basesrcdir=
## Sanity checks
if [ -z "$basedir" ]; then
basedir=.
fi
if [ -z "$basesrcdir" ]; then
basesrcdir=$basedir/src
fi
## Load user-related variables
if [ -e "$basedir/user-config.sh" ]; then
source "$basedir/user-config.sh"
fi
## Set C/C++ environments
if [ ! -z "$USR_CPPFLAGS" ]; then
CPPFLAGS="$CFLAGS $USR_CPPFLAGS"
fi
if [ ! -z "$USR_CFLAGS" ]; then
CFLAGS="$CFLAGS $USR_CFLAGS"
fi
if [ ! -z "$USR_CXXFLAGS" ]; then
CXXFLAGS="$CXXFLAGS $USR_CXXFLAGS"
fi
if [ ! -z "$USR_LDFLAGS" ]; then
LDFLAGS="$LDFLAGS $USR_LDFLAGS"
fi
## Check for Boost
have_boost=`dcs_check_boost`
if [ "$have_boost" = "yes" ]; then
have_boost_bool='true'
else
have_boost_bool='false'
dcs_log_error "Wanted Boost but Boost not found."
found_errors=yes
fi
## Auto-generation of files.
if [ "$found_errors" = "yes" ]; then
dcs_log_info "Configuration maker has finished."
dcs_log_error "Exit with errors!"
echo "There are some errors. Check the $logfile log-file."
exit 1
fi
# Create base config dir
mkdir -p "$basesrcdir/config"
cat > $basedir/config.mk <<EOT
## \file config.mk
##
## \brief Configurations for the Make build system.
##
## [$dtnow]
## This is an autogenerated file. Do not edit.
##
## \author Marco Guazzone, <[email protected]>
##
CPPFLAGS_release+=$USR_CPPFLAGS
CFLAGS_release+=$USR_CFLAGS
CXXFLAGS_release+=$USR_CXXFLAGS
LDFLAGS_release+=$USR_LDFLAGS
CPPFLAGS_debug+=$USR_CPPFLAGS
CFLAGS_debug+=$USR_CFLAGS
CXXFLAGS_debug+=$USR_CXXFLAGS
LDFLAGS_debug+=$USR_LDFLAGS
CPPFLAGS_test+=$USR_CPPFLAGS
CFLAGS_test+=$USR_CFLAGS
CXXFLAGS_test+=$USR_CXXFLAGS
LDFLAGS_test+=$USR_LDFLAGS
CPPFLAGS_xmp+=$USR_CPPFLAGS
CFLAGS_xmp+=$USR_CFLAGS
CXXFLAGS_xmp+=$USR_CXXFLAGS
LDFLAGS_xmp+=$USR_LDFLAGS
EOT
dcs_log_info "Configuration maker has finished."