-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bash_functions.build
276 lines (265 loc) · 8.9 KB
/
.bash_functions.build
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# vim: ft=bash noet:
! declare 2>&1 | grep -wq ^colors= && [ $BASH_VERSINFO -ge 4 ] && source $initDir/.colors
test "$debug" -gt 0 && echo "=> Running $bold${colors[blue]}$(basename ${BASH_SOURCE[0]})$normal ..."
test "$debug" -gt 0 && Echo "\n=> \${BASH_SOURCE[*]} = ${BASH_SOURCE[*]}\n"
type -P nproc >/dev/null 2>&1 && nproc=$(nproc) || nproc=$(getconf _NPROCESSORS_ONLN)
myMakeOptions="-j$nproc"
test "$make" || { type -P remake >/dev/null 2>&1 && export make="command remake $myMakeOptions" || export make="command make $myMakeOptions"; }
test "$install" || { type -P checkinstall >/dev/null 2>&1 && export install="command checkinstall" || export install="make install"; }
function buildSourceCode {
local basicCompiler="command $(echo $HOSTTYPE-$OSTYPE-gcc | sed "s/armv[^-]*-/arm-/")"
test $CC || [ -z "$basicCompiler" ] || export CC=$(\ls ${basicCompiler}{-?,} 2>/dev/null | awk -F/ 'END{print$NF}')
local host=$(echo "$@" | grep -oP -- "--host=\K\S+")
local defaultBuildOptions=""
local returnCode=0
local project=$(basename $PWD)
[ -s Makefile ] || [ -s makefile ] || [ -s GNUmakefile ] || configure $defaultBuildOptions "$@"
returnCode=$?
if [ $returnCode = 0 ] && ( [ -s Makefile ] || [ -s makefile ] || [ -s GNUmakefile ] )
then
echo "=> make ..."
if make
then
test -n "$CC" && echo "=> CC = $CC"
if [ -z "$host" ] # if building for this host then install
then
returnCode=$?
if groups | \egrep -wq "sudo|adm|root"
then
if type -P checkinstall >/dev/null
then
if git rev-parse --git-dir >/dev/null 2>&1;then
checkinstallWithGitRepoInformation
else
echo "=> sudo checkinstall ..."
sudo checkinstall
fi
else
echo "=> sudo $make install ..."
sudo $make install
fi
returnCode=$?
else
echo "=> make install ..."
make install
returnCode=$?
fi
fi
else
returnCode=$?
fi
else
returnCode=$?
printf "=> ERROR: The Makefile could not be generated therefore the building the <$project> source code has failed !\n=> Listing the files :\n$(ls -l)\n" >&2
fi
echo "=> returnCode = $returnCode" >&2
[ $returnCode = 0 ] && [ -z "$host" ] && set -x && sudo ldconfig
set +x
test -n "$CC" && echo "=> CC = $CC"
export -n CC
return $returnCode
}
function checkinstallWithGitRepoInformation {
[ $osFamily = Darwin ] && local sed="command sed -E"
[ $osFamily = Linux ] && local sed="command sed -r"
local gitHTTP_URL=$(\git config --get remote.origin.url | $sed "s|^git@|https://|;s|(\.\w+):|\1/|")
local gitHub_API_Repo_URL=$(echo $gitHTTP_URL | $sed "s|github.com|api.github.com/repos|")
echo "=> Running $FUNCNAME ..."
printf "=> The project description is : "
# \curl -qs $gitHTTP_URL | \pup --charset utf8 "title text{}" | cut -d: -f2- | cut -d' ' -f2- | tee description-pak
# xidel -s -e //title $gitHTTP_URL | cut -d: -f2- | cut -d' ' -f2- | tee description-pak
\curl -qs $gitHub_API_Repo_URL | jq -r .description | cut -d: -f3- | cut -d' ' -f2- | tee description-pak
echo
local pkgname=$(basename -s .git $gitHTTP_URL)
local pkgversion=$(\git describe --tags --abbrev=0 | $sed "s/^v|^[Vv]ersion//g;")
local pkgsource=$gitHTTP_URL
set -x
sudo checkinstall --pkgname $pkgname --pkgversion $pkgversion --pkgsource=$pkgsource
set +x
}
function buildSourceCodeForAndroid {
local dest=arm-linux-androideabi
test $CC || export CC=$dest-gcc
local defaultBuildOptions="--prefix=$HOME/build/android --host=$dest --build=$MACHTYPE"
local returnCode=0
buildSourceCode $defaultBuildOptions "$@"
return $?
}
function buildSourceCodeForJolla {
local dest=arm-linux-gnueabihf
test $CC || export CC=$dest-gcc
local defaultBuildOptions="--prefix=$HOME/build/jolla --host=$dest"
local returnCode=0
buildSourceCode $defaultBuildOptions "$@"
return $?
}
function build_in_HOME {
test -s configure || time ./bootstrap.sh || time ./bootstrap || time ./autogen.sh
test -s Makefile || time ./configure --prefix=$HOME/gnu --sysconfdir=$HOME/gnu $@
test -s Makefile && time $make && $make install
test -s GNUmakefile && time $make && $make install
}
function build_in_usr {
test -s configure || time ./bootstrap.sh || time ./bootstrap || time ./autogen.sh
test -s Makefile || time ./configure --prefix=/usr --sysconfdir=/etc $@
test -s Makefile && time $make && sudo $make install
test -s GNUmakefile && time $make && sudo $make install
}
function build_in_usr_DEBIAN {
test -s configure || time ./bootstrap.sh || time ./bootstrap || time ./autogen.sh
test -s Makefile || time ./configure --prefix=/usr --sysconfdir=/etc $@
test -s Makefile && time $make && sudo $make install
test -s GNUmakefile && time $make && sudo checkinstall
}
function build_in_usr_local {
test -s configure || time ./bootstrap.sh || time ./bootstrap || time ./autogen.sh
test -s Makefile || time ./configure --prefix=/usr/local $@
test -s Makefile && time $make && sudo $make install
test -s GNUmakefile && time $make && sudo $make install
}
function build_in_usr_local_DEBIAN {
test -s configure || time ./bootstrap.sh || time ./bootstrap || time ./autogen.sh
test -s Makefile || time ./configure --prefix=/usr/local $@
test -s Makefile && time $make && sudo checkinstall
test -s GNUmakefile && time $make && sudo checkinstall
}
function configure {
local basicCompiler="command $(echo $HOSTTYPE-$OSTYPE-gcc | sed "s/armv[^-]*-/arm-/")"
test $CC || [ -z "$basicCompiler" ] || export CC=$(\ls ${basicCompiler}{-?,} 2>/dev/null | awk -F/ 'END{print$NF}')
local defaultBuildOptions=""
local project=$(basename $PWD)
local returnCode=0
./configure --help | \grep -q -- "--enable-shared" && defaultBuildOptions="--enable-shared"
test "$1" = "-h" && {
echo "=> Usage: $FUNCNAME [--prefix=/installation/path] [./configure arguments ...]" >&2
return 1
}
if [ $# = 0 ] || ! echo "$@" | \grep -q -- "--prefix="
then
if groups | \egrep -wq "sudo|adm|root"
then
prefix=/usr/local
elif grep -wq GNU README* COPYING
then
prefix=$HOME/gnu
mkdir -p $prefix
else
prefix=$HOME/local
mkdir -p $prefix
fi
else
for arg in $@;do echo $arg | \grep -q -- --prefix= && prefix=${arg/*=/};done
prefix=$(echo $prefix | sed 's/~/$HOME/') #Configure ne supporte parfois pas les chemins contenant '~'
mkdir -p $prefix
shift
fi
configureArgs="--prefix=$prefix --exec-prefix=$prefix $defaultBuildOptions $@"
echo "=> pwd = $PWD"
echo "=> prefix = $prefix"
\grep -w url ./.git/config && type -P git >/dev/null 2>&1 && git pull
if [ -f CMakeLists.txt ]
then
mkdir -p build
cd build
if groups | \egrep -wq "sudo|adm|root" && echo $prefix | grep -q /usr
then
unset CC
echo "=> cmake .. $@"
cmake .. $@
else
unset CC
echo "=> cmake .. -DPREFIX=$prefix -DEPREFIX=$prefix $@ ..."
cmake .. -DPREFIX=$prefix -DEPREFIX=$prefix $@
fi
returnCode=$?
grep ":PATH=.*$prefix" CMakeCache.txt
test $returnCode != 0 && cd ../ # You need to be in the parent directory to re-run the "buildSourceCode" function
else
if [ ! -s configure ]
then
# test -s ./bootstrap.sh && time ./bootstrap.sh || { test -s ./bootstrap && time ./bootstrap || test -s ./autogen.sh && time ./autogen.sh; }
for autoconfProg in bootstrap.py bootstrap.sh bootstrap autogen.sh build.sh
do
if test -x $autoconfProg
then
set -x
time ./$autoconfProg $configureArgs || time ./$autoconfProg
returnCode=$?
set +x
break
fi
done
set -x
if [ $returnCode = 0 ]
then
if [ -x ./waf ]
then
./waf configure
else
test -x ./configure || time autoreconf -vim || time autoreconf -vimf
fi
returnCode=$?
fi
set +x
fi
if [ ! -s Makefile ]
then
test -s ./configure && set -x && time ./configure $configureArgs
returnCode=$?;set +x
fi
fi
echo "=> returnCode = $returnCode" >&2
return $returnCode
}
function configureForAndroid {
local dest=arm-linux-androideabi
test $CC || export CC=$dest-gcc
local defaultBuildOptions="--prefix=$HOME/build/android --host=$dest --build=$MACHTYPE"
local returnCode=0
configure $defaultBuildOptions "$@"
return $?
}
function configureForJolla {
local dest=arm-linux-gnueabihf
test $CC || export CC=$dest-gcc
local defaultBuildOptions="--prefix=$HOME/build/jolla --host=$dest"
local returnCode=0
configure $defaultBuildOptions "$@"
return $?
}
function make {
if [ -s Makefile ] || [ -s makefile ] || [ -s GNUmakefile ]
then
time CFLAGS="-g" $make $@
else
\mkdir ../bin 2>/dev/null
if type -P gcc >/dev/null 2>&1
then
for file
do
echo gcc -ggdb $file.c -o ../bin/$file
time command gcc -ggdb $file.c -o ../bin/$file
done
else
for file
do
echo cc -g $file.c -o ../bin/$file
time command cc -g $file.c -o ../bin/$file
done
fi
fi
}
function pipInstallFromDIR {
local dir=${1:-../$(basename $PWD)} # Set dir to current directory by default
if $isAdmin
then
set -x
$sudo -H pip install $dir
else
set -x
pip install --user $dir
fi
set +x
}
set +x
test "$debug" -gt 0 && echo "=> END of $bold${colors[blue]}$(basename ${BASH_SOURCE[0]})$normal"