forked from RoaringBitmap/CRoaring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amalgamation.sh
executable file
·183 lines (148 loc) · 5.18 KB
/
amalgamation.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
#!/bin/bash
########################################################################
# Generates an "amalgamation build" for roaring. Inspired by similar
# script used by whefs.
########################################################################
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
echo "We are about to amalgamate all CRoaring files into one source file. "
echo "See https://www.sqlite.org/amalgamation.html and https://en.wikipedia.org/wiki/Single_Compilation_Unit for rationale. "
AMAL_H="roaring.h"
AMAL_C="roaring.c"
# order does not matter
ALLCFILES=$( ( [ -d $SCRIPTPATH/.git ] && ( type git >/dev/null 2>&1 ) && ( git ls-files $SCRIPTPATH/src/*.c $SCRIPTPATH/src/**/*c ) ) || ( find $SCRIPTPATH/src -name '*.c' ) )
# order matters
ALLCHEADERS="
$SCRIPTPATH/include/roaring/roaring_version.h
$SCRIPTPATH/include/roaring/portability.h
$SCRIPTPATH/include/roaring/containers/perfparameters.h
$SCRIPTPATH/include/roaring/array_util.h
$SCRIPTPATH/include/roaring/roaring_types.h
$SCRIPTPATH/include/roaring/utilasm.h
$SCRIPTPATH/include/roaring/bitset_util.h
$SCRIPTPATH/include/roaring/containers/array.h
$SCRIPTPATH/include/roaring/containers/bitset.h
$SCRIPTPATH/include/roaring/containers/run.h
$SCRIPTPATH/include/roaring/containers/convert.h
$SCRIPTPATH/include/roaring/containers/mixed_equal.h
$SCRIPTPATH/include/roaring/containers/mixed_subset.h
$SCRIPTPATH/include/roaring/containers/mixed_andnot.h
$SCRIPTPATH/include/roaring/containers/mixed_intersection.h
$SCRIPTPATH/include/roaring/containers/mixed_negation.h
$SCRIPTPATH/include/roaring/containers/mixed_union.h
$SCRIPTPATH/include/roaring/containers/mixed_xor.h
$SCRIPTPATH/include/roaring/containers/containers.h
$SCRIPTPATH/include/roaring/roaring_array.h
$SCRIPTPATH/include/roaring/misc/configreport.h
$SCRIPTPATH/include/roaring/roaring.h
"
for i in ${ALLCHEADERS} ${ALLCFILES}; do
test -e $i && continue
echo "FATAL: source file [$i] not found."
exit 127
done
function stripinc()
{
sed -e '/# *include *"/d' -e '/# *include *<roaring\//d'
}
function dofile()
{
echo "/* begin file $1 */"
# echo "#line 8 \"$1\"" ## redefining the line/file is not nearly as useful as it sounds for debugging. It breaks IDEs.
stripinc < $1
echo "/* end file $1 */"
}
timestamp=$(date)
echo "Creating ${AMAL_H}..."
echo "/* auto-generated on ${timestamp}. Do not edit! */" > "${AMAL_H}"
{
for h in ${ALLCHEADERS}; do
dofile $h
done
} >> "${AMAL_H}"
echo "Creating ${AMAL_C}..."
echo "/* auto-generated on ${timestamp}. Do not edit! */" > "${AMAL_C}"
{
echo "#include \"${AMAL_H}\""
echo ""
echo "/* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */"
echo "#ifdef DMALLOC"
echo "#include \"dmalloc.h\""
echo "#endif"
echo ""
for h in ${ALLCFILES}; do
dofile $h
done
} >> "${AMAL_C}"
DEMOC="amalgamation_demo.c"
echo "Creating ${DEMOC}..."
echo "/* auto-generated on ${timestamp}. Do not edit! */" > "${DEMOC}"
cat <<< '
#include <stdio.h>
#include "roaring.c"
int main() {
roaring_bitmap_t *r1 = roaring_bitmap_create();
for (uint32_t i = 100; i < 1000; i++) roaring_bitmap_add(r1, i);
printf("cardinality = %d\n", (int) roaring_bitmap_get_cardinality(r1));
roaring_bitmap_free(r1);
return 0;
}
' >> "${DEMOC}"
echo "Done with C amalgamation. Proceeding with C++ wrap."
AMAL_HH="roaring.hh"
echo "Creating ${AMAL_HH}..."
ALLCPPHEADERS="$SCRIPTPATH/cpp/roaring.hh $SCRIPTPATH/cpp/roaring64map.hh"
echo "/* auto-generated on ${timestamp}. Do not edit! */" > "${AMAL_HH}"
{
echo "#include \"${AMAL_H}\""
for h in ${ALLCPPHEADERS}; do
dofile $h
done
} >> "${AMAL_HH}"
DEMOCPP="amalgamation_demo.cpp"
echo "Creating ${DEMOCPP}..."
echo "/* auto-generated on ${timestamp}. Do not edit! */" > "${DEMOCPP}"
cat <<< '
#include <iostream>
#include "roaring.hh"
#include "roaring.c"
int main() {
Roaring r1;
for (uint32_t i = 100; i < 1000; i++) {
r1.add(i);
}
std::cout << "cardinality = " << r1.cardinality() << std::endl;
Roaring64Map r2;
for (uint64_t i = 18000000000000000100ull; i < 18000000000000001000ull; i++) {
r2.add(i);
}
std::cout << "cardinality = " << r2.cardinality() << std::endl;
return 0;
}
' >> "${DEMOCPP}"
echo "Done with C++."
echo "Done with all files generation. "
echo "Files have been written to current directory: $PWD "
ls -la ${AMAL_C} ${AMAL_H} ${AMAL_HH} ${DEMOC} ${DEMOCPP}
echo "Giving final instructions:"
CBIN=${DEMOC%%.*}
CPPBIN=${DEMOCPP%%.*}
echo
echo "The interface is found in the file 'include/roaring/roaring.h'."
echo
echo "Try :"
echo "cc -march=native -O3 -std=c11 -o ${CBIN} ${DEMOC} && ./${CBIN} "
echo
echo "For C++, try :"
echo "c++ -march=native -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} && ./${CPPBIN} "
lowercase(){
echo "$1" | tr 'A-Z' 'a-z'
}
OS=`lowercase \`uname\``
echo
echo "You can build a shared library with the following command :"
if [ $OS == "darwin" ]; then
echo "cc -march=native -O3 -std=c11 -shared -o libroaring.dylib -fPIC roaring.c"
else
echo "cc -march=native -O3 -std=c11 -shared -o libroaring.so -fPIC roaring.c"
fi
echo "You can try compiling with the extra flags -DDISABLEAVX or -DROARING_DISABLE_X64 to disable AVX and all x64 optimization respectively."