-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuildpkg.packaging.solaris
1023 lines (935 loc) · 33.2 KB
/
buildpkg.packaging.solaris
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
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Function library for buildpkg framework
# It adds support for creating Solaris packages in 'sysv' format
# 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]>.
#
# Define tool programs
# *only* platform specific tools should be listed here
# generic tools go in buildpkg.functions
PKGMK=/usr/bin/pkgmk
PKGTRANS=/usr/bin/pkgtrans
# Override generic location
__strip=/usr/ccs/bin/strip
# /usr/ccs/bin/strip destroys the symbol table in static archives
# So this is disabled by default
dostrip_static=0
# Setup default args for strip. They match SGU 4.0 from Solaris 8
# Change these if you're using strip from GNU Binutils (recommended)
strip_elf_args="" # GNU default is -g
strip_shared_args="" # GNU default is --strip-unneeded
strip_static_args="" # GNU default is -g
META_CLEAN="prototype prototype.in pkginfo files.tmp depend.*.auto depend.*.all sums sums.*"
# Define defaults
# pkginfo information.
# Override as necessary.
pkgcat="application" # A reasonable default
pkgvendor="http://change/me/please"
pkgdesc="mumble mubmle... hmm someone forgot to fill this out!"
# vendor & contact information
pkgedby="Tom G. Christensen"
# Set some helper vars that describes arch and OS version
arch=`uname -p`
[ "$arch" = "sparc" ] && { vendor="sun"; sparc=1; } || { vendor="pc"; intel=1; }
os=sunos`${__uname} -r`
gnu_os_ver=$(${__uname} -r | ${__sed} -e 's/^5/2/')
# By default, the build_arch is the same as arch, alternatives are sparc64 and
# x86_64. It should be set to either when building for tgcware64.
build_arch=$arch
# Default pkginfo.in file
pkginfo=$buildpkgscripts/pkginfo.in
# Variables that control functionality
usedepend=1 # default to looking for a depend file in $metadir
usescripts=1 # default to add pre/post scripts if available
usespace=1 # default to looking for a space file in $metadir
usecompver=1 # default to add compver if available in $metadir
ignore_unpackaged_files=0 # default to check for unpackaged files in the stage area
deps_resolve_symlinks=0 # Set to 1 to resolve symlinks before computing deps (requires GNU readlink)
create_versioned_deps=1 # Set to 1 to create versioned dependencies
version_all_deps=0 # Set to 1 to add version on *all* deps, even SUNW (if enabled)
include_all_deps=1 # Set to 1 to create deps on packages regardless of vendor
# Maximum length of the PKG attribute in pkginfo(4) files
# According to pkginfo(4) this is limited to 9 characters on Solaris < 9
# and 32 characters on Solaris 9 and later.
# However more than 9 chars seems to work fine on Solaris 7 & 8.
case $os in
sunos5.[0123456]) maxpkgnamelen=9;;
*) maxpkgnamelen=32;;
esac
# To exclude a dependency, add its name to this variable
ignore_deps=""
# Solaris doesn't know how to handle any kind of compressed manpages
gzman=0
# If not using gcc then please set this to 1
suncc=0
# Try and get it right from the beginning on Solaris
_mandir=share/man
_infodir=share/info
# Default configure args
configure_args=(--prefix=$prefix --mandir=${prefix}/${_mandir} --infodir=${prefix}/${_infodir})
# Host specific configuration
[ -r $buildpkgscripts/config.`hostname`.solaris ] && . $buildpkgscripts/config.`hostname`.solaris
# Distfiles should be named like this
# <name>-<version>-<pkgver>.sb-<os>-<arch>-<pkgdirdesig>
# ie: libmad-0.14.2b-1.sb-sol5.8-sparc-local
# We hardquote it so that we can control when we want it
# evaluated (using _upls)
distfile='$secname-$version-$secver.tgc-$os-$build_arch-$pkgdirdesig'
# What pkgdef file to use
pkgdef_file=pkgdef
# Check and see if there is an arch specific pkgdef file
[ -r $metadir/pkgdef.$arch ] && pkgdef_file=pkgdef.$arch
[ -r $metadir/pkgdef.$build_arch ] && pkgdef_file=pkgdef.$build_arch
#####################################################
# "external" functions
#####################################################
# make_pkg(): Create the final package
# params: $1 = meta file suffix
#
make_pkg()
{
if [ $# -lt 1 ]; then
error $E_MISSING_ARGS make_pkg
fi
local secname=$1
local prototype=prototype.$secname
local secver=$(get_pkgrev $secname)
local dfile=$(_upls $distfile)
local pname=$(get_pkgname $secname)
echo "Creating package and transferring it to datastream format"
$PKGMK -r `pwd` -d $buildpkgbase/$pkgdir -o -f $metadir/$prototype
$PKGTRANS -o -s $buildpkgbase/$pkgdir $distdir/$dfile $pname
echo "Done. Package was created as $dfile"
}
# pack_info(): Create the pkginfo file
# params: $1 = metafile suffix
# Will create the pkginfo file with pkginfo.in as a template
# Both the template and the result will be in $metadir
# Substitutions will be done on pkgname,version,pkgver,name & topinstalldir
# they will be replaced with the value of their variable counterparts
pack_info()
{
if [ $# -lt 1 ]; then
error $E_MISSING_ARGS pack_info
fi
local secname=$1
local pstamp="$os-$(${__uname} -n)`date '+%Y%m%d%H%M'`"
# Check length of pkgname and name to make sure we're within limits
[ ${#pkgname} -gt $maxpkgnamelen ] && error $E_SVR4_PKG_OVERFLOW pack_info
[ ${#name} -gt 256 ] && error $E_SVR4_NAME_OVERFLOW pack_info
${__sed} -e "s#%%pkgname%%#$pkgname#g" \
-e "s#%%version%%#$version#g" \
-e "s#%%pkgcat%%#$pkgcat#g" \
-e "s#%%pkgvendor%%#$pkgvendor - packaged by $pkgedby#g" \
-e "s#%%pkgver%%#$pkgver#g" \
-e "s#%%name%%#$name#g" \
-e "s#%%topinstalldir%%#$topinstalldir#g" \
-e "s#%%pkgdesc%%#$pkgdesc#g" \
-e "s#%%pstamp%%#$pstamp#g" \
-e "s#%%email%%#$email#g" \
-e "s#%%maxinst%%#$maxinst#g" \
-e "s#%%arch%%#$arch#g" \
$pkginfo > $metadir/pkginfo.$secname
}
# list_pkgs(): Find all the section names of all defined pkgs
# params: none
list_pkgs()
{
local i
local it
# We can't rely on shell expansion here since we would be burned if * is empty!
for i in $(${__ls} -1 $metadir/prototype.* 2>/dev/null)
do
it=$(${__basename} $i)
echo ${it##prototype.}
done
}
# add_meta_file(): add a metafile entry to the prototype file
# params: $1 = keyword $2 = filename $3 = metafile suffix
# Additions will be done to the file $metadir/prototype
add_meta_file()
{
if [ $# -lt 3 ]; then
error $E_MISSING_ARGS add_meta_file
fi
local secname=$3
if [ -r "$2" ]; then
echo "i $1=$2" >> $metadir/prototype.$secname
else
error $E_BAD_FILE add_meta_file
fi
}
# add_scripts(): Add scripts to prototype
# params: $1 = metafile suffix
add_scripts()
{
if [ $# -lt 1 ]; then
error $E_MISSING_ARGS add_scripts
fi
local secname=$1
# If a dependency file is available then use it
if [ $usedepend -eq 1 ]; then
[ -r $metadir/depend.$secname ] && cat $metadir/depend.$secname > $metadir/depend.${secname}.all
[ -r $metadir/depend.${secname}.auto ] && cat $metadir/depend.${secname}.auto >> $metadir/depend.${secname}.all
add_meta_file depend "$metadir/depend.${secname}.all" $secname
fi
# If a compver file is available then use it
[ -r $metadir/compver.$secname -a $usecompver -eq 1 ] && add_meta_file compver "$metadir/compver.$secname" $secname
# If a space file is available then use it
[ -r $metadir/space.$secname -a $usespace -eq 1 ] && add_meta_file space "$metadir/space.$secname" $secname
if [ $usescripts -eq 1 ]; then
[ -r $metadir/preinstall.$secname ] && add_meta_file preinstall "$metadir/preinstall.$secname" $secname
[ -r $metadir/postinstall.$secname ] && add_meta_file postinstall "$metadir/postinstall.$secname" $secname
[ -r $metadir/preremove.$secname ] && add_meta_file preremove "$metadir/preremove.$secname" $secname
[ -r $metadir/postremove.$secname ] && add_meta_file postremove "$metadir/postremove.$secname" $secname
fi
}
# add_file(): add a file entry to the prototype file
# params: $1 = owner $2 = group $3 = permissions $4 = filename $5 = metafile suffix
# Additions will be done to the file $metadir/prototype
# $4 must be relative to $stagedir$prefix (or just $stagedir if using shortroot)
add_file()
{
if [ $# -lt 5 ]; then
error $E_MISSING_ARGS add_file
fi
local owner=$1
local group=$2
local perms=$3
local file=$4
local secname=$5
if [ -r "$file" ]; then
echo "f none $file $perms $owner $group" >> $metadir/prototype.$secname
else
error $E_BAD_FILE add_file
fi
}
# add_proto(): Add entries to prototype file
# params: $1 = permission $2 = owner $3 = group $4 = filespec $5 = metafile suffix
# $5 is usually the section header from pkgdef
# Additions will be done to the file $metadir/prototype.$secname
add_proto()
{
if [ $# -lt 5 ]; then
error $E_MISSING_ARGS add_proto
fi
local i
local defperm=$1
local owner=$2
local group=$3
local fspec=$(_upls $4)
local secname=$5
local FILES=$(${__find} $fspec -type f -print|${__tee} -a $metadir/files.tmp)
OIFS=$IFS
IFS="
"
for i in $FILES
do
IFS=$OIFS
if [ "$defperm" == "-" ]; then
permlist=$(${__ls} -l "$i" | ${__cut} -d " " -f 1)
perm=$(compute_octal $permlist)
else
perm=$defperm
fi
echo "f none $i $perm $owner $group" >> $metadir/prototype.$secname
done
IFS=$OIFS
# Handle symlinks
local FILES=$(${__find} $fspec -type l -print|${__tee} -a $metadir/files.tmp)
OIFS=$IFS
IFS="
"
for i in $FILES
do
IFS=$OIFS
if [ "$defperm" == "-" ]; then
permlist=$(${__ls} -l "$i" | ${__cut} -d " " -f 1)
perm=$(compute_octal $permlist)
fi
local temp=`${__ls} -l "$i"|${__cut} -d '>' -f 2`
local symval=${temp# }
echo "s none $i=$symval $perm $owner $group" >> $metadir/prototype.$secname
done
IFS=$OIFS
# Handle directories
local FILES=$(${__find} $fspec -type d -print|${__tee} -a $metadir/files.tmp)
OIFS=$IFS
IFS="
"
for i in $FILES
do
IFS=$OIFS
if [ "$defperm" == "-" ]; then
permlist=$(${__ls} -ld "$i" | ${__cut} -d " " -f 1)
perm=$(compute_octal $permlist)
else
perm=$defperm
fi
echo "d none $i $perm $owner $group" >> $metadir/prototype.$secname
done
IFS=$OIFS
# Handle hardlinks - FIXME!
}
# add_dir(): Add a single dir to prototype file
# params: $1 = perms $2 = owner $3 = group $4 = dir $5 = metafile suffix
add_dir()
{
if [ $# -lt 5 ]; then
error $E_MISSING_ARGS add_dir
fi
local defperm=$1
local owner=$2
local group=$3
local dir=$(_upls $4)
local secname=$5
if [ "$defperm" == "-" ]; then
permlist=$(${__ls} -ld "$dir" | ${__cut} -d " " -f 1)
perm=$(compute_octal $permlist)
else
perm=$defperm
fi
echo "d none $dir $perm $owner $group" >> $metadir/prototype.$secname
echo "$dir" >> $metadir/files.tmp
}
# identify_compiler(): This outputs information about the compiler
# params: $1 = { log }
# This generates the compiler information used in relnotes and logging
identify_compiler()
{
local mycc
local compiler
local compiler_temp
if [ $suncc -eq 0 ]; then
[ -n "$CC" ] && mycc=$CC || mycc=gcc
[ "$1" = "log" ] && $mycc -v
compiler="$($mycc -v 2>&1 | ${__sed} -n '/^gcc/p')"
else # not gcc
[ -n "$CC" ] && mycc=$CC || mycc=cc
[ "$1" = "log" ] && $mycc -version
compiler="$($mycc -version 2>&1)"
if [ "$CXX" = "g++" ]; then
# SUN cc with gnu g++
[ "$1" = "log" ] && $CXX -v
compiler_temp="$($CXX -v 2>&1 | ${__sed} -n '/^gcc/ s/gcc/g++/p')"
compiler="$((echo $compiler; echo $compiler_temp) | ${__awk} '{ printf "%s\\n",$0 }')"
compiler="${compiler%\\*}"
fi
fi
[ -z "$1" ] && echo "$compiler"
}
# auto_rel(): Fix up and add releasenotes to stagedir
# params: $1 = secname
# This will make some substitutions on a release note template
# and then copy the result to $stagedir/${metainstalldir}relnotes/$topdir-$version-$pkgver.txt
auto_rel()
{
local secname=$1
local i
local rn
for i in relnotes relnotes.${_os} relnotes.$secname relnotes.${_os}.$secname
do
[ -r ${metadir}/${i} ] && rn=${metadir}/$i
done
# No local relnotes use global template
if [ ! -r "${rn}" ]; then
echo "auto_rel: Using global relnotes template"
rn=$buildpkgscripts/relnotes.template.irix
fi
local relmetadir=${stagedir}${metainstalldir}relnotes/$secname-$version-$pkgver
### compute configure info for relnotes
[ -n "$ac_overrides" ] && local aco="$(for ar in $ac_overrides; do echo $ar; done | ${__awk} '{ printf "%s \\\\ \\n",$0 }')"
local fullcf="${aco}${__configure} "${configure_args[@]}""
###
local pkgnam=$(get_pkgname $secname)
local vendor=$(get_pkgvendor $secname)
local packager="${pkgedby} <${email}>"
### Compute SHA1 sums for all source entries
local s
local path
local file
local source_sha1sum
local temp_source_sha1sum=""
# older bash 2.x doesn't like C-style for loops (observed on Solaris 2.x)
#for ((snum=0; $snum < ${#source[@]}; s++))
local snum=0
while [ $snum -lt ${#source[@]} ]
do
path="$(get_source_path ${source[$snum]})"
file="$(get_source_filename ${source[$snum]})"
(cd "$path"; ${__sha1sum} "$file") >> $metadir/sums.${secname}
let snum=snum+1
done
[ -r "$metadir/sums.${secname}" ] && temp_source_sha1sum="$(cat $metadir/sums.${secname} | ${__awk} '{ printf "%s\\n",$0 }')"
source_sha1sum="${temp_source_sha1sum%\\*}"
### End of SHA1 sum computing
### Extract environtment variables
local temp_extracted_env="$(${__sed} -e 's/export /echo ENV /g' ${buildpkgbase}/${pkgdir}/build.sh | ${__bash} | ${__sed} -n 's/^ENV \([^=]*\)=.*/echo \1=$\1/p' | ${__bash} | ${__awk} '{ printf "%s\\n",$0 }')"
# Remove trailing \n
local extracted_env="${temp_extracted_env%\\*}"
###
### Add dependencies
local temp_deps="$(${__cat} $metadir/depend.$secname.all | ${__sed} -e '/^$/d;/^ /d' | ${__sort} -u | ${__sed} -e 's;\&;\\&;g' | ${__awk} '{ printf "%s\\n",$0 }')"
local deps="${temp_deps%\\*}"
###
${__mkdir} -p $relmetadir
${__gsed} -e "s;%%PKGNAME%%;${pkgnam};g" \
-e "s;%%SOURCE_AND_VER%%;${topdir}-${version};g" \
-e "s;%%CONFIGURE%%;${fullcf};g" \
-e "s;%%COMPILER%%;$(identify_compiler);g" \
-e "s;%%VENDOR%%;${vendor};g" \
-e "s;%%PKGEDBY%%;${packager};g" \
-e "s;%%SOURCE_SHA1SUM%%;${source_sha1sum};g" \
-e "s;%%ENVIRONMENT%%;${extracted_env};g" \
-e "s;%%DEPENDENCIES%%;${deps};g" \
${rn} > "$relmetadir/${secname}.txt"
# Add a ChangeLog
echo "auto_rel: Adding ChangeLog to relnotes"
echo >> "$relmetadir/${secname}.txt"
cat $metadir/ChangeLog >> "$relmetadir/${secname}.txt"
### Add the relnotes to the prototype file
add_dir $defaultperms $defaultuid $defaultgid "${metaprefix}relnotes" $secname
add_proto $defaultperms $defaultuid $defaultgid "${metaprefix}relnotes/$secname-$version-$pkgver" $secname
}
# auto_dir(): Make sure all necessary dir entries are in prototype
# param: $1 = secname
# To avoid an endless amount of dir entries in the pkgdef this
# function will try to automatically determine all the needed
# entries and then add anyone missing
auto_dir()
{
local secname=$1
local fdirs
local ddirs
local i
local j
fdirs=$(${__awk} '/^[fs]/ { print $3 }' $metadir/prototype.$secname | ${__sed} -e 's,\(.*\)=.*$,\1,' | ${__sed} -e 's,\(.*\)/.*$,\1,' | ${__sort} -u)
ddirs=$(${__awk} '/^d/ { print $3 }' $metadir/prototype.$secname | ${__sort} -u)
for i in $fdirs
do
# Ugly, but we need to strip first in the while loop to be able to
# determine exit condition properly
local path_comp="$i/dummy"
local done=0
# for each fdir we verify that all path components have dir entries
# by checking with ddirs. If one is missing it is added
while [ $done -eq 0 ]
do
# To see if we're done the string must be the same after stripping
[ "$path_comp" = "${path_comp%/*}" ] && done=1
path_comp=${path_comp%/*}
#echo "auto_dir: Checking $path_comp"
local found=0
for j in $ddirs
do
if [ "$path_comp" = "$j" ]; then
found=1
break
fi
done
if [ "$found" -eq 0 ]; then
# No match, we must add an entry
ddirs="$(echo $ddirs $path_comp)"
### FIXME defaultperms, defaultuid and defaultgid as essentially uninitialized here!
add_dir $defaultperms $defaultuid $defaultgid "$path_comp" $secname # Add dir entry
echo "auto_dir: Adding $path_comp for $secname"
fi
done
done
}
# dep_pkg_name: Given a filename it will look it up and find the PKGNAME
# Params: A list of filenames
# For each file we use pkgchk -l -p to find the package containing it
dep_pkg_name()
{
local pkg
local i
while read files
do
for i in $files
do
[ -L "$i" -a $deps_resolve_symlinks -eq 1 ] && i=$(${__readlink} -f "$i")
pkg=$(pkgchk -l -p $i | ${__awk} '/^\t/ { print $1 }')
if [ -n "$pkg" -a $(echo $pkg | wc -l) -eq 1 ]; then
#echo "Found $i in $pkg" >> /tmp/depdebug
echo "$pkg"
else
echo "dep_pkg_name: $i returned more than one package" >> /tmp/depdebug
fi
done
done
}
# extract_deps(): Given a section name it will extract the dependencies
# params: $1 = section name (like libiconv)
# It goes through the prototype.$1 file and computes the dependencies
# for all files and returns the PKGINST attribute
extract_deps()
{
local secname=$1
# Can't use setdir since it has output
cd ${stagedir}${topinstalldir}
# Grab the filelist and classify files
local filelist=$(${__awk} '{ print $3 }' $metadir/prototype.$secname | ${__grep} '.')
local exelist=$(echo $filelist | ${__xargs} ${__file} | ${__egrep} -v ":.* (commands|script)" | ${__grep} -v "ar archive" | ${__grep} ":.*executable" | ${__cut} -d: -f1)
local scriptlist=$(echo $filelist | ${__xargs} ${__file} | ${__egrep} ":.* (commands|script)" | ${__cut} -d: -f1)
local liblist=$(echo $filelist | ${__xargs} ${__file} | ${__grep} -v "ar archive" | ${__grep} ":.*dynamic lib" | ${__cut} -d: -f1)
# Compute dependencies for executables
if [ -n "$exelist" ]; then
for f in $exelist; do
[ -r $f -a -x $f ] || continue
# Generic Solaris ldd
${__ldd} $f | ${__grep} -v 'not found' | ${__awk} '/\=/ { print $3 }'
done | ${__sort} -u | dep_pkg_name | ${__sort} -u
fi
# Compute dependencies for dynamic libraries
if [ -n "$liblist" ]; then
for f in $liblist; do
[ -r $f ] || continue
# Generic Solaris ldd
${__ldd} $f | ${__grep} -v 'not found' | ${__awk} '/\=/ { print $3 }'
done | ${__sort} -u | dep_pkg_name | ${__sort} -u
fi
# Compute dependencies for scripts
if [ -n "$scriptlist" ]; then
for f in $scriptlist; do
[ -r $f -a -x $f ] || continue
interp="$(${__head} -n 1 $f | ${__cut} -d\! -f2- | ${__sed} -e 's/ -.*//')"
if [ -L "$interp" ]; then
echo $(${__file} -h "$interp" | ${__sed} -e 's/.* to //')
else
if [ "$(echo $interp | ${__cut} -d' ' -f1)" = "/usr/bin/env" ]; then
echo "/usr/bin/env"
else
echo $interp
fi
fi
done | ${__sort} -u | dep_pkg_name | ${__sort} -u
fi
}
# auto_deps(): Compute dependencies
# params: $1 = section name $2 = pkgname
# It will call extract_deps() to get the packagenames of the
# dependencies. The dependencies will be added to $metadir/depend.$1.auto
auto_deps()
{
local j
local deps
local i
local ignore
local secname=$1
local pkgname=$(get_pkgname $secname)
local temp
local depend_file=depend
# Check and see if there is an arch specific depend file
[ -r $metadir/depend.$arch ] && depend_file=depend.$arch
[ -r $metadir/depend.$build_arch ] && depend_file=depend.$build_arch
deps="$(extract_deps $secname | ${__sort} -u)"
# We need to sort out any packages created from the same build
# Internal deps *must* be recorded in a depend file instead
for j in $(list_pkgs)
do
temp=$(get_pkgname $j)
deps=$(echo $deps | ${__sed} -e "s/$temp//")
done
# Parse any speciel depends
# We don't do ignore_deps processing for these deps
if [ -r $metadir/$depend_file ]; then
local extra_pkgname # Package that should have the depend
local extra_dep_pkgname # The name of depend (either a pkgname or a secname)
local extra_dep_version # version of the depend (or auto keyword)
${__sed} -n "/^$pkgname /p" $metadir/$depend_file |
while read extra_pkgname extra_dep_pkgname extra_dep_version
do
local internal_dep=0
for i in $(list_pkgs)
do
[ "$extra_dep_pkgname" = "$i" ] && internal_dep=1
done
if [ $internal_dep -eq 1 ]; then
echo "P $(get_pkgname $extra_dep_pkgname) $(get_pkgdesc $extra_dep_pkgname)"
else
echo "P $extra_dep_pkgname $(pkgparam $extra_dep_pkgname NAME)"
fi
if [ $create_versioned_deps -eq 1 ]; then
# create versioned_deps
if [ "$extra_dep_version" = "auto" ]; then
if [ $internal_dep -eq 1 ]; then
extra_dep_version="$(get_pkgversion $extra_dep_pkgname)"
extra_dep_pkgname=$(get_pkgname $extra_dep_pkgname) # For later use we can now resolve this permanently
else
extra_dep_version="$(pkgparam $extra_dep_pkgname VERSION)"
fi
fi
# Only for deps with $pkgprefix?
if [ $version_all_deps -eq 0 ]; then
[ -n "$(echo $extra_dep_pkgname | ${__grep} $pkgprefix)" ] && echo -e "\t($arch) $extra_dep_version"
else
echo -e "\t($arch) $extra_dep_version"
fi
fi
done > $metadir/depend.$secname.auto
fi
if [ $include_all_deps -eq 0 ]; then
deps=$(echo $deps | sed -n "/$pkgprefix/p")
fi
for j in $deps
do
ignore=0
for i in $ignore_deps
do
# if there's a match then set ignore flag and break the loop
[ "$i" = "$j" ] && ignore=1 && break
done
[ $ignore -eq 0 ] && echo "P $j $(pkgparam $j NAME)"
if [ $ignore -eq 0 -a $create_versioned_deps -eq 1 ]; then
# create versioned_deps
# Only for deps with $pkgprefix?
if [ $version_all_deps -eq 0 ]; then
[ -n "$(echo $j | ${__grep} $pkgprefix)" ] && echo -e "\t($arch) $(pkgparam $j VERSION)"
else
echo -e "\t($arch) $(pkgparam $j VERSION)"
fi
fi
done >> $metadir/depend.$secname.auto
}
# parse_pkgdef(): Read in $metadir/$pkgdef_file
# params: none
# This will parse the package descriptions in
# pkgdef that tells us how many packages there
# should be and what they include.
parse_def()
{
local section=0
local foundfiles=0
local secname=""
local secpos=0
local legalend=0
local hasaddedpkginfo=0
local condexpr=""
while read line
do
case ${line:0:1} in
'#') ;;
'[')
if [ $section -eq 1 ]; then
error $E_BAD_SECTION_BEGIN parse_def
else
section=1
secname="${line:1:((${#line}-2))}"
legalend=0
# Set default value for maxinst for the new section
maxinst=1
fi
;;
'')
if [ $section -eq 0 ]; then
error $E_BAD_SECTION_END parse_def
else
section=0 # Finished this section
foundfiles=0 #
legalend=1 # We encountered a syntacticly correct section end
hasaddedpkginfo=0
fi
;;
*)
equalindex=$(${__expr} index "$line" =)
if [ ! $equalindex -eq 0 ]; then
case "${line:0:(($equalindex-1))}" in
'pkgname')
pkgname="$(_upls ${line:$equalindex:${#line}})"
;;
'name')
name="$(_upls ${line:$equalindex:${#line}})"
;;
'pkgcat')
pkgcat="$(_upls ${line:$equalindex:${#line}})"
;;
'pkgvendor')
pkgvendor="$(_upls ${line:$equalindex:${#line}})"
;;
'pkgdesc'|'shortdesc')
pkgdesc="$(_upls ${line:$equalindex:${#line}})"
;;
'pkgver')
pkgver="$(_upls ${line:$equalindex:${#line}})"
;;
'maxinst')
maxinst="$(_upls ${line:$equalindex:${#line}})"
;;
esac
else # Perhaps we hit 'files'?
if [ "${line:0:5}" == "files" ]; then
triplet="${line:6:((${#line}-5-2))}"
defaultperms=$(echo $triplet | ${__awk} -F, '{ print $1 }')
defaultuid=$(echo $triplet | ${__awk} -F, '{ print $2 }')
defaultgid=$(echo $triplet | ${__awk} -F, '{ print $3 }')
foundfiles=1
if [ $hasaddedpkginfo -eq 0 ]; then
# start a new package
pack_info $secname # Create pkginfo
# Start the prototype file by adding the pkginfo file
add_meta_file pkginfo "$metadir/pkginfo.$secname" $secname
hasaddedpkginfo=1
fi
else
if [ $foundfiles -eq 1 ]; then # We already found the 'files' line so this must be the filelist
if [ "${line:0:4}" == "dir " ]; then
add_dir $defaultperms $defaultuid $defaultgid "${line:4}" $secname # Add dir entry
elif [ "${line:0:3}" = "if(" ]; then
# Conditional expression
condexpr=${line#if(}
condexpr=${condexpr%%)*}
if [ "x${!condexpr}" != "x" ]; then
# value of condexpr was defined so we should process the line as normal
add_proto $defaultperms $defaultuid $defaultgid "${line#if(*)}" $secname
fi
elif [ "${line:0:12}" = "default_docs" ]; then
add_proto $defaultperms $defaultuid $defaultgid "${line:12}${metaprefix}${_docdir}/${secname}-${version}" $secname # Add std. doc location
else
add_proto $defaultperms $defaultuid $defaultgid "$line" $secname # Build protype file from filespec
fi
fi
fi
fi
;;
esac
done < $metadir/$pkgdef_file
# If there is no blank line at the end of a pkgdef section (if there is only one section that is very
# likely) then we end up here without having executed the 'section end' actions (case '' above)
if [ $legalend -eq 0 ]; then
if [ $section -eq 0 ]; then
error $E_BAD_SECTION_END parse_def
else
section=0 # Finished this section
foundfiles=0 #
fi
fi
}
# check_unpackaged(): Check if there are unpackaged files in the stage area
# params: none
check_unpackaged()
{
local upf
local i
local indent4=" "
${__find} . -type f -print|${__sed} -e 's/\.\///g' > $tmpdir/files.tmp
${__find} . -type l -print|${__sed} -e 's/\.\///g' >> $tmpdir/files.tmp
${__find} . -type d -print|${__sed} -e 's/\.\///g'|${__grep} -v '^\.' >> $tmpdir/files.tmp
${__sort} $metadir/files.tmp|${__uniq} > $tmpdir/f1
${__sort} $tmpdir/files.tmp > $tmpdir/f2
upf="$(${__cat} $tmpdir/f1 $tmpdir/f2 | ${__sort} | ${__sed} -e '/^relnotes/d' | ${__uniq} -u)"
if [ ! -z "$upf" ]; then
echo "There are unpackaged files in the stagedir:"
for i in $upf
do
echo "${indent4}${i}"
done
${__rm} -f $tmpdir/f1 $tmpdir/f2
if [ "$ignore_unpackaged_files" -eq 0 ]; then
error $E_UNPACKAGED_FILES check_unpackaged
fi
fi
${__rm} -f $tmpdir/f1 $tmpdir/f2
}
# get_pkgname(): Extract pkgname (PKG) from a pkginfo file
# params: $1 = metafile suffix
get_pkgname()
{
local secname=$1
if [ -r $metadir/pkginfo.$secname ]; then
local pn=$(${__grep} PKG $metadir/pkginfo.$secname)
local pname=$(_upls ${pn##PKG=})
echo $pname
fi
}
# get_pkgrev(): Extract pkgrev (REV part of VERSION field) from pkginfo file
# params: $1 = metafile suffix
get_pkgrev()
{
local secname=$1
local verfield="$(${__grep} VERSION $metadir/pkginfo.$secname|${__sed} -e 's/"//g')"
local secver=$(_upls ${verfield#*REV=})
echo $secver
}
# get_pkgversion(): Extract pkgversion (VERSION field) from pkginfo file
# params: $1 = metafile suffix
get_pkgversion()
{
local secname=$1
local verfield="$(${__grep} VERSION $metadir/pkginfo.$secname|${__sed} -e 's/"//g')"
local secver=$(_upls ${verfield##VERSION=})
echo $secver
}
# get_pkgdesc(): Extract pkgdesc from a pkginfo file
# params: $1 = metafile suffix
get_pkgdesc()
{
local secname=$1
if [ -r $metadir/pkginfo.$secname ]; then
local pd=$(${__grep} NAME $metadir/pkginfo.$secname)
local pdesc=$(_upls ${pd##NAME=})
echo $pdesc
fi
}
# get_pkgvendor(): Extract upstram vendor information from a pkginfo file
# params: $1 = metafile suffix
get_pkgvendor()
{
local secname=$1
if [ -r $metadir/pkginfo.$secname ]; then
local pv=$(${__sed} -n 's/VENDOR=\(.*\) - .*/\1/p' $metadir/pkginfo.$secname | ${__tr} -d '"')
echo $(_upls $pv)
fi
}
# compat(): Add a series of entries to a compver file
# params: $1 = secname $2 = version $3 = startrev $4 = endrev
compat()
{
local secname=$1
local compat_version=$2
local startrev=$3
local endrev=$4
local i
while [ $startrev -le $endrev ]
do
echo "$compat_version,REV=$startrev" >> $metadir/compver.${secname}
let "startrev=startrev+1"
done
}
# docs_for(): Add files from srcdir to specific package doc dir
# params: $1 = secname $2....x = files to copy
# Copies files from $srcdir to $_docdir/$secname-$version
docs_for()
{
local secname=$1
shift
local f
local ddir # Holds internal value of _docdir
if [ ! -z $# ]; then
setdir source
ddir=${stagedir}${prefix}/${_docdir}/${secname}-${version}
${__mkdir} -p $ddir
echo "Adding docs"
until [ -z "$1" ]
do
for f in $(_upls $1)
do
(${__tar} -cf - "$f")|(cd $ddir; ${__tar} -xvBpf -)
done
shift
done
fi
}
# do_strip_bin(): Strip binaries
# params: none
do_strip_bin()
{
echo "Stripping ELF binaries..."
for f in `${__find} . -type f \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -exec ${__file} {} \; | \
${__grep} -v ' dynamic lib ' | \
${__sed} -n -e 's/^\(.*\):[ ]*ELF.*, not stripped.*/\1/p'`; do
${__strip} $strip_elf_args $f || :
done
}
# do_strip_shared(): Strip shared libraries
# params: none
do_strip_shared()
{
echo "Stripping ELF shared objects..."
# Strip ELF shared objects (see brp-strip-shared from RPM)
# Please note we don't restrict our search to executable files because
# our libraries are not (should not be, at least) +x.
for f in `${__find} . -type f -a -exec ${__file} {} \; | \
grep ' dynamic lib ' | \
${__sed} -n -e 's/^\(.*\):[ ]*ELF.*, not stripped/\1/p'`; do
${__strip} $strip_shared_args $f
done
}
# do_strip_static(): Strip static archives
# params: none
do_strip_static()
{
echo "Stripping static archives..."
# Strip static libraries. (see brp-strip-static-archive from RPM)
for f in `${__find} . -type f -a -exec ${__file} {} \; | \
${__grep} 'current ar archive' | \
${__sed} -n -e 's/^\(.*\):[ ]*current ar archive,.*/\1/p'`; do
${__strip} $strip_static_args $f
done
}
#####################################################
# Define generic functions for different build stages
#####################################################
# generic_pack(): Build package using files from 'install' stage
# params: none
# We expect generic_install to have made $stagedir the "root" dir
# in that all paths below will be complete (ie. /usr/local/bin and not
# just bin) *unless* shortroot=1.
generic_pack()
{
if [ "$1" == "shortroot" ]; then
error $E_ARG_OBSO generic_pack
fi
# Before doing any expensive operations
# check that the ChangeLog is in order
check_changelog
clean meta
if [ -d "${stagedir}${topinstalldir}${dir_prefix}/${_mandir}" ]; then
setdir ${stagedir}${topinstalldir}${dir_prefix}/${_mandir}
[ "$catman" -eq 1 ] && fix_man
[ "$gzman" -eq 1 ] && compress_man
fi
if [ -d "${stagedir}${topinstalldir}${dir_prefix}/${_infodir}" ]; then
setdir ${stagedir}${topinstalldir}${dir_prefix}/${_infodir}
[ "$gzinfo" -eq 1 ] && compress_info
fi
# pkgdef entries should always be relative to topinstalldir
# except for the auto ones - src,dist,relnotes
# In that case we use metaprefix to designate their position relative
# to topinstalldir (note metainstalldir can never be above topinstalldir)
# ie. topinstalldir=/usr/local/gcc & metainstalldir=/usr/local is a no no.
# but topinstalldir=/usr/local & metainstalldir=/usr/local is okay and is the
# default
# This mostly matters when we have topinstalldir=/ and prefix=/usr/local like
# with prngd and openssh
# Also note that metaprefix is entirely for internal use in create_idb when
# we create the "auto" entries.
# Determine at what level metainstalldir is compared to topinstalldir
metaprefix=${metainstalldir##$topinstalldir}
metaprefix="${metaprefix#/*}"
# If we have a path then we'll need a / appended
[ ! -z "$metaprefix" ] && metaprefix="${metaprefix}/"
# We need to add slash to the end of metainstalldir but *only* if
# metainstalldir is not /. We do this to avoid creating an absolute path