forked from aix27249/mkpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkpkg_build_functions
939 lines (878 loc) · 24.8 KB
/
mkpkg_build_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
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
#!/bin/bash
. "${startdir}"/ABUILD
r_startdir="${startdir}"
r_pkgname=${pkgname} #will deprecate
p_pkgname=${pkgname}
p_pkgver=${pkgver}
p_adddep="${adddep}"
p_arch=${arch}
p_pkgdir="${startdir}/${pkgname}"
p_shortdesc="${shortdesc}"
if [ -n "${longdesc}" ]; then
p_longdesc=("$longdesc")
fi
pkgdir="${p_pkgdir}"
#==================================
# begin prepare block
#==================================
get_extract_source() {
if [ -n "${source}" ]; then
d_echo "source processing"
mkdir -p "${srcdir}"
for it in `seq 0 $((${#source[@]}-1))`; do
if [ -z "${_first}" ]; then
_first="first"
else
_first="second"
fi
set -- ${source[it]}
item=$1
d_echo " item ${item}"
local ifn=""
#FIXME коряво сделан разбор опций. Надо бы поправить.
if [ "$2" == "n" -o "$3" == "n" ]; then
#do not unpack
ifn=n
fi
cd "$scrache"
cd "$srcdir" || exit 1
loc_source=$(basename "$item")
if [ "$2" == "o" -o "$3" == "o" ]; then
#overwrite anyway
rm -rf "${srcache}/${loc_source}"
rm -rf "${srcache}/${loc_source}.part"
fi
loc_source_arr[${#loc_source_arr[@]}]="${loc_source}"
loc_source_files+="$(basename ${loc_source}) "
if [ -f "${srcache}/$loc_source" ]; then
item="$loc_source"
fi
local protocol=$(echo "$item" | sed 's|:.*||')
d_echo " Discover source file ${item} download protocol as '$protocol'"
case $protocol in
http|ftp|https)
if [ ! "${ext_arg}" ]; then
wget -c --no-check-certificate ${wgetopts} -O "${srcache}/${loc_source}".part $item || exit 1
mv "${srcache}/${loc_source}".part "${srcache}/${loc_source}"
if [ ! "$ifn" = "n" ]; then
unpack "${srcache}/$loc_source" || exit 1
fi
fi
;;
svn)
cd "${srcache}"
if [ ! ${ext_arg} ]; then
item=$(echo "$item" | sed 's/^svn:*//')
svn checkout $svn_opts $item ${pkgname}_svn_${loc_source}.src
cp -a -r "${srcache}/${pkgname}_svn_${loc_source}".src "${srcdir}"
fi
if [ ! "${strict_version}" -a "${_first}" != "second" ]; then
cd "${pkgname}_svn_${loc_source}".src || exit 1
pkgver+=_svn`svn info | grep Revi | cut -d ":" -f2 | cut -c2-`
cd - >/dev/null || exit 1
fi
cd - >/dev/null
;;
git)
cd "${srcache}"
if [ ! ${ext_arg} ];then
item=$(echo "$item" | sed 's/^git:*//')
if [ ! -d "${pkgname}_git_${loc_source}.src" ]; then
git clone $item "${pkgname}_git_${loc_source}.src"
else
cd "${pkgname}_git_${loc_source}".src
git pull
fi
cp -a -r "${srcache}/${pkgname}_git_${loc_source}".src "${srcdir}"
fi
if [ ! "${strict_version}" -a "${_first}" != "second" ]; then
pkgver+=_git`date "+%Y%m%d"`
fi
cd - >/dev/null
;;
hg)
cd "${srcache}"
if [ ! ${ext_arg} ];then
#cd ${srcache}
item=$(echo "$item" | sed 's/^hg:*//')
if [ ! -d "${pkgname}_hg_${loc_source}.src" ]; then
hg clone $item "${pkgname}_hg_${loc_source}.src"
else
cd "${pkgname}_hg_${loc_source}.src"
hg pull && hg update
fi
cp -a -r "${srcache}/${pkgname}_hg_${loc_source}".src "${srcdir}"
fi
if [ ! "${strict_version}" -a "${_first}" != "second" ]; then
pkgver+=_hg`date "+%Y%m%d"`
fi
cd - >/dev/null
;;
bzr)
cd "${srcache}"
if [ ! ${ext_arg} ];then
cd "${srcache}"
item=$(echo $item | sed 's/^bzr:*//')
loc_source=${pkgname}
if [ ! -d "${loc_source}.src" ]; then
bzr branch $item "${loc_source}.src"
else
cd "${pkgname}.src"
bzr merge
if [ "$?" != "0" ]; then
cd ..
d_echo "deleting corrupted bzr archive"
rm -rf "${loc_source}.src"
bzr branch $item "${loc_source}.src"
fi
fi
cp -a -r "${srcache}/${loc_source}".src "${srcdir}"
fi
if [ ! "${strict_version}" -a "${_first}" != "second" ]; then
cd "${srcache}/${loc_source}.src" || exit 1
local bzr_rev=mkpkg_${pkgname}
bzr log -r -1 lp:${pkgname} | grep revno: | cut -d " " -f2 > ${bzr_rev}
pkgver+=_bzr`cat ${bzr_rev}`
rm -f ${bzr_rev}
echo "setting to ${pkgver}"
cd - >/dev/null
fi
cd - >/dev/null
;;
*)
if [ ! "${ifn}" = "n" -a -z "${ext_arg}" ]; then
unpack "${srcache}/$loc_source" || exit 1
fi
;;
esac
if [ "$(parent_package)" -a ! ${strict_version} ]; then
modif_version=${pkgver}
fi
done
loc_source_count=${#source[@]}
fi
}
unpack()
{
d_echo "unpack() $1"
local file_2_unpack="$1"
#local state=0
cd "${srcdir}"
local file_type=$(file -biz ${file_2_unpack})
unset cmd
case "$file_type" in
*application/x-tar*)
cmd="tar -xf" ;;
*application/zip*)
cmd="unzip" ;;
*application/x-zip*)
cmd="unzip" ;;
*application/x-gzip*)
cmd="gunzip -d -f" ;;
*application/x-bzip*)
cmd="bunzip2 -f" ;;
*application/x-rar*)
cmd="unrar e" ;;
*application/x-rpm*)
cmd=`rpm2cpio ${file_2_unpack} | cpio -dimv` ;;
*application/x-deb*)
cmd=`ar -p ${file_2_unpack} data.tar.gz | tar zx` ;;
esac
if [ "$cmd" != "" ]; then
show_message BEGIN_UNPACK ${file_2_unpack}
$cmd ${file_2_unpack}
chown -R root:root .
chmod -R u+w,go+r-w,a-s .
if [ ! $? -eq 0 ]; then
show_message SOURCE_EXTR_FAILED
rm -f "${file_2_unpack}"
exit 1
fi
fi
}
#get num for -j option
get_numjobs()
{
d_echo "get_numjobs"
if [ -z "${numjobs}" ]; then
x=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ -n "$x" ]; then
let "numjobs=x+1"
else
numjobs=2
fi
fi
}
#change curr dir to first dir in unpacked source
go_src_dir() {
if [ -d "${srcdir}" ]; then
local src_subdirs="$1"
cd "${srcdir}"
local dirs=$(ls -1 -F | grep / | sed 's/\///g' | sed q)
if [ -n "${dirs}" ]; then
cd "${dirs}"
if [ -n "${src_subdir}" -a -d "$(pwd)"/${src_subdir} ]; then
cd "$(pwd)/${src_subdir}"
fi
fi
fi
}
burn_patches() {
d_echo "burn_patchces()"
echo ""
if [ -d "$startdir"/patches -a "${RESUME}" != "1" ]; then
local curr_dir=`pwd`
cd "$startdir/patches"
local patch_list=`ls -1 *.patch *.patch.gz *.diff *.diff.gz *.patch.bz2 *.diff.bz2 *.patch.xz *.patch.xz 2>/dev/null`
cd "$curr_dir"
for file in $patch_list; do
local p=1
local minus_t="-N"
if [ -n "$patch_opts" ]; then
for patch_item in `seq 0 $((${#patch_opts[@]}-1))`; do
set ${patch_opts[patch_item]}
if [ "$file" = "$1" ]; then
local patch_file=$1
shift
while [ ! -z "$1" ]; do
case $1 in
r) d_echo "Enabling reverse patch for ${patch_file}"
minus_t="-t"
shift
;;
*) if ! [[ "$1" =~ ^[0-9]+$ ]] ; then
show_message NOT_A_NUMBER "${patch_file}"
exit 1
else
p=$1
fi
shift
;;
esac
done
fi
done
fi
echo "Using patch file ${file}"
local readfunc=cat
case ${file##*.} in
gz)
d_echo "Using gz"
readfunc=zcat
;;
z2)
d_echo "Using bz2"
readfunc=bzcat
;;
xz)
d_echo "Using xz"
readfunc=xzcat
;;
*)
d_echo "using common"
readfunc=cat
;;
esac
# Trying -p1
for p_level in $p 2 1 0 ; do
set +e
patchresult_text="$($readfunc "$startdir/patches/$file" | LC_ALL=C patch -p${p_level} -f --verbose ${minus_t} 2>&1)"
patchresult_ret=$?
err_type=$(echo "$patchresult_text" | grep 'No file to patch')
set -e
if [ "$patchresult_ret" != "0" ] ; then
if [ "$err_type" == "" ] ; then
echo -e "$patchresult_text"
echo ""
echo "Patch $file failed to apply: incorrect patch."
exit 1
else
if [ "$p_level" == "0" ] ; then
echo -e "$patchresult_text"
echo ""
echo "Failed to apply patch $file:"
exit 1
fi
fi
else
echo "Patch $file successfully applied with -p${p_level}"
break
fi
done
done
fi
echo ""
}
autobuild() {
d_echo "autobuild with ${BUILD_SYSTEM} build system"
case ${BUILD_SYSTEM} in
autotools)
MAKE_KEYS+=" -j${numjobs}"
MAKE_WORD=${MAKE_WORD:-make}
BUILD_WORD=${BUILD_WORD:-"LDFLAGS=\"$SLKLDFLAGS\" CFLAGS=\"$SLKCFLAGS\" CXXFLAGS=\"$SLKCFLAGS\" ./configure"}
BUILD_KEYS=${BUILD_KEYS:-"--prefix=/usr --libdir=/usr/lib$LIBDIRSUFFIX --mandir=/usr/man --sysconfdir=/etc"}
INSTALL_WORD=${INSTALL_WORD:-"make install"}
INSTALL_KEYS=${INSTALL_KEYS:-"DESTDIR=$pkgdir"}
if [ "$enable_distcc" = "yes" ] ; then
PATH="/usr/lib${LIBDIRSUFFIX}/distcc/bin:$PATH"
export PATH
export DISTCC_POTENTIAL_HOSTS
MAKE_KEYS=" -j${distcc_numjobs}"
d_echo "Running DISTCC mode with ${MAKE_KEYS}"
fi
;;
cmake)
mkdir -p build && cd build || exit 1
MAKE_KEYS+=" -j${numjobs}"
MAKE_WORD=${MAKE_WORD:-make}
BUILD_WORD=${BUILD_WORD:-"cmake -DCMAKE_C_FLAGS:STRING=\"$SLKCFLAGS\" -DCMAKE_CXX_FLAGS:STRING=\"$SLKCFLAGS\""}
BUILD_WORD_SUFFIX=${BUILD_WORD_SUFFIX:-".."}
INSTALL_WORD=${INSTALL_WORD:-"make install"}
INSTALL_KEYS=${INSTALL_KEYS:-"DESTDIR=\"$pkgdir\""}
if [ "$enable_distcc" = "yes" ] ; then
PATH="/usr/lib${LIBDIRSUFFIX}/distcc/bin:$PATH"
export PATH
export DISTCC_POTENTIAL_HOSTS
MAKE_KEYS=" -j${distcc_numjobs}"
d_echo "Running DISTCC mode with ${MAKE_KEYS}"
fi
;;
perl)
MAKE_KEYS=
BUILD_WORD=${BUILD_WORD:-perl}
INSTALL_WORD=${INSTALL_WORD:-"make install"}
INSTALL_KEYS+="DESTDIR=\"$pkgdir\""
;;
python)
BUILD_WORD=${BUILD_WORD:-}
MAKE_WORD=${MAKE_WORD:-}
MAKE_KEYS=
INSTALL_WORD="python setup.py install"
INSTALL_KEYS+="--root=\"$pkgdir\""
;;
qmake)
MAKE_KEYS+=" -j${numjobs}"
MAKE_WORD=${MAKE_WORD:-make}
BUILD_WORD=${BUILD_WORD:-"LDFLAGS=\"$SLKLDFLAGS\" CFLAGS=\"$SLKCFLAGS\" CXXFLAGS=\"$SLKCFLAGS\" qmake"}
INSTALL_WORD=${INSTALL_WORD:-"make install"}
INSTALL_KEYS+="INSTALL_ROOT=\"$pkgdir\""
if [ "$enable_distcc" = "yes" ] ; then
PATH="/usr/lib${LIBDIRSUFFIX}/distcc/bin:$PATH"
export PATH
export DISTCC_POTENTIAL_HOSTS
MAKE_KEYS=" -j${distcc_numjobs}"
d_echo "Running DISTCC mode with ${MAKE_KEYS}"
fi
;;
waf)
BUILD_WORD=${BUILD_WORD:-"./waf configure"}
MAKE_WORD=${MAKE_WORD:-"./waf build"}
INSTALL_WORD=${INSTALL_WORD:-"./waf install"}
INSTALL_KEYS+=" --destdir=\"${pkgdir}\""
;;
scons)
BUILD_WORD=${BUILD_WORD:-"scons"}
# BUILD_KEYS="DESTDIR=\"${pkgdir}\" ${BUILD_KEYS}"
INSTALL_WORD=${INSTALL_WORD:-"scons install"}
# INSTALL_KEYS+="DESTDIR=\"${pkgdir}\""
;;
*)
echo "hmmm... wrong build system!"
exit 1
;;
esac
eval "${BUILD_WORD} ${BUILD_KEYS} ${BUILD_WORD_SUFFIX}" || exit 1
eval "${MAKE_WORD} ${MAKE_KEYS}" || exit 1
eval "${INSTALL_WORD} ${INSTALL_KEYS}" || exit 1
}
parent_package() {
# local checked_pkgname="$1"
if [ "${p_pkgname}" == "${pkgname}" ]; then
echo 1
fi
}
strip_binaries() {
set +e
if [ "${NO_STRIP}" != "1" ]; then
d_echo "strip_binaries start"
cd "${pkgdir}"
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | \
xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | \
xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip -g 2> /dev/null
d_echo "strip_binaries end"
fi
set -e
}
set_build_options() {
CHOST=$ARCH
case ${ARCH} in
i386)
SLKCFLAGS=${SLKCFLAGS:--O2 -march=i386 -mtune=i686}
;;
i486)
SLKCFLAGS=${SLKCFLAGS:--O2 -march=i486 -mtune=i686}
;;
i686)
SLKCFLAGS=${SLKCFLAGS:--O2 -march=i686 -mtune=i686 -fomit-frame-pointer -fPIC}
;;
s390)
SLKCFLAGS=${SLKCFLAGS:--O2}
;;
x86_64)
SLKCFLAGS=${SLKCFLAGS:--O2 -fPIC}
;;
esac
export SLKCFLAGS
export CFLAGS="$SLKCFLAGS"
export SLKCXXFLAGS="$SLKCFLAGS"
export CXXFLAGS="$SLKCFLAGS"
}
set_post_permissions() {
d_echo "Setting post_permissions in ${pkgdir}"
set +e
if [ "${NO_POSTPERM}" != "1" ]; then
find "${pkgdir}" -type f -perm /o+w -exec chmod o-w {} \;
find "${pkgdir}" -type d -perm /o+w -exec chmod o-w {} \;
for DIRS in usr/share usr/doc; do
if [ -d "${pkgdir}/$DIRS" ]; then
if [ "$DIRS" == "usr/doc" -o "${DIRS}" == "usr/share/doc" ]; then
find "${pkgdir}/$DIRS" -type f -exec chmod 644 {} \;
find "${pkgdir}/$DIRS" -type d -exec chmod 755 {} \;
fi
fi
[ -d "${pkgdir}/$DIRS" ] && chown root:root -R "${pkgdir}/$DIRS"
done
fi
for DIRS in etc bin sbin usr/bin usr/sbin boot dev sys; do
if [ -d "${pkgdir}/$DIRS" ]; then
find "${pkgdir}/$DIRS" -type d -exec chmod 755 {} \;
fi
[ -d "${pkgdir}/$DIRS" ] && chown root:root -R "${pkgdir}/$DIRS"
done
[ -d "${pkgdir}/usr/bin" ] && find "${pkgdir}/usr/bin" -user root -group bin -exec chown root:root {} \;
[ -d "${pkgdir}/tmp" ] && chmod -R o+t,a+rwx "${pkgdir}/tmp"
set -e
}
gzip_man_and_info_pages() {
d_echo "gzip_man_and_info_pages()"
for DOCS in man info; do
if [ -d "${pkgdir}/usr/share/$DOCS" ]; then
mv "${pkgdir}/usr/share/$DOCS" "${pkgdir}/usr/$DOCS"
if [[ ! "$(ls ${pkgdir}/usr/share)" ]]; then
rm -rf "${pkgdir}/usr/share" 2>/dev/null
fi
fi
if [ -d "${pkgdir}/usr/$DOCS" ]; then
# I've never seen symlinks in info pages....
if [ "$DOCS" == "man" ]; then
(cd "${pkgdir}/usr/$DOCS"
for manpagedir in $(find . -type d -name "man*" 2> /dev/null) ; do
( cd $manpagedir
for eachpage in $( find . -type l -maxdepth 1 | grep -v '\.gz$' 2> /dev/null) ; do
ln -s $( readlink $eachpage ).gz $eachpage.gz
rm $eachpage
done )
done)
fi
find "${pkgdir}/usr/$DOCS" -type f -exec gzip -9 '{}' \;
fi
done
local pkginfodir="$pkgdir/usr/info"
if [ -d "$pkginfodir" ] ; then
local infolist
rm -f "$pkginfodir/dir.gz"
infolist=$(ls -1 "$pkginfodir")
if [ ! -z "$infolist" ] ; then
echo "" >> "$pkgdir/install/doinst.sh"
echo "#Install info file(s)" >> "$pkgdir/install/doinst.sh"
echo "" >> "$pkgdir/install/preremove.sh"
echo "#Remove info file(s)" >> "$pkgdir/install/preremove.sh"
for infofile in $infolist ; do
echo "install-info --quiet usr/info/$infofile usr/info/dir" >> "$pkgdir/install/doinst.sh"
echo "install-info --delete --quiet usr/info/$infofile usr/info/dir" >> "$pkgdir/install/preremove.sh"
done
fi
fi
if [ -d "$pkgdir/usr/doc/${pkgname}-${pkgver}" ]; then
if [ -z "$(ls "$pkgdir"/usr/doc/${pkgname}-${pkgver})" ]; then
rm -rf "$pkgdir"/usr/doc/${pkgname}-${pkgver} 2>/dev/null
fi
fi
if [ -d "$pkgdir/usr/doc" ]; then
if [ -z "$(ls "$pkgdir/usr/doc")" ]; then
rm -rf "$pkgdir"/usr/doc 2>/dev/null
fi
fi
}
copy_doinst() {
d_echo "copy_doinst"
if [ -e "$startdir/preremove.sh" ]; then
cp -a "$startdir/preremove.sh" "$pkgdir/install/preremove.sh"
fi
if [ -e "$startdir/postremove.sh" ]; then
cp "$startdir/postremove.sh" "$pkgdir/install/postremove.sh"
fi
case `file -b $startdir/doinst.sh*` in
gzip*)
zcat "$startdir"/doinst.sh.gz > "$pkgdir"/install/doinst.sh
chmod 755 "$pkgdir"/install/doinst.sh
;;
*ASCII*)
install -m755 "$startdir"/doinst.sh "$pkgdir"/install/doinst.sh
;;
esac
}
copy_doc() {
d_echo "copy_doc begin"
local real_src_dir="$1"
if [ -n "${real_src_dir}" ]; then
d_echo " using ${real_src_dir} as src dir"
real_src_dir+="/"
fi
go_src_dir
docs+=("AUTHORS BUGS BUILD COMPILERS COPYING* NEWS README* \
TODO ChangeLog* Changelog* CHANGELOG* LICENSE* License* HACKING")
local docdir=
if [ -d "${pkgdir}/usr/doc" -a "$(ls -1 "${pkgdir}"/usr/doc 2>/dev/null)" ]; then
docdir="${pkgdir}"/usr/doc/$(ls -1 "${pkgdir}"/usr/doc)
else
docdir="${pkgdir}/usr/doc/${pkgname}-${pkgver}"
fi
mkdir -p "$docdir"
for docfile in ${docs[@]}; do
if [ -d "${docfile}" ]; then
cp -a "${real_src_dir}${docfile}" "$docdir" 2>/dev/null
else
install -m644 "${real_src_dir}${docfile}" "${docdir}"/`basename ${docfile}` 2>/dev/null
fi
done
}
install_desktop_and_pixmap() {
d_echo "install_desktop_and_pixmap()"
if [ -d "${filedir}" ]; then
cd "${filedir}"
if [ "$(ls *.desktop 2>/dev/null)" ];then
mkdir -p "${pkgdir}/usr/share/applications/"
cp -a *.desktop "${pkgdir}/usr/share/applications/"
fi
local pic_list=$(ls -1 *.png *.xpm *.svg 2>/dev/null)
if [ -n "${pic_list}" ]; then
mkdir -p "${pkgdir}/usr/share/pixmaps/"
for file in ${pic_list}; do
cp -a ${file} "${pkgdir}/usr/share/pixmaps/"
done
fi
cd - >/dev/null
fi
}
create_package() {
d_echo "create package in ${pkgdir}"
cd "$pkgdir"
local sdescfile="/tmp/sdescfile.${RANDOM}"
local ldescfile="/tmp/ldescfile.${RANDOM}"
echo "${shortdesc}"> "${sdescfile}"
if [ -n "${longdesc}" ]; then
echo "${longdesc}"> "${ldescfile}"
else
if [ -n "${p_longdesc}" ]; then
echo "${p_longdesc}"> "${ldescfile}"
fi
fi
if [ -e "${ldescfile}" ]; then
META_OPTIONS+=" --longdesc=${ldescfile}"
fi
META_OPTIONS+=" --shortdesc=${sdescfile// /\ }"
mkdir -p "${pkgdir}/install" || exit 1
mpkg-setmeta "${pkgdir}" $META_OPTIONS || exit 1 #1530
set +e
rm -r "${ldescfile}" "${sdescfile}" 2>/dev/null
set -e
if [ "${SKIP_GENDEPS}" != "1" ]; then
if [ -n "${gendeps_blacklist}" ]; then
local black_file="${startdir}"/deps_blacklist-${RANDOM}
for i in ${gendeps_blacklist};do
echo $i >> "${black_file}"
done
local black_opts=" -E \"${black_file}\""
fi
mpkg -G -P ${black_opts} gendeps2 "${pkgdir}" || exit 1
if [ -n "${black_file}" ]; then
rm -f "${black_file}"
fi
fi
mpkg-setmeta "${pkgdir}" $DELDEP
# Add deps without duplication
local pkg_deps="$(mkpkg_xml_parser ${pkgdir}/install/data.xml -d)"
for dep in ${pkg_deps// / }; do
dep_name_str+="$(echo ${dep} | sed 's/[>=<!].*//g') "
done
ADDDEP=""
if [ -n "${adddep}" ]; then
for dep in ${adddep// / }; do
local find_deps=`echo "${dep_name_str}" | grep -w "$(echo ${dep} | sed 's/[>=<!].*//g')"`
if [ -z "${find_deps}" ]; then
ADDDEP+="--add-dep=${dep} "
fi
done
fi
mpkg-setmeta "${pkgdir}" $ADDDEP
# Configuration files import
if [ -n "${config_files}" ] ; then
local config_files_file="${startdir}/config_files-${RANDOM}"
echo "$config_files" > "$config_files_file"
mpkg-setmeta "${pkgdir}" -f "${config_files_file}"
# Now, we need to move files
for c_file in `cat ${config_files_file} | grep -v '^ *$' | sed -e 's/\([^\\]\) .*/\1/'` ; do
echo "moving ${c_file} to ${c_file}.new"
mv "${pkgdir}/${c_file}" "${pkgdir}/${c_file}.new"
done
rm "${config_files_file}"
unset config_files
fi
make_build_tree
#я сидел в двух футболках, когда писал этот код
local out_dir=
if [ "$USE_REMOTE" = "1" ]; then
out_dir="$package_out_dir"
else
out_dir="${startdir}"
fi
local package="${pkgname}-${pkgver//-/_}-${ARCH}-${pkgbuild//-/_}"
d_echo "create_package : ${out_dir}/${package}.txz"
/sbin/makepkg -l n -c n -p "${out_dir}/${package}.txz" || exit 1
echo "${out_dir}/${package}.txz" >> "${install_list}"
if [ "${SKIP_VALIDATE}" != 1 ]; then
mpkg-validate "${out_dir}/$package.txz" || exit 1
val_size=`du ${out_dir}/$package.txz.validate --apparent-size -h | cut -f1`
if [ "$val_size" = "19" ]; then
rm -f "${out_dir}/$package.txz.validate"
fi
fi
d_echo "done create package"
}
gen_meta_options(){
META_OPTIONS="--keep-symlinks --name=${pkgname} --version=${pkgver//-/_} --arch=${ARCH} --build=${pkgbuild//-/_} "
for tag in ${tags// / } ;do
if [ -n "$(echo ${tag} | grep -w 'compat32')" ]; then
continue
fi
META_OPTIONS+="--add-tag=${tag} "
done
if [ -e "$startdir"/CHANGELOG -a "$(parent_package) ${pkgname}" ]; then
META_OPTIONS+="--changelog=$startdir/CHANGELOG "
fi
if [ -n "${provides}" ]; then
META_OPTIONS+="--provides=${provides} "
fi
if [ -n "${conflicts}" ]; then
META_OPTIONS+="--conflicts=${conflicts} "
fi
META_OPTIONS+="--maintainer-name=${mn} --maintainer-email=${me} "
DELDEP=""
if [ -n "$removedep" ]; then
for rd in ${removedep// / } ; do
DELDEP+="--remove-dep=$rd "
done
fi
DELDEP+=" --remove-dep=fakeroot "
}
make_build_tree() {
d_echo "start make_build_tree for ${pkgname}"
#Creating Build Tree
if [ "$(parent_package ${pkgname})" ]; then
cd "${startdir}"
d_echo "making build tree with files in $(pwd)"
mkdir -p "${pkgdir}/usr/src/BuildTrees" || exit 1
tarfiles="files patches CHANGELOG doinst.sh doinst.sh.gz postremove.sh preremove.sh"
mkdir -p "${startdir}/files"
cp -a "${pkgdir}"/install/data.xml "$startdir"/files/data.xml || exit 1
if [ "${APPEND_DEPS}" == 1 ]; then
local _pkgdeps="$(mkpkg_xml_parser ${pkgdir}/install/data.xml -d)"
appenddeps "${_pkgdeps}"
fi
tar Jcf "${pkgdir}/usr/src/BuildTrees/${pkgname}-${pkgver//-/_}.build_tree.tar.xz" --ignore-failed-read \
--owner=root --group=root ${tarfiles} ABUILD 2>/dev/null
cd - >/dev/null
d_echo "make_build_tree end"
else
mkdir -p "${pkgdir}/usr/src/BuildTrees"
cp -a "${p_pkgdir}"/usr/src/BuildTrees/*build_tree.tar.xz "${pkgdir}"/usr/src/BuildTrees/${pkgname}-${pkgver//-/_}.build_tree.tar.xz
fi
d_echo "making_build_tree finished"
}
#append build_deps in abuild with package deps
appenddeps() {
d_echo "appenddeps()"
local checked_deps="$1"
local _new_bd=
if [ -z "$build_deps" ]; then
build_deps="${checked_deps}"
else
for bd in ${checked_deps}; do
if [ -z "$(echo ${build_deps} | grep $bd)" ]; then
build_deps+=" $bd"
fi
done
fi
if [ "$(grep ^build_deps= "${startdir}/ABUILD")" ]; then
change_builddeps "${build_deps}" "${startdir}/ABUILD"
if [ "${BT_BUILD}" != 1 -a -w "${REAL_CWD}" ]; then
change_builddeps "${build_deps}" "${REAL_CWD}/ABUILD"
fi
else
add_builddeps "${build_deps}" "${startdir}/ABUILD"
if [ "${BT_BUILD}" != 1 -a -w "${REAL_CWD}" ]; then
add_builddeps "${build_deps}" "${REAL_CWD}/ABUILD"
fi
fi
}
add_builddeps() {
local l_build_deps="$1"
local abuild_path="$2"
sed -i "0,/^tags=.*/{/^tags=.*/abuild_deps=\"${l_build_deps}\"
}" "${abuild_path}" || exit 1
}
change_builddeps() {
local l_build_deps="$1"
local abuild_path="$2"
sed -i "0,/build_deps=.*/s/build_deps=.*/build_deps=\"${l_build_deps}\"/" "${abuild_path}" || exit 1
}
build_sequence() {
local createpkg=$1
d_echo "build_sequence() with ${pkgname}"
set_custom_opts
strip_binaries
gzip_man_and_info_pages
set_post_permissions
gen_meta_options
if [ "${createpkg}" == "yes" ]; then
create_package
fi
}
process_subpackages() {
d_echo "process_subpackages(): ready to build:$1 "
local ready_to_create="$1"
for pkg in ${pkglist}; do
d_echo "processing ${pkg}"
unsetter
${pkg}
pkgdir="${startdir}/${pkgname}"
if [ "${ready_to_create}" == "yes" -a "${PARENT_ONLY}" != "1" ]; then
${pkg}_arch
if [ -n "${child_opts}" ]; then
for copt in ${child_opts}; do
case ${copt} in
inherit_parent_adddeps)
adddep+=" ${p_adddep}"
;;
esac
done
fi
build_sequence ${ready_to_create}
else
mkdir -p "${pkgdir}" || exit 1
if [ "$(grep ^${pkg}_prep\(\) "${startdir}"/ABUILD)" ]; then
${pkg}_prep
fi
fi
done
}
unsetter() {
unset provides
unset child_opts
unset adddep
unset longdesc
SKIP_VALIDATE=${CLI_SKIP_VALIDATE}
SKIP_GENDEPS=${CLI_SKIP_GENDEPS}
NO_STRIP=${CLI_NO_STRIP}
NO_POSTPERM=${CLI_NO_POSTPERM}
NO_COPYDOC=${CLI_NO_COPYDOC}
}
set_custom_opts() {
if [ -n "${custom_opts}" ]; then
for opt in ${custom_opts}; do
case $opt in
skip_validate)
SKIP_VALIDATE=${CLI_SKIP_VALIDATE:-1}
;;
skip_gendeps)
SKIP_GENDEPS=${CLI_SKIP_GENDEPS:-1}
;;
no_strip)
NO_STRIP=${CLI_NO_STRIP:-1}
;;
no_postperm)
NO_POSTPERM=${CLI_NO_POSTPERM:-1}
;;
no_ccache)
export CC="gcc"
export CXX="g++"
;;
no_copydoc)
NO_COPYDOC=${CLI_NO_COPYDOC:-1}
;;
*)
show_message UNKNOWN_CUSTOM_OPT ${opt}
;;
esac
done
fi
}
##############################################################################
#
##############################################################################
. "${startdir}/ABUILD"
set_custom_opts
get_extract_source
get_numjobs
set_build_options
set -e
if [ "${USE_CUSTOM}" == "1" -o "${build_exists}" == "1" ]; then
if [ "$(grep '^before_build\(\)' "${startdir}"/ABUILD)" ]; then
before_build
fi
build
else
go_src_dir
burn_patches
if [ "$(grep '^before_build\(\)' "${startdir}"/ABUILD)" ]; then
before_build
fi
autobuild
fi
set +e
if ! [ "${NO_COPYDOC}" == "1" ]; then
copy_doc
fi
set -e
if [ "$(grep '^after_build\(\)' "${startdir}/ABUILD")" ]; then
after_build
fi
set +e
copy_doinst
install_desktop_and_pixmap
#make_build_tree
install_list="${startdir}/install_list.${pkgname}"
rm -f "${install_list}" 2>/dev/null
#now we must process all subpackages
set -e
process_subpackages
set +e
#and now we are ready to make packages
#reread main vars (crunchy!)
unsetter
. "${startdir}/ABUILD"
pkgdir="${startdir}/${pkgname}"
if [ ! ${strict_version} ]; then
if [ "${pkgver}" != "${modif_version}" -a -n "${modif_version}" ]; then
d_echo "restoring main package version from ${pkgver} to ${modif_version}"
pkgver=${modif_version}
p_pkgver=${modif_version}
fi
fi
build_sequence "yes"
set -e
process_subpackages "yes"
set +e