-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_sharedlib.sh
More file actions
executable file
·78 lines (64 loc) · 1.86 KB
/
make_sharedlib.sh
File metadata and controls
executable file
·78 lines (64 loc) · 1.86 KB
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
#!/usr/bin/env bash
# @file make_sharedlib.sh
# @brief A script for creating shared library ``libcuba.so``.
# @author Johannes Buchner (C) 2015
# @author Mike S Wang (C) 2024
# Preamble
function bfecho {
echo -e "\033[1m$@\033[0m"
}
LIBNAME=libcuba
if [[ $(uname -s) == 'Darwin' ]]; then
LIBSUFFIX=.dylib
elif [[ $(uname -s) == 'Linux' ]]; then
LIBSUFFIX=.so
else
echo "Unsupported operating system: $(uname -s)"
exit 1
fi
DISTDIR=dist
CC=${CC:-gcc}
# Patch the source code.
bfecho "Patching up source code..."
patch -p1 < $(find patches -type f -name "*.patch")
echo
# Export environment variables.
bfecho "Exporting environment variables..."
CFLAGS_LIST=(-fPIC -fomit-frame-pointer -Ofast -Wall)
if [[ $(uname -s) == 'Darwin' ]]; then
CFLAGS_LIST+=(-mmacos-version-min=11.0 -mcpu=apple-m1 -mtune=native)
else
CFLAGS_LIST+=(-march=native)
fi
echo "export CFLAGS=\${CFLAGS:-${CFLAGS_LIST[@]}}"
export CFLAGS=${CFLAGS:-${CFLAGS_LIST[@]}}
echo
# Configure
bfecho "Configuring..."
./configure
echo
# Build default static library.
bfecho "Rebuilding static library..."
make -B ${LIBNAME}.a
echo
# Build shared library from unpacked static library.
bfecho "Unpacking static library..."
OBJFILES=$(ar xv libcuba.a | sed 's|x - ||g' | grep -v '__.SYMDEF SORTED')
echo
bfecho "Building shared library..."
${CC} -shared -Wall ${OBJFILES} -o ${LIBNAME}${LIBSUFFIX} -lm
echo
# Move libraries to dist directory.
bfecho "Moving libraries to dist directory..."
mkdir -p "${DISTDIR}"
find . -maxdepth 1 -type f -name "${LIBNAME}.*" -exec mv {} "${DISTDIR}" \;
echo
# Clean up.
bfecho "Cleaning up..."
echo "... unpatching source code"
patch -R -p1 < $(find patches -type f -name "*.patch")
echo
echo "... deleting auxiliary files"
find . -type f -name "*.rej" -o -name "*.orig" -exec rm {} \;
rm config.h config.log config.status makefile '__.SYMDEF SORTED' ${OBJFILES}
echo