-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·165 lines (143 loc) · 4.27 KB
/
install
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
#!/bin/sh
# Copyright (C) 2017, 2018, 2019 Karl Landstrom <karl@miasap.se>
#
# This file is part of obnc-libext.
#
# obnc-libext is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# obnc-libext is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.
set -o errexit -o nounset
readonly selfDirPath="$(cd "$(dirname "$0")"; pwd -P)"
readonly packageName="$(basename "$selfDirPath")"
readonly packageNameSansVersion="${packageName%%-[0-9]*}"
readonly libName="${packageNameSansVersion#obnc-lib}"
readonly modules="$(ls "$selfDirPath/$libName"/*.obn | grep -v 'Test\.obn$' | while read file; do basename "${file%.obn}"; done)"
prefix="/usr/local"
libdir="lib"
destdir=
destIncludeDir=
destLibDir=
destObncdocDir=
includeLibCSrc=false
EchoAndRun()
{
echo "$@"
eval "$@"
}
UpdateObncdocIndex()
{
EchoAndRun cd "$destObncdocDir/.."
if obncdoc-index >/dev/null 2>&1; then
EchoAndRun obncdoc-index \> index.html
fi
cd - >/dev/null
}
Install()
{
local srcDir="$selfDirPath/$libName"
#install library
EchoAndRun mkdir -p "$destIncludeDir"
EchoAndRun mkdir -p "$destLibDir"
local module=
for module in $modules; do
EchoAndRun cp "$srcDir/.obnc/$module.h" "$destIncludeDir"
EchoAndRun cp "$srcDir/.obnc/$module.o" "$destLibDir"
EchoAndRun cp "$srcDir/.obnc/$module.sym" "$destLibDir"
if [ -e "$srcDir/.obnc/$module.imp" ]; then
EchoAndRun cp "$srcDir/.obnc/$module.imp" "$destLibDir"
fi
if [ -e "$srcDir/$module.env" ]; then
EchoAndRun cp "$srcDir/$module.env" "$destLibDir"
fi
if "$includeLibCSrc"; then
local source="$srcDir/$module.c"
if [ ! -e "$source" ]; then
source="$srcDir/.obnc/$module.c"
fi
EchoAndRun sed -e "'s|#include \"\(\.obnc/\)\?$module\.h\"|#include <obnc/ext/$module.h>|'" "'$source'" \> "'$destLibDir/$module.c'"
fi
done
#install documentation
EchoAndRun mkdir -p "$destObncdocDir"
EchoAndRun cp "$srcDir/obncdoc/$libName"* "$destObncdocDir"
for file in "$srcDir/obncdoc/"*; do
if [ "$file" = "${file%Test.*}" ]; then
EchoAndRun cp "$file" "$destObncdocDir"
fi
done
UpdateObncdocIndex
}
Uninstall()
{
#delete library files
local module=
for module in $modules; do
EchoAndRun rm -f "$destIncludeDir/$module.h"
EchoAndRun rm -f "$destLibDir/$module.o"
EchoAndRun rm -f "$destLibDir/$module.sym"
EchoAndRun rm -f "$destLibDir/$module.imp"
EchoAndRun rm -f "$destLibDir/$module.env"
EchoAndRun rm -f "$destLibDir/$module.c"
done
#delete documentation
EchoAndRun rm -f "$destObncdocDir"/*
UpdateObncdocIndex
}
Help()
{
echo "usage: "
printf "\tinstall [u] [--prefix=PREFIX] [--libdir=LIBDIR] [--destdir=DESTDIR] [--include-lib-c-src]\n"
printf "\tinstall -h\n"
echo
printf "\tu\t\t\tuninstall\n"
printf "\t--prefix\t\ttoplevel installation dir instead of /usr/local\n"
printf "\t--libdir\t\tlibrary installation directory instead of lib\n"
printf "\t--destdir\t\tspecify directory for staged installation\n"
printf "\t--include-lib-c-src\tmake cross compilation possible\n"
printf "\t-h\t\t\tdisplay help and exit\n"
}
uninstall=false
for arg in "$@"; do
case "$arg" in
u)
uninstall=true;;
--prefix=*)
prefix="${arg#--prefix=}"
if [ "${prefix#/}" = "$prefix" ]; then
echo "prefix must be an absolute path: $prefix" >&2
exit 1
fi;;
--libdir=*)
libdir="${arg#--libdir=}"
if [ "${libdir#*/}" != "$libdir" ]; then
echo "libdir must be a prefix relative path, not an absolute path: $prefix" >&2
exit 1
fi;;
--destdir=*)
destdir="${arg#--destdir=}";;
--include-lib-c-src)
includeLibCSrc=true;;
-h)
Help
exit;;
*) { echo "invalid command"; Help; } >&2
exit 1
esac
done
destIncludeDir="$destdir$prefix/include/obnc/$libName"
destLibDir="$destdir$prefix/$libdir/obnc/$libName"
destObncdocDir="$destdir$prefix/share/doc/obnc/obncdoc/$libName"
if "$uninstall"; then
Uninstall
else
Install
fi