-
Notifications
You must be signed in to change notification settings - Fork 69
/
compile.sh
executable file
·177 lines (140 loc) · 4.45 KB
/
compile.sh
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
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash
# Purpose: `Compile` libraries from `lib/*` to create `pacapt` script.
# Author : Anh K. Huynh
# License: Fair license (http://www.opensource.org/licenses/fair)
# Source : http://github.com/icy/pacapt/
# Copyright (C) 2010 - 2015 Anh K. Huynh et al.
#
# Usage of the works is permitted provided that this instrument is
# retained with the works, so that any entity that uses the works is
# notified of this instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
set -u
set -e
unset GREP_OPTIONS
VERSION="${VERSION:-$(git log --pretty="%h" -1 2>/dev/null || true)}"
VERSION="${VERSION:-unknown}"
if [[ "${VERSION}" == "unknown" ]]; then
echo >&2 ":: Unable to get version information."
echo >&2 ":: You may to install or reconfigure your 'git' package."
exit 1
fi
: "${PACAPT_STATS:=yes}" # List implemented operations to STDERR
: "${GREP:=grep}" # Need to update on SunOS
: "${AWK:=awk}" # Need to update on SunOS
# At compile time, `_sun_tools_init` is not yet defined.
if [[ -f "lib/sun_tools.sh" ]]; then
# shellcheck disable=1091
source "lib/sun_tools.sh" :
_sun_tools_init || true
fi
export GREP AWK VERSION PACAPT_STATS
########################################################################
# Print the shebang and header
########################################################################
cat <<EOF
#!/usr/bin/env sh
#
# Purpose: A wrapper for all Unix package managers
# License: Fair license (http://www.opensource.org/licenses/fair)
# Source : http://github.com/icy/pacapt/
# Version: $VERSION
# Authors: Anh K. Huynh et al.
# Copyright (C) 2010 - $(date +%Y) \\
$( \
< README.md \
sed -e '1,/AUTHORS/d' \
| $GREP '*' \
| sed -e 's,*,# |,g')
#
# Usage of the works is permitted provided that this instrument is
# retained with the works, so that any entity that uses the works is
# notified of this instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
#
_print_pacapt_version() {
cat <<_EOF_
pacapt version '$VERSION'
Copyright (C) 2010 - $(date +%Y) \\\\
$( \
< README.md \
sed -e '1,/AUTHORS/d' \
| $GREP '*' \
| sed -e 's,*, |,g')
Usage of the works is permitted provided that this
instrument is retained with the works, so that any
entity that uses the works is notified of this instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
_EOF_
}
export PACAPT_VERSION='$VERSION'
EOF
########################################################################
# Create help method
########################################################################
cat <<'EOS'
_help() {
cat <<'EOF'
EOS
# The body of help message
cat ./lib/help.txt
cat <<'EOS'
EOF
}
EOS
########################################################################
# Creating a list of files to print out
########################################################################
library_files() {
ls ./lib/*.sh
}
library_POSIX_ready() {
"$GREP" -qi '#!/usr/bin/env sh' -- "$@"
}
########################################################################
# Print the source of all library files, except (zz_main.sh)
########################################################################
for L in $(library_files); do
bash -n "$L" || exit 1
[[ "${L##*/}" != "zz_main.sh" ]] \
|| continue
if library_POSIX_ready "$L"; then
>&2 echo ":: POSIX library '$L'"
$GREP -v '^#' "$L"
else
$GREP -v '^#' "$L" | awk '{printf("#_!_POSIX_# %s\n", $0)}'
fi
done
########################################################################
# Create the `_validate_operation` method.
# Detect all supported operations.
########################################################################
echo "_validate_operation() {"
echo " case \"\$1\" in"
for L in $(library_files); do
_PKGNAME="${L##*/}"
_PKGNAME="${_PKGNAME%.*}"
case "$_PKGNAME" in
"zz_main"|"00_*") continue ;;
esac
while read -r F; do
echo " \"$F\") ;;"
done < \
<(
# shellcheck disable=2016
$GREP -hE "^${_PKGNAME}_[^ \\t]+\\(\\)" "$L" \
| $AWK -F '(' '{print $1}'
)
done
echo " *) return 1 ;;"
echo " esac"
echo "}"
########################################################################
# Print the source of `zz_main.sh`.
# `zz_main` doesn't contain only Bash function.
# It should be included in the last part of the script.
########################################################################
$GREP -v '^#' lib/zz_main.sh
echo >&2 "pacapt version '$VERSION' has been generated."