forked from arras-energy/gridlabd-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomize
executable file
·218 lines (207 loc) · 5.77 KB
/
customize
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
CUSTOMFILE="custom.mk"
CONFIGURE="configure.opt"
function help_syntax ()
{
echo "Syntax: $(basename $0) <command> [<options> ...]"
}
function help ()
{
help_syntax
echo "
add <module> Add <module> to $CUSTOMFILE
delete <module> Delete <module> from $CUSTOMFILE
enable <module> Enable <module> in $CUSTOMFILE
disable <module> Disable <module> in $CUSTOMFILE
status Display status of modules matching <pattern>
sync_validate Add/remove validate.no files according to custom.mk
configure [<options>] Manage ./configure script
"
}
function add ()
{
F="module/$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "include $F" >>$CUSTOMFILE
else
echo "module $1 is not a valid module (missing $F)"
fi
else
echo "$1 is already listed in $CUSTOMFILE"
sync_validate
fi
}
function delete ()
{
F="module/$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "module $1 is not listed in $CUSTOMFILE"
else
echo "module $1 is not a valid module (missing $F)"
fi
else
T=".tmp$$"
grep -v $F $CUSTOMFILE >$T && mv $T $CUSTOMFILE
fi
}
function enable ()
{
F="module/$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "module $1 is not listed in $CUSTOMFILE"
else
echo "module $1 is not a valid module (missing $F)"
fi
else
T=".tmp$$"
sed -e "1,\$s:^#include $F:include $F:" < $CUSTOMFILE >$T && mv $T $CUSTOMFILE
sync_validate
fi
}
function disable ()
{
F="module/$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "module $1 is not listed in $CUSTOMFILE"
else
echo "module $1 is not a valid module (missing $F)"
fi
else
T=".tmp$$"
sed -e "1,\$s:^include $F:#include $F:" < $CUSTOMFILE >$T && mv $T $CUSTOMFILE
sync_validate
fi
}
function status ()
{
ENABLED=$(grep '^include' <$CUSTOMFILE | sed -e 's/include //g;s:/Makefile.mk::g')
DISABLED=$(grep '^#include' <$CUSTOMFILE | sed -e 's/#include //g;s:/Makefile.mk::g')
echo Enabled: $ENABLED
echo Disabled: $DISABLED
}
function sync_validate ()
{
ENABLED=$(grep '^include' <$CUSTOMFILE | sed -e 's/include //g;s:/Makefile.mk::g')
DISABLED=$(grep '^#include' <$CUSTOMFILE | sed -e 's/#include //g;s:/Makefile.mk::g')
for F in $ENABLED; do
if [ -f $F/validate.no ]; then
echo -n "removing $F/validate.no..."
rm $F/validate.no && echo "ok"
fi
done
for F in $DISABLED; do
if [ ! -f $F/validate.no ]; then
echo -n "adding $F/validate.no..."
echo "$*: $(date)" > $F/validate.no && echo "ok"
fi
done
}
function configure ()
{
if [ ! -f ./source/gridlabd.in -o ./source/gridlabd.m4sh -nt ./source/gridlabd.in ]; then
m4 ./source/gridlabd.m4sh >./source/gridlabd.in
fi
if [ ! -f ./configure ]; then
autoreconf -isf
fi
if [ $# -eq 0 ]; then
autom4te -l M4sh source/gridlabd.m4sh > source/gridlabd.in
if [ -f $CONFIGURE ]; then
eval "./configure $(sed 's/$/ /' < $CONFIGURE | tr -d '\n')"
else
echo "configure.opt not found"
fi
elif [ $1 == "status" ]; then
cat $CONFIGURE
elif [ $1 == "silent" ]; then
if [ $# -eq 1 ]; then
if [ -z "$(grep '^--enable-silent-rules' $CONFIGURE)" ]; then
echo "silent rules are disabled"
else
echo "silent rules are enabled"
fi
elif [ $2 == "enable" ]; then
if [ -z "$(grep '^--enable-silent-rules' $CONFIGURE)" ]; then
echo '--enable-silent-rules' >> $CONFIGURE
fi
elif [ $2 == "disable" ]; then
grep -v '^--enable-silent-rules' $CONFIGURE > $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
else
echo "error: '$2' is not a valid silent option"
fi
elif [ $1 == "prefix" ]; then
if [ $# -eq 1 ]; then
grep '^--prefix=' $CONFIGURE
elif [ $2 == "clear" ]; then
grep -v '^--prefix=' $CONFIGURE > $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
else
grep -v '^--prefix=' $CONFIGURE > $CONFIGURE.$$
echo "--prefix=$2" >> $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
fi
elif [ $1 == "flags" ]; then
if [ $# -eq 1 ]; then
grep 'FLAGS=' $CONFIGURE
elif [ $2 == "clear" ]; then
grep -v 'FLAGS=' $CONFIGURE > $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
else
shift
grep -v 'FLAGS=' $CONFIGURE > $CONFIGURE.$$
echo "'CXXFLAGS=$*'" >> $CONFIGURE.$$
echo "'CFLAGS=$*'" >> $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
fi
elif [ $1 == "mysql" ]; then
if [ $# -eq 1 ]; then
grep '^--with-mysql=' $CONFIGURE
elif [ $2 == "clear" ]; then
grep -v '^--with-mysql=' $CONFIGURE > $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
else
grep -v '^--with-mysql=' $CONFIGURE > $CONFIGURE.$$
echo "--with-mysql=$2" >> $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
fi
elif [ $1 == "matlab" ]; then
if [ $# -eq 1 ]; then
grep '^--with-matlab=' $CONFIGURE
elif [ $2 == "clear" ]; then
grep -v '^--with-matlab=' $CONFIGURE > $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
else
grep -v '^--with-matlab=' $CONFIGURE > $CONFIGURE.$$
echo "--with-matlab=$2" >> $CONFIGURE.$$
mv $CONFIGURE.$$ $CONFIGURE
fi
elif [ $1 == "help" ]; then
echo "Configure syntax:"
echo " configure Run configure script"
echo " configure status Show configuration options"
echo " configure silent [enable|disable] Enable/disable silent rules"
echo " configure prefix [<path>|clear] Set/clear prefix path"
echo " configure flags [<flags>|clear] Set/clear build CXXFLAGS and CFLAGS"
echo " configure mysql [<path>|clear] Set/clear mysql path"
echo " configure matlab [<path>|clear] Set/clear matlab path"
else
echo "configure syntax error"
fi
}
if [ $# -eq 0 ]; then
help_syntax
else
case $1 in
(help|add|delete|enable|disable|status|sync_validate|configure)
$*
;;
(*)
echo "$(basename $0): $1 is not a valid command"
;;
esac
fi