-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_amalgated.sh
executable file
·69 lines (58 loc) · 1.94 KB
/
make_amalgated.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
#!/bin/sh
#
# This script tries to make an amalgated header by using gcc dependency
# generation to find out which files depend on which. Then it uses
# tsort to find out in which order they need to be include. After that,
# it extracts standard includes and put them at the top. The output
# is an amalgated source file which is verified to make sense using
# gcc.
# The result can be used to create a single file include for installation
# or perhaps copy pasting into some online IDE.
#
# Invoke with *all* header files, each individual file
# as a command line argument.
#
# Paul Dreik 20181007
set -e
#we expect to be executed in the include/ folder.
if [ ! -d safe_compare ] ; then
echo "expected to be executed in the include/ folder"
exit 1
fi
IPATH=.
#strip this path from the given includes
pathtostrip=$(pwd)/
#given a file $1, lists which non-system header it depends on
#into the deps file, on a format recognized by gnu tsort.
depends_on() {
strippedfilename=$(echo $1 | sed -e "s@$pathtostrip\(.*\)@\1@g")
echo "#include \"$strippedfilename\"" | \
$CXX -xc++ -std=c++1y -MM -I $IPATH -E - | \
tr -d '\\' | \
tr '\n' ' ' | \
xargs -n1 echo $strippedfilename >>deps
}
cat /dev/null >deps
while [ $# -gt 0 ] ; do
depends_on $1
shift
done
tsort deps | \
tac | \
grep -v ':' >deps.tmp
cat /dev/null >amalgated.hpp
for f in $(cat deps.tmp) ; do
echo "// begin include of file $f" >>amalgated.hpp
grep -v '#include "' $f |grep -v "#pragma once" >>amalgated.hpp
echo "// end include of file $f" >>amalgated.hpp
done
#make sure the file is ok, by compiling it
$CXX -xc++ -std=c++1y -c amalgated.hpp -o /dev/null
#assemble the complete file
mv amalgated.hpp amalgated.hpp.orig
echo '//amalgated source of lib safe_compare' > amalgated.hpp
echo "#pragma once" >>amalgated.hpp
grep "#include <" amalgated.hpp.orig |sort |uniq >>amalgated.hpp
grep -v "#include <" amalgated.hpp.orig >>amalgated.hpp
#clean up the garbage
rm deps deps.tmp amalgated.hpp.orig