-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuildpkg.packaging.irix
1359 lines (1263 loc) · 41.8 KB
/
buildpkg.packaging.irix
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 Irix packages in 'inst' 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 packaging tools should be listed here
# generic tools go in buildpkg.functions
GENDIST="/usr/sbin/gendist"
GENDIST_OPTS="-nostrip"
SHOWPRODS="/usr/sbin/showprods"
SHOWFILES="/usr/sbin/showfiles"
# This is the hostname command we'll want on Irix
HOSTNAME=/usr/bsd/hostname
# Configuration vars
imageconf=$buildpkgscripts/image.conf
subsysconf=$buildpkgscripts/subsys.conf
idbfile=$metadir/$topdir.idb
specfile=$metadir/$topdir.spec
depends=$metadir/depends
replaces=$metadir/replaces
updates=$metadir/updates
opsfile=$metadir/ops
hidefile=$metadir/hide
showfilescache=/tmp/sf.cache
# Preformat manpages since Irix is not likely to have nroff available
symlinkman=1 # resolve .so links or formatting/compressing will fail
catman=1
# Compress manpages
gzman=1
compressman=0
# strip?
dostrip=1
dostrip_static=0 # Atleast std. Irix strip seems to mangle archives if strip -f is used
# Setup default args for strip. They match /usr/bin/strip in Irix 6.2
# For 5.3 you must have the new linker from patchSG0001068 otherwise
# -f is undocumented and renders DSOs unlinkable.
# Change these if you're using strip from GNU Binutils (*not* recommended)
strip_elf_args="" # GNU default is -g
strip_shared_args="-f" # GNU default is -g
strip_static_args="-f" # GNU default is -g
# Other
usedepend=1 # Don't use depend file even if it's available
usescripts=1 # Don't add ops even if they're available
useupdates=1 # Enable/disable the use of an updates file if available
ignore_unpackaged_files=0 # default to check for unpackaged files in the stage area
include_source=0 # Include source[x] in the opt.src subsystem and not just patch[x]
useautodir=1 # Enable or disable the auto_dir run
# vendor & contact information to be added in relnotes
pkgedby="Tom G. Christensen"
email="[email protected]"
# ver_width controls the width of the pkgversion numbers created
# do *not* change this blindly
# inst uses an INT value for the version number which can atmost be
# 2,147,483,647 that means it's not safe to extend the version number
# beyond 9 digits. With 10 digits a version starting with 22.xxxx will overflow
# the INT and crash inst.
ver_width=9
# Some versioning causes trouble with the normal version transformation (like 2.8->2.10)
# which ends up as 210 (2.10) < 280 (2.8) which is wrong
# This control will turn on zero prefixing of single digit version components in a version string
# so that 0210 (2.10) > 0208 (2.8).
# The default is on but be aware that it can also give problems with version transformation (like 2.08->2.1)
# which ends up as 0208 (2.08) > 0201 (2.1).
useextendedver=1
# Use run_configure
generic_configure=0
# Check config.log for nono libs
check_ac=1
configlog=config.log # override as necessary
# If you need to override any autoconf values put them in this string
# ie. ac_cv_lib_sun_mntent=no etc.
ac_overrides=""
# Run this command for the configure stage
__configure="./configure"
# When using autodeps sometimes we get undesired dependencies
# add them to this var to have them filtered out
ignore_deps=""
# When matching dependencies with packages should we resolve
# symlinks before looking in the showfilescache?
# Requires readlink from GNU coreutils.
deps_resolve_symlinks=0
# If not using gcc then please set this to 1½
mipspro=0
# Comment these declarations to get it to run with ksh
declare -a pc # Array of product categories (image.subsys)
declare -a pd # Array of matching descriptions
declare -a ps # Array of subsystem properties - default or nodefault
declare -a pctop # Array of toplevel product categories (image)
declare -a pdtop # Array of matching descriptions
declare -a reqs # Array of subsystems with prereqs
declare -a reqp # Array of prereqs (should match up with reqs)
declare -a replacess # Array of subsystems that replaces another
declare -a replacepkg # Array of what is replaced (should match up with replacess)
declare -a updates # Array of subsystems that updates another
declare -a updatepkg # Array of what is updated (should match up with updatess)
declare -a hide # Files that should be "hidden" with nohist
declare -a opfiles # Files that should have an ops associated
declare -a opscript # Ops to associate with opfiles
#override defaults
pkgprefix=tgc_
pkgname=$pkgprefix$topdir
os=irix`${__uname} -r`
_os=$(${__uname} -sr|${__sed} -e 's/ //g' -e 's/\.//g' -e 's/IRIX64/IRIX/g'|${__tr} '[A-Z]' '[a-z]')
cpu=mips3
configure_args=(--prefix=$prefix --mandir=${prefix}/${_mandir} --infodir=${prefix}/${_infodir})
META_CLEAN="$topdir.spec $topdir.idb files.tmp ${depends##*/}_auto ${depends##*/}_all sums"
# Host specific configuration
[ -r $buildpkgscripts/config.$($HOSTNAME -s).irix ] && . $buildpkgscripts/config.$($HOSTNAME -s).irix
distfile='$topdir-$version-$pkgver.tgc-$os-$cpu-$pkgdirdesig.tardist'
#####################################################
# Internal helper functions
#####################################################
indent4=" "
indent8=" "
indent12=" "
indent16=" "
indent24=" "
# fix_ver(): "normalize" a version-pkgver pair
# params: $1=version
# Removes any '.' and '-' characters from a version string
# It also extends the width to $ver_width by moving the package revision
# to the far right and padding with zeroes inbetween.
fix_ver()
{
local numpad
local extendedwidth
local extendedver=""
local i
local version=$1
local rev=${version##*-}
local ver=$(echo ${version%%-*} | ${__sed} -e 's/-//g' -e 's/[a-zA-Z]//g')
if [ $useextendedver -eq 1 ]; then
### experimental
### zero prefixes all single digits in a versionstring
OIFS=$IFS
IFS=".
"
for i in $ver
do
if [ ${#i} -eq 1 ]; then
extendedver=${extendedver}0${i}
else
extendedver=${extendedver}${i}
fi
done
ver=$extendedver
fi
if [ $useextendedver -eq 0 ]; then
# Remove the dots
ver=$(echo $ver | ${__sed} -e 's/\.//g')
fi
let "numpad = $ver_width - ${#ver} - ${#rev}"
[ $numpad -lt 0 ] && error $E_BAD_VERSION fix_ver
while [ $numpad -gt 0 ]
do
ver="${ver}0"
let "numpad = $numpad - 1"
done
ver="${ver}${rev}"
echo $ver
}
# spec_header()
# param: $1=product name $2=description
spec_header()
{
echo "product $1"
echo "$indent4 id \"$2\""
}
spec_footer()
{
echo "endproduct"
}
# spec_img_header()
# param: $1=image name $2=image description $3=version
spec_img_header()
{
local nver=$(fix_ver $3)
echo "$indent4 image $1"
echo "$indent8 id \"$2\""
echo "$indent8 version $nver"
echo "$indent8 order 9999"
}
# spec_img_footer()
spec_img_footer()
{
echo "$indent4 endimage"
}
# spec_subsys_header()
# param: $1=image $2=subsys $3=description $4=subsys property
spec_subsys_header()
{
echo "$indent8 subsys $2 $4"
echo "$indent12 id \"$3\""
echo "$indent12 exp $pkgname.$1.$2"
}
# spec_subsys_req_header()
# param: none
spec_subsys_req_header()
{
echo "$indent16 prereq ("
}
# spec_subsys_req()
# param: $1=prereq
spec_subsys_req()
{
echo "$indent24 $1"
}
# spec_subsys_req_footer()
# param: none
spec_subsys_req_footer()
{
echo "$indent24"")"
}
# spec_subsys_replaces()
# param: $1 = subsystem that is replaced
spec_subsys_replaces()
{
echo "$indent12 replaces $1"
}
# spec_subsys_updates()
# param: $1 = subsystem that is updated
spec_subsys_updates()
{
echo "$indent12 updates $1"
}
# spec_subsys_footer()
# param: none
spec_subsys_footer()
{
echo "$indent8 endsubsys"
}
# check_ops(): Is there an opscript associated with $1
# param: $1=file to check
check_ops()
{
local file="$1"
local return=""
if [ "$usescripts" -eq 0 ]; then
echo $return
fi
#echo "file is $file" >> /tmp/debug
for ((i=0; $i < ${#opfiles[@]}; i++))
do
#echo "opfiles $i is ${opfiles[$i]}" >> /tmp/debug
if [ "${opfiles[$i]}" == "$file" ]; then
return="${opscript[$i]}"
fi
done
echo $return
}
# fix_fname(): Sanitize filename
# param: $1=filename to fix
# The purpose is to "fix" filenames that gendist won't like
# ie. names with space are a no-no.
fix_fname()
{
local name="$1"
local return
# Replace ' ' with '_'
return=$(echo $name|${__sed} -e 's/ /_/g')
echo $return
}
# add_files()
# Create IDB entries for all files in a specfic product category
# Takes the following parameters
# $1 = dirname to descend into
# $2 = product_category to assign files
# $3 = permissions to set on the files we find
# $4 = user
# $5 = group
# $6 = special attribute
add_files()
{
local fspec=$(_upls $1)
local prodcat=$2
local defperm=$3
local owner=$4
local group=$5
local specattr=$6
local slash=''
local topinstd=${topinstalldir:1}
[ ! "$topinstalldir" == "/" ] && slash='/' #="${topinstalldir}/"
# This is a workaround
# Sometimes $topinstalldir:1 returns garbage when topinstalldir=/
[ "$topinstalldir" = "/" ] && topinstd=""
local FILES=$(${__find} $fspec -type f -print|${__tee} -a $metadir/files.tmp)
OIFS=$IFS # We play IFS tricks so we can handle filenames with embedded spaces
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
doop=$(check_ops "$i")
fname=$(fix_fname "$i")
if [ ! -z "$doop" ]; then
if [ ! -z "$specattr" ]; then
specattr="$specattr $doop"
else
specattr=$doop
fi
fi
if [ ! -z "$specattr" ]; then
echo "f $perm $owner $group ${topinstd}${slash}$fname $i ${pkgname}.${prodcat} $specattr" >>$idbfile
else
echo "f $perm $owner $group ${topinstd}${slash}$fname $i ${pkgname}.${prodcat}" >>$idbfile
fi
specattr="" # If there's more than one file we must reset specattr to avoid polluting the next entries
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)
else
perm=$defperm
fi
local temp=`${__ls} -l "$i"|${__cut} -d '>' -f 2`
local symval=${temp# }
fname=$(fix_fname "$i")
echo "l $perm $owner $group ${topinstd}${slash}$fname $i ${pkgname}.${prodcat} symval($symval)" >>$idbfile
done
IFS=$OIFS
}
# add_dir(): Add a single dir entry to the IDB file
# params: $1=dir $2=subsys $3=default permissons $4=defuid $5=defgid
# Currently ops and specattr are unimplemented for dirs
add_dir()
{
local fspec=$(_upls $1)
local prodcat=$2
local defperm=$3
local owner=$4
local group=$5
local topinstd="$topinstalldir"
#[ ! "$topinstalldir" == "/" ] && topinstalldir="${topinstalldir}/"
[ ! "$topinstd" = "/" ] && topinstd="${topinstd:1}/"
# This is a workaround
# Sometimes $topinstalldir:1 returns garbage when topinstalldir=/
[ "$topinstd" = "/" ] && topinstd=""
# Note that dir blablah is *not* added to $metadir/files.tmp
#local FILES=$(${__find} $fspec -type d -print)
local FILES=$fspec
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
fname=$(fix_fname "$i")
echo "d $perm $owner $group ${topinstd}$fname $i ${pkgname}.${prodcat}" >>$idbfile
done
IFS=$OIFS
}
# fetch_imageconf(): Fetch a list of toplevel image entries with descriptions
# params: none
# Discard the ones that we don't have any subsystems for
fetch_imageconf()
{
local pctopidx=0
local numloops=${#pc[@]}
local i=0
while read image desc
do
for ((i=0; i < $numloops; i++))
do
temp="${pc[$i]%%.*}"
if [ "$image" == "$temp" ]; then
pctop[$pctopidx]=$image
pdtop[$pctopidx]=$desc
let "pctopidx = $pctopidx + 1"
break # We found a match no need to loop further
fi
done
done < $imageconf
}
# fetch_subsysdesc(): Fetch a list of subsystem descriptions
# params: none
fetch_subsysdesc()
{
local i=0
local numloops=${#pc[@]}
local ss
local sp
local desc
while read ss sp desc
do
for ((i=0; i < $numloops; i++)) # Find subsystem...
do
if [ "${pc[$i]}" = "$ss" ]; then
pd[$i]="$desc"
if [ "$sp" == "nodefault" ]; then
ps[$i]=""
else
ps[$i]=$sp
fi
break # Found it, skip to the next line
fi
done
done < $subsysconf
}
# fetch_depends(): Fetch a list of subsystems and their prereqs
# params: none
#
fetch_depends()
{
local reqidx=0
local havedep=0
[ -r ${depends} ] && ${__cat} ${depends} > ${depends}_all
[ -r ${depends}_auto ] && ${__cat} ${depends}_auto >> ${depends}_all
# Are there any deps we should ignore?
if [ -n "$ignore_deps" ]; then
local j
local cmd
for j in $ignore_deps
do
cmd="$(echo $j | ${__sed} -e 's;\.;\\\.;g')"
${__gsed} -i "/$cmd/d" ${depends}_all
done
fi
if [ -r ${depends}_all ]; then
while read ss reqpkg reqvers
do
havedep=0
if [ "$reqvers" == "auto" ]; then # auto create depend on $reqpkg
# Check if it's an internal depend
# There's no real safe way to check but we will assume
# That if there's only a single . in the $reqpkg then it's internal
local deplen=$((${#reqpkg}-1)) # String length -1 (a single dot)
# Now if $deplen is longer than the same string with all dots removed
# then we know there was more than one dot and we can assume it's
# not an internal depend
if [ $deplen -gt "$(/bin/echo -n "$reqpkg" | ${__tr} -d '.' | wc -c)" ]; then
# External depend
# Grab version
nver="$($SHOWPRODS -n $reqpkg | ${__grep} $reqpkg | ${__awk} '{ print $3 }')"
req="$reqpkg $nver maxint"
havedep=1
else
nver=$(fix_ver "$version-$pkgver")
req="$pkgname.$reqpkg $nver $nver"
havedep=1
fi
else
# When rebuilding a package we want to avoid the autodeps
# from adding deps on the already installed parts.
# Internal deps must be handled in depends with the auto keyword
# or chaos will ensue.
# We will try to check if the package name in the autodep matches the
# package we're building
if [ ! "${reqpkg%%.*}" == "$pkgname" ]; then
req="$reqpkg $reqvers"
havedep=1
else
echo "skipping depend: $ss $reqpkg $reqvers"
fi
fi
# Only increment and update arrays if we actually add the dep
if [ $havedep -gt 0 ]; then
reqs[$reqidx]=$ss
reqp[$reqidx]=$req
let "reqidx = $reqidx + 1"
fi
done < ${depends}_all
fi
}
# fetch_replaces(): Fetch information about subsystem replacements
# params: none
#
fetch_replaces()
{
local reqidx=0
if [ -r ${replaces} ]; then
while read ss replpkg reqvers
do
if [ "$reqvers" == "auto" ]; then
reqvers="0 maxint" # Replace all versions of a subsystem
fi
replacess[$reqidx]=$ss
replacepkg[$reqidx]="$replpkg $reqvers"
let "reqidx = $reqidx + 1"
done < ${replaces}
fi
}
# fetch_updates(): Fetch information about subsystem updates
# params: none
#
fetch_updates()
{
local reqidx=0
if [ -r ${updates} ]; then
while read ss updpkg reqvers
do
if [ "$reqvers" == "auto" ]; then
reqvers="0 maxint" # Update all versions of a subsystem
fi
updatess[$reqidx]=$ss
updatepkg[$reqidx]="$updpkg $reqvers"
let "reqidx = $reqidx + 1"
done < ${updates}
fi
}
# fetch_ops(): Fetch ops
# params: none
# Populates the firstop and lastop variables
# and the opfiles and opscript arrays
fetch_ops()
{
if [ -r $opsfile ]; then
opsidx=0
while read optype op
do
case $optype in
'firstop')
firstop="$op"
;;
'lastop')
lastop="$op"
;;
esac
opfiles[$opsidx]=$optype
opscript[$opsidx]=$op
let "opsidx = $opsidx + 1"
done < $opsfile
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.*/\1/p'`; do
echo "strip_bin: $f"
${__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.*/\1/p'`; do
echo "strip_shared: $f"
${__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
echo "strip_static: $f"
${__strip} $strip_static_args $f
done
}
##################################
# "external" functions
##################################
# create_idb(): Create the .idb file
# params: none
# Create idb file and insert any firstop/lastops
# Note that parse_def does most of the work.
create_idb()
{
fetch_ops
parse_def
local temp
# hackish - FIXME perhaps?
local pcpos=${#pc[@]} # First vacant position in the subsys list array $pc
if [ -d "${stagedir}${metainstalldir}src" ]; then # We have a srcdir which means we have patches, so add them to the idb file
add_files "${metaprefix}src" opt.src - root sys ""
pc[$pcpos]="opt.src"
let "pcpos = pcpos + 1"
fi
# We unconditionally assume that relnotes are installed now that we
# always use the global template as a fallback in auto_rel
local relmetadir=${stagedir}${metainstalldir}relnotes/$topdir-$version-$pkgver
${__mkdir} -p $relmetadir
echo "" > ${relmetadir}/${topdir}.txt
add_files "${metaprefix}relnotes" opt.relnotes - root sys ""
pc[$pcpos]="opt.relnotes"
let "pcpos = pcpos + 1"
# spec & idb files are added unconditionally
pc[$pcpos]="opt.dist"
# Add entries for the spec & idb files (opt.dist), they will be installed later, after they've actually been created
echo "f 0644 root sys ${metainstalldir:1}dist/$topdir-$version-$pkgver/$topdir.idb ${metaprefix}dist/$topdir-$version-$pkgver/$topdir.idb ${pkgname}.opt.dist" >>$idbfile
echo "f 0644 root sys ${metainstalldir:1}dist/$topdir-$version-$pkgver/$topdir.spec ${metaprefix}dist/$topdir-$version-$pkgver/$topdir.spec ${pkgname}.opt.dist" >>$idbfile
echo "${metaprefix}dist/$topdir-$version-$pkgver/$topdir.idb" >> $metadir/files.tmp
echo "${metaprefix}dist/$topdir-$version-$pkgver/$topdir.spec" >> $metadir/files.tmp
# Go through each subsys and add any missing dir entries
# This must go here, after the idb file is created and before
# doing the final sort on the idb file.
if [ $useautodir -eq 1 ]; then
for temp in $(${__awk} '{ print $7 }' $idbfile | ${__sort} -u)
do
auto_dir $temp
done
fi
${__sort} +4u -6 < $idbfile > $metadir/idbtemp
lines=$(wc -l < $metadir/idbtemp)
if [ ! -z "$firstop" ]; then
echo "$(head -1 $metadir/idbtemp) $firstop" > $metadir/idbtemp2
tail +2 $metadir/idbtemp >> $metadir/idbtemp2
else
mv $metadir/idbtemp $metadir/idbtemp2
fi
if [ ! -z "$lastop" ]; then
let "lines=$lines - 1"
echo "$(head -$lines $metadir/idbtemp2)" > $idbfile
echo "$(tail -1 $metadir/idbtemp2) $lastop" >> $idbfile
else
mv $metadir/idbtemp2 $idbfile
fi
${__rm} -f $metadir/idbtemp $metadir/idbtemp2
}
# create_spec(): Create the .spec file.
# params: none
# Uses name, pkgname & pkgver variables
# Iterate through pctop and for each iteration find
# all entries in pc belonging to that image
#
create_spec()
{
fetch_imageconf
fetch_subsysdesc
fetch_depends
fetch_replaces
[ $useupdates -eq 1 ] && fetch_updates
spec_header $pkgname "$name $version-${pkgver}${shortdesc}" > $specfile
local pcsize=${#pc[@]}
local pctopsize=${#pctop[@]}
local reqidlist
for ((i=0; i < $pctopsize; i++))
do
local pcidx=0
spec_img_header ${pctop[$i]} "${pdtop[$i]}" $version-$pkgver >> $specfile
while [ "$pcidx" -lt "$pcsize" ]
do
rv=`${__expr} match "${pc[$pcidx]}" ''${pctop[$i]}\\\.''`
if [ ! "$rv" -eq 0 ]; then # We got a hit!
spec_subsys_header ${pctop[$i]} `echo ${pc[$pcidx]}|${__cut} -d . -f 2` "${pd[$pcidx]}" "${ps[$pcidx]}" >> $specfile
# Add 'replaces' statements
spec_subsys_replaces self >> $specfile
replacepkgsize=${#replacepkg[@]}
if [ "$replacepkgsize" -ge 1 ]; then # Atleast one replaces statement needed
for ((j=0; j < $replacepkgsize; j++))
do
if [ "${replacess[$j]}" = "${pc[$pcidx]}" ]; then
spec_subsys_replaces "${replacepkg[$j]}" >> $specfile
fi
done
fi
# Add 'updates' statements
updatepkgsize=${#updatepkg[@]}
if [ "$updatepkgsize" -ge 1 ]; then # Atleast one updates statement needed
for ((j=0; j < $updatepkgsize; j++))
do
if [ "${updatess[$j]}" = "${pc[$pcidx]}" ]; then
spec_subsys_updates "${updatepkg[$j]}" >> $specfile
fi
done
fi
# Find 'prereq' statements
reqsize=${#reqs[@]}
unset reqidlist # Zero the array
reqidlidx=0
for ((j=0; j < $reqsize; j++))
do
if [ "${reqs[$j]}" == "${pc[$pcidx]}" ]; then
reqidlist[$reqidlidx]=$j
let "reqidlidx=$reqidlidx + 1"
fi
done
# Add 'prereq' statements
reqidlsize=$reqidlidx
if [ "$reqidlsize" -ge 1 ]; then
spec_subsys_req_header >> $specfile
for ((j=0; j < $reqidlsize; j++))
do
id=${reqidlist[$j]}
spec_subsys_req "${reqp[$id]}" >> $specfile
done
spec_subsys_req_footer >> $specfile
fi
spec_subsys_footer >> $specfile
fi
let "pcidx = $pcidx + 1"
done
spec_img_footer >> $specfile
done
spec_footer >> $specfile
}
# make_dist(): Create inst image
# params: none
# Run gendist to create the instimage
make_dist()
{
if [ "$1" == "shortroot" ]; then
error $E_ARG_OBSO make_dist
fi
local sbase=${stagedir}${topinstalldir}
local disttmp=/tmp/disttmp$$
${__mkdir} $disttmp
local dfile=$(_upls $distfile)
$GENDIST $GENDIST_OPTS -rbase $topinstalldir -sbase $sbase -idb $idbfile -spec $specfile -dist $disttmp
setdir $disttmp
${__vtar} -cf $distdir/$dfile $pkgname*
setdir stage
${__rm} -rf $disttmp
echo "Done. Package was created as $dfile"
}
# parse_pkgdef(): Read in $metadir/pkgdef
# 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 index=0
local found=0
local i=0
local equalindex=""
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
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
fi
;;
*)
equalindex=$(expr index "$line" "\=")
if [ $equalindex -ne 0 ]; then
case "${line:0:(($equalindex-1))}" in
'pkgname')
pkgname="$(_upls ${line:$equalindex:${#line}})"
;;
'name')
name="$(_upls ${line:$equalindex:${#line}})"
;;
'pkgver')
pkgver="$(_upls ${line:$equalindex:${#line}})"
;;
'subsys') subsys="$(_upls ${line:$equalindex:${#line}})"
found=0
for i in ${pc[@]} # If $subsys is already there then don't add it again
do
if [ "$i" = "$subsys" ]; then
found=1
break # It's already there so skip out
fi
done
if [ $found -eq 0 ]; then
pc[$index]=$subsys
let "index = $index + 1"
fi
;;
'shortdesc')
shortdesc="$(_upls ${line:$equalindex:${#line}})"
if [ ! -z "$shortdesc" ]; then
shortdesc=" - $shortdesc"
fi
;;
esac
else # Perhaps we hit 'files'?
if [ "${line:0:5}" == "files" ]; then
triplet="${line:6:((${#line}-5-2))}"
defaultperms=$(_upls $(echo $triplet | ${__awk} -F, '{ print $1 }'))
defaultuid=$(_upls $(echo $triplet | ${__awk} -F, '{ print $2 }'))
defaultgid=$(_upls $(echo $triplet | ${__awk} -F, '{ print $3 }'))
foundfiles=1
else
if [ $foundfiles -eq 1 ]; then # We already found the 'files' line so this must be the filelist
if [ "${line:0:5}" == "hide " ]; then
specattr="nohist"
line=${line:5}
fi
if [ "${line:0:4}" == "dir " ]; then
add_dir "${line:4}" $subsys $defaultperms $defaultuid $defaultgid # Add dir entry to idb file
else
add_files "$line" $subsys $defaultperms $defaultuid $defaultgid "$specattr" # Build idb file from filespec
fi
specattr="" # Reset special attribute
fi
fi
fi
;;
esac
done < $metadir/pkgdef
# 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
${__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} | ${__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
}
# auto_src(): Automatically place any patches and srcfiles into the stagedir
# params: none
# Grabs the original source and any patches and shoves them into
# ${metainstalldir}src/$topdir-$version-$pkgver for adding to the opt.src subsystem
auto_src()
{
local distsrcdir="${stagedir}${metainstalldir}src/$topdir-$version-$pkgver"
# Add patches
local numpatch=${#patch[@]}
local pnum=0
if [ "$numpatch" -gt 0 ]; then
${__mkdir} -p $distsrcdir
for ((pnum=0; pnum < $numpatch; pnum++))
do
if [ ! -z ${patch[$pnum]} ]; then # They didn't give us an empty string
if [ "${patch[$pnum]:0:1}" != "/" ]; then # We have a relative pathname
# expand to absolute
patch[$pnum]=$(get_source_absfilename ${patch[$pnum]})
fi # We are now sure that $patch[$pnum] contains file with absolute path
if [ -r ${patch[$pnum]} ]; then # file is readable
echo "Copying patch[$pnum] - ${patch[$pnum]}"
${__cp} -p ${patch[$pnum]} $distsrcdir
else
error $E_BAD_FILE patch
fi
else
echo "Patch $pnum has empty filename"
fi
done
fi
# Add sourcecode
if [ $include_source -eq 1 ]; then
${__mkdir} -p $distsrcdir
local numsource=${#source[@]}
local snum=0
for ((snum=0; $snum < $numsource; snum++))
do
local absfile=$(get_source_absfilename ${source[$snum]})
${__cp} -p $absfilename $distsrcdir
done
fi
}
# identify_compiler(): This outputs information about the compiler
# params: $1 = { log }
# This generates the compiler information used in relnotes and logging
identify_compiler()