]> begriffs open source - libderp/blob - install.sh
Set rpath in linked binaries
[libderp] / install.sh
1 #!/bin/sh
2 set -eu
3
4 MAJOR_VER=0
5 MINOR_VER=0
6 PATCH_VER=0
7
8 if [ $# -lt 1 ]
9 then
10         if [ -d /opt ]
11         then
12                 DEST=/opt
13         else
14                 DEST=/usr/local
15         fi
16 else
17         DEST=$1
18 fi
19
20 if [ ! -d "$DEST" ]
21 then
22         printf "ERROR: Destination directory '%s' does not exist\n" "$DEST"
23         exit 1
24 fi
25 PREFIX="$DEST/libderp.$MAJOR_VER.$MINOR_VER.$PATCH_VER"
26 SYM="$DEST/libderp.$MAJOR_VER"
27
28 if [ -d "$PREFIX" ]
29 then
30         printf "ERROR: Directory already exists: %s\n" "$PREFIX"
31         echo Remove it and run script again to reinstall.
32         exit 1
33 fi
34
35 if [ ! -f build/release/libderp.so ] || [ ! -f build/release/libderp.a ]
36 then
37         echo ERROR: Run make first to build the shared library
38         exit 1
39 fi
40
41 mkdir -p "$PREFIX/include" "$PREFIX/lib/pkgconfig" "$PREFIX/man"
42 rm -f "$SYM"
43 ln -s "$PREFIX" "$SYM"
44
45 cp -R include/derp "$PREFIX/include"
46 cp build/release/*.so build/release/*.a "$PREFIX/lib"
47
48 # oh mac, you so crazy
49 if command -v install_name_tool
50 then
51         install_name_tool -id @rpath/libderp.so "$PREFIX/lib/libderp.so"
52 fi
53
54 # m4 is not universally available...posix scofflaws
55 sed -e "s%PREFIX%$SYM%" \
56         -e "s%MAJOR%$MAJOR_VER%" -e "s%MINOR%$MINOR_VER%" -e "s%PATCH%$PATCH_VER%" \
57         libderp.pc > "$PREFIX/lib/pkgconfig/libderp.pc"
58
59 echo "Libderp $MAJOR_VER.$MINOR_VER.$PATCH_VER installed." 
60 echo
61 printf "To use with pkg-config\n\tadd %s/lib/pkgconfig to PKG_CONFIG_PATH\n" "$SYM"
62 printf "To view man pages\n\tadd %s/man to MANPATH\n" "$SYM"