forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnlopt-gen-hpp.sh
executable file
·51 lines (42 loc) · 1.78 KB
/
nlopt-gen-hpp.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
# Invoked by nlopt.BUILD to create api/nlopt.hpp. Do not invoke directly.
# This script reimplements the CMake logic in api/CMakeLists.txt. The goal is
# to take the enumerated integer constants from the C header nlopt.h and make
# them available to the C++ header nlopt.hpp. The contents of nlopt.hpp are
# lines taken from nlopt.h that look like "NLOPT_FOO_BAR". The NLOPT_ prefix
# is removed (because in C++ they are in a namespace).
set -ex
me="$0"
nlopt_in_hpp="$1" # Template in -- copied to the output, with constants added.
nlopt_h="$2" # Enums in -- scraped for constants to use.
nlopt_hpp="$3" # Header out.
# Inputs should exist; outputs and intermediates should not.
[ -r "$nlopt_in_hpp" ]
[ -r "$nlopt_h" ]
[ ! -e "$nlopt_hpp" ]
[ ! -e algorithms.inc ]
[ ! -e results.inc ]
[ ! -e enums.inc ]
[ ! -e nlopt.hpp.tmp ]
# Filter api/nlopt.h ...
# ... lines matching " NLOPT_FOO..." become " FOO...".
# ... stop printing algorithms after "NUM_ALGORITHMS" ...
sed -n 's/^\( *\)NLOPT_\([A-Z0-9_][A-Z0-9_]*\)/\1\2/p; /^ *NUM_ALGORITHMS/q' "$nlopt_h" > algorithms.inc
# Filter api/nlopt.h ...
# ... first match will be "FAILURE"; continue searching until EOF ...
# ... lines matching " NLOPT_FOO..." become " FOO...".
sed -n '/ NLOPT_FAILURE/,99999 s/^\( *\)NLOPT_\([A-Z0-9_][A-Z0-9_]*\)/\1\2/p' "$nlopt_h" > results.inc
# Create the "GEN ENUMS HERE" content.
cat <<EOF >enums.inc
enum algorithm {
$(cat algorithms.inc)
};
enum result {
$(cat results.inc)
};
EOF
# When nlopt-in.hpp says "GEN_ENUMS_HERE", insert the enums.inc content.
sed '/GEN_ENUMS_HERE/ r enums.inc' "$nlopt_in_hpp" > nlopt.hpp.tmp
mv nlopt.hpp.tmp "$nlopt_hpp"
# Debugging output; change the 0 to 1 if you want to get a debugging dump.
head -n 120 algorithms.inc results.inc enums.inc "$nlopt_hpp"
exit 0