-
Notifications
You must be signed in to change notification settings - Fork 4
/
LFSMakeTemplate
executable file
·344 lines (300 loc) · 7.69 KB
/
LFSMakeTemplate
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/bin/bash -e
#©keithhedger Thu 5 Oct 11:51:31 BST 2023 [email protected]
. /usr/share/LFSPkg/LFSFunctions
SCRIPTPKGNAME="${SCRIPTPKGNAME:-$NAME}"
SCRIPTTARNAME=""
SCRIPTPKGVERSION=""
SCRIPTPKGSECTION=""
SCRIPTSUFFIX=""
SCRIPTTARBALL=""
SCRIPTARCHIVEDIR=""
SCRIPTTARURL=""
getBool ()
{
if [[ -z "$1" ]];then
echo 0
else
echo 1
fi
}
makeGetArchive ()
{
local gitoptions=""
if [ $ISGITREPO -eq 0 ];then
echo gettar \"${SCRIPTPKGARCHIVEDIR}/\${TARBALL}\" \$SECTION
else
if [[ $GITTYPE = "tag" ]];then
gitoptions=" --branch ${GITTAG} --single-branch"
fi
cat<<EOF
mkdir -p \${SOURCEARCHIVES}/GITREPOS
pushd \${SOURCEARCHIVES}/GITREPOS
if [[ ! -e \${TARNAME} ]];then
git clone ${SCRIPTPKGTARURL}/\${TARNAME}.git$gitoptions
EOF
if [[ $GITTYPE = "commit" ]];then
cat<<EOF
cd \${TARNAME}
git reset --hard ${GITTAG}
git clean -df
EOF
fi
cat<<EOF
else
if [ "X\${DOWHAT:0:2}" = "Xup" ];then
cd \${TARNAME}
git pull
fi
fi
popd
EOF
fi
}
makeCommonHeader ()
{
mkdir -vp $SCRIPTPKGNAME||true
echo -e "#!/bin/bash\n#©$USER $(date)\n\n. /usr/share/LFSPkg/LFSFunctions\n">${SCRIPTPKGNAME}/preinstall
echo -e "#!/bin/bash\n#©$USER $(date)\n\n. /usr/share/LFSPkg/LFSFunctions\n">${SCRIPTPKGNAME}/postinstall
infodata=$(lfspkg -I ${SCRIPTPKGNAME} 2>/dev/null) 2>/dev/null||true
if [ "X$infodata" != X ];then
echo "$infodata" > ${SCRIPTPKGNAME}/info
fi
cat >"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
#!/bin/bash -e
. /usr/share/LFSPkg/LFSFunctions
trap 'echo -e "\$0 \${RED}FAILED\${NORMAL} at line \${GREEN}\${LINENO}\${NORMAL}"' ERR
DEPENDS=""
if ! lfspkg -B "\$DEPENDS";then
exit 100
fi
PKGNAME="$SCRIPTPKGNAME"
TARNAME="$SCRIPTTARNAME"
VERSION="$SCRIPTPKGVERSION"
BUILD=\${BUILD:-1}
SECTION="$SCRIPTPKGSECTION"
SUFFIX="LFSPKG"
$(if [ $ISGITREPO -eq 0 ];then echo "TARBALL=\"\${TARNAME}-\${VERSION}${SCRIPTPKGSUFFIX}\"";else echo TARBALL=\"\";fi)
PKG="\${OUTPUT}/\${PKGNAME}"
DOWHAT=\${1:-"build"}
CWD=\$(pwd)
rm -rf "\$PKG" || true
mkdir -p "\$PKG"
scriptLog "\${PKGNAME}-\${VERSION}"
EOF
if [ $ISPIP -eq 0 ];then
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
$(makeGetArchive)
if [ \$USESYSTEMD -eq 0 ];then
:
fi
pushd \$COMPILEAT 2>/dev/null||true
EOF
else
echo -e "\npip install --root="\$PKG" \${TARNAME}\n" >> "${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
return
fi
if [ $ISGITREPO -eq 0 ];then
echo -e "\textractarchive \"\${SOURCEARCHIVES}/\${SECTION}/\${TARBALL}\"" >> "${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
echo -e "\tpushd \"\${TARNAME}-\${VERSION}\"" >> "${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
else
echo -e "\tpushd \"\${SOURCEARCHIVES}/GITREPOS/\${TARNAME}\"" >> "${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
fi
}
makeCommonFooter ()
{
if [ $ISPIP -eq 0 ];then
TABS=" "
TAB1=" "
else
TAB1=""
TABS=" "
fi
if [ $ISPIP -eq 0 ];then
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
${TABS}popd
EOF
fi
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
${TAB1}checketc \$PKG
${TAB1}packageclean "\$PKG" "\$CWD"
${TAB1}pushd "\$PKG"
${TAB1}${TABS}lfspkg -n "\$PKGNAME" -p "\$VERSION" -d "\$SECTION" -b "\$BUILD" -s "\$SUFFIX" -m
${TAB1}popd
${TAB1}case \$DOWHAT in
${TAB1}${TABS}up*)
${TAB1}${TABS}${TABS}lfspkg "^\${PKGNAME}-[0-9][0-9]*" "\${PKGARCHIVES}/\${SECTION}/\${PKGNAME}-\${VERSION}-\${BUILD}_\${SECTION}_\${SUFFIX}.tar.gz" -u
${TAB1}${TABS}${TABS};;
${TAB1}${TABS}"install")
${TAB1}${TABS}${TABS}lfspkg "\${PKGARCHIVES}/\${SECTION}/\${PKGNAME}-\${VERSION}-\${BUILD}_\${SECTION}_\${SUFFIX}.tar.gz" -i
${TAB1}${TABS}${TABS};;
${TAB1}${TABS}"build")
${TAB1}${TABS}${TABS}echo "Just built"
${TAB1}${TABS}${TABS};;
${TAB1}${TABS}*)
${TAB1}${TABS}${TABS}echo "*** Unknown command ***"
${TAB1}${TABS}${TABS}exit 1
${TAB1}esac
EOF
if [ $ISPIP -eq 0 ];then
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
${TAB1}rm -rf "\$PKG"$(if [ $ISGITREPO -eq 0 ];then echo " "\"\${TARNAME}-\${VERSION}\";fi)
popd 2>/dev/null||true
EOF
else
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
${TAB1}rm -rf "\$PKG"
EOF
fi
}
getScriptData ()
{
local url bn section
url=${DOWNLOADARCHIVE}
bn="$(basename "$url")"
section="$(basename "$(pwd)")"
SCRIPTPKGSECTION=${section^^}
SCRIPTPKGARCHIVEDIR=$(dirname "$url")
SCRIPTPKGVERSION=$PKGVERSION
if [ $ISGITREPO -eq 0 ];then
if [[ -z "$NAME" ]];then
SCRIPTPKGNAME=${bn%-?*}
SCRIPTTARNAME="\$PKGNAME"
else
SCRIPTPKGNAME="$NAME"
SCRIPTTARNAME="${bn%-?*}"
fi
if [[ -z $PKGVERSION ]];then
SCRIPTPKGVERSION="$(echo ${bn##?*-}|sed -n 's/\([[:digit:]][\.[[:digit:]]*]*\)\...*/\1/p')"
fi
SCRIPTPKGSUFFIX="$(echo ${bn##?*-}|sed -n 's/[[:digit:]][\.[[:digit:]]*]*\(\...*\)/\1/p')"
SCRIPTPKGTARBALL=${SCRIPTPKGNAME}-${SCRIPTPKGVERSION}.${SCRIPTPKGSUFFIX}
SCRIPTPKGTARURL=${SCRIPTPKGARCHIVEDIR}/${SCRIPTPKGTARBALL}
else
SCRIPTPKGNAME="${SCRIPTPKGNAME:-${bn%.git}}"
if [[ -z $PKGVERSION ]];then
SCRIPTPKGVERSION="$LFSVERSION"
fi
SCRIPTPKGTARURL=${SCRIPTPKGARCHIVEDIR}
if [[ -z "$NAME" ]];then
SCRIPTTARNAME="\$PKGNAME"
else
SCRIPTTARNAME="$(basename "$bn" .git)"
fi
fi
if false;then
echo -------------------
echo SCRIPTPKGNAME=$SCRIPTPKGNAME
echo SCRIPTTARNAME=$SCRIPTTARNAME
echo SCRIPTPKGVERSION=$SCRIPTPKGVERSION
echo SCRIPTPKGSECTION=$SCRIPTPKGSECTION
echo SCRIPTPKGSUFFIX=$SCRIPTPKGSUFFIX
echo SCRIPTPKGTARBALL=$SCRIPTPKGTARBALL
echo SCRIPTPKGARCHIVEDIR=$SCRIPTPKGARCHIVEDIR
echo SCRIPTPKGTARURL=$SCRIPTPKGTARURL
echo GITTAG=$GITTAG
echo ===================
echo $NAME
echo $PKGVERSION
echo +++++++++++++++++++
fi
}
makeConfigureScript ()
{
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
CFLAGS="\$LFSFLAGS" CXXFLAGS="\$LFSFLAGS" ./configure \${CONFIGOPTIONS}
make \$MAKEFLAGS||make -j1|| exit 100
make install DESTDIR=\$PKG || exit 100
EOF
}
makeMesonScript ()
{
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
mkdir -p build
cd build
CFLAGS="\$LFSFLAGS" CXXFLAGS="\$LFSFLAGS" meson setup \${MESONCONFIGOPTIONS} ..
ninja \$MAKEFLAGS||ninja -j1||exit 100
DESTDIR=\$PKG ninja install
EOF
}
makeCMakeScript ()
{
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
mkdir -p build
cd build
cmake \$CMAKEOPTIONS ..
make \$MAKEFLAGS||make -j1|| exit 100
make install DESTDIR=\$PKG || exit 100
EOF
}
makePerlScript ()
{
cat >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"<< EOF
perl Makefile.PL
make \$MAKEFLAGS||make -j1|| exit 100
make install DESTDIR=\$PKG || exit 100
EOF
}
makePythonScript ()
{
if [[ ${1} -eq 2 ]] || [[ ${1} -eq 23 ]];then
echo -e "\t\tpython2 setup.py build||exit 100" >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
echo -e "\t\tpython2 setup.py install --optimize=1 --root=\$PKG||exit 100" >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
fi
if [[ $1 -eq 3 ]] || [[ ${1} -eq 23 ]];then
echo -e "\t\tpython3 setup.py build||exit 100" >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
echo -e "\t\tpython3 setup.py install --optimize=1 --root=\$PKG||exit 100" >>"${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
fi
}
DOWNLOADARCHIVE="$2"
ISGITREPO=$(getBool "$3")
GITTYPE=""
GITTAG=""
case "${3%%=?*}" in
tag)
GITTYPE="tag"
GITTAG=${3##?*=}
;;
commit)
GITTYPE="commit"
GITTAG=${3##?*=}
;;
git)
GITTYPE="git"
GITTAG=""
;;
esac
getScriptData
if [[ ${1} = "pip" ]];then
ISPIP=1
SCRIPTPKGVERSION=$(pip index versions $SCRIPTPKGNAME 2>/dev/null|head -n1|sed 's/.*(\(.*\))/\1/')
else
ISPIP=0
fi
makeCommonHeader
case ${1} in
conf*)
makeConfigureScript
;;
meson)
makeMesonScript
;;
cmake)
makeCMakeScript
;;
perl)
makePerlScript
;;
python)
makePythonScript 23
;;
python2)
makePythonScript 2
;;
python3)
makePythonScript 3
;;
esac
makeCommonFooter
chmod +x "${SCRIPTPKGNAME}/$SCRIPTPKGNAME.LFSBuild"
chmod +x "${SCRIPTPKGNAME}/preinstall"
chmod +x "${SCRIPTPKGNAME}/postinstall"