forked from tgc/buildpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh.functions
120 lines (104 loc) · 2.87 KB
/
build.sh.functions
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
# Function library for buildpkg build.sh
# This is only for build.sh helper functions.
# Copyright (C) 2003 Jens Henrik Leonhard Jensen
# Copyright (C) 2003-2019 Tom G. Christensen <[email protected]>
# This program 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.
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
# Written by Tom G. Christensen <[email protected]>.
# Automatic logging is enabled by default
autolog=1
# Don't log these methods
nolog="prep distclean"
# date format string
dateformat="%Y%m%d%H%M%S"
# Define script functions and register them
METHODS=""
reg() {
METHODS="$METHODS $1"
}
all()
{
for METHOD in $METHODS
do
case $METHOD in
all*|*clean|check) ;;
*) $METHOD
;;
esac
done
}
usage() {
echo Usage $0 "{"$(echo $METHODS | tr " " "|")"}"
exit 1
}
build_sh() {
# Register internal functions last
# The empty reg is trickery to get exactly 1 space at each end of the METHODS string
reg all
reg
#
local OK=0
for METHOD in $*
do
METHOD=" $METHOD *"
if [ "${METHODS%$METHOD}" == "$METHODS" ] ; then
usage
fi
OK=1
done
if [ $OK = 0 ] ; then
usage;
fi
for METHOD in $*
do
( log_start $METHOD; $METHOD; log_stop $METHOD )
done
}
# Write out a timestamp
timestamp()
{
date +$dateformat
}
# Start a logfile
# Note this should only be used *after* the buildpkg.* libraries
# have been sourced, otherwise most of the variables used to construct
# the logfile name are undefined.
log_start()
{
local func=$1
build_sh_logfile=${topdir}-${version}_${pkgver}-${os}-${build_arch}-${func}-$(timestamp).log
if [ $autolog -eq 1 ]; then
if [ -z "$(${__expr} "$nolog" : ".*\($func\)")" ]; then
# save stdout and stderr to file descriptors 3 and 4
# then redirect them to $build_sh_logfile
echo "Opening logfile: $build_sh_logfile"
exec 3>&1 4>&2 >$build_sh_logfile 2>&1
# Log a timestamp
timestamp
# Get information about the compiler into the logfile
identify_compiler log
else # $nolog function, just add a timestamp
timestamp
fi
fi
}
# Stop logging
log_stop()
{
local func=$1
if [ $autolog -eq 1 -a -z "$(${__expr} "$nolog" : ".*\($func\)")" ]; then
# Log a timestamp
timestamp
# restore stdout and stderr
exec 1>&3 2>&4
echo "Closing logfile: $build_sh_logfile"
fi
}