buildlib: supply -fPIC or -fpic if supported
[blocksruntime.git] / installlib
blobfbf2136f12b04d473fdafe117a74b1ae51255040
1 #!/bin/sh
3 set -e
5 : "${prefix:=/usr/local}"
6 : "${includedir:=$prefix/include}"
7 : "${libdir:=$prefix/lib}"
8 : "${DESTDIR:=}"
10 HEADER=BlocksRuntime/Block.h
11 LIB=libBlocksRuntime.a
12 SHLIB=
14 docmd()
16 echo "$*"
17 if [ -z "$dryrun" ]; then eval "$*"; fi
20 if ! myid="$(id -u)"; then
21 echo "Cannot run id, aborting!"
22 exit 1
24 if [ ! -r $HEADER ]; then
25 echo "Cannot find $HEADER, aborting!"
26 exit 1
28 dryrun=
29 if [ "$1" = '-n' ] || [ "$1" = '--dry-run' ]; then
30 dryrun=1
31 shift
33 static=1
34 shared=1
35 case "$1" in
36 "-static"|"--static")
37 shift
38 shared=
40 "-shared"|"--shared")
41 shift
42 static=
44 esac
45 if [ "$#" != 0 ]; then
46 echo "Usage: [prefix=prefixdir] $0 [-n | --dry-run] [-shared | -static]"
47 exit 1
49 if [ -n "$shared" ]; then
50 UNAME_S="$(uname -s 2>/dev/null)" || :
51 case "$UNAME_S" in
52 Darwin)
53 SHLIB="${LIB%.a}.dylib"
54 SHLIBMODE=755
57 SHLIB="${LIB%.a}.so"
58 SHLIBMODE=644
60 esac
61 if [ -n "$static" ]; then
62 # ignore a missing shared library
63 [ -e "$SHLIB" ] || SHLIB=
64 else
65 LIB=
68 if [ -n "$LIB" ] && [ ! -r "$LIB" ]; then
69 echo "Cannot find $LIB, did you run \`buildlib\` or \`buildlib-osx\`?"
70 exit 1
72 if [ -n "$SHLIB" ] && [ ! -r "$SHLIB" ]; then
73 echo "Cannot find $SHLIB, did you run \`buildlib -shared\` or \`buildlib-osx -shared\`?"
74 exit 1
77 [ -z "$DESTDIR" ] ||
78 echo "Destination Root(\$DESTDIR): $DESTDIR (default is \"\")"
79 echo "Install Prefix(\$prefix): $prefix (default is /usr/local)"
80 echo "Include Directory(\$includedir): $includedir (default is \$prefix/include)"
81 echo "Library Directory(\$libdir): $libdir (default is \$prefix/lib)"
82 echo "(use prefix=prefixdir $0 [or similar] to change)"
83 echo ''
85 if [ -z "$DESTDIR" -a -z "$dryrun" -a "$myid" != 0 ]; then
86 echo "Must be root to install, use sudo $0"
87 echo "(Or try using the --dry-run option)"
88 exit 1
90 docmd "install -d "$DESTDIR"$includedir "$DESTDIR"$libdir"
91 docmd "install -m 644 $HEADER "$DESTDIR"$includedir/"
92 [ -z "$LIB" ] ||
93 docmd "install -m 644 $LIB "$DESTDIR"$libdir/"
94 [ -z "$SHLIB" ] ||
95 docmd "install -m $SHLIBMODE $SHLIB "$DESTDIR"$libdir/"