nim-leveldb/build.sh

57 lines
1.5 KiB
Bash
Raw Normal View History

2024-05-09 08:18:06 +00:00
#!/bin/bash
root=$(dirname "$0")
2024-05-09 13:37:37 +00:00
sourceDir="${root}/vendor"
2024-05-09 12:58:31 +00:00
buildDir="${root}/build"
2024-05-13 12:08:17 +00:00
output="${root}/leveldbstatic/raw.nim"
2024-05-09 08:18:06 +00:00
# install nimterop, if not already installed
if ! [ -x "$(command -v toast)" ]; then
nimble install -y nimterop@0.6.13
fi
2024-05-09 09:58:18 +00:00
git submodule deinit -f "${root}"
git submodule update --init --recursive --checkout "${root}"
2024-05-09 12:58:31 +00:00
cmake -S "${sourceDir}" -B "${buildDir}"
2024-05-09 09:01:21 +00:00
2024-05-09 09:58:18 +00:00
# Remove testing, benchmarking, third-party libraries.
2024-05-09 12:58:31 +00:00
rm -Rf "${sourceDir}/third_party"
rm -Rf "${sourceDir}/benchmarks"
rm "${sourceDir}/util/testutil.cc"
2024-05-09 09:58:18 +00:00
2024-05-09 12:05:01 +00:00
# Prelude:
2024-05-15 07:33:30 +00:00
cat "${root}/leveldbstatic/prelude.nim" > "${output}"
echo >> "${output}"
2024-05-09 09:01:21 +00:00
# assemble files to be compiled:
extensions="c cc cpp"
for ext in ${extensions}; do
2024-05-09 12:58:31 +00:00
for file in `find "${sourceDir}" -type f -name "*.${ext}" \
2024-05-09 12:05:01 +00:00
| grep -v "_test" \
| grep -v "env_windows.cc" \
2024-05-09 12:11:08 +00:00
| grep -v "env_posix.cc" \
| grep -v "leveldbutil.cc"`; do
2024-05-09 12:05:01 +00:00
compile="${compile} --compile=${file}"
2024-05-09 09:01:21 +00:00
done
done
2024-05-09 08:18:06 +00:00
# generate nim wrapper with nimterop
2024-05-09 09:26:26 +00:00
toast \
$compile \
--pnim \
--preprocess \
--noHeader \
2024-05-13 09:01:43 +00:00
--includeDirs="${sourceDir}" \
--includeDirs="${sourceDir}/helpers" \
--includeDirs="${sourceDir}/helpers/memenv" \
--includeDirs="${sourceDir}/port" \
--includeDirs="${sourceDir}/include" \
--includeDirs="${buildDir}/include" \
2024-05-09 12:58:31 +00:00
"${sourceDir}/include/leveldb/c.h" >> "${output}"
2024-05-13 09:01:43 +00:00
sed -i 's/\bpassC\b/passc/g' "${output}"
sed -i 's/{\.compile\:\ \"\./{\.compile\:\ root\ \&\ \"/g' "${output}"
sed -i 's/{\.passc\:\ \"-I\./{\.passc\:\ \"-I\"\ \&\ root\ \&\ \"/g' "${output}"