forked from fwmiller/Conserver-Freescale-Linux-U-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathltib
executable file
·3176 lines (2788 loc) · 104 KB
/
ltib
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
#!/usr/bin/perl -w
eval 'LANG=C exec perl -w -S $0 ${1+"$@"}'
if $running_under_some_shell;
$running_under_some_shell = 0;
$ENV{LANG} = 'C';
######################################################################
#
# Copyright ? Freescale Semiconductor, Inc. 2004-2007. All rights reserved.
#
# Stuart Hughes, [email protected], 22nd Feb 2005
#
# This file is part of LTIB.
#
# LTIB 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 2 of the License, or
# (at your option) any later version.
#
# LTIB 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 LTIB; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Freescale GNU/Linux Target Image Builder.
# ------------------------------------------
# This script can be used to build target images from source.
# See: doc/LtibFaq for more details
#
######################################################################
use 5.006_000; # now known to work on 5.6.0, don't know the oldest ver yet
use Getopt::Long;
use POSIX qw(uname);
use FindBin;
use lib("$FindBin::Bin/bin");
use Ltibutils;
#use LWP::Debug qw(+);
use IO::File;
# globals, this can be set/overridden in the resource file .ltibrc
# This can be in the same directory as the script, or in the user's
# home directory. First one found wins
chomp($hostname = `hostname`);
$top = $FindBin::Bin;
$bdir = "/opt/freescale";
$verbose = 0;
$cf = {
# configuration options
bldbase => $top,
rpmipfx => '/',
rpmdb => '/var/lib/rpm',
rpmdir => "$top/rpm",
_rpmdir => "$top/rpm/RPMS",
rpm => "$bdir/ltib/usr/bin/rpm",
rpmbuild => "rpmbuild",
sudo => "sudo",
dodrop => 'yes',
prefix => "/usr",
sysconfdir => "/etc",
localstatedir=> "/var",
mandir => "share/man",
tmppath => "/tmp/ltib",
projtmp => "$top/tmp",
bin_path => "$top/bin",
defpfx => "$bdir/ltib",
lpp => "$bdir/pkgs",
spoof_path => "$bdir/ltib/usr/spoof",
pps => "ppp gpp",
gpp_url => "",
ppp_url => "",
ldirs => "",
http_proxy => "",
ftp_proxy => "",
proxy => "",
force_md5get => "",
quiet => "",
wget_opts => "--passive-ftp -nc --tries=1 --timeout=12 -nv",
configured => "",
pre_install_deps => "
glibc 2.2.4
glibc-headers 0
glibc-devel 0
binutils 2.11.90
libstdc++ 0
gcc 2.96
gcc-c++ 2.96
sudo 0
zlib 0
zlib-devel 0
rpm 0
rpm-build 0
wget 0
ncurses 5.1
ncurses-devel 0
m4 0
bison 0
patch 0
# flex 0 # added to the host packages we install
# texinfo 0 # added to the host packages we install
gettext 0
# autoconf 2.54 # added to the host packages we install
# libtool 1.4.2 # added to the host packages we install
# byacc 0 # needed? report was for 8548 install
make 0
tcl 0 # needed by git for internal work
",
frb_deps => "PLATFORM GNUTARCH LINTARCH CFGHOST TOOLCHAIN
TOOLCHAIN_CFLAGS DISTRO PKG_UCLIBC PKG_GLIBC
LIBC_HACKING",
app_version => "9.1.1",
cvs_version => '$Revision: 1.445.6.1 $',
fakeroot => "",
config_dir => "$top/config",
platforms_dir => "$top/config/platform",
plat_dir => "",
mainlkc => "$top/config/main.lkc",
release_info => "$top/RELEASE_INFO",
conf => "mconf",
defdist => "dist/lfs-5.1",
pfx => "/",
buildarch => (uname())[4],
hostconfig => "$top/config/platform/host/ltib.preconfig",
rpmdb_nfs_warning => "$top/.rpmdb_nfs_warning",
host_wait_warning => "$top/.host_wait_warning27", # update .ltibrc now!
top => $top,
home => $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($<))[7],
username => scalar(getpwuid($<)),
hostname => $hostname,
path_orig => $ENV{PATH},
path_std => "/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin",
redirected => "",
something_got_built => 0,
pkg_build_failures => "",
normal_exit => 1,
stime => time(),
sdate => scalar(localtime()),
gmsdate => scalar(gmtime()),
hostinst => 0,
enrootn => 1,
oneroot => 0,
root_cf => "$top/.root_cf",
lock_file => "$top/.lock_file",
# buildcc could modified if we need to install a newer version
# changed from /usr/bin/gcc -B/usr/bin// to /usr/bin/gcc
# on old gcc-2.95.3, "gcc: file path prefix `/usr/bin//' never used"
# causes configure not to detect header when building binutils for build
# had to restore this this or can't build cross packages (u-boot)
# had to include buildcpp to get gdb-6.2 to build (path prefix problem)
buildcc => "/usr/bin/gcc -B/usr/bin//",
buildcxx => "/usr/bin/g++ -B/usr/bin//",
buildcpp => "/usr/bin/cpp",
buildld => "/usr/bin/ld",
buildstrip => "/usr/bin/strip",
buildranlib => "/usr/bin/ranlib",
cc => "gcc",
cxx => "g++",
ld => "ld",
ar => "ar",
# command line options
mode => "buildrpms",
sn => "",
configure => 0,
upreconfig => "",
preconfig => "",
profile => "",
rcfile => "",
logfile => "$top/host_config.log",
keepsrpms => 0,
batch => 0,
force => 0,
reinstall => 0,
erase => 0,
nodeps => 0,
conflicts => 0,
dry => 0,
coe => 0,
version => 0,
noredir => 0,
do_deploy => 0,
no_deploy => 0,
download_only=> 0,
dltest => 0,
external => 0,
leavesrc => 0,
prof => 0,
hostcf => 0,
fullbsp => 0,
distmap => 0,
use_git_mode => "",
no_sudo_check => 0, # fc9 work-around
help => 0,
};
use strict 'vars';
use vars qw($cf $config_deps $build_deps $install_deps
$echo $pcf $ppcf $rev_install_deps $pcac $verbose);
# package config dependencies
# re-build the key (lhs) if any of the dependents (rhs) in the list have changed
$config_deps = {
PKG_U_BOOT => [ qw/PKG_U_BOOT_CONFIG_TYPE PKG_U_BOOT_BUILD_ARGS
PKG_U_BOOT_LEAVESRC/ ],
PKG_KERNEL => [ qw/PKG_KERNEL_PRECONFIG PKG_KERNEL_WANT_HEADERS
PKG_KERNEL_WANT_CF PKG_KERNEL_LEAVESRC
SYSCFG_DTC_NAME/ ],
PKG_UCLIBC => [ qw/PKG_LIBC_WANT_CF/ ],
PKG_BASE_LIBS => [ qw/PKG_LIBC_WANT_SHARED_LIBS
PKG_LIBC_WANT_CRT_FILES
PKG_LIBC_WANT_HEADERS1 PKG_LIBC_WANT_STATIC_LIBS
PKG_LIBC_WANT_LOCALES
PKG_CXX_WANT_SHARED_LIBS PKG_CXX_WANT_HEADERS
PKG_CXX_WANT_STATIC_LIBS
PKG_GCC_WANT_LIBGCC_SHARED/ ],
PKG_BUSYBOX => [ qw/PKG_BUSYBOX_PRECONFIG PKG_BUSYBOX_WANT_CF/ ],
PKG_DIRECTFB => [ qw/PKG_DIRECTFB_WANT_TS/ ],
PKG_DTC => [ qw/PKG_DTC_WANT_FDT/ ],
PKG_GDB => [ qw/PKG_GDB_NATIVE_WANT_ED PKG_GDB_CROSS_WANT_ED
PKG_GDB_SERVER_WANT_ED
PKG_GDB_M68K_BDM_WANT_ED/ ],
PKG_OPENSSL => [ qw/PKG_OPENSSL_WANT_SEC/ ],
PKG_OPENSSH => [ qw/PKG_OPENSSH_WANT_HACKABLE_KEYS/ ],
PKG_DROPBEAR => [ qw/PKG_DROPBEAR_WANT_URANDOM_DEV
PKG_DROPBEAR_WANT_NO_REV_DNS
PKG_DROPBEAR_WANT_NO_X11FWD
PKG_DROPBEAR_WANT_HACKABLE_KEY/ ],
PKG_SYSCONFIG=> [ qw/SYSCFG_HOSTNAME
SYSCFG_MODLIST SYSCFG_START_SYSLOG
SYSCFG_LOGING_TTY SYSCFG_WANT_LOGIN_TTY
SYSCFG_START_INETD SYSCFG_START_PORTMAP
SYSCFG_START_DROPBEAR_SSH SYSCFG_START_BOA
SYSCFG_SETTIME SYSCFG_NTP_SERVER SYSCFG_RAM_DIRS
SYSCFG_START_NETWORK SYSCFG_TMPFS_SIZE
SYSCFG_NET_GATEWAY0 SYSCFG_NAMESERVER0
SYSCFG_NET_GATEWAY1 SYSCFG_NAMESERVER1
SYSCFG_IFACE0 SYSCFG_DHCPC0 SYSCFG_NET_INTERFACE0
SYSCFG_IPADDR0 SYSCFG_NET_MASK0 SYSCFG_NET_BROADCAST0
SYSCFG_IFACE1 SYSCFG_DHCPC1 SYSCFG_NET_INTERFACE1
SYSCFG_IPADDR1 SYSCFG_NET_MASK1 SYSCFG_NET_BROADCAST1
SYSCFG_IFACE2 SYSCFG_DHCPC2 SYSCFG_NET_INTERFACE2
SYSCFG_IPADDR2 SYSCFG_NET_MASK2 SYSCFG_NET_BROADCAST2
SYSCFG_IFACE3 SYSCFG_DHCPC3 SYSCFG_NET_INTERFACE3
SYSCFG_IPADDR3 SYSCFG_NET_MASK3 SYSCFG_NET_BROADCAST3
SYSCFG_IFACE4 SYSCFG_DHCPC4 SYSCFG_NET_INTERFACE4
SYSCFG_IPADDR4 SYSCFG_NET_MASK4 SYSCFG_NET_BROADCAST4
SYSCFG_READONLY_FS SYSCFG_START_DEVFSD
SYSCFG_START_UDEV SYSCFG_START_MDEV
SYSCFG_DEPLOYMENT_STYLE SYSCFG_INETD_ARGS
SYSCFG_START_DHCPD SYSCFG_DHCPC_CMD SYSCFG_DHCP_ARG
SYSCFG_START_WATCHDOG SYSCFG_START_SSHD
SYSCFG_START_SAMBA SYSCFG_SMBD_ARGS SYSCFG_NMBD_ARGS
SYSCFG_BOA_ARGS SYSCFG_DROPBEAR_ARGS/ ],
PKG_NCURSES => [ qw/PKG_NCURSES_WANT_REDUCED_SET/ ],
PKG_BASH => [ qw/PKG_BASH_WANT_NO_SH_SYMLINK/ ],
PKG_DHCP => [ qw/PKG_DHCP_WANT_SERVER PKG_DHCP_WANT_CLIENT/ ],
PKG_PPP => [ qw/PKG_PPP_WANT_FILTER/ ],
PKG_SKELL => [ qw/PKG_SKELL_WANT_TERMINFO/ ],
};
# package build dependencies
# rebuild all packages in the list (rhs) if the key (lhs) has been installed
$build_deps = { PKG_KERNEL => [ qw/PKG_MODEPS/ ],
PKG_SKELL => [ qw/PKG_SYSCONFIG/ ],
PKG_MERGE => [ qw/PKG_MODEPS/ ],
PKG_TSLIB => [ qw/PKG_XORG_SERVER PKG_ENLIGHTENMENT
PKG_ECORE/ ]
};
# packages install dependencies
# re-install all the pkgs in the list (rhs) if the key (lhs) has been installed
$install_deps = { PKG_SKELL => [ qw/PKG_SYSCONFIG/ ],
PKG_BUSYBOX => [ qw/PKG_INETUTILS PKG_SYSKLOGD
PKG_SYSVINIT PKG_COREUTILS
PKG_SED PKG_TIME PKG_UTIL_LINUX
PKG_UNZIP PKG_NET_TOOLS
PKG_FINDUTILS PKG_TINYLOGIN
PKG_MODUTILS PKG_MODULE_INIT_TOOLS
PKG_KBD PKG_BZIP2 PKG_PSMISC
PKG_PROCPS PKG_NCURSES PKG_WGET
PKG_GAWK PKG_SASH PKG_BASH
PKG_TAR PKG_GREP PKG_DIFFUTILS
PKG_HDPARM PKG_PATCH PKG_LFS_UTILS
PKG_WHICH PKG_DEVFSD/],
PKG_UCLIBC => [ qw/PKG_GCC/ ],
PKG_GLIBC => [ qw/PKG_GCC/ ],
PKG_BASE_LIBS => [ qw/PKG_GCC/ ],
PKG_SASH => [ qw/PKG_SYSVINIT PKG_BASH/ ],
PKG_TINYLOGIN => [ qw/PKG_SYSVINIT/ ],
PKG_POPT => [ qw/PKG_RPM/ ],
PKG_DROPBEAR => [ qw/PKG_OPENSSH/ ],
};
my $usage =<<TXT;
This script is used to manage the building of BSPs with common target
root filesystems.
Normally the system default are what you need. However, if you need to fine
tune some of the setup parameters, edit the file .ltibrc in this directory,
alternatively you may use a common .ltibrc file by placing one in your home
directory.
ltib [-m <mode>] [options....]
Where:
--mode|m
Where mode is either:
prep just prep the package
scbuild rpmbuild -bc --short-circuit
scinstall rpmbuild -bi --short-circuit
scdeploy does an scinstall followed by an install to the rootfs
patchmerge generate and merge a patch (requires -p <pkg>)
clean clean/uninstall target packages
distclean full cleanup, removes nearly everything
listpkgs list packages (alphanumeric)
listpkgseula list package names and licenses
listpkgstw list packages in twiki format
listpkgscsv list packages in a format for import into spreadsheet
release make a binary release iso image
trelease make a non-distributable test iso release
config configure selected platform (no build)
selectype sub-platform selection (no build)
shell enter ltib shell mode (sets up spoofing etc)
addsrpms import srpms into ltib (semi-automatic)
--rootn|R : Root context number (0 is the primary and implicit)
--pkg|p : operate on this package only
--configure|c : run the interactive configuration and build
--selectype : run the sub-platform configuration and build
--preconfig : configuration file to build from (defaults to .config)
--profile : profile file. This is used to select an alternate
set of userspace packages, this is saved and used
on later runs of ltib (e.g config/profiles/max.config)
--rcfile|r <f>: use this resource file
--batch|b : batch mode, assume yes to all questions
--force|f : force rebuilds even if they are up to date
--reinstall|e : re-install rpms (but don't force rebuild)
--erase|E : remove (erase) rpm
--nodeps|n : turn off install/uninstall dependency checks
--conflicts|k : don't force install rpms that have file conflicts
--keepsrpms|s : keep the srpms after the build (deleted by default)
--verbose|v : more output
--dry-run|d : mostly a dry run (calls to system are just echos)
--continue|C : try to continue on package build errors (autobuilds)
--version|V : print the application version and quit
--noredir|N : do not redirect any output
--deploy|D : run the deploy scripts even if build is up to date
--no-deploy : disabled deployment (even with -p <pkg>
--dlonly : just download the packages only
--dltest : test that the BSP's packages are available
--external : check against external staging repositories
--leavesrc|l : leave the sources unpacked (only valid for pkg mode)
--sticky : Make the selected root number sticky
--no-sticky : Remove root stickiness
--hostcf : (re)configure/build/install the host support package set
--enabled : use with package listings
--ignorelock : use if you really want to ignore any locks (careful!)
--fullbsp : used with -m release to copy additional content
--distmap : used with -m release to copy specical packages into ISO
--no-sudo : don't check sudo, work around for broken sudo (fc9)
--use-git-mode : use git for some package's build
where use-git-mode is either:
internal Use fsl internal git
external Use fsl external git
--external-git : use external git for some package's build
--help|h : help on usage
TXT
# set stdout to autoflush
$| = 1;
if( $> == 0) {
print <<TXT;
You should not be root when running ltib, do you really
want to continue ? y|N
TXT
$_ = <STDIN>;
die "Goodbye\n" unless /^y/i;
}
Getopt::Long::Configure("no_ignore_case", "bundling");
GetOptions(
"mode|m:s" => \$cf->{mode},
"rootn|R:i" => \$cf->{rootn},
"pkg|p:s" => \$cf->{sn},
"configure|c"=> \$cf->{configure},
"selectype" => \$cf->{selectype},
"preconfig:s"=> \$cf->{upreconfig},
"profile:s" => \$cf->{profile},
"rcfile|r:s" => \$cf->{rcfile},
"keepsrpms|s"=> \$cf->{keepsrpms},
"verbose|v" => \$verbose,
"batch|b" => \$cf->{batch},
"force|f" => \$cf->{force},
"reinstall|e"=> \$cf->{reinstall},
"erase|E" => \$cf->{erase},
"nodeps|n" => \$cf->{nodeps},
"conflicts|k"=> \$cf->{conflicts},
"dry-run|d" => \$cf->{dry},
"continue|C" => \$cf->{coe},
"version|V" => \$cf->{version},
"noredir|N" => \$cf->{noredir},
"deploy|D" => \$cf->{do_deploy},
"no-deploy" => \$cf->{no_deploy},
"dlonly" => \$cf->{download_only},
"dltest" => \$cf->{dltest},
"external" => \$cf->{external},
"prof" => \$cf->{prof},
"leavesrc|l" => \$cf->{leavesrc},
"sticky!" => \$cf->{sticky},
"hostcf" => \$cf->{hostcf},
"enabled" => \$cf->{enabled},
"ignorelock" => \$cf->{ignorelock},
"fullbsp" => \$cf->{fullbsp},
"distmap" => \$cf->{distmap},
"use-git-mode:s" => \$cf->{use_git_mode},
"no-sudo" => \$cf->{no_sudo_check},
"help|h" => \$cf->{help},
) or die $usage;
die $usage if $cf->{help};
die <<TXT if $cf->{version};
ltib $cf->{app_version} ($cf->{cvs_version})
Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
This is free software; it is licensed under the terms of the
GNU General Public License, see 'COPYING' for the license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
TXT
# command line validation
die "invalid mode $cf->{mode}\n", $usage
unless $cf->{mode} =~ m,^(buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell|trelease|selectype),;
if($cf->{use_git_mode}) {
die "invalid use-git-mode $cf->{use_git_mode}\n", $usage
unless $cf->{use_git_mode} =~ m,^(internal|external),;
}
if($cf->{sn}) {
if($cf->{configure}) {
$cf->{configure} = '';
$ENV{SCB_WANT_CF} = 'y';
} elsif($cf->{profile}) {
#### TODO: temporarily allow preconfig until lkc bug is fixed
die <<TXT;
The options: --profile cannot be used when
passing the --pkg|-p option.
TXT
}
} else {
if($cf->{mode} =~m,^(scbuild|scinstall|prep|scdeploy)$, ) {
die <<TXT;
The options prep, scbuild, scinstall and scdeploy are only allowed when working
on a single package, not a list. You need to supply the option -p|--pkg <pkg>
TXT
}
if($cf->{leaverc}) {
die "--leavesrc|l only work on a single package, use -p <pkg>\n";
}
}
if($cf->{upreconfig} && ! -e $cf->{upreconfig}) {
die "preconfig file: $cf->{upreconfig} does not exist\n";
}
if($cf->{profile} && ! -e $cf->{profile}) {
die "profile file: $cf->{profile} does not exist\n";
}
$cf->{logfile} ||= "$cf->{top}/host_config.log";
# allow for dry-runs
$echo = $cf->{dry} ? "echo" : "";
# scdeploy implies deploy
$cf->{do_deploy} = 1 if $cf->{mode} eq 'scdeploy';
# specifying --batch implies continue on error
$cf->{coe} = 1 if $cf->{batch};
$cf->{conf} = $cf->{batch} ? "yes '' | conf >&2" : "mconf";
# mode 'config' implies --configure
$cf->{configure} = 1 if $cf->{mode} eq 'config';
# mode 'selectype' implies --selectype and --configure
$cf->{selectype} = 1 if $cf->{mode} eq 'selectype';
$cf->{configure} = 1 if $cf->{selectype};
if($cf->{selectype} && ($cf->{upreconfig} || $cf->{profile}) ) {
die "selectype can't be used with preconfig and/or profiles\n";
}
# dltest implied noredir(ect)
$cf->{noredir} = 1 if $cf->{dltest};
# used to focus only on a single root
if( defined($cf->{sticky}) ) {
$cf->{sticky} ?
write_config($cf->{root_cf}, { rootn => $cf->{rootn} || 0 })
: unlink($cf->{root_cf});
}
if( defined($cf->{rootn}) ) {
$cf->{oneroot} = 1;
} elsif(-f $cf->{root_cf}) {
$cf->{oneroot} = 1;
my $hr = parse_config(fn => $cf->{root_cf}) or die;
$cf->{rootn} = $hr->{rootn} || 0;
} else {
$cf->{oneroot} = 0;
$cf->{rootn} = 0;
}
# load the system level configuration (download url etc)
load_system_config($cf);
# make sure the root prefix for rpm is never set to / by the user
$cf->{rpmroot} = $cf->{rfsbase} = "$cf->{bldbase}/rootfs";
# make sure that the user has reviewed basic application configuration
check_app_is_configed();
# allow for cleanup code
foreach my $sig (qw/INT/) {
$SIG{$sig} = \&sig_handler;
}
$SIG{__DIE__} = \&die_handler;
# setup basic path to parts we will install
$ENV{PATH} = "$cf->{defpfx}/usr/bin:$cf->{path_std}";
# remove possible CROSS_COMPILE prefix that could mess up spoofing
$ENV{CROSS_COMPILE} = "";
# turn off timestamps in the lkc menu system to prevent constant
# check-ins of unchanged files
$ENV{KCONFIG_NOTIMESTAMP} = "no";
# do distclean before other modes to prevent re-installing parts
if($cf->{mode} eq 'distclean') {
f_distclean() or die;
exit(0);
}
if($cf->{mode} =~ m,listpkgs,) {
&{"f_" . $cf->{mode}}();
exit(0);
}
# load a config for the host development system,
# run pre build checks
# build and install host parts according to config
host_checks();
# if doing host stuff, run that command
build_host_rpms(1) if $cf->{hostcf};
# get/set the platform directory
$cf->{plat_dir} = get_plat_dir() or die;
my @rl = build_root_list();
foreach my $n (reverse @rl) {
print "\nProcessing root number: ", $n+1, " of ", $#rl+1, "\n",
"--------------------------------\n" if $#rl > 0;
$cf->{rootn} = $n;
# do setup before target building
pre_build_checks();
# run the requested mode
&{"f_" . $cf->{mode}}()
or die("\n\nf_$cf->{mode}() returned an error, exiting\n");
# clear transient configuration flags
clear_transient_configs();
}
if($cf->{mode} eq 'buildrpms' &&
! ($cf->{dltest} || $cf->{download_only} || $cf->{dry}) ) {
# write out a release info file
write_release_info($cf->{release_info});
# copy release info to the rootfs
if(! -w "$cf->{rfsbase}/etc/ltib-release") {
warn("$cf->{rfsbase}/etc/ltib-release is not writable\n");
} else {
system_nb("cp $cf->{release_info} $cf->{rfsbase}/etc/ltib-release")
== 0 or die;
}
}
# run the deployment section
if( $cf->{rootn} == 0
&& $cf->{no_deploy} == 0
&& ($cf->{mode} eq 'buildrpms' || $cf->{mode} eq 'scdeploy')
&& ($cf->{something_got_built} || $cf->{do_deploy}) ) {
my $msg = "\nProcessing deployment operations\n";
$msg .= '=' x length($msg) . "\n";
print $msg;
mk_fs_image($cf->{rfsbase}, $pcf) or die unless $echo;
if($pcf->{POST_BUILD_SCRIPT}) {
print "\nrunning post build user command: $pcf->{POST_BUILD_SCRIPT}\n";
system_nb($pcf->{POST_BUILD_SCRIPT}) == 0 or die;
}
}
summary();
exit(0);
#############################################
# command line mode subroutines
#############################################
sub f_clean
{
remove_unselected_pkgs();
local $_;
my @pkg_list = map { $$_->{en} ? get_pkg_name($_) : () } mk_buildlist();
foreach my $pkg (reverse @pkg_list) {
my $cmd = "$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} "
. "-q $pkg";
$_ = qx($cmd);
print("$pkg is not installed\n"), next unless m,^\Q$pkg\E,;
$_ = qx($cmd-devel);
$pkg .= " $pkg-devel" if m,^\Q$pkg\E,;
die $cmd if $? && ! m,is not installed,;
$cmd = "$cf->{sudo} $cf->{rpm} --root $cf->{rpmroot} "
. "--dbpath $cf->{rpmdb} -e --allmatches "
. "--define '_tmppath $cf->{tmppath}' $pkg";
$cmd .= " --nodeps" if $cf->{nodeps};
print "$cmd\n";
system_nb($cmd) unless $echo;
return if $?
}
return 1;
}
sub remove_rfsbase
{
die("Request to remove too filesystem denied, expected .../rootfs")
unless $cf->{rfsbase} =~ m,rootfs$,;
print("Removing target root filesystem\n");
# remove all rootfs files and the rpm database itself
my $opcf = $pcf;
$pcf = {};
$pcf->{PLATFORM_COMMENT} = 'host support';
$pcf->{DISTRO} = 'dist/lfs-5.1';
$pcf->{PLATFORM} = 'host';
$pcf->{GNUTARCH} = $cf->{buildarch};
$pcf->{LINTARCH} = g2larch($cf->{buildarch}) or die;
$pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH}) or die;
$pcf->{CFGHOST} = "$cf->{buildarch}-linux";
my $di = $ENV{DEV_IMAGE} || '';
my $sav = {};
my @sav_list = qw/sn force rpmipfx rpmroot rpmdb tmppath enrootn/;
foreach my $k (@sav_list) {
$sav->{$k} = $cf->{$k}
}
pkg_cache_init();
$cf->{sn} = "mkdistclean.spec";
$cf->{force} = 1;
$ENV{DEV_IMAGE} = $cf->{rpmipfx} = $cf->{rfsbase};
$cf->{rpmroot} = '/';
$cf->{rpmdb} = "$cf->{bldbase}/cleanupdb";
$cf->{tmppath} = $cf->{projtmp};
$cf->{enrootn} = 0;
setup_rpmdb();
build_rpm() or die;
f_clean() or die;
system_nb("rm -rf $cf->{rpmdb} $cf->{tmppath}");
foreach my $k (@sav_list) {
$cf->{$k} = $sav->{$k}
}
undef $sav;
$ENV{DEV_IMAGE} = $di;
$pcf = $opcf;
}
sub f_distclean
{
if(! $cf->{batch}) {
print(<<TXT);
You are about remove all the work you have been doing, are you really
sure you want to completely remove files from:
$cf->{rfsbase}
TXT
print "To continue type in 'yes': ";
local $_ = <STDIN>;
print("aborted\n"), return 1 unless /^yes$/;
}
remove_rfsbase() if -e $cf->{rfsbase};
system_nb(<<TXT);
set -x
$echo rm -f .wget_warning .rpm_warning .sudo_warning .config .tmpconfig.h .config.old .config.cmd
$echo find config \\( -name .config\\* -o -name .tmpconfig.h \\) -exec rm {} \\;
$echo rm -rf $cf->{top}/lib
$echo rm -rf $cf->{top}/man
$echo rm -rf $cf->{projtmp}
$echo rm -rf $cf->{tmppath}
$echo rm -rf $cf->{rfsbase}
$echo rm -rf $cf->{top}/rpmdb
$echo rm -rf $cf->{rpmdir}/RPMS
$echo rm -rf $cf->{rpmdir}/SRPMS
$echo find $cf->{rpmdir}/SOURCES -type l -exec rm {} \\;
$echo rmdir rpm/BUILD rpm/SOURCES rpm/SPECS rpm 2>/dev/null
$echo rm -f rootfs.ext2.* vmlinux.*
$echo rm -f $cf->{logfile} $cf->{lock_file} $cf->{root_cf}
$echo rm -f $cf->{config_dir}/main.lkc
$echo rm -f .host_wait_warning* .tc_test_*
$echo rm -f $cf->{rpmdb_nfs_warning} $cf->{release_info}
$echo rm -f rootfs.jffs2 rootfs.ext2.gz rootfs_image
$echo rm -rf rootfs.tmp
$echo rm -f config/platform/host/host.config
$echo find $cf->{platforms_dir} \\( -name *.dev -o -name *.bak \\) -exec rm {} \\;
$echo for i in faked fakeroot mkimage gdb tmake .gdbinit mpc.init netperf netserver; do rm -rf $cf->{top}/bin/\$i ; done
TXT
return 1;
}
sub build_rpm
{
my $args = { @_ };
my $key = $args->{key} || '';
if(! $key) {
validate_sn();
$key = get_key_by_sn($cf->{sn});
}
return 1 unless $$key->{en};
my $unpack = $args->{unpack} || 'yes';
my $leavesrc = $args->{leavesrc}|| $cf->{leavesrc};
my $rpmopts = $args->{rpmopts} || ( $cf->{keepsrpms} ? '-ba' : '-bb' );
my $sn = $$key->{sn};
my $rebuilt = 0;
my $cmd = '';
$$key->{build} = 1 if $pcf->{$key . '_FORCE'} || $args->{force};
my $msg = "\nProcessing: $sn\n";
$msg .= '=' x length($msg) . "\n";
print $msg;
my $spec = get_spec($sn);
die("can't find spec file for $sn\n") unless $spec && -e $spec;
unless( $spec && -e $spec ) {
$cf->{pkg_build_failures} .= "$sn ";
warn("specfile not found\n");
return;
}
my $tok = parse_spec($spec) or die();
my @rpms = glob("$cf->{_rpmdir}/$pcf->{RPMTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*");
my $pkgfail = 0;
# check for rebuild conditions
my $dir_bld = -e "$cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}"
|| $tok->{version} eq 'local';
my $spec_upd = @rpms && (-M $spec < -M $rpms[0]) && ! $cf->{hostinst};
my $r = '';
$r .= "directory build, " if $dir_bld;
$r .= "force set, " if $cf->{force};
$r .= "build key set, " if $$key->{build};
$r .= "dltest mode, " if $cf->{dltest};
$r .= "download only, " if $cf->{download_only};
$r .= "no prebuilt rpm, " if ! @rpms;
$r .= "spec file newer than rpm, " if $spec_upd;
if($r) {
warn("Build path taken because: $r\n") unless $cf->{dltest};
# don't do this clause if running in short-circuited mode
if( $unpack eq 'yes' ) {
# commit to installing a new rpm (enforced if build fails)
unlink(@rpms) if $cf->{force} || $$key->{build} || $spec_upd;
foreach my $url ( split(/\s*\n/, $tok->{sources}),
split(/\s*\n/, $tok->{patches}) ) {
(undef, $url) = split(/:\s*/, $url, 2);
my ($file) = $url =~ m-/?([^/]+)$-;
my $tgt = "$cf->{rpmdir}/SOURCES/$file";
if(! -e $tgt || $cf->{dltest} || $cf->{download_only}) {
my $src;
unless( $src = get_file($url, $cf, 1) ) {
$cf->{pkg_build_failures} .= "$sn " unless $pkgfail;
$pkgfail = 1;
if($cf->{dltest}) {
push @{$cf->{dlfails}{$sn}}, $url;
next;
}
warn("Can't get: $file");
return;
}
next if $cf->{dltest};
# needed if the lpp moves and links break
unlink($tgt);
symlink($src, $tgt)
or die("symlink $cf->{lpp}/$file, $tgt: $!");
}
}
return 1 if $cf->{download_only};
return 1 if $cf->{dltest};
if( $dir_bld ) {
# Don't allow scbuild/scdeploy of host rpms
if($cf->{hostinst} || $cf->{mode} ne 'buildrpms') {
warn(<<TXT) unless $tok->{version} eq 'local';
Cowardly refusing to clobber existing directory:
$cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}
Remove this by hand if you really want to rebuild this package from scratch
TXT
$cf->{pkg_build_failures} .= "$sn ";
return;
}
# Rebuild something with the source already unpacked
if( $rpms[0] && -f $rpms[0] ) {
my $src_dir = "$cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}";
if($tok->{version} eq 'local') {
$cmd = "$cf->{rpmbuild} --nobuild "
. "--define '_topdir $cf->{rpmdir}' "
. "--define 'showsrcpath 1' $spec";
$src_dir= `$cmd 2>&1`;
die unless $? == 0;
if(substr($src_dir, 0, 1) ne '/') {
$src_dir = "$cf->{rpmdir}/BUILD/$src_dir";
}
die("'$src_dir' doesn't exist\n") unless -e $src_dir;
}
# See if the source tree has been touched
$cmd = "find $src_dir -newer $rpms[0] -print";
print "checking if sources have been updated: ";
if(`$cmd`) {
print "yes\n";
} else {
print "no\n";
return 1;
}
}
warn "scbuild/scdeploy already unpacked package\n";
my $ret = f_scbuild($key) && f_scdeploy($key);
return $ret;
}
}
# we may not have needed to download source, so this gets
# repeated. Really time for a re-structure of code
return 1 if $cf->{download_only};
my $rpmclean;
if($leavesrc || $pcf->{$key . '_LEAVESRC'}) {
$rpmclean = '';
$ENV{$key . '_LEAVESRC'} = 'y';
} else {
$rpmclean = '--clean --rmsource ';
}
# build the binary rpms
$cmd =
"$cf->{rpmbuild} "
. "--dbpath $cf->{rpmroot}/$cf->{rpmdb} "
. "--target $pcf->{RPMTARCH} "
. "--define '_unpackaged_files_terminate_build 0' "
. "--define '_target_cpu $pcf->{RPMTARCH}' "
. "--define '__strip strip' "
. "--define '_topdir $cf->{rpmdir}' "
. "--define '_prefix $cf->{prefix}' "
. "--define '_tmppath $cf->{projtmp}' "
. "--define '_rpmdir $cf->{_rpmdir}' "
. "--define '_mandir $cf->{prefix}/$cf->{mandir}' "
. "--define '_sysconfdir $cf->{sysconfdir}' "
. "--define '_localstatedir $cf->{localstatedir}' "
. "$rpmopts $rpmclean $spec";
print "\n$cmd\n";
my $stime = time();
my $ec = system_nb("$echo $cf->{fakeroot} $cmd");
print "Build time for $sn: ${\( time() - $stime )} seconds\n\n";
$rebuilt = 1;
if($ec) {
warn("Failed building $sn\n");
$cf->{pkg_build_failures} .= "$sn ";
return;
}
}
# short circuited rpm modes don't install rpms
return 1 if $rpmopts =~ m,--short-circuit,;
# if anything got build, try to install it
if( ( $cf->{hostinst} && rpm_needs_update($tok))
|| (! $cf->{hostinst} &&
( $rebuilt || $cf->{reinstall}
|| (exists $$key->{install} && $$key->{install})
|| `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -q $tok->{name}-$tok->{version}-$tok->{release} 2>/dev/null` =~ m,is not installed,) ) ) {
# make a note that something got built
$cf->{something_got_built} = 1;
# handle packages that have sub-packages
# seh: 20070312: sub-packages have not ever really worked.
# seh: 20071030: remove rpm -e as using Uvh, not ivh
# seh: 20071119: put it back otherwise orphaned files left behind
foreach my $rpm ( glob("$cf->{_rpmdir}/$pcf->{RPMTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*") ) {
# make sure we're not going to clobber host files
check_host_clobber($rpm);
# We need to remove the package first. This is needed
# because otherwise files that previously existed
# but no longer exist in a package would be left behind
# un-owned by any package
my ($subpkg) = $rpm =~ m,/([^/]+)-[^-]+-[^-]+\.\w+\.rpm$,;
die( "Error: could not match rpm with pattern: "
. "$cf->{_rpmdir}/$pcf->{RPMTARCH}/$tok->{name}-"
. "$tok->{version}-$tok->{release}*\n") unless $subpkg;
$cmd = "$cf->{sudo} $cf->{rpm} ";
$cmd .= "--root $cf->{rpmroot} ";
$cmd .= "--dbpath $cf->{rpmdb} ";
$cmd .= "-e --allmatches --nodeps ";
$cmd .= "--define '_tmppath $cf->{tmppath}' ";
$cmd .= "$subpkg 2>/dev/null";
print "$cmd\n";
system_nb($cmd);
# install the new package
$cmd = "$cf->{sudo} $cf->{rpm} ";
$cmd .= "--root $cf->{rpmroot} ";
$cmd .= "--dbpath $cf->{rpmdb} ";
$cmd .= "--prefix $cf->{rpmipfx} " if $cf->{rpmipfx};
$cmd .= "--ignorearch -ivh ";
$cmd .= "--force " unless $cf->{conflicts} || $cf->{hostinst};
$cmd .= "--replacepkgs --replacefiles " if $cf->{hostinst};
$cmd .= "--nodeps " if $cf->{nodeps};
$cmd .= "--excludedocs ";
$cmd .= "--define '_tmppath $cf->{tmppath}' ";
$cmd .= "$rpm";
print "$cmd\n";
# in dry-run mode (echo), don't actually install
unless($echo) {
system_nb($cmd);
my $ec = ($? & 0xffff) >> 8;
# return code of 2 indicates a newer package installed
if($ec != 0 && $ec != 2) {
return;
}
}
# the install of this package may cause others to install
process_pkg_triggers($key);
}
}
return 1;
}
sub f_buildrpms
{
# single package erase
if($cf->{erase} && $cf->{hostinst} == 0) {
die "Please specify package with -p <pkg>\n" if ! $cf->{sn};
return f_clean();
}
my $ret = 1;
my $msg = "\nProcessing platform: $pcf->{PLATFORM_COMMENT}\n";
$msg .= '=' x length($msg) . "\n";
print $msg;
print "using $cf->{preconfig}\n" if $cf->{preconfig};
# remove any packages that are not in the build list
remove_unselected_pkgs() unless $cf->{dltest};
# process the package dependencies
foreach my $key ( mk_buildlist() ) {
process_pkg_deps($key, $$key->{sn}) if $$key->{en};
}
foreach my $key( mk_buildlist() ) {
next unless $$key->{sn};
build_rpm(key => $key) or do {
undef $ret;
return unless $echo || $cf->{coe} || $cf->{dltest};
};
}
return $ret;
}