head	1.29;
access;
symbols
	import-20090318:1.1.1.17
	import-20081205:1.1.1.16
	rel-8-1-2-sv:1.18
	import-20080404:1.1.1.15
	import-20071105:1.1.1.14
	import-20070116:1.1.1.13
	import-20061124:1.1.1.12
	rel-6-2-2-sv:1.2
	rel-6-2-1-sv:1.1.1.11
	import-20060615:1.1.1.11
	import-20060530:1.1.1.10
	import-20060516:1.1.1.9
	import-20060421:1.1.1.8
	import-20060406:1.1.1.8
	import-29mar06:1.1.1.7
	import-14mar06:1.1.1.6
	import-13mar06:1.1.1.5
	fixed-post-import-14feb06:1.1.1.4
	import-14feb06:1.1.1.4
	fixed-post-import-6feb06:1.1.1.3
	import-6feb06:1.1.1.3
	import-6sep05:1.1.1.2
	start:1.1.1.1
	freescale:1.1.1;
locks; strict;
comment	@# @;


1.29
date	2009.05.22.10.30.41;	author seh;	state Exp;
branches;
next	1.28;
commitid	HDx6gIgZlOQd4ROt;

1.28
date	2009.04.16.09.08.29;	author seh;	state Exp;
branches;
next	1.27;
commitid	mYsrBSKUkbYULdKt;

1.27
date	2009.03.18.18.34.19;	author seh;	state Exp;
branches;
next	1.26;
commitid	79MEonpmK9zOPxGt;

1.26
date	2009.03.18.18.20.05;	author seh;	state Exp;
branches;
next	1.25;
commitid	QYBbSyrKKuTQKxGt;

1.25
date	2008.12.12.17.11.31;	author seh;	state Exp;
branches;
next	1.24;
commitid	MuPLluIkxnmDscut;

1.24
date	2008.12.12.13.59.17;	author seh;	state Exp;
branches;
next	1.23;
commitid	eiHiACX3BPORobut;

1.23
date	2008.12.09.15.56.14;	author seh;	state Exp;
branches;
next	1.22;
commitid	GhmGqA8SQBSX8Ott;

1.22
date	2008.12.05.16.32.12;	author seh;	state Exp;
branches;
next	1.21;
commitid	URaWZkvY7PTctitt;

1.21
date	2008.11.27.10.56.20;	author seh;	state Exp;
branches;
next	1.20;
commitid	2SdragqFDG0PRest;

1.20
date	2008.11.18.09.45.01;	author seh;	state Exp;
branches;
next	1.19;
commitid	qNy2DpX2cSlqL4rt;

1.19
date	2008.10.22.09.24.56;	author seh;	state Exp;
branches;
next	1.18;
commitid	HjE2kfWuwgAmwBnt;

1.18
date	2008.04.07.14.01.20;	author seh;	state Exp;
branches;
next	1.17;
commitid	RqMkf6rLQsrNpbYs;

1.17
date	2008.04.04.16.02.32;	author seh;	state Exp;
branches;
next	1.16;
commitid	KUzNcriNvTMdbOXs;

1.16
date	2008.04.04.15.48.10;	author seh;	state Exp;
branches;
next	1.15;
commitid	4LGH7zo3sfbm6OXs;

1.15
date	2008.01.30.16.13.09;	author seh;	state Exp;
branches;
next	1.14;
commitid	YNQu13t0lb0oksPs;

1.14
date	2007.11.19.17.40.34;	author seh;	state Exp;
branches;
next	1.13;
commitid	FiOhb4GNu83Y7dGs;

1.13
date	2007.11.19.17.29.51;	author seh;	state Exp;
branches;
next	1.12;
commitid	r3HE2LioWzyT3dGs;

1.12
date	2007.11.07.14.15.04;	author seh;	state Exp;
branches;
next	1.11;
commitid	EGTWia6z4yxOmEEs;

1.11
date	2007.08.31.09.13.43;	author seh;	state Exp;
branches;
next	1.10;
commitid	EzTQ0RGdjJmyTSvs;

1.10
date	2007.08.31.09.10.11;	author seh;	state Exp;
branches;
next	1.9;
commitid	OXbwudxk1sD0SSvs;

1.9
date	2007.03.21.10.55.46;	author seh;	state Exp;
branches;
next	1.8;

1.8
date	2007.01.17.11.19.50;	author seh;	state Exp;
branches;
next	1.7;

1.7
date	2006.12.29.16.30.40;	author seh;	state Exp;
branches;
next	1.6;

1.6
date	2006.12.05.16.36.45;	author seh;	state Exp;
branches;
next	1.5;

1.5
date	2006.12.05.14.45.44;	author galak;	state Exp;
branches;
next	1.4;

1.4
date	2006.11.27.14.24.39;	author seh;	state Exp;
branches;
next	1.3;

1.3
date	2006.11.27.11.42.55;	author seh;	state Exp;
branches;
next	1.2;

1.2
date	2006.08.18.14.17.00;	author seh;	state Exp;
branches;
next	1.1;

1.1
date	2005.08.23.08.54.14;	author seh;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2005.08.23.08.54.14;	author seh;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2005.09.06.10.07.52;	author seh;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2006.02.06.14.19.55;	author seh;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	2006.02.14.09.52.34;	author seh;	state Exp;
branches;
next	1.1.1.5;

1.1.1.5
date	2006.03.13.17.44.05;	author seh;	state Exp;
branches;
next	1.1.1.6;

1.1.1.6
date	2006.03.14.16.22.26;	author seh;	state Exp;
branches;
next	1.1.1.7;

1.1.1.7
date	2006.03.29.14.43.09;	author seh;	state Exp;
branches;
next	1.1.1.8;

1.1.1.8
date	2006.04.06.14.36.24;	author seh;	state Exp;
branches;
next	1.1.1.9;

1.1.1.9
date	2006.05.16.14.20.51;	author seh;	state Exp;
branches;
next	1.1.1.10;

1.1.1.10
date	2006.05.30.14.08.26;	author seh;	state Exp;
branches;
next	1.1.1.11;

1.1.1.11
date	2006.06.15.09.35.15;	author seh;	state Exp;
branches;
next	1.1.1.12;

1.1.1.12
date	2006.11.27.11.19.16;	author seh;	state Exp;
branches;
next	1.1.1.13;

1.1.1.13
date	2007.01.17.10.48.12;	author seh;	state Exp;
branches;
next	1.1.1.14;

1.1.1.14
date	2007.11.06.15.44.41;	author seh;	state Exp;
branches;
next	1.1.1.15;
commitid	AdKoH3Xx8FxdUwEs;

1.1.1.15
date	2008.04.04.10.51.51;	author seh;	state Exp;
branches;
next	1.1.1.16;
commitid	GVikqE6sLnKPsMXs;

1.1.1.16
date	2008.12.05.14.25.44;	author seh;	state Exp;
branches;
next	1.1.1.17;
commitid	A4gB7k6PjRrWLhtt;

1.1.1.17
date	2009.03.18.17.53.24;	author seh;	state Exp;
branches;
next	;
commitid	2ZWvH4Ejl9NUBxGt;


desc
@@


1.29
log
@Use the gcc in the user's path for buildcc rather than forcing /usr/bin
@
text
@#!/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, stuarth@@freescale.com, 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`);
chomp($_        = `which gcc`);
($gccpath)      = m,(.+)/,;
$top  = $FindBin::Bin;
$bdir = "/opt";
$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/ltib/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.28 $',
    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      => "$gccpath/gcc -B$gccpath//",
    buildcxx     => "$gccpath/g++ -B$gccpath//",
    buildcpp     => "$gccpath/cpp",
    buildld      => "$gccpath/ld",
    buildstrip   => "$gccpath/strip",
    buildranlib  => "$gccpath/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,
    no_sudo_check => 0,  # fc9 work-around

    help         => 0,
};

use strict 'vars';
use vars qw($cf $config_deps $build_deps $install_deps $tspec
            $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
        --no-sudo     : don't check sudo, work around for broken sudo (fc9)
        --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},
        "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->{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
$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;
}


sub f_prep
{
    my ($key) = @@_ or ();
    return build_rpm( key      => $key,
                      leavesrc => 1,
                      force    => 1,
                      rpmopts  => '-bp');
}

sub f_scbuild
{
    my ($key) = @@_ or ();
    return build_rpm( key      => $key,
                      leavesrc => 1,
                      force    => 1,
                      unpack   => 'no',
                      rpmopts  => '-bc --short-circuit');
}

sub f_scinstall
{
    my ($key) = @@_ or ();
    return build_rpm( key      => $key,
                      leavesrc => 1,
                      force    => 1,
                      unpack   => 'no',
                      rpmopts  => '-bi --short-circuit');
}

sub f_scdeploy
{
    validate_sn();
    my ($key) = @@_;
    my $sn;
    if($key) {
        $sn    = $$key->{sn};
        die("f_scdeploy: $key has no spec name set") unless $sn;
    } else {
        die("f_scdeploy: no spec name passed") unless $cf->{sn};
        $sn    = $cf->{sn};
        $key   = get_key_by_sn($sn);
    }
    $tspec = "$cf->{rpmdir}/SPECS/$sn.spec";
    unlink($tspec) if -f $tspec;

    # we expect the user to have run these before
    # f_scbuild($key) or die();
    f_scinstall($key) or return;

    my $spec = get_spec($sn) or die("can't find spec file for $sn");
    my $tok = parse_spec($spec, 1) or die();
    open(SPEC, ">$tspec") or die("can't open $tspec for write: $!");
    print SPEC <<TXT;
${\( exists $tok->{base} ? "%define base $tok->{base}" : '' )}
%define pfx $tok->{pfx}
%define __os_install_post %{nil}

Summary         : test deployment of $tok->{name}
Name            : $tok->{name}
Version         : $tok->{version}
Release         : $tok->{release}
License         : $tok->{license}
Vendor          : Freescale
Packager        : auto-generated
Group           : test/test
BuildRoot       : $tok->{buildroot}
Prefix          : %{pfx}
Autoreqprov     : no

%Description
%{summary}

From an scdeploy !!!!

%Prep

%Build

%Install

%Clean
rm -rf \$RPM_BUILD_ROOT

%Files$tok->{files}
TXT
    close SPEC;

    # invalidate the cache entry as we want to find the new one next
    get_spec($sn, 'del') or die("can't find spec file for $sn");

    my $ret = build_rpm( key     => $key,
                         unpack  => 'no',
                         rpmopts => '-bb');
    unlink($tspec);
    return $ret;
}

sub f_addsrpms
{
    require Ltibaddsrpms;
    return  addsrpms();
}

sub f_patchmerge
{
    warn(<<TXT), return 1 if $echo;

Cannot run patchmerge with --dry-run

TXT
    die(<<TXT) unless $cf->{sn};

-m patchmerge only works on one package which you must supply with the
-p <pkg> option
TXT

    validate_sn();
    my ($specout, $specin) = get_spec($cf->{sn})
                                   or die("can't find spec file for $cf->{sn}");
    my $spec = $specin || $specout;
    my $tok = parse_spec($spec) or die();
    my $pkg_dir_name = $tok->{pkg_dir_name};
    die(<<TXT) unless -d "$cf->{rpmdir}/BUILD/$pkg_dir_name";

Cannot generate a patch for $spec,
the directory: $cf->{rpmdir}/BUILD/$pkg_dir_name
is missing (maybe you haven't built it with -m scbuild ?)
TXT
    die(<<TXT) unless $tok->{prep};

Can't find the prep token to insert the patch unpack command
TXT

    die(<<TXT) if -e "$cf->{rpmdir}/BUILD/$pkg_dir_name.modified";

The directory '$cf->{rpmdir}/BUILD/$pkg_dir_name.modified'
already exists.  You need to move this out the way before running
patchmerge.  Patchmerge will preserve your working copy of the
source by moving:
   $cf->{rpmdir}/BUILD/$pkg_dir_name
to:
   $cf->{rpmdir}/BUILD/$pkg_dir_name.modified
TXT

    # read in the spec file and work out the next patch number to use
    my ($num, @@p);
    local $/ = undef;
    open(SPEC, $spec) or die("can't open $spec : $!");
    local $_ = <SPEC>;
    close(SPEC);
    (@@p) = m,^patch(\d*),gim;
    @@p = sort { $a <=> $b } @@p;
    $num = $p[-1] || 0;
    $num++;

    # ensure his patch name is not already in the gpp (use seconds since 1970)
    my $pname = "$tok->{name}-$tok->{version}-$cf->{stime}.patch";

    system_nb(<<TXT) == 0 or die;
set -x
mv $cf->{rpmdir}/BUILD/$pkg_dir_name $cf->{rpmdir}/BUILD/$pkg_dir_name.modified
cd $cf->{rpmdir}/BUILD/$pkg_dir_name.modified
make distclean
cd -
$cf->{rpmbuild} --dbpath $cf->{rpmroot}/$cf->{rpmdb} --define '_target_cpu $pcf->{RPMTARCH}' --define '_topdir $cf->{rpmdir}' --define '_prefix $cf->{prefix}' --define '_tmppath $cf->{projtmp}' --define '_mandir $cf->{prefix}/$cf->{mandir}' --define '_sysconfdir $cf->{sysconfdir}' -bp $specout >/dev/null || exit 1
cd $cf->{rpmdir}/BUILD
diff --exclude CVS --exclude .git -uNr $pkg_dir_name $pkg_dir_name.modified > $cf->{lpp}/$pname
rm -rf $cf->{rpmdir}/BUILD/$pkg_dir_name
TXT

    open(SPEC, ">$spec.bak") or die("can't open $spec.bak for writing: $!");
    print SPEC $_;
    close SPEC;
    s,^(BuildRoot\s*:.*),Patch$num          : $pname\n$1,mi;
    s,^(%[Pp]rep.+?)(?=\s*(^%[Bb]uild|\Z)),$1\n%patch$num -p1,sm;

    open(SPEC, ">$spec") or die("can't open $spec for writing : $!");
    print SPEC $_;
    close SPEC;
    print <<TXT;

A patch has been generated and placed in:

    $cf->{lpp}/$pname

You need to check this and removed any bogus entries that may exist
due to and incomplete "make distclean"

In addition, the specfile:
    $spec
had been edited, and an entry for the new patch has been put in there,
a backup of the original specfile is in
    $spec.bak

TXT
    return 1;
}

sub f_listpkgseula
{
    return f_listpkgs('eula');
}

sub f_listpkgstw
{
    return f_listpkgs('twiki');
}

sub f_listpkgscsv
{
    return f_listpkgs('csv');
}

sub f_listpkgs
{
    my $mode = shift || '';
    require Ltiblistpkgs;
    return listpkgs($mode);
}

sub write_release_info
{
    my ($file, $tag, $rel) = @@_;
    $tag ||= get_scm_tag() || 'none';
    $rel ||= 'none';
    my $wtag = get_scm_branch() || 'none';

    open(RI, ">$file") or warn("open: >$file : $!"), return;
    print RI <<TXT;
Release date = $cf->{gmsdate} UTC
Release user = $cf->{username}
Release host = $cf->{hostname}
Release dir  = $cf->{top}
SCM wtag     = $wtag
SCM tag      = $tag
Release tag  = $rel
App version  = $cf->{app_version}
TXT
    close RI;
    return 1;
}

sub f_release
{
    require Ltibrelease;
    return release_main(fullbsp => $cf->{fullbsp});
}

sub f_trelease
{
    require Ltibrelease;
    return release_main(fullbsp => $cf->{fullbsp}, warnonly => 1);
}


#############################################
# application support subroutines
#############################################

sub check_app_is_configed
{
    my ($missing, $var) = ("");

    foreach $var (qw/rfsbase rpmdir rpmdb bin_path
                     defpfx lpp spoof_path config_dir
                     platforms_dir mainlkc conf defdist pfx buildarch
                     top home username path_std
                     pre_install_deps/ ) {
            $missing .= "$var " unless $cf->{$var};
        die <<TXT if $missing;

This utility uses configuration values that are set in:

$cf->{rcfile}

The following configuration symbols have not been set:

$missing

TXT
    }
    # ltib should be run from the ltib directory
    if( ! -d "./config/platform" ) {
        die <<TXT;

Cannot find directory: ./config/platforms

This does not look like an ltib directory.  To run ltib, you should
cd first to the directory: $cf->{top}

TXT
    }
    if($cf->{external}) {
        $cf->{pp_list} = [ 'gpp_stage', 'cpp_stage' ];
    } else {
        @@{$cf->{pp_list}} = grep { ! m,^\s*$, && ! m,\s*#, }
                                                      split(/\s+/, $cf->{pps});
    }
    warn "No remote package pools defined\n" unless @@{$cf->{pp_list}};

    return 1;
}

sub load_system_config
{
    my($cf) = @@_;

    # if passed, the cfile should exist
    die <<TXT if $cf->{rcfile} && ! -f $cf->{rcfile};
The passed rcfile: $cf->{rcfile} is missing
TXT
    foreach my $rc ($cf->{rcfile}, "$cf->{home}/.ltibrc", "$cf->{top}/.ltibrc"){
        if(-f $rc) {
            my $hr = parse_config(fn => $rc) or die;
            $hr->{rcfile} = $rc;
            while( my($k,$v) = each(%$hr) ) {
                $cf->{$k} = $v;
            }
            # Do a one pass, simple expansion for a few config items
            use warnings FATAL => 'uninitialized';
            foreach my $k (qw/CCACHE_DIR _rpmdir/) {
                next unless $cf->{$k};
                $cf->{$k} =~ s,\$([\w]+),$cf->{$1},g;
            }
            last;
        }
    }
    die(<<TXT) unless $cf->{rcfile};
top = $cf->{top}
could not locate resource file:
    $cf->{rcfile}
    $cf->{home}/.ltibrc
    $cf->{top}/.ltibrc
TXT
    return 1;
}


sub build_host_rpms
{
    my ($host_pkg_dev) = @@_;

    # save some old config values
    my $sav = {};
    my @@sav_list = qw/rpmroot rpmipfx prefix sysconfdir rpmdir rpmdb tmppath
                      nodeps force hostinst reinstall dodrop sn _rpmdir
                      preconfig enrootn something_got_built plat_dir/;
    foreach my $k (@@sav_list) {
        $sav->{$k} = $cf->{$k};
    }
    # override with suitable host values (some host pkgs are not relocatable)
    $cf->{rpmroot}       = '/';                  # rpm (ch)root path
    $cf->{rpmipfx}       = '/';                  # install prefix
    $cf->{prefix}        = "$cf->{defpfx}/usr";  # build prefix
    $cf->{sysconfdir}    = "$cf->{defpfx}/etc";  # config files
    $cf->{rpmdir}        = "$cf->{defpfx}/usr/src/rpm";
    $cf->{_rpmdir}       = "$cf->{rpmdir}/RPMS";
    $cf->{rpmdb}         = "$cf->{defpfx}/var/lib/rpm";
    $cf->{tmppath}       = $cf->{projtmp};
    $cf->{nodeps}        = 1;
    $cf->{force}         = 0 if $host_pkg_dev == 0;
    $cf->{hostinst}      = 1 if $host_pkg_dev == 0;
    $cf->{reinstall}     = 0;
    $cf->{enrootn}       = 0;
    $cf->{plat_dir}      = "config/platform/host";

    # pull in and parse the host platform config
    if($host_pkg_dev == 1) {
        # we are working on host packages
        ltib_host_config();
        $cf->{dodrop} = 'ask';
    } else {
        # this is the case where we are doing just the basic host packages
        $cf->{dodrop} = 'no';
        $cf->{preconfig} = $cf->{hostconfig};
        $cf->{sn} = '';
    }
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{preconfig});
    check_platform_config($pcf);
    setup_env_vars($cf, $pcf);
    check_toolchain_setup($pcf);

    # we can get here at install time, or later config of host packages
    if($cf->{hostcf} && $cf->{mode} ne 'config' ) {
        &{"f_" . $cf->{mode}}()
                    or die("\n\nf_$cf->{mode}() returned an error, exiting\n");
        exit 0;
    }

    # build host rpms
    f_buildrpms() or die;

    # restore
    foreach my $k (@@sav_list) { $cf->{$k} = $sav->{$k} }
    undef $sav;

    return 1;
}

sub host_checks
{
    # do not attempt to re-install host packages once
    # we have got through here completely once
    return 1 if -f $cf->{host_wait_warning} && (! $cf->{dltest} 
                                                  || $cf->{sn} || $cf->{batch});

    # check the basic build host package dependencies
    check_basic_deps() or die;

    # check that this host has the necessary applications available
    # to at least install binary rpms
    check_sudo_setup() unless $cf->{no_sudo_check};

    # after this may take some time to complete
    print <<TXT unless $cf->{dltest};

Installing host support packages.

This only needs to be done once per host, but may take up to
an hour to complete ...

If an error occurs, a log file with the full output may be found in:
$cf->{logfile}

TXT

    # remove the previous logfile
    unlink($cf->{logfile});

    # redirect output to logfile
    redirect(">> $cf->{logfile}");

    # use the host's rpm to bootstrap a known version of rpm
    check_rpm_setup() or die;

    # check/create required directories
    check_dirs();

    # turn on output again as the user may have to interact
    redirect();

    # redirect output to logfile
    redirect(">> $cf->{logfile}");

    # build and install rpms for the host
    build_host_rpms(0);

    redirect();
    touch($cf->{host_wait_warning});
    return 1;
}

sub pre_build_checks
{
    ltib_config();
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{preconfig});
    check_platform_config($pcf);
    setup_rpmdb();
    setup_env_vars($cf, $pcf);
    process_full_rebuild();
    legacy_rpm_fixups();
    check_spoofing();
    check_toolchain_setup($pcf);
    check_merge_updates($pcf);
    system("rm -f $cf->{tmppath}/rpm-tmp.*");

    return 1;
}

sub setup_env_vars
{
    my($cf, $pcf) = @@_;

    $ENV{UNSPOOF_PATH} =
                 "$cf->{bin_path}:"
                 . "$cf->{defpfx}/usr/bin:"
                 . ($pcf->{TOOLCHAIN_PATH} ? "$pcf->{TOOLCHAIN_PATH}/bin:" : "")
                 .  $cf->{path_std};
    $ENV{SPOOF_PATH} =
                 "$cf->{bin_path}:"
                 .  ($pcf->{TOOLCHAIN_PREFIX} ? "$cf->{spoof_path}:" : "")
                 .  $ENV{UNSPOOF_PATH};
    $ENV{PATH}      = $ENV{SPOOF_PATH};
    $ENV{TOP}       = $cf->{top};
    $ENV{DEV_IMAGE} = $cf->{rpmroot};
    $ENV{DEFPFX}    = $cf->{defpfx};
    $ENV{BUILDCC}   = $cf->{buildcc};
    $ENV{BUILDCXX}  = $cf->{buildcxx};
    $ENV{BUILDCPP}  = $cf->{buildcpp};
    $ENV{BUILDLD}   = $cf->{buildld};
    $ENV{BUILDSTRIP}= $cf->{buildstrip};
    $ENV{BUILDARCH} = $cf->{buildarch};
    $ENV{BUILDRANLIB} = $cf->{buildranlib};
    $ENV{CC}        = $cf->{cc};
    $ENV{CXX}       = $cf->{cxx};
    $ENV{LD}        = $cf->{ld};
    $ENV{AR}        = $cf->{ar};
    $ENV{GNUTARCH}  = $pcf->{GNUTARCH};
    $ENV{LINTARCH}  = $pcf->{LINTARCH};
    $ENV{CFGHOST}   = $pcf->{CFGHOST};
    $ENV{TOOLCHAIN} = $pcf->{TOOLCHAIN} || "";
    $ENV{TOOLCHAIN_PREFIX} = $pcf->{TOOLCHAIN_PREFIX};
    $ENV{TOOLCHAIN_PATH} = $pcf->{TOOLCHAIN_PATH};
    $ENV{PLATFORM_PATH} = "$cf->{top}/$cf->{plat_dir}";
    $ENV{CONFIG_DIR}    = $cf->{config_dir};
    $ENV{TOOLCHAIN_TYPE} = $pcf->{TOOLCHAIN_TYPE} || "";
    $ENV{PLATFORM}      = $pcf->{PLATFORM};
    $ENV{CPU}           = $pcf->{CPU} || "";
    $ENV{ENDIAN}        = $pcf->{ENDIAN} || "big";
    $ENV{PKG_U_BOOT_CONFIG_TYPE} = $pcf->{PKG_U_BOOT_CONFIG_TYPE} || "";
    $ENV{PKG_U_BOOT_BUILD_ARGS}  = $pcf->{PKG_U_BOOT_BUILD_ARGS}  || "";
    $ENV{UCLIBC} = $pcf->{UCLIBC} || "";
    $ENV{DYNAMIC_LINKER} = $pcf->{DYNAMIC_LINKER} || "";
    $ENV{LIBC_HACKING} = $pcf->{LIBC_HACKING} || "";
    $ENV{TOOLCHAIN_CFLAGS} = $pcf->{TOOLCHAIN_CFLAGS} || "";
    $ENV{PKG_CONFIG_PATH} = "$cf->{rpmroot}/usr/lib/pkgconfig" || "";
    $ENV{PKG_DIRECTFB}    = $pcf->{PKG_DIRECTFB} || "";
    $ENV{LTIB_BATCH}      = $cf->{batch} || "";
    $ENV{PKG_BUSYBOX}    = $pcf->{PKG_BUSYBOX} || "";
    $ENV{PKG_SYSVINIT}    = $pcf->{PKG_SYSVINIT} || "";
    $ENV{INITTAB_LINE}    = $pcf->{INITTAB_LINE} || "";
    $ENV{SOFT_FP_ARCH} = $pcf->{SOFT_FP_ARCH} || "";
    $ENV{GLIBC_WANT_KERNEL_HEADERS} = $pcf->{GLIBC_WANT_KERNEL_HEADERS} || "";

    if($cf->{enrootn}) {
        $ENV{DISTCC_HOSTS} = $cf->{DISTCC_HOSTS}
                       if ! defined $ENV{DISTCC_HOSTS} && $cf->{DISTCC_HOSTS};
        $ENV{DISTCC_TCP_CORK} = $cf->{DISTCC_TCP_CORK}
         if ! defined $ENV{DISTCC_TCP_CORK} && defined $cf->{DISTCC_TCP_CORK};
    	$ENV{MAKEFLAGS} = $cf->{MAKEFLAGS}
                             if ! defined $ENV{MAKEFLAGS} && $cf->{MAKEFLAGS};
        if(! defined $ENV{CCACHE_DIR} && $cf->{CCACHE_DIR}) {
            $ENV{CCACHE_DIR} = $cf->{CCACHE_DIR}; 
        }
        $cf->{buildcc} = "ccache $cf->{buildcc}" if  defined $ENV{CCACHE_DIR};
    }

    if($verbose) {
        foreach my $v (qw/PATH TOP DEV_IMAGE BUILDCC BUILDLD BUILDSTRIP
                          BUILDARCH BUILDRANLIB GNUTARCH LINTARCH CFGHOST
                          TOOLCHAIN_PREFIX PLATFORM_PATH
                          CPU PKG_U_BOOT_CONFIG_TYPE PKG_U_BOOT_BUILD_ARGS
                          UCLIBC CONFIG_DIR ENDIAN/ ) {
            warn("setting ENV{$v}=$ENV{$v}\n");
        }
    }

    foreach my $k ( grep { m,(_PRECONFIG|_WANT_|SYSCFG_), } keys %$pcf ) {
        if($pcf->{$k}) {
            warn("setting ENV{$k}=$pcf->{$k}\n") if $verbose;
            $ENV{$k} = $pcf->{$k};
        } else {
            delete $ENV{$k};
        }
    }
    return 1;
}

sub process_full_rebuild
{
    # lock ltib
    if(! try_lock_file($cf->{lock_file}, $$) ) {
        warn("$cf->{lock_file} locked\n");
        die unless $cf->{ignorelock};
    }

    # process any toolchain switch
    save_binary_rpms();

    return 1 unless -f "$cf->{preconfig}.old";

    $ppcf = parse_dotconfig("$cf->{preconfig}.old");
    if(-M "$cf->{preconfig}.old" <= -M $cf->{preconfig}) {
        return 1;
    }

    if(system_nb("diff -qN $cf->{preconfig} $cf->{preconfig}.old >/dev/null")) {
        $cf->{do_deploy} = 1;
    }

    my $need_frb = 0;
    foreach my $dep (split(/[\s\n]+/,$cf->{frb_deps})) {
        my $cur = $pcf->{$dep}  || "";
        my $pre = $ppcf->{$dep} || "";
        if( $cur ne $pre ) {
            $need_frb= 1;
            print("CONFIG_$dep forced a full rebuild\n");
            last;
        }
    }
    if($need_frb && ! $cf->{dry}) {
        f_clean() if -e "$cf->{rpmroot}/$cf->{rpmdb}/Name";
        $ENV{LTIB_FULL_REBUILD} = "y";
    }
    system_nb("cp -f $cf->{preconfig} $cf->{preconfig}.old") unless $cf->{dry};
    return 1;
}

sub save_binary_rpms
{
    die("pcf  not defined") unless $pcf;

    my $newarch = g2larch($pcf->{LINTARCH}) or die;
    my $cfn     = '.config';
    my $dir     = $cf->{_rpmdir};
    my $nset    = gen_build_setup($pcf);
    my $ts      = "$cf->{stime}.00";
    my $oset    = '';
    my $oldarch;
    my $pon     = ! $cf->{dltest};

    # figure out if there has been a change that invalidates the current rpms
    if(-f "$dir/$cfn") {
        my $lcf  = parse_dotconfig("$dir/$cfn");
        $oldarch = g2larch($lcf->{LINTARCH});
        unlink("$dir/$cfn"), die("old LINTARCH not in $dir/$cfn, removing\n")
                                                               unless $oldarch;
        local $/ = undef;
        open(F, "$dir/$cfn") or die("open $dir/$cfn : $!");
        $oset = <F> || '';
        close F;
    } else {
        # fresh install or legacy updated project, assume okay
        $oset = $nset;
    }
    write_file("$dir/$cfn", $nset);

    return 1 if $oset eq $nset;


    print "Flushing old rpm set\n" if $pon;

    # This is used to signal u-boot/kernel to do distcleans as their
    # sources are commonly left unpacked.  The only alternative is
    # to deny continuing unpacked builds (clobber).
    $ENV{LTIB_FULL_REBUILD} = 'y';

    # we need to switch to a new set of rpms (or remove)
    if($pcf->{FEAT_CACHE_RPMS} || ! defined($pcf->{FEAT_CACHE_RPMS}) ) {
        if(glob("$dir/$oldarch/*.rpm")) {
            if(! -f "$dir/$oldarch/$cfn") {
                write_file("$dir/$oldarch/$cfn", $oset);
            }
            while(-d "$dir/$ts") { $ts += 0.01; }
            print("Saving rpms from $oldarch to $dir/$ts\n") if $pon;
            rename("$dir/$oldarch", "$dir/$ts")
                       or die("rename $dir/$oldarch", "$dir/$ts : $!");
        } else {
            print "No binary rpms to save\n" if $pon;
            system_nb("rm -rf $dir/$oldarch") if -e "$dir/$oldarch";
        }

        # look for an existing set of binary rpms matching the new settings
        opendir(DIR, $dir) or die("opendir: $dir: $!");
        while( defined(my $ent = readdir(DIR)) ) {
            next unless -d "$dir/$ent";
            next if $ent eq '.' || $ent eq '..' || $ent eq $newarch;
            next unless -f "$dir/$ent/$cfn";
            system_nb("rm -rf $dir/$ent"), next
                                             unless glob("$dir/$ent/*.rpm");
            local $/ = undef;
            open(F, "$dir/$ent/$cfn") or die("open $dir/$ent/$cfn : $!");
            my $ck = <F> || '';
            close F;
            if($ck eq $nset) {
                print "Using cached pre-built packages for $pcf->{PLATFORM} ",
                      "from rpm/$ent\n" if $pon;
                die "$dir/$newarch already exists" if -d "$dir/$newarch";
                rename("$dir/$ent", "$dir/$newarch")
                     or die "rename: $dir/$ent, $dir/$newarch : $!";
                last;
            }
        }
        closedir DIR;
        mkdir("$dir/$newarch", 0755);
        write_file("$dir/$newarch/$cfn", $nset);

    } else {
        print "Removing binary rpms\n" if $pon;
        system_nb("rm -f $dir/$oldarch");
    }
    return 1;
}

sub gen_build_setup
{
    my $hr = shift or die;
    my $buf = '';
    foreach my $k (split(/[\s\n]+/, $cf->{frb_deps})) {
        $buf .= "CONFIG_$k=" . ($hr->{$k} || '') . "\n";
    }
    return $buf;
}

sub process_pkg_deps
{
    my ($key, $spec_name) = @@_;

    # return if there is no previous platform config structure
    return 1 unless $ppcf;

    my $spec = get_spec($spec_name) or return;

    # assume done if the specfile was touched after the .config file
    return 1 if -M $spec <= -M $cf->{preconfig};

    foreach my $dep ( @@{$config_deps->{$key}} ) {
        next unless $pcf->{$key} && $ppcf->{$key};
        my $cur = $pcf->{$dep}  || "";
        my $pre = $ppcf->{$dep} || "";
        if( $cur ne $pre ) {
            warn "$dep has changed, $spec_name needs a rebuild\n"
                                            unless $cf->{mode} eq 'release';
            touch($spec);
        }
    }
    return 1;
}

sub process_pkg_triggers
{
    my ($key) = @@_;
    return unless exists $build_deps->{$key} || $install_deps->{$key};
    foreach my $dep ( @@{$build_deps->{$key}} ) {
        if(exists $$dep->{was_en} && $$dep->{was_en}) {
            $$dep->{en} = 1;
        }
        $$dep->{build} = 1;
        warn "$$dep->{sn} rebuild forced by $$key->{sn}\n" if $$dep->{en};
    }
    if($key eq 'PKG_KERNEL') {
        foreach my $mod ( grep { m,PKG_[\w_]+_MOD$, } mk_buildlist() ){
            if(exists $$mod->{was_en} && $$mod->{was_en}) {
                $$mod->{en} = 1;
            }
            $$mod->{build} = 1;
            warn "$$mod->{sn} rebuild forced by $$key->{sn}\n" if $$mod->{en};
        }
    }
    foreach my $dep ( @@{$install_deps->{$key}} ) {
        if(exists $$dep->{was_en} && $$dep->{was_en}) {
            $$dep->{en} = 1;
        }
        $$dep->{install} = 1;
        warn "$$dep->{sn} install forced by $$key->{sn}\n" if $$dep->{en};
    }
}

sub build_rev_triggers
{
    return if defined $rev_install_deps;

    foreach my $hr ($build_deps, $install_deps) {
        foreach my $k ( keys %$hr ) {
            foreach my $dep ( @@{$hr->{$k}} ) {
                push @@{$rev_install_deps->{$dep}}, $k;
            }
        }
    }
}

sub has_rev_trigger
{
    my ($key) = @@_;

    build_rev_triggers();

    return exists $rev_install_deps->{$key} ? 1: 0;
}

sub get_rev_triggers
{
    build_rev_triggers();
    return keys %$rev_install_deps;
}

sub process_pkg_rev_triggers
{
    my ($key) = @@_;

    build_rev_triggers();

    # it is valid that a package may not have a key during development
    return unless $key;

    foreach my $k (@@{$rev_install_deps->{$key}}) {
        next unless defined $$k->{sn};
        warn("re-installing $$k->{sn} because $$key->{sn} was dropped\n");
        $$k->{install} = 1;
    }
}

sub pkg_cache_init
{
    return unless exists $pcac->{mk_buildlist};

    # clear any pre-existing keys so package maps work on multiple runs
    foreach my $key (mk_buildlist()) {
        undef $$key
    }

    # this was changed from an outer lexical to global to keep older
    # version from warning about 'not staying shared'
    $pcac = {};
}

#
# Process build list.
# Cycle through all packages and build a list of keys for each package,
# these keys are placed in a build ordered array.
# For a key to be added, it needs to be in both the platforms .config
# file and in one of the pkg_map files.
# As the keys are process, attributes for that key are saved into
# a hash that is referenced using a soft reference to the key name
#
sub mk_buildlist
{
    die("no platform config has been parsed (\$pcf)") unless defined $pcf;

    return @@{$pcac->{mk_buildlist}} if exists $pcac->{mk_buildlist};

    warn("PROFILE:: mk_buildlist():\n", caller_stack(), "\n") if $cf->{prof};

    my $pre = '^([\w]+)\s*=\s*([\S]*)';
    my $key;
    local $_;

    # load up the main map
    my $map = "$cf->{config_dir}/userspace/pkg_map";
    open(MAP, $map) or die("open($map): $!");
    while(<MAP>) {
        chomp;
        next if m,^\s*$,;
        next if m,^\s*#,;
        m,$pre,o or warn("invalid token: $_"), next;
        $key = $1;
        $pcf->{$key} ||= '';
        push @@{$pcac->{mk_buildlist}}, $key;

        # if the package name is in the .config use that name, otherwise
        # use the one from the package map
        $$key->{sn} = $pcf->{$key} && $pcf->{$key} ne 'y' ?  $pcf->{$key} : $2;
        $$key->{en} = $pcf->{$key} ? 1 : 0;
        $cf->{pkg_map}{$2} = $$key->{en};
        warn "mk_buildlist: key=$key, sn=$$key->{sn}, en=$$key->{en}\n"
                                                            if $verbose;
    }
    close MAP;

    # load up the override map if present.
    $map = "$cf->{plat_dir}/pkg_map";
    if( -f $map ) {
        my $seen = {};
        local *read_pkg_map =
        sub {
            my ($fn) = shift;
            return if $seen->{$fn};
            $seen->{$fn} = 1;
            my $FH = IO::File->new($fn) or die("open $fn : $!");
            while(<$FH>) {
                proc_pkg_map($_)
            }
            delete($seen->{fn});
        };
        local *proc_pkg_map =
        sub {
            local $_ = shift;
            chomp;
            return if m,^\s*$,;
            return if m,^\s*#,;
            m,$pre,o or warn("invalid token: $_"), return;
            $key = $1;
            if($key eq 'source') {
                read_pkg_map("$cf->{config_dir}/userspace/$2");
                return;
            }
            if(! exists $$key->{sn}) {
                if(! exists $pcf->{$key}) {
                    warn("$key in $map is not selectable\n") if $verbose;
                    $pcf->{$key} = '';
                }
                # insert just before sysconfig (3rd from last)
                splice(@@{$pcac->{mk_buildlist}}, -3, 0, $key);
            }
            $$key->{sn} = $pcf->{$key} && $pcf->{$key} ne 'y' ?  $pcf->{$key} : $2;
            $$key->{en} = $pcf->{$key} ? 1 : 0;
            $cf->{pkg_map}{$2} = $$key->{en};
            warn "mk_buildlist (plat/pkg_map): key=$key, sn=$$key->{sn}, en=$$key->{en}\n"
                                                            if $verbose;
        };
        read_pkg_map($map);
    }

    # A user can specifiy -p <pkg>.  Without the '.spec' extention
    # means we should lookup the specfile name from the package.
    # If the '.spec' extension is passed, then the user means
    # the actual spec file name.  This is needed
    # so we can ask to build a specific package without regard to
    # whether it's part of our current platform configuration
    if($cf->{sn}) {
        # bug alert: this is a one-shot, you can't later run pkg_cache_init
        if( substr($cf->{sn}, -5, 5) eq ".spec" ) {
            substr($cf->{sn}, -5, 5) = "";
        } else {
            my ($lu_pkg, $pkg, $pkg_len, $found);
            $pkg     = $cf->{sn};
            $pkg_len = length($cf->{sn});
            foreach $key ( @@{$pcac->{mk_buildlist}} ) {
                $lu_pkg = get_pkg_name($key) or next;
                if( unpack("A" . $pkg_len, $lu_pkg) eq $pkg ) {
                    $found = $$key->{sn};
                    last;
                }
            }
            die <<TXT unless $found;

Cannot find spec file that contains the package name $pkg.
If necessary please give the whole spec file name (with the .spec extension).

TXT
            $cf->{sn} = $found;
        }
        pkg_iterate($cf->{sn});
    }

    return @@{$pcac->{mk_buildlist}};
}

# If a spec name is passed, turn off all packages except that one
# if no spec name is passed, restore all packages to their previous state
sub pkg_iterate
{
    my ($sn) = @@_;
    my $key = 'userpkg';

    foreach my $tkey (@@{$pcac->{mk_buildlist}}) {
        if($sn) {
            $$tkey->{was_en} = $$tkey->{en};
            $$tkey->{en} = 0;
            $key = $tkey if $$tkey->{sn} eq $sn;
        } else {
            $$tkey->{en} = $$tkey->{was_en};
        }
    }
    return 1 unless $sn;

    # if this spec name is unknown, fabricate a key
    unless(exists $$key->{sn}) {
        # this is not nice as pcac should be private to mk_buildlist
        push @@{$pcac->{mk_buildlist}}, $key;
        $$key->{sn} = $sn;
    }
    $$key->{en} = 1;
    $$key->{build} = 1 if $cf->{force};
    return 1;
}

sub validate_sn
{
    mk_buildlist();
}

sub get_key_by_sn
{
    my ($sn) = @@_;
    foreach my $key ( mk_buildlist() ) {
        return $key if $$key->{sn} eq $sn;
    }
    return 'userpkg';
}

# Return the name of a package referenced by key
# this is from the Name: field in the spec file, which
# may be different from the spec file name
# This is an ugly optimisation as the cost of parsing the spec files
# and reducing the macros is quite high
sub get_pkg_name
{
    my ($key) = @@_;
    return $$key->{pkg} if exists $$key->{pkg};

    my $sn = $$key->{sn} or return;
    my $spec = get_spec($sn) or return;
    my $tok = parse_spec($spec, 0, 'name') or die();
    $$key->{pkg} = $tok->{name};
    return $$key->{pkg};
}

sub remove_unselected_pkgs
{
    # don't do this if user is working on a single package
    return 1 if $cf->{sn} || $cf->{dodrop} eq 'no';
    local $_;
    my $cmd = "$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -qa "
            . "--queryformat '%{name} '";
    $_ = qx($cmd);
    die $cmd if $?;
    my @@installed = split(/[\s\n]+/);
    my @@drop_list = ();
    my $pkg2key   = {};
    my ($key, $pkg);

    mk_buildlist();
    foreach my $inst ( @@installed ) {
        if(exists($cf->{pkg_map}{$inst}) && ! $cf->{pkg_map}{$inst}) {
            push(@@drop_list, $inst);

            # check to see if this package has any reverse triggers
            foreach $key ( get_rev_triggers() ) {
                $pkg = get_pkg_name($key) or next;
                if( $inst eq $pkg ) {
                    $pkg2key->{$inst} = $key;
                    last;
                }
            }
        }
    }
    warn("installed = ", join(", ", @@installed), "\n") if $verbose;
    warn("drop_list = ", join(", ", @@drop_list), "\n") if $verbose;
    return 1 unless @@drop_list;

    print "\n" if @@drop_list;
    foreach my $rpmname ( reverse(@@drop_list) ) {
        next if $rpmname =~ m,^(?:rpm-fs|tc-mtwk-|mtwk-lnx-|ppc-uclibc-tc|tc-fsl-|freescale-coldfire-),;
        if($cf->{dodrop} eq 'ask') {
            print "Drop package $rpmname ? (y|N)" if $cf->{dodrop} eq 'ask';
            $_ = <STDIN>;
            next unless m,^y,;
        }
        print "Dropping de-selected package $rpmname\n";
        my $cmd =   "$cf->{sudo} $cf->{rpm} "
               . "--root $cf->{rpmroot} --dbpath $cf->{rpmdb} "
               . "-e --allmatches --nodeps "
               . "--define '_tmppath $cf->{tmppath}' "
               . "$rpmname";
        print "$cmd\n";
        system_nb($cmd) == 0 or die unless $echo;
        process_pkg_rev_triggers($pkg2key->{$rpmname});
    }
    return 1;
}

# this extra block is to emulate static variables
sub BEGIN {
my $rpm_specs  = "";
my $pcf_distro = "";
my $defdist    = "";
my $plat_specs = "";
my $cache      = {};
my @@dirs       = ();

sub get_spec
{
    my ($sn, $mode) = @@_;
    return unless $sn;

    warn "get_spec($sn)\n" if $verbose;
    my $spec  = "$sn.spec";
    $mode ||= "";
    delete $cache->{$sn} if $mode eq 'del';
    $cache = {}          if $mode eq 'delall';

    if(   $rpm_specs  ne "$cf->{rpmdir}/SPECS"
       || $pcf_distro ne "$cf->{top}/$pcf->{DISTRO}"
       || $defdist    ne "$cf->{top}/$cf->{defdist}"
       || $plat_specs ne $cf->{plat_dir} ) {
        $rpm_specs   = "$cf->{rpmdir}/SPECS";
        $pcf_distro  = "$cf->{top}/$pcf->{DISTRO}";
        $defdist     = "$cf->{top}/$cf->{defdist}";
        $plat_specs  = $cf->{plat_dir};

        @@dirs    = ($rpm_specs, $plat_specs, glob("$pcf_distro/*") );
        push(@@dirs, glob("$defdist/*")) unless $defdist eq $pcf_distro;
        $cache = {};
    }
    if(exists $cache->{$sn} && -e $cache->{$sn}) {
        return wantarray ? @@{$cache->{$sn}} : $cache->{$sn}[0];
    }
    warn("PROFILE:: get_spec ($sn):\n", caller_stack(), "\n") if $cf->{prof};

    # try to locate the spec file
    foreach my $dir ( @@dirs ) {
        my $specpath = "$dir/$spec";
        my $specinpath = "";
        if(-e "$specpath.in") {
            $specinpath = "$specpath.in";
            $specpath   = "$cf->{projtmp}/$spec";
            open(SPECIN, $specinpath) or die("can't open $specinpath: $!");
            local $_ = <SPECIN>;
            close(SPECIN);

            my $tmplpath;
            my ($tmpl) = m,template\s*=\s*([\S]+),i or die("no template");
            foreach my $tdir ( $dir, @@dirs ) {
               $tmplpath = "$tdir/$tmpl", last if -e "$tdir/$tmpl";
            }
            die("no template") unless $tmplpath;
            warn("template: $tmplpath\n") if $verbose;

            my @@dlist = sort { -M $a <=> -M $b } ($specinpath, $tmplpath);
            if(! -f $specpath  || (-M $dlist[0] < -M $specpath) ) {
                expand_spec($specpath, $specinpath, $tmplpath);
                my ($atime, $mtime) = (stat($dlist[0]))[8,9];
                utime($atime, $mtime, $specpath);
            } elsif( -f $specpath ) {
                expand_spec("$specpath.new", $specinpath, $tmplpath);
                if( md5sum("$specpath.new") ne md5sum($specpath) ) {
                    unlink($specpath) or die("unlink $specpath : $!");
                    rename("$specpath.new", $specpath)
                             or die("rename $specpath.new, $specpath: $!");
                } else {
                    unlink("$specpath.new") or die("unlink $specpath.new : $!");
                }
            }
        }
        if(-e $specpath) {
           warn("spec files: [ $specpath, $specinpath ]\n") if $verbose;
           $cache->{$sn} = [ $specpath, $specinpath ];
           return wantarray ? @@{$cache->{$sn}} : $cache->{$sn}[0];
        }
    }
    delete $cache->{$sn};

    my $msg = <<TXT;

get_spec: can't find spec file $spec

in search any of the directories:
    $rpm_specs
    $plat_specs
    $pcf_distro

TXT
    $msg .= "    $defdist\n" if $defdist ne $pcf_distro;
    warn $msg if $verbose;
    return wantarray ? () : undef;
}
}

# check the most basic host services are available
sub check_basic_deps
{
    my @@failed = ();

    foreach my $dep ( split(/\n/, $cf->{pre_install_deps}) ) {
        next if $dep =~ m,^\s*$,;
        next if $dep =~ m,^\s*#,;
        $dep =~ s,^\s*,,;
        my ($pkg, $min) = split(/\s+/, $dep);
        my ($ver, $info) = get_ver($pkg);
        warn "pkg=$pkg, min=$min, got: $ver, $info\n" if $verbose;
        if($ver ne -1) {
            next if cmp_ver($ver, $min) >= 0;
            $info = $ver;
        }
        push @@failed, [ $pkg, $min, $info ];
    }
    return 1 unless @@failed;

    no strict 'vars';
    $~ = 'inst';
    $^ = 'inst_top';
    my @@ar;

format inst_top =
@@<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<  @@<<<<<<<<<<<<<<<
'Package',             'Minimum ver', 'Installed info'
@@<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<  @@<<<<<<<<<<<<<<<
'-------',             '-----------','---------------'
.
format inst =
@@<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<  @@*
$ar->[0],              $ar->[1],     $ar->[2]
.

    print(<<TXT);

ltib cannot be run because one or more of the host packages needed to run it
are either missing or out of date or not in ltib's standard path.  Please
install/upgrade these packages on your host.  If you have your own utilities
in non-standard paths, please add an entry into the .ltibrc file for example:

%path_std
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/my/own/exes

TXT
    foreach $ar ( @@failed ) {
       write;
    }
    print "\n";
    return;
}

sub check_platform_config
{
    my ($pcf) = @@_;

    # mandatory direct values
    my $ndef = "";
    foreach my $k (qw/TOOLCHAIN_PREFIX TOOLCHAIN_PATH
                   GNUTARCH LINTARCH CFGHOST PLATFORM/) {
        $ndef .= "$k " unless exists $pcf->{$k};
    }
    die "You must set configuration values in $cf->{preconfig} for:\n  $ndef\n"
                                                                   if $ndef;
    # indirect checks
    if( ! $pcf->{TOOLCHAIN} && $pcf->{TOOLCHAIN_PATH}) {
        die("Cannot find $pcf->{TOOLCHAIN_PREFIX}gcc in $pcf->{TOOLCHAIN_PATH}/bin") unless -x "$pcf->{TOOLCHAIN_PATH}/bin/$pcf->{TOOLCHAIN_PREFIX}gcc"
    }

    # these are "special cases"
    $pcf->{GNUTARCH} = $cf->{buildarch} if $pcf->{GNUTARCH} eq "buildarch";
    $pcf->{LINTARCH} = g2larch($cf->{buildarch}) or die
                                        if $pcf->{LINTARCH} eq "buildarch";
    $pcf->{CFGHOST} = "$cf->{buildarch}-linux"
                                        if $pcf->{CFGHOST} eq "buildarch";

    # RPM wants a value of ppc for powerpc platforms for its architecture
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH}) or die;
}

sub legacy_rpm_fixups
{
    # this is to catch mangled databases before we had a known rpm
    # once this has rippled through all users it could come out
    die "$cf->{rpm} has gone missing" unless -f $cf->{rpm};
    my $qo = `$cf->{rpm} --root $cf->{rpmroot} --dbpath -q $cf->{rpmdb} bogus-package 2>&1`;
    if($qo =~ m,unsupported hash version:,m) {
        system_nb("rm -rf $cf->{rpmdb}/*") == 0 or die;
    }

    # auto-migrate old rpmdb
    if(-e "$cf->{top}/rpmdb") {
        print "Updating to new rpm database placement, running a clean\n";
        my $sav = {};
        my @@sav_list   = qw/sn force rpmipfx rpmroot rpmdb tmppath enrootn/;
        foreach my $k (@@sav_list) {
            $sav->{$k} = $cf->{$k}
        }
        $cf->{rpmipfx} = $cf->{rpmroot};
        $cf->{rpmroot} = '/';
        $cf->{rpmdb}   = "$cf->{top}/rpmdb";
        $cf->{tmppath} = $cf->{projtmp};
        $cf->{enrootn} = 0;
        f_clean();
        pkg_cache_init();
        $cf->{sn}      = "mkdistclean.spec";
        $cf->{force}   = 1;
        f_buildrpms() or die;
        f_clean();
        pkg_cache_init();
        system_nb("rm -rf $cf->{rpmdb}");
        foreach my $k (@@sav_list) {
            $cf->{$k} = $sav->{$k}
        }
    }
    return 1;
}

sub check_rpm_ipfx()
{
    # IMPORTANT: make sure users don't install in /
    # Note:      rpmipfx is not set, this indicate a non-relocatable install
    #            even in this case the prefix must be at least /a/b/c
    #            for example: /opt/freescale/pkgs or /opt/ltib/pkgs

    die  "rpmroot undefined" if ! $cf->{rpmroot};
    my $ipath = $cf->{rpmroot};
    $ipath   .= $cf->{rpmipfx} if $cf->{rpmipfx};
    if($ipath =~ m,^\s*/+[^/]*/*\s*$, && $cf->{prefix} !~ m,^/+[^/]+/+[^/]+,) {
        die "Install path cannot be set to '$ipath' ",
            "with prefix: '$cf->{prefix}'\n",
            "rpmroot = $cf->{rpmroot}, rpmipfx = $cf->{rpmipfx}";
    }
}

sub setup_rpmdb
{
    if($cf->{enrootn}) {
        $cf->{rpmroot}  = $cf->{rfsbase};
        $cf->{rpmroot} .= "/R$cf->{rootn}" if $cf->{rootn};
    }

    # check the install prefix is safe
    check_rpm_ipfx();

    # make the basic rpm directory structure
    system_nb(<<TXT) == 0 or die;
for i in BUILD SOURCES SPECS SRPMS
do
    mkdir -p $cf->{rpmdir}/\$i
done
mkdir -p $cf->{_rpmdir}
for i in "$cf->{rpmroot}/$cf->{rpmdb}"
do
    if [ ! -e \$i ]
    then
        mkdir -p \$i
    fi
done
TXT

    # make sure rootfs is a directory and ipath has write permissions
    # by the real user id unless in host/clean mode
    die "rpmroot: $cf->{rpmroot} is not a directory" unless -d $cf->{rpmroot};
    die "rpmroot: $cf->{rpmroot} is not writable by $cf->{username}"
                              if ! -w $cf->{rpmroot} && $cf->{rpmroot} ne '/';

    if(! -f $cf->{rpmdb_nfs_warning} ) {
        # make sure the rpmdb directory is not an nfs mount
        my $fstype = cmd_w_to(5, "df -PT $cf->{rpmroot}/$cf->{rpmdb} |tail -1") || "fake nfs";
        $fstype = (split(/\s+/, $fstype))[1];
        if($fstype eq 'nfs') {
            warn(<<TXT);

Ideally the rpm database should not be located in an NFS mounted filesystem.
On some systems this may cause cause problems due to filesystem locking
and this application.  If you have this problem, you'll see error
messages like: "error: cannot get exclusive lock on ..../Packages"

Press <enter to continue>
TXT
            local $_ = <STDIN>;
            touch($cf->{rpmdb_nfs_warning});
        }
    }

    # initialise the target's rpm database directory if not done before
    # otherwise rebuilt it if the target has run and altered it.  This
    # is needed as I think different endianesses store data differently
    # so a rpm database build on an x86 host is not readable on a ppc
    # machine until you run rpm --rebuilddb, similarly once that's been
    # done you can no longer read it properly on an x86 machine
    my $do_rebuild = 1 unless -e "$cf->{rpmroot}/$cf->{tmppath}";
    system_nb("mkdir -p $cf->{rpmroot}/$cf->{tmppath}");

    if(! -e "$cf->{rpmroot}/$cf->{rpmdb}/Packages") {
        system_nb(<<TXT) == 0 or die;
set -e
$cf->{sudo} $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --initdb
TXT
    } elsif($do_rebuild) {
        system_nb(<<TXT) == 0 or die;
set -e
$cf->{sudo} $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --define '_tmppath $cf->{tmppath}' --rebuilddb
TXT
    }

    return 1;
}

sub check_rpm_setup
{
    my ($hrpm) = `which rpm`;
    return 1 if $hrpm =~ m,$cf->{defpfx},;

    # use the host's rpm to build and install a known version
    # at this point we haven't parsed any pcf (platform config)
    # so we write our own
    $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";

    # invalidate the cache
    my $sav = {};
    my @@sav_list = qw/rpmroot rpmipfx nodeps sn force reinstall
                      dodrop ldirs prefix sysconfdir rpmbuild
                      rpm rpmdir _rpmdir rpmdb lpp tmppath sudo enrootn/;
    foreach my $k (@@sav_list) { $sav->{$k} = $cf->{$k} }
    pkg_cache_init();
    $cf->{rpmroot}       = '/';
    $cf->{rpmipfx}       = "";
    $cf->{nodeps}        = 1;
    $cf->{sn}            = "rpm-fs.spec";
    $cf->{force}         = 0;
    $cf->{reinstall}     = 1;
    $cf->{dodrop}        = 'no';
    $cf->{prefix}        = "$cf->{defpfx}/usr";
    $cf->{sysconfdir}    = "$cf->{defpfx}/etc";
    chomp($cf->{rpmbuild} = `which rpmbuild 2>/dev/null` || "rpm\n");
    $cf->{rpm}           = "rpm";
    $cf->{lpp}           = "/tmp";
    $cf->{ldirs}         = $cf->{lpp};
    $cf->{tmppath}       = $cf->{projtmp};
    $cf->{enrootn}       = 0;

    # we need to make a known rpm using the host's rpm first of all
    # we use a bogus database area
    $cf->{rpmdir} = "/tmp/rpm-$cf->{username}";
    $cf->{rpmdir} =~ s,[\\],-,g;
    $cf->{_rpmdir} = "$cf->{rpmdir}/RPMS";
    $cf->{rpmdb}  = "$cf->{rpmdir}/rpmdb";
    $cf->{sudo}   = "";
    setup_rpmdb();
    $cf->{sudo}   = $sav->{sudo};
    f_buildrpms();
    # put back the database information
    my @@rpms = glob("$cf->{_rpmdir}/$pcf->{RPMTARCH}/$cf->{sn}-*");
    my $rpm  = $rpms[0] or die  "could not glob rpm in: "
                        . "$cf->{_rpmdir}/$pcf->{RPMTARCH}/$cf->{sn}-*";
    my $cmd  = "$cf->{sudo} $sav->{rpm} ";
       $cmd .= "--root $cf->{rpmroot} ";
       $cmd .= "--dbpath $cf->{defpfx}/var/lib/rpm ";
       $cmd .= "-Uv --justdb --notriggers --noscripts --nodeps ";
       $cmd .= "$rpm";
    print "$cmd\n";
    system_nb($cmd);
    system_nb("rm -rf $cf->{rpmdir}") == 0 or die;

    # The existing host rpms are possibly invalid now so remove them
    system_nb("rm -f $cf->{_rpmdir}/$pcf->{RPMTARCH}/*");

    # restore cf
    foreach my $k (@@sav_list) {
        $cf->{$k} = $sav->{$k}
    }
    undef $sav;

    return 1;
}

#
# Check that the user has sudo permission to run rpm as root without
# the need to enter a password.  If this has not been correctly configured
# then ask the user to get this added to the sudoers file and abort.
#
sub check_sudo_setup
{
    my ($hostrpm) = `PATH=$cf->{path_std} ; which rpm`;
    chomp($hostrpm);
    my $s = `yes "" | sudo -S -l 2>&1`;
    my $bre = '(?:\(root\)|\(ALL\))\s+(?:ROLE=\s+)?NOPASSWD:';
    my $hostrpm_ok = $s =~ /$bre.*[\s,]$hostrpm/m;
    my $fsrpm_ok   = $s =~ /$bre.*[\s,]$cf->{rpm}/m;
    my $all_ok     = $s =~ /$bre\s+ALL/m,;
    return 1 if $all_ok;
    return 1 if $hostrpm_ok && $fsrpm_ok;

    die <<TXT;

I ran the command: sudo -S -l which returned:

$s
This means you don't have sudo permission to execute rpm commands as root
without a password.  This is needed for this build script to operate correctly.

To configure this, as root using the command "/usr/sbin/visudo",
and add the following line in the User privilege section:

$cf->{username} ALL = NOPASSWD: $hostrpm, $cf->{rpm}

TXT
die;
    return 1;
}

sub check_dirs
{
    # create the project tmp directory
    system_nb("mkdir -p $cf->{projtmp}") unless -e $cf->{projtmp};

    # we share the download cache area, all must be able to write there
    if(! -e $cf->{lpp} ) {
        system_nb("mkdir -p $cf->{lpp}") == 0 or die(<<TXT);

Cannot create the download directory:
 $cf->{lpp}

Either change to a global directory you have write permissions to,
or create it as root.  Please set the permissions to 777

TXT
    }
    my $lpp_mode = (stat("$cf->{lpp}"))[2];
    unless( ($lpp_mode & 040777) == 040777 ) {
        chmod(0777, $cf->{lpp}) == 1  or die <<TXT;

Build script aborting as the lpp directory is not configured properly.
Directory: $cf->{lpp} must exist with read, write, and search
permissions for owner, group, and world, i.e. drwxrwxrwx

TXT
    }
    if( -d "$cf->{top}/pkgs" ) {
        print "Updating lpp from local packages\n";
        my ($path, $fn);
        foreach $path ( glob("$cf->{top}/pkgs/*") ) {
            ($fn) = $path =~ m,([^/]+)$,;
            next if -f "$cf->{lpp}/$fn";
            system_nb("set -x; cp -dp $path $cf->{lpp}/$fn") == 0 or die;
        }
        system_nb("rm -rf $cf->{top}/pkgs 2>/dev/null");
    }
    return 1;
}

sub check_spoofing
{
    die("spoofing is not set up") unless -e $cf->{spoof_path};
    return 1;
}

sub tc_name
{
    my ($tcname) = @@_;
    if($cf->{buildarch} =~ m,^ppc,) {
        $tcname =~ s,i\d86,ppc,;
        $tcname =~ s,-x86,-ppc,;
    }
    return $tcname;
}

sub check_toolchain_setup
{
    my ($pcf) = @@_;
    return if $cf->{mode} =~ m,^listpkgs,;

    # test whether the compiler is present on the system, and if
    # not then install it (this is one package we can't build)
    # note: deal with x86-isms in a crude way (subst)
    if($pcf->{TOOLCHAIN}) {
        my $tc_rpm = tc_name($pcf->{TOOLCHAIN});
        $tc_rpm =~ s/\.\w+\.rpm//;
        `$cf->{rpm} -q $tc_rpm 2>/dev/null`;
        if(! -e  "$pcf->{TOOLCHAIN_PATH}/bin/$pcf->{TOOLCHAIN_PREFIX}gcc"
           || `$cf->{rpm} -q $tc_rpm 2>/dev/null` =~ m,is not installed,
           || $cf->{dltest}) {
            $pcf->{TOOLCHAIN} = tc_name($pcf->{TOOLCHAIN});
            print "Installing: $pcf->{TOOLCHAIN}\n" unless $cf->{dltest};
            my $tc = get_file($pcf->{TOOLCHAIN}, $cf, 1);
            return 1 if $cf->{dltest};
            warn("Can't get: $pcf->{TOOLCHAIN}"), die unless $tc;

            my $cmd =   "$cf->{sudo} $cf->{rpm} "
                   . "--dbpath $cf->{defpfx}/var/lib/rpm "
                   . "-ivh --force --ignorearch $tc";
            print "$cmd\n";
            return 1 if $echo;

            # switch stdout with stderr and run the command to capture stderr
            my $err = `$cmd 3>&1 1>&2 2>&3 3>&-`;
            if($? && $err !~ m,is already installed,) {
                die "Failed to install: $pcf->{TOOLCHAIN}:\n$err\n"
            }
        }
    }

    # check that this toolchain can be accessed without the abs path
    my $gcc_path = `which $pcf->{TOOLCHAIN_PREFIX}gcc 2>/dev/null`
                                                                or die(<<TXT);

$pcf->{TOOLCHAIN_PREFIX}gcc is not in your PATH environment:

PATH=$ENV{PATH}

TXT
    chomp($gcc_path);

    # no more checks if purely through our PATH
    return 1 if ! $pcf->{TOOLCHAIN_PATH};

    # short hand for a long name
    my $tc_exe =  "$pcf->{TOOLCHAIN_PATH}/bin/$pcf->{TOOLCHAIN_PREFIX}gcc";

    # check that there is a compiler at the specified path
    die(<<TXT) unless -x $tc_exe;

Cannot find executable toolchain:

$tc_exe

Please check your configuration.

TXT

    # make sure that the gcc in the path and tc_exe are the same
    die(<<TXT) if $gcc_path ne $tc_exe;

Found $pcf->{TOOLCHAIN_PREFIX}gcc through your PATH at:

$gcc_path

Expected to find it at:

$tc_exe

PATH=$ENV{PATH}

TXT
    # If we just installed a toolchain, check that we can compile something
    if($pcf->{TOOLCHAIN} && ! -f ".tc_test_$pcf->{TOOLCHAIN}") {
        my $cmd = <<TXT;
echo '#include <stdio.h>
int main() { printf("hello world"); }' | $gcc_path -x c - -c -o /dev/null
TXT

        die(<<TXT) if system_nb($cmd) != 0;

Error $gcc_path can't compile a simple hello world test program:

$cmd

TXT
        touch(".tc_test_$pcf->{TOOLCHAIN}");
    }
    return 1;
}

sub check_merge_updates
{
    my ($pcf) = @@_;
    my $spec = get_spec("merge");
    if( ! -w "$cf->{rfsbase}/etc/ltib-release") {
        touch($spec);
        return 1;
    }
    foreach my $dir ( $ENV{PLATFORM_PATH}, $ENV{TOP} ) {
        next unless -d "$dir/merge";
        local $_ = `find $dir/merge -newer $spec 2>/dev/null`;
        warn "newer than $spec: $_\n" if $_ && $verbose;
        touch($spec), last if $_;
    }
    return 1;
}

# we have to be very careful with packages that have a
# prefix of effectively /, if the package builds wrongly
# it will scribble over the host's installation.  For this
# reason we check carefully that this cannot happen
# This is to handle building packages that need to be installed
# on the host under {defpfx}
sub check_host_clobber
{
    my ($rpm) = @@_;
    my ($len, $cmd, $pkg_prefix, $inst_pfx, $path, $line);

    $pkg_prefix = `$cf->{rpm} -qp --queryformat "%{PREFIXES}\n" $rpm`;
    chomp($pkg_prefix);
    $pkg_prefix  = '' if $pkg_prefix eq '(none)';
    $inst_pfx = "$cf->{rpmroot}/$cf->{rpmipfx}";
    $inst_pfx =~ s,/+,/,g;

    # if a relocatable package, and we are installing in our project area
    # then we can bypass this strict test
    my $rootfs = "$cf->{top}/rootfs";
    $len = length($rootfs);
    if($pkg_prefix && unpack("A$len", $inst_pfx) eq $rootfs) {
       warn("skip host clobber check, pkg_prefix=$pkg_prefix inst=$inst_pfx\n")
                                                              if $verbose;
       return 1;
    }

    # if removing the install prefix results in anything in getting installed
    # under anything except /opt, /tmp, /home exit in a big hurry.
    $len = length($pkg_prefix);
    $cmd = "$cf->{rpm} -qlp $rpm";
    open(CMD, "$cmd |") or die("can't fork $cmd: $!");
    while(defined($line = <CMD>)) {
        chomp($line);
        last if $line eq '(contains no files)';
        ($path) = unpack ("x$len A*", $line);
        $path   = $inst_pfx . $path;
        $path   =~ s,/+,/,g;
        if( $path !~ m,^(?:/opt|/tmp|/home|$cf->{rfsbase}), ) {
            die("ERROR: $rpm\nwould clobber '$path'\n");
        }
    }
    close CMD;
    return 1;
}

sub summary
{
    unlink($tspec) if $tspec;
    return 1 unless $cf->{mode} eq 'buildrpms';

    my $edate = localtime();
    my $elapsed  = time() - $cf->{stime};
    $cf->{normal_exit} = 0 if $cf->{pkg_build_failures};

    print <<TXT;

Started: $cf->{sdate}
Ended:   $edate
Elapsed: $elapsed seconds

TXT

    if( $cf->{normal_exit} ) {
        print "Build Succeeded\n\n";
        return 1;
    }
    if( $cf->{pkg_build_failures}) {
        if($cf->{dltest}) {
            print "These packages would not have complete downloads ",
                                                                "available:\n";
            foreach my $sn (split(/\s+/, $cf->{pkg_build_failures})) {
                print "$sn:\n";
                foreach my $fn (@@{$cf->{dlfails}{$sn}}) {
                    print "    $fn\n";
                }
            }
        } else {
            print "These packages failed to build:\n",
                  "$cf->{pkg_build_failures}\n";
        }
    }
    print "\nBuild Failed\n\n";
    return;
}

sub sig_handler
{
    my $sig = shift;
    warn("killed by SIG$sig\n");
    bad_exit_handler();
}

sub die_handler
{
    warn @@_;
    warn("traceback:\n", caller_stack(1), "\n");
    bad_exit_handler();
}

sub bad_exit_handler
{
    $cf->{normal_exit} = 0;
    summary();
    my $logfile = $cf->{redirected};
    redirect();
    warn "Exiting on error or interrupt\n";
    warn "Please see $logfile for details\n" if $logfile;
    exit(1);
}

sub ltib_host_config
{
    my $hostpath = "$cf->{top}/config/platform/host";
    my $PLATFORM = $pcf->{PLATFORM} || 'host';

    # so you want to add some new host packages
    system_nb(<<TXT) == 0 or die;
set -ex
cd $hostpath
if [ ! -f .config ]
then
    if [ -f ${PLATFORM}.config ]
    then
        cp ${PLATFORM}.config .config
    else
        cp $cf->{hostconfig} .config
    fi
fi
if [ "$cf->{configure}" = "1" ]
then
    $cf->{conf} main.lkc
fi
if [ -f .config ]
then
    cp .config ${PLATFORM}.config
fi
TXT
    $cf->{preconfig} = "$hostpath/.config";
    die("No config saved") unless -f $cf->{preconfig};
    return 1;
}


sub ltib_config
{
    if($cf->{upreconfig} && $cf->{dltest}) {
        $cf->{preconfig} = $cf->{upreconfig};
        return 1;
    }
    my $plat_dir = $cf->{plat_dir};
    my $kconfig  = "main.lkc";
    my $rootn    = $cf->{rootn} || '';
    my $plat_cf  = "$plat_dir/.config$rootn";
    my $conf_cf  = "$cf->{config_dir}/.config$rootn";

    # this is the normal path after a choice for the target has been set
    if(   ! $cf->{configure} && ! $cf->{upreconfig} && ! $cf->{profile}
       && ! $cf->{selectype} && -f "$cf->{top}/.config" ) {
        if(-f $plat_cf) {
            # The normal case where the .config is new than the defconfig
            if(   ! -e "$plat_dir/defconfig$rootn"
               ||   -M $plat_cf <= -M "$plat_dir/defconfig$rootn") {
                $cf->{preconfig} = $plat_cf;
                return 1;
            }

            # the defconfig is newer than the .config, this is normally
            # because someone else has updated the scm.  In this case, use
            # the new defconfig.  Note mconf/conf use defconfig if .config
            # is missing.
            warn("Using updated $plat_dir/defconfig$rootn\n");
            rename($plat_cf, "$plat_cf.$cf->{stime}") if -f $plat_cf;
            system_nb("cp $plat_dir/defconfig$rootn $plat_cf") == 0 or die;
            $cf->{batch} = 1;
        }
    }

    # In batch mode, we don't want any user interaction
    $cf->{conf} = $cf->{batch} ? "yes '' | conf >&2" : "mconf";

    if(    -f "$plat_dir/preconfigs.lkc"
       && ($cf->{selectype}
            || (! -f $plat_cf && ! -f $conf_cf && ! $cf->{upreconfig})) ) {
        do {
            system_nb(<<TXT) == 0 or die;
set -ex
cd $cf->{config_dir}
$cf->{conf} ../$plat_dir/preconfigs.lkc $conf_cf
cd -
TXT
        } while(! -f $conf_cf);
    }
    if(-f $conf_cf) {
        my $cf_plat = parse_dotconfig($conf_cf);
        $kconfig    = $cf_plat->{PCF_KCONFIG} if $cf_plat->{PCF_KCONFIG};

        # something changed in selectype or never copied
        if(! -f $plat_cf || (-M $conf_cf < -M $plat_cf) ) {
            $cf->{upreconfig} = "$plat_dir/$cf_plat->{PCF_PRECONFIG}"
                                                 if $cf_plat->{PCF_PRECONFIG};
            if($cf_plat->{PCF_PROFILE}) {
                foreach my $dir ($plat_dir, "$cf->{config_dir}/profile",
                                                                 $cf->{top}){
                    my $path = "$dir/$cf_plat->{PCF_PROFILE}";
                    if(-f $path) {
                        $cf->{profile} = $path;
                        last;
                    }
                }
            }
        }
    }
    return run_plat_config($plat_dir, $kconfig);
}

sub run_plat_config
{
    my ($plat_dir, $kconfig) = @@_;
    my ($atime, $mtime);

    # Run the platform specific config
    die "No platform directory set" unless $plat_dir && -d $plat_dir;

    my $rootn   = $cf->{rootn} || '';
    my $plat_cf = "$plat_dir/.config$rootn";
    my $pdef_cf = "$plat_dir/defconfig$rootn";
    my $conf_cf = "$cf->{config_dir}/.config$rootn";

    # preconfigs/profiles effectively invalidate the .config.old output
    # from mconf/conf.  We save it and restore it later as .config.old
    my $oldconfig = "$plat_cf.old";
    if(($cf->{selectype} || $cf->{upreconfig} || $cf->{profile})
        && -f $oldconfig ) {
        ($atime, $mtime) = (stat($oldconfig))[8,9];
        system_nb("cp $oldconfig $oldconfig.$cf->{stime}");
    }

    system_nb(<<TXT) == 0 or die;
set -ex
if [ -n "$cf->{upreconfig}" ]
then
    cp $cf->{upreconfig} $plat_cf
    chmod +w $plat_cf
else
    if [ -f $conf_cf ]
    then
        cat $conf_cf | perl -ne 'print if m,^CONFIG_(?!PCF),' >> $plat_cf
    fi
fi
if [ ! -f $plat_cf -a -f $pdef_cf ]
then
    cp $pdef_cf $plat_cf
fi
if [ -n "$cf->{profile}" ]
then
    $cf->{top}/bin/splice_profile $plat_cf $cf->{profile} > .config.tmp
    mv -f .config.tmp $plat_cf
fi
cd $plat_dir
$cf->{conf} $kconfig .config$rootn
    cp .config$rootn defconfig$rootn.dev
TXT
    $cf->{preconfig} = $plat_cf;
    if(-f "$oldconfig.$cf->{stime}") {
        rename("$oldconfig.$cf->{stime}", $oldconfig);
        utime($atime, $mtime, $oldconfig)
                   or warn "could not reset times on $oldconfig : $!";
    }
    $cf->{mode} =~ m,(?:config|selectype), ? exit 0 : return 1;
}

sub get_plat_dir
{
    my $plat_dir;
    my $hr;

    if($cf->{upreconfig}) {
        if(-d $cf->{upreconfig}) {
            if($cf->{upreconfig} =~ m,(config/platform/[^/]+)$,) {
                $plat_dir = $1;
                $cf->{upreconfig} = '';
            }
        } else {
            $hr = parse_dotconfig($cf->{upreconfig});
            die "ERROR: $cf->{upreconfig} is non-ltib" unless $hr->{PLATFORM};

            # Balancing correctness against backward compatibility
            if($cf->{upreconfig} =~ m,(config/platform/[^/]+)/[^/]+\s*$,) {
                $plat_dir = $1;
            } else {
                $plat_dir = $hr->{PLATFORM_SUBDIR} || $hr->{PLATFORM};
                $plat_dir = "config/platform/$plat_dir";
            }
        }
        die "can't derive a platform directory from $cf->{upreconfig}"
                                                              unless $plat_dir;
        die "invalid platform directory: $plat_dir in $cf->{upreconfig}"
                                                           unless -d $plat_dir;

        return $plat_dir if $cf->{dltest} || $cf->{mode} =~ m,^listpkgs,;

        # set in the platform .config for subsequent runs
        my ($platform) = $plat_dir =~ m,([^/]+)\s*$,;
        open(TOPCF, ">$cf->{top}/.config") or die "open $cf->{top}/.config:$!";
        print TOPCF "CONFIG_PLATFORM_$platform=y\n";
        print TOPCF "CONFIG_PLATFORM_DIR=\"$plat_dir\"\n";
        close TOPCF;

        return $plat_dir;
    }

    mk_main_conf() unless -f $cf->{mainlkc};

CHOOSE_TOP_PLATFORM:
    while(! -f "$cf->{top}/.config") {
        system_nb("$cf->{conf} $cf->{mainlkc}") == 0 or die;
    }

    # extract the choice
    $hr = parse_dotconfig("$cf->{top}/.config");
    $plat_dir = $hr->{PLATFORM_DIR};
    if(! -d $plat_dir) {
        warn("Platform choice rejected as: '$plat_dir' doesn't exist\n");
        unlink "$cf->{top}/.config";
        die if $cf->{batch};
        goto CHOOSE_TOP_PLATFORM;
    }

    return $plat_dir;
}

sub mk_main_conf
{
    my ($dir, $ent, $p, $mcf) = ("config/platform", "", {});
    my $platforms = ();
    opendir(DIR, $dir) or die("can't open $dir: $!");
    while( defined($ent = readdir(DIR)) ) {
        next unless -d "$dir/$ent";
        next if $ent eq 'CVS' || $ent eq '.' || $ent eq '..' || $ent eq 'host';
        next if $ent eq 'git';
        $p->{$ent} = 0;
    }
    closedir(DIR);
    local $/ = "";
    foreach my $mcf (keys %$p) {
        open(CF, "$dir/$mcf/main.lkc")
                     or warn("mk_main_conf: skipping config dir: $mcf\n"), next;
        while(<CF>) {
            m,^config PLATFORM_COMMENT.+default\s+(.+)\n,ms && do {
                $p->{$mcf} = $1;
                last
            };
        }
        close CF;
    }
    open(MCF, ">$cf->{mainlkc}") or die "open $cf->{mainlkc} : $!";
    print MCF <<TXT;
config CONFIG_TITLE
    string
    default "GNU/Linux Target Image Builder : Platform Selection"

mainmenu "GNU/Linux Target Image Builder main menu"

choice
    prompt "Platform choice"
    help
       This menu will let you choose from a list of boards

TXT
    foreach $mcf (sort keys %$p) {
        next if ! $p->{$mcf};
        print MCF "    config PLATFORM_$mcf\n";
        print MCF "        bool $p->{$mcf}";
    }
    print MCF <<TXT;
endchoice

config PLATFORM_DIR
    string
TXT
    foreach $mcf (keys %$p) {
        print MCF "    default \"$dir/$mcf\" if PLATFORM_$mcf\n";
    }
    close MCF;

    return 1;
}

sub build_root_list
{
    my @@rl;
    if( $cf->{oneroot} || $cf->{sn} ) {
        @@rl = $cf->{rootn};
    } else {
        @@rl = (0);
        opendir(DIR, $cf->{plat_dir}) or die("opendir $cf->{plat_dir} : $!");
        while(defined(my $ent = readdir(DIR)) ) {
            next unless $ent =~ m,defconfig(\d\d?)$,;
            push(@@rl, $1);
        }
        closedir(DIR);
    }
    return @@rl;
}

sub clear_transient_configs
{
    my $file = $cf->{preconfig};
    my ($atime, $mtime) = (stat($file))[8,9];
    local $^I = '.bak';
    @@ARGV = $file;
    while(<>) {
        s,^(\w+WANT_CF)=y,# $1 is not set,;
        s,^(\w+LEAVESRC)=y,# $1 is not set,;
        print;
    }
    utime($atime, $mtime, $file) or warn "could not reset times on $file: $!";
}

sub f_shell
{
    check_rpm_ipfx();
    print "Entering ltib shell mode, type 'exit' to quit\n";
    my $rc = 'ltib_bashrc';
    open(RC, ">$rc") or die("can't open $rc for write: $!");

    print RC <<TXT;
export PS1="LTIB> "
alias rpm="$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb}"
alias rpme="sudo $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --define '_tmppath $cf->{tmppath}' -e "
alias rpmi="sudo $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --prefix $cf->{rpmipfx} --ignorearch -ivh  --define '_tmppath $cf->{tmppath}' "
alias rpm-host="$cf->{rpm}"
alias rpme-host="sudo $cf->{rpm} --dbpath $cf->{defpfx}/var/lib/rpm -e "
# seh: I've remove the rpm aliases for rpmi-host as it's too dangerous
#      without running the check_host_clobber test first

# Target man pages
function tman()
{
    export MANPATH=\$DEV_IMAGE/man:\$DEV_IMAGE/usr/man:\$DEV_IMAGE/usr/share/man:\$DEV_IMAGE/usr/local/man
    man \$1
}
TXT
    close RC;
    system_nb("/bin/bash --rcfile $rc");
    unlink $rc;
    exit 0;
}

sub redirect
{
    return 1 if $cf->{noredir};
    my ($file) = @@_;

    if($file) {
        if( ! $cf->{redirected} ) {
            open(SAVEOUT, ">&STDOUT");
            open(SAVEERR, ">&STDERR");
        }
        open(STDOUT, $file) or die("can't redirect stderr to $file: $!");
        open(STDERR, ">&STDOUT") or die("can't dup stderr to stdout");
        select STDERR; $| = 1;
        select STDOUT; $| = 1;
        # prevent: Filehandle STDERR reopened as only for input on later opens
        open(JUNK1, ">/dev/null");
        if(0) {
           my $msg = "hack to prevent used only once warning\n";
           print SAVEOUT $msg; print SAVEERR $msg; print JUNK1 $msg;
        }
        $cf->{redirected} = $file;
        return 1;
    }

    # if we get here and we're not redirected, just return
    return 1 unless $cf->{redirected};

    # we are redirected, so restore the original STDOUT/STDERR
    close STDERR;
    close STDOUT;
    open(STDOUT, ">&SAVEOUT");
    open(STDERR, ">&SAVEERR");
    close SAVEOUT;
    close SAVEERR;
    $cf->{redirected} = '';
    return 1;
}

sub expand_spec
{
    my ($specpath, $specinpath, $tmplpath) = @@_;
    open(SPECIN, "$specinpath")   or die("can't open $specpath.in: $!");
    open(TMPL, $tmplpath)         or die("can't open $tmplpath: $!");
    open(SPEC, ">$specpath")      or die("can't open $specpath for write: $!");
    while(<SPECIN>) {
        print SPEC;
    }
    close(SPECIN);
    while(<TMPL>) {
        print SPEC;
    }
    close(TMPL);
    close(SPEC);

    return 1;
}

sub rpm_needs_update
{
    my ($tok) = @@_;
    # In this case we're installing the host support package (clean install).
    # The policy here is that packages should only be upgraded (never down).
    # The idea is to prevent the install of an old BSP downgrading a
    # host support package.  The added wrinkle is that in cases where
    # the normal version comparision fails (e.g dtc version went
    # from 20070307 to 1.0.0) needs to be taken care of as exceptions
    # for now it's been left.
    my ($ver) = `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -q --queryformat %{VERSION}.%{RELEASE} $tok->{name} 2>&1`;
    return 1 if $ver =~  m,is not installed,;
    warn   "installed version=$ver, "
         . "new version = $tok->{version}.$tok->{release}\n" if $verbose;
    my $ret = cmp_ver("$tok->{version}.$tok->{release}", $ver);
    warn "ret = $ret\n" if $verbose;
    return ($ret > 0) ? 1 : 0;
}
@


1.28
log
@Remove auto-generated spec file for scdeploy if interrupted
@
text
@d48 2
d117 1
a117 1
    cvs_version  => '$Revision: 1.27 $',
d156 6
a161 6
    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",
d1524 1
@


1.27
log
@final fixups from import-2009031
@
text
@d115 1
a115 1
    cvs_version  => '$Revision$',
d200 1
a200 1
use vars qw($cf $config_deps $build_deps $install_deps
d1028 1
a1028 1
    my $tspec = "$cf->{rpmdir}/SPECS/$sn.spec";
d2665 1
@


1.26
log
@resolve conflicts from import-20090318
@
text
@a2917 2
        return $plat_dir if $cf->{dltest};

@


1.25
log
@Upgrade dropbear from 0.45 to 0.52 and add ability to set startup args
@
text
@d57 1
d114 2
a115 2
    app_version  => "8.4.1",
    cvs_version  => '$Revision: 1.24 $' . ' sv',
d321 1
a321 1
            listpkgcsv  list packages in a format for import into spreadsheet
d469 1
a469 1
$cf->{conf} = $cf->{batch} ? "yes '' | conf" : "mconf";
d520 1
a520 1
delete $ENV{CROSS_COMPILE};
d523 1
a523 1
# cvs checkings of unchanged files
d531 4
d642 2
a643 2
    $pcf->{LINTARCH} = g2larch($cf->{buildarch});
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH});
d711 1
d750 1
a750 1
    my @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*");
d753 4
a756 1
    # build if force, no rpms or if the spec file was updated
d758 1
d762 1
d764 1
a764 2
    $r   .= "spec file newer than rpm, " if @@rpms && (-M $spec < -M $rpms[0])
                                                  && ! $cf->{hostinst};
d766 1
a766 1
        warn("Build path taken because: $r\n\n") unless $cf->{dltest};
d771 1
a771 2
            unlink(@@rpms) unless $cf->{dltest} || $cf->{download_only}
                                               || $cf->{dry};
d775 1
d802 4
a805 3
            # don't allow clobbering of existing builds
            if( -e "$cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}" ) {
                warn(<<TXT);
a811 5
                my $ret;
                if($cf->{hostinst} == 0 && $cf->{mode} eq 'buildrpms') {
                    warn "scbuild/scdeploy already unpacked package\n";
                    $ret = f_scbuild($key) && f_scdeploy($key);
                } else {
d813 26
d840 2
d868 1
d873 1
a873 1
        print "$cmd\n";
d901 1
a901 1
        foreach my $rpm ( glob("$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*") ) {
d911 1
a911 1
                . "$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$tok->{name}-"
d976 1
d1152 1
a1152 1
diff --exclude CVS -uNr $pkg_dir_name $pkg_dir_name.modified > $cf->{lpp}/$pname
d1208 2
a1209 2
    my ($file, $cvs, $rel) = @@_;
    $cvs ||= 'none';
d1211 1
a1211 2
    my $wtag = get_cvs_tag() || 'none';
    my $gv   = -d "$cf->{top}/.git" ? `setlocalversion` : 'none';
d1219 2
a1220 2
CVS wtag     = $wtag
CVS tag      = $cvs
a1222 2
CVS version  = $cf->{cvs_version}
git version  = $gv
d1304 6
d1331 1
a1331 1
                      nodeps force hostinst reinstall dodrop sn
d1342 1
d1509 2
a1519 2
            # For this variable, interpolate 
            $cf->{CCACHE_DIR} =~ s,\$([\w]+),$cf->{$1},g;
d1589 1
a1589 1
    my $newarch = g2larch($pcf->{LINTARCH});
d1591 1
a1591 1
    my $dir     = "$cf->{rpmdir}/RPMS";
d1602 2
a1615 1
    die("old LINTARCH not defined in $dir/$cfn") unless $oldarch;
d1804 2
d1810 1
a1810 1
    my $pre = '^([\w]+)\s*=\s*([\S]+)';
d1828 2
a1829 7
        if($pcf->{$key} && $pcf->{$key} ne 'y') {
            $$key->{sn} = $pcf->{$key};
            $$key->{en} = 1;
        } else {
            $$key->{sn} = $2;
            $$key->{en} = $pcf->{$key} eq 'y' ? 1 : 0;
        }
d1836 1
a1836 2
    # load up the override map if present.  These should be bools.
    # It makes no sense to have u-boot or kernels in them
d1868 2
a1869 8
                # insert packages not in the main pkg_map before
                # merge and modep
                # For a minimal system (lwe) it may not have these
                my $pos = defined($pcf->{PKG_MODEPS})
                                                   + defined($pcf->{PKG_MERGE});
                $pos = $pos ? -$pos : $#{$pcac->{mk_buildlist}}+1;
                splice(@@{$pcac->{mk_buildlist}}, $pos, 0, $key);
                $$key->{en} = $pcf->{$key} eq 'y' ? 1 : 0;
d1871 2
a1873 1
            $$key->{sn} = $2;
d2041 2
a2042 4
    unless($sn) {
        warn("get_spec():\n", caller_stack(), "\n");
        return;
    }
a2048 1

d2199 1
a2199 1
    $pcf->{LINTARCH} = g2larch($cf->{buildarch})
d2205 1
a2205 1
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH});
d2275 1
a2275 1
for i in BUILD RPMS SOURCES SPECS SRPMS
d2279 1
a2321 1
    system_nb("mkdir -p $cf->{projtmp}");
d2351 2
a2352 2
    $pcf->{LINTARCH} = g2larch($cf->{buildarch});
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH});
d2359 1
a2359 1
                      rpm rpmdir rpmdb lpp tmppath sudo enrootn/;
d2382 1
d2389 1
a2389 1
    my @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$cf->{sn}-*");
d2391 1
a2391 1
                        . "$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$cf->{sn}-*";
d2402 1
a2402 1
    system_nb("rm -f $cf->{defpfx}/usr/src/rpm/RPMS/$pcf->{RPMTARCH}/*");
d2450 3
d2784 1
a2784 1
            # because someone else has updated cvs.  In this case, use
d2795 1
a2795 1
    $cf->{conf} = $cf->{batch} ? "yes '' | conf" : "mconf";
a2892 2
    mk_main_conf() unless -f $cf->{mainlkc};

d2913 4
d2921 1
a2921 10
        my $choice;
        open(MC, $cf->{mainlkc}) or die "open $cf->{mainlkc} : $!";
        while(<MC>) {
            if( m,$plat_dir"\s+if\s+(\w+), ) {
                $choice = "CONFIG_$1";
                last;
            }
        }
        close MC;
        die "No match for $plat_dir in $cf->{mainlkc}" unless $choice;
d2923 1
a2923 1
        print TOPCF "$choice=y\n";
d2930 2
d2958 1
@


1.24
log
@make rpm-build test more robust
cleaup --dltest output
@
text
@d114 1
a114 1
    cvs_version  => '$Revision: 1.23 $' . ' sv',
d252 1
a252 1
                          SYSCFG_START_DHCPD SYSCFG_DHCPC_CMD
d254 2
a255 1
                          SYSCFG_START_SAMBA SYSCFG_SMBD_ARGS SYSCFG_NMBD_ARGS/ ],
@


1.23
log
@fixup dltest mode (no config, no build reason)
@
text
@d114 1
a114 1
    cvs_version  => '$Revision: 1.22 $' . ' sv',
d1349 2
a1350 1
    return 1 if -f $cf->{host_wait_warning} && (! $cf->{dltest} || $cf->{sn});
d1360 1
a1360 1
    print <<TXT;
d1555 1
d1575 1
a1575 1
    print "Flushing old rpm set\n";
d1589 1
a1589 1
            print("Saving rpms from $oldarch to $dir/$ts\n");
d1593 1
a1593 1
            print "No binary rpms to save\n";
d1611 1
a1611 1
                      "from rpm/$ent\n";
d1623 1
a1623 1
        print "Removing binary rpms\n";
d2882 2
d2895 2
a2896 1
        open(TOPCF, ">$cf->{top}/.config") or die "open $cf->{top}/.config:$!";         print TOPCF "$choice=y\n";
@


1.22
log
@resolve conflicts after import-20081205
@
text
@d114 1
a114 1
    cvs_version  => '$Revision$' . ' sv',
d538 1
a538 1
# get/set the platorm directory
d755 1
a755 1
        warn("Build path taken because: $r\n\n");
d2726 4
@


1.21
log
@update crams to 20081121 cvs version
@
text
@d53 1
a53 1
    rfsbase      => "$top",
d108 1
d110 5
a114 3

    app_version  => "8.1.2",
    cvs_version  => '$Revision: 1.20 $' . ' sv',
d118 1
a125 1
    pkg_map      => "pkg_map",
d127 1
a127 1
    host_wait_warning => "$top/.host_wait_warning17",
d142 4
d158 1
d168 1
d185 1
d189 1
d193 1
a201 4

# make sure the root prefix for rpm is never set to / by the user
$cf->{rpmroot} = "$cf->{rfsbase}/rootfs";

d203 1
d219 2
d225 1
d250 1
d253 2
a254 3
                          SYSCFG_START_WATCHDOG
                          CONFIG_SYSCFG_START_SAMBA CONFIG_SYSCFG_SMBD_ARGS
                          CONFIG_SYSCFG_NMBD_ARGS/ ],
a259 1
           PKG_HELLOWORLD_MOD => [ qw/PKG_KERNEL/ ],
d272 1
d298 1
a298 2
root filesystems.  The rpms are installed as they are built
in the directory $cf->{rpmroot} (unless overriden in the resource file)
d300 4
a303 2
Edit the file .ltibrc in this directory to change the default system
configuration, or .ltibrc in your home directory.
d319 1
d325 2
d348 1
d353 2
d357 1
d359 1
d378 1
a378 1
Getopt::Long::Configure("no_ignore_case");
d381 1
d385 1
a385 1
        "preconfig:s"=> \$cf->{preconfig},
d401 1
d407 1
d410 1
d412 1
d451 2
a452 2
if($cf->{preconfig} && ! -e $cf->{preconfig}) {
    die "preconfig file: $cf->{preconfig} does not exist\n";
d467 1
d475 3
d482 16
d502 3
d524 4
a527 6
# do clean/distclean before other modes to prevent re-installing parts
# this can't be repeatedly run as cleaning depends on a built package list
if($cf->{mode} eq 'clean' || $cf->{mode} eq 'distclean') {
    pre_clean_checks() or exit(0);
    my $ret = &{"f_" . $cf->{mode}}() || 0;
    exit($ret == 0);
d538 8
a545 2
# do setup before target building
pre_build_checks();
d547 2
a548 2
# write out a release info file
write_release_info($cf->{release_info});
d550 2
a551 2
# run the requested mode
&{"f_" . $cf->{mode}}()
d554 29
a582 2
# clear transient configuration flags
clear_transient_configs();
d584 3
a586 18
if(   $cf->{something_got_built} || $cf->{do_deploy} ) {
    # run the deployment section
    if(     $cf->{mode} eq 'scdeploy'
        || $cf->{do_deploy}
        || ($cf->{mode} eq 'buildrpms' && ! $cf->{sn}) ) {

        my $msg = "\nProcessing deployment operations\n";
        $msg .= '=' x length($msg) . "\n";
        print $msg;

        mk_fs_image($cf->{rpmroot}, "$cf->{rpmroot}.tmp",
                    "$cf->{bin_path}/device_table.txt", $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;
        }
d603 11
a613 5
        print("$pkg is not installed\n"), next
            unless `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -q $pkg` =~ m,^\Q$pkg\E,;
        $pkg .= " $pkg-devel"
            if `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -q $pkg-devel` =~ m,^\Q$pkg\E,;
        my $cmd = "$cf->{sudo} $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -e --allmatches --define '_tmppath $cf->{tmppath}' $pkg";
d622 1
a622 1
sub f_distclean
d624 2
a625 4
    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:
d627 1
a627 2
$cf->{rpmdir}
$cf->{rpmroot}
d629 11
a639 8
TXT
        print "To continue type in 'yes': ";
        local $_ = <STDIN>;
        print("aborted\n"), return 1 unless /^yes$/;
    }
    my $rpmdb = "$cf->{rpmroot}/$cf->{rpmdb}";
    die("no rpm database dir $rpmdb") unless -d $rpmdb;
    f_clean();
d642 1
a642 1
    my @@sav_list = qw/sn force rpmipfx rpmroot rpmdb tmppath/;
d649 1
a649 1
    $cf->{rpmipfx} = $cf->{rpmroot};
d651 1
a651 1
    $cf->{rpmdb}   = "$cf->{top}/cleanupdb";
d653 5
a657 3
    mk_rpm_dirs();
    f_buildrpms() or die;
    f_clean();
d663 10
d674 11
a684 1
system_nb(<<TXT);
d687 1
a687 1
$echo find config \\( -name .config -o -name .tmpconfig.h -o -name .config.old  -o -name .config.cmd \\) -exec rm {} \\;
d692 1
a692 1
$echo rm -rf $cf->{rpmroot}
d699 1
a699 1
$echo rm -f $cf->{logfile}
d701 1
a701 1
$echo rm -f .host_wait_warning*
d706 1
a706 1
$echo for i in faked fakeroot mkimage gdb tmake .gdbinit mpc.init; do rm -rf $cf->{top}/bin/\$i ; done
d722 1
a722 1
    my $leavesrc   = $args->{leavesrc}|| '';
d734 3
a736 1
    unless( $spec ) {
d747 9
a755 3
    if(   $cf->{force}  || $cf->{download_only}
       || (exists $$key->{build} && $$key->{build})
       || $cf->{dltest} || ! @@rpms || -M $spec < -M $rpms[0]){
d757 1
a757 1
        # don't do this clause if running s short-circuited mode
d760 2
a761 1
            unlink(@@rpms) unless $cf->{dltest} || $cf->{download_only};
d772 4
a775 1
                        next if $cf->{dltest};
d801 1
a801 1
                if($cf->{mode} eq 'buildrpms') {
d900 1
a900 1
            # in dry-run mode (echo), don't actually install)
d929 1
a929 1
    print "using $cf->{preconfig}\n" if $cf->{preconfig} || $cf->{redirected};
d934 5
d998 1
a998 1
    my $spec = get_spec($sn) or die();
d1037 1
a1037 1
    get_spec($sn, 'del');
d1066 2
a1067 1
    my ($specout, $specin) = get_spec($cf->{sn}) or die();
d1149 1
a1149 1
        return f_listpkgs('eula');
d1151 1
d1156 6
d1164 3
a1166 54
   my ($mode) = @@_;
   $mode ||= 'text';
   $^L = '';
        if ($mode eq "eula") {
                # Set large FORMAT_LINES_PER_PAGE so there is only one page
                $= = 10000;
        }
   my ($tok, $en, $sn);
   # Set FORMAT_NAME
   $~ = $mode;
   $^ = $mode . "_top";

format text_top =
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'-----------------------','----------------','-------','-------','-----------------------------------------'
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'Package', 'Spec file', 'Enabled','License','Summary'
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'-----------------------','----------------','-------','-------','-----------------------------------------'
.
format text =
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$tok->{name}.'-'.$tok->{version}.'-'.$tok->{release}, $sn, $en, $tok->{license}, $tok->{summary}
.
format twiki_top =
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<@@<@@|||||@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@*@@<
'|','*Package*','|','*Spec Name*','|','*En*','|','*Summary*','|','*License*','|'
.
format twiki =
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<@@<@@|||||@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@*@@<
'|',$tok->{name}.'-'.$tok->{version}.'-'.$tok->{release},'|',$sn,'|',$en,'|',$tok->{summary},'|',$tok->{license},'|'
.
format eula_top =
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<
'Package', 'License'
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<
'-----------------------','-------'
.
format eula =
@@<<<<<<<<<<<<<<<<<<<<<<< @@*
"$tok->{name}-$tok->{version}-$tok->{release}", $tok->{license}
.

   # sort the keylist by alphabetic spec name
   my @@keylist = sort { $$a->{sn} cmp $$b->{sn} } mk_buildlist();
   foreach my $key ( @@keylist  ) {
       next if $cf->{enabled} && $$key->{en} == 0;
       $sn = $$key->{sn};
       $en = $$key->{en} ? 'y' : 'n';
       my $spec = get_spec($sn) or warn("skipping $sn\n"), next;
       $tok = parse_spec($spec) or die();
       write;
   }
   return 1;
d1175 2
d1188 1
d1215 1
a1215 1
    foreach $var (qw/rpmroot rpmdir rpmdb bin_path
d1218 1
a1218 1
                     pkg_map top home username path_std
d1265 5
a1269 4
            parse_config($rc, $cf, { strip_blank => 1,
                                     strip_comment => 1,
                                     strip_trailing => 1} );
            $cf->{rcfile} = $rc;
d1286 1
a1286 1
    my ($allow_hostcf) = @@_;
d1291 2
a1292 1
                      nodeps force hostinst reinstall dodrop preconfig sn/;
d1305 2
a1306 2
    $cf->{force}         = 0 if $allow_hostcf == 0;
    $cf->{hostinst}      = 1 if $allow_hostcf == 0;
d1308 2
d1312 1
a1312 1
    if($allow_hostcf == 1) {
d1349 1
a1349 1
    return 1 if -f $cf->{host_wait_warning} && ! $cf->{dltest};
d1356 1
a1356 1
    check_sudo_setup();
d1403 1
d1405 2
a1406 51
    if( -f "$cf->{preconfig}.old" ) {
        $ppcf = parse_dotconfig("$cf->{preconfig}.old");
        process_full_rebuild();
    }

    # add distcc hosts if this has been setup
    $ENV{DISTCC_HOSTS} = $cf->{DISTCC_HOSTS}
                       if ! defined $ENV{DISTCC_HOSTS} && $cf->{DISTCC_HOSTS};
    $ENV{DISTCC_TCP_CORK} = $cf->{DISTCC_TCP_CORK}
         if ! defined $ENV{DISTCC_TCP_CORK} && defined $cf->{DISTCC_TCP_CORK};
    $ENV{MAKEFLAGS} = $cf->{MAKEFLAGS}
                       if ! defined $ENV{MAKEFLAGS} && $cf->{MAKEFLAGS};

    # this is to catch mangled databases before we had a known rpm
    # once this has rippled through all users it could come out
    die "$cf->{rpm} has gone missing" unless -f $cf->{rpm};
    my $qo = `$cf->{rpm} --root $cf->{rpmroot} --dbpath -q $cf->{rpmdb} bogus-package 2>&1`;
    if($qo =~ m,unsupported hash version:,m) {
        system_nb("rm -rf $cf->{rpmdb}/*") == 0 or die;
    }

    # auto-migrate old rpmdb
    if(-e "$cf->{top}/rpmdb") {
        print "Updating to new rpm database placement, running a clean\n";
        my $sav = {};
        my @@sav_list   = qw/sn force rpmipfx rpmroot rpmdb tmppath/;
        foreach my $k (@@sav_list) {
            $sav->{$k} = $cf->{$k}
        }
        $cf->{rpmipfx} = $cf->{rpmroot};
        $cf->{rpmroot} = '/';
        $cf->{rpmdb}   = "$cf->{top}/rpmdb";
        $cf->{tmppath} = $cf->{projtmp};
        f_clean();
        pkg_cache_init();
        $cf->{sn}      = "mkdistclean.spec";
        $cf->{force}   = 1;
        mk_rpm_dirs();
        f_buildrpms() or die;
        f_clean();
        pkg_cache_init();
        system_nb("rm -rf $cf->{rpmdb}");
        foreach my $k (@@sav_list) {
            $cf->{$k} = $sav->{$k}
        }
    }

    # make rpm directories
    mk_rpm_dirs();

    # make sure spoofing is working
a1407 2

    # make shure we can build packages
a1408 2

    # check merge updates and force merge package build if necessary
a1409 2

    # clean up stale rpm-tmp files
a1411 19
    # we only want to record something go built for target packages
    $cf->{something_got_built} = 0;

    return 1;
}

sub pre_clean_checks
{
    warn("can't clean, no preconfig or .config file"), return
                            unless $cf->{preconfig} || -f "$cf->{top}/.config";
    ltib_config();
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{preconfig});
    check_platform_config($pcf);
    setup_env_vars($cf, $pcf);

    # check/create required directories
    check_dirs();

d1438 1
d1449 1
a1449 1
    $ENV{PLATFORM_PATH} = "$cf->{platforms_dir}/$pcf->{PLATFORM}";
d1463 18
d1484 1
a1484 1
                          BUILDARCH GNUTARCH LINTARCH CFGHOST
d1493 6
a1498 3
        next unless $pcf->{$k};
        warn("setting ENV{$k}=$pcf->{$k}\n") if $verbose;
        $ENV{$k} = $pcf->{$k};
d1505 15
a1519 1
    return 1 if -M "$cf->{preconfig}.old" <= -M $cf->{preconfig};
d1526 1
a1526 1
    foreach my $dep (qw/PLATFORM GNUTARCH LINTARCH CFGHOST TOOLCHAIN DISTRO PKG_UCLIBC PKG_GLIBC LIBC_HACKING/) {
d1531 1
a1531 1
            warn("CONFIG_$dep forced a full rebuild\n");
d1535 2
a1536 4
    if($need_frb) {
        f_clean() if -d "$cf->{rpmroot}/$cf->{rpmdb}";
        my $oldarch = g2larch($ppcf->{LINTARCH});
        system_nb("rm -f $cf->{rpmdir}/RPMS/$oldarch/*");
d1543 94
d1673 9
d1769 1
a1769 1
    my $map = "$cf->{config_dir}/userspace/$cf->{pkg_map}";
d1777 1
a1777 1
        next unless defined $pcf->{$key};
d1789 1
d1797 1
a1797 1
    $map = "$cf->{plat_dir}/$cf->{pkg_map}";
d1823 12
a1834 4
            unless(exists $$key->{sn}) {
                warn("$key in $map is not selectable\n"), return
                                                    unless exists $pcf->{$key};
                push @@{$pcac->{mk_buildlist}}, $key;
d1837 1
d1839 2
d1852 1
d1869 1
a1869 2
If necessary please give the whole spec file name (with the
.spec extension).
a1876 5
    # process the package dependencies
    foreach $key ( @@{$pcac->{mk_buildlist}} ) {
        process_pkg_deps($key, $$key->{sn}) if $$key->{en};
    }

d1945 5
a1949 1
    my @@installed = split(/[\s\n]+/, `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -qa --queryformat "%{name} "`);
d1952 1
a1952 3
    my @@buildlist = mk_buildlist();
    my @@wanted    = grep { $$_->{en} } @@buildlist;
    my ($key, $pkg, $len);
d1954 1
a1954 1
INST:
d1956 10
a1965 15
        foreach $key ( @@wanted ) {
            $pkg = get_pkg_name($key) or next;
            $len = length $inst;
            next INST if $inst eq $pkg;
        }
        # the installed package is not in the list of enabled packages
        push(@@drop_list, $inst);

        # check to see if this package has any reverse triggers
        foreach $key ( get_rev_triggers() ) {
            $pkg = get_pkg_name($key) or next;
            $len = length $pkg;
            if( $inst eq $pkg ) {
                $pkg2key->{$inst} = $key;
                last;
d2030 1
a2030 1
    if(exists $cache->{$sn}) {
d2054 2
a2055 2
            if(! -f $specpath  || (-M $specinpath < -M $specpath)
                               || (-M $tmplpath   < -M $specpath)   ) {
d2057 2
a2058 1

d2076 1
a2076 1
    undef $cache->{$sn};
d2078 1
a2078 1
    warn(<<TXT);
d2088 2
a2089 1
    warn "    $defdist\n" if $defdist ne $pcf_distro;
d2132 4
a2135 2
ltib cannot be run because one or more of the host packages needed
to run it are either missing or out of date.
d2137 2
a2138 1
Please install/upgrade these packages and then re-try.
d2144 1
d2174 11
d2186 26
a2211 2
    $cf->{plat_dir} = "$cf->{platforms_dir}/$pcf->{PLATFORM}"
                                                    unless $cf->{plat_dir};
d2217 5
d2224 3
a2226 2
    if($ipath =~ m,^\s*/+[^/]*\s*$, && $cf->{prefix} !~ m,/+[^/]+/+[^/]+,) {
        die "Install path cannot be set to '$ipath'\n",
d2231 1
a2231 1
sub mk_rpm_dirs
d2233 5
d2255 1
d2257 1
a2257 1
    # by the real user id
d2259 2
d2284 1
a2284 1
    # so a rpm database build on an x86 host is not readable on a ppc 
d2326 2
a2327 2
                      dodrop ldirs prefix sysconfdir rpmbuild 
                      rpm rpmdir rpmdb lpp tmppath sudo plat_dir/;
d2329 1
a2332 1
    pkg_cache_init();
d2344 1
a2344 1
    $cf->{plat_dir}      = "$cf->{platforms_dir}/$pcf->{PLATFORM}";
d2352 1
a2352 1
    mk_rpm_dirs();
d2354 1
a2354 1
    f_buildrpms() or die;
d2390 4
a2393 3
    my $hostrpm_ok = $s =~ /(?:\(root\)|\(ALL\))\s+NOPASSWD:.*[\s,]$hostrpm/m;
    my $fsrpm_ok   = $s =~ /(?:\(root\)|\(ALL\))\s+NOPASSWD:.*[\s,]$cf->{rpm}/m;
    my $all_ok     = $s =~ /(?:\(root\)|\(ALL\))\s+NOPASSWD:\s+ALL/m,;
d2475 1
a2475 1
    # not deal with x86 isms in a crude way (subst)
d2545 16
d2567 5
a2571 1
    my $spec;
a2573 1
        $spec = get_spec("merge") unless $spec;
d2619 1
a2619 1
        if( $path !~ m,^/(?:opt|tmp|home), ) {
d2643 20
a2662 10
if( $cf->{normal_exit} ) {
    print "Build Succeeded\n\n";
    return 1;
}
if( $cf->{pkg_build_failures}) {
    my $desc = $cf->{dltest} ? "would not have complete downloads available"
                             : "failed to build";
    print "These packages $desc:\n$cf->{pkg_build_failures}\n";
}
print "Build Failed\n\n";
a2663 1

a2692 2
    my $cf_main = {};

d2711 1
a2711 1
    mconf main.lkc
d2726 5
a2730 9
    # this is a special case that should not really exist
    return if $cf->{preconfig} && (    $cf->{dltest}
                                    || $cf->{mode} =~ m,^listpkgs,);

    my $cf_main = {};
    my $cf_plat = {};
    my ($plat_dir, $atime, $mtime, $pcf, $pcfname, $kconfig);
    $kconfig = "main.lkc";
    $pcfname = "defconfig";
d2733 3
a2735 7
    if( ! $cf->{configure} && ! $cf->{preconfig} && ! $cf->{profile}
                                                 && -f "$cf->{top}/.config" ) {
        $cf_main = parse_dotconfig("$cf->{top}/.config");
        $plat_dir = $cf_main->{PLATFORM_DIR} or die "no PLATFORM_DIR";
        $cf->{plat_dir} = $plat_dir;

        if(-f "$plat_dir/.config") {
d2737 3
a2739 3
            if(   ! -e "$plat_dir/defconfig"
               ||   -M "$plat_dir/.config" <= -M "$plat_dir/defconfig") {
                $cf->{preconfig} = "$plat_dir/.config";
d2747 3
a2749 3
            warn("Using update $plat_dir/defconfig\n");
            rename("$plat_dir/.config", "$plat_dir/.config.$cf->{stime}")
                                                     if -f "$plat_dir/.config";
a2750 5

        } else {
            # the platform's .config is missing, need to re-select the
            # platform again
            unlink "$cf->{top}/.config";
d2757 5
a2761 51
    # if passed a preconfig, we use this as a starting point
    if($cf->{preconfig} ) {
        my $th = parse_dotconfig($cf->{preconfig});
        die "ERROR: attempting to use a non-LTIB preconfig"
                                                        unless $th->{PLATFORM};
        $plat_dir = "config/platform/$th->{PLATFORM}";
        $cf->{plat_dir} = $plat_dir;
        undef $th;

        # auto-generate the main config file
        mk_main_conf() or die;

        # this is here to take care of the situation where you
        # run an autobuild (--preconfig x --profile y --batch)
        # and you then want to run a configure on a subsequent run
        my $platform = "";
        open(MC, $cf->{mainlkc}) or die "open $cf->{mainlkc} : $!";
        while(<MC>) {
            if( m,$plat_dir"\s+if\s+(\w+), ) {
                $platform = "CONFIG_$1";
                last;
            }
        }
        close MC;
        die "No match for $plat_dir in $cf->{mainlkc}" unless $platform;
        open(TOPCF, ">$cf->{top}/.config") or die("open $cf->{top}/.config:$!");
        print TOPCF "$platform=y\n";
        print TOPCF "CONFIG_PLATFORM_DIR=\"$plat_dir\"\n";
        close TOPCF;

    } else {
        # Choose the system if not already chosen
        if(! -f "$cf->{top}/.config") {
            mk_main_conf() or die;
            system_nb("$cf->{conf} $cf->{mainlkc}") == 0 or die;
        }
        # Source the .config file and turn into a hash
        $cf_main = parse_dotconfig(".config");

        # set the platform directory
        $plat_dir = $cf_main->{PLATFORM_DIR};
        $cf->{plat_dir} = $plat_dir;

        # If there is a preconfigs.lkc file and user passes --selectype
        # or there is no .config file at all run mconf
        if(     -f "$plat_dir/preconfigs.lkc"
           && (   $cf->{selectype} 
               || (   ! -f "$cf->{config_dir}/.config" 
                   && ! -f "$cf->{plat_dir}/.config"   ))) {
 
        system_nb(<<TXT) == 0 or die;
d2764 1
a2764 1
$cf->{conf} ../$plat_dir/preconfigs.lkc
d2767 1
a2767 1
        }
d2769 8
a2776 21

    if($cf->{preconfig}) {
        # user provided preconfigs override anything else
        unlink("$plat_dir/.config");

    } elsif(-f "$plat_dir/preconfigs.lkc" && -f "$cf->{config_dir}/.config") {
        # For platforms with preconfigs.lkc, the $kconfig lets us change
        # the kconfig file use for configuration of the platform
        $cf_plat   = parse_dotconfig("$cf->{config_dir}/.config");
        $kconfig   = $cf_plat->{PCF_KCONFIG}   if $cf_plat->{PCF_KCONFIG};
        if($cf_plat->{PCF_PRECONFIG}) {
            $pcfname         = $cf_plat->{PCF_PRECONFIG};
            $cf->{preconfig} = "$plat_dir/$pcfname";
        }
        # If the platform has not been configured or the a new preconfig
        # has been selected (selectype) the remove the current platform
        # .config, this triggers a copy of the selected preconfig to
        # the platforms .config
        if(    ! -f "$plat_dir/.config"
            || (-M "$cf->{config_dir}/.config" < -M "$plat_dir/.config") ){
            unlink("$plat_dir/.config");
d2789 7
d2798 6
a2803 1
    die "No platform directory set" unless $plat_dir;
d2807 2
a2808 2
    my $oldconfig = "$plat_dir/.config.old";
    if(($cf->{selectype} || $cf->{preconfig} || $cf->{profile})
d2816 1
a2816 1
if [ -n "$cf->{preconfig}" -a ! -f "$plat_dir/.config" ]
d2818 4
a2821 2
    cp $cf->{preconfig} $plat_dir/.config
    if [ -f "$cf->{config_dir}/.config" ]
d2823 1
a2823 1
        cat $cf->{config_dir}/.config | perl -ne 'print if m,^CONFIG_(?!PCF),' >> $plat_dir/.config
d2826 4
d2832 2
a2833 2
    $cf->{top}/bin/splice_profile $plat_dir/.config $cf->{profile} > .config.tmp
    mv -f .config.tmp $plat_dir/.config
d2836 2
a2837 2
$cf->{conf} $kconfig
cp .config defconfig.dev
d2839 1
a2839 2
    # we probably changed it, so now this becomes the new user selection
    $cf->{preconfig} = "$plat_dir/.config";
d2848 64
d2916 1
a2916 1
    opendir(DIR, $dir) or warn("can't open $dir: $!"), return;
d2968 17
d3001 1
a3001 1
    check_rpm_ipfx();    
@


1.20
log
@re-instate POST_BUILD_SCRIPT
@
text
@d111 1
a111 1
    cvs_version  => '$Revision: 1.19 $' . ' sv',
d124 1
a124 1
    host_wait_warning => "$top/.host_wait_warning16",
@


1.19
log
@minor fixups to enlightenment packages
@
text
@d111 1
a111 1
    cvs_version  => '$Revision: 1.18 $' . ' sv',
d517 5
@


1.18
log
@Fixup selectype logic
@
text
@d111 1
a111 1
    cvs_version  => '$Revision: 1.17 $' . ' sv',
d252 7
a258 1
$build_deps = { PKG_KERNEL => [ qw/PKG_SYSCONFIG/ ] };
@


1.17
log
@put back savannah centric changes for ltib script
@
text
@d111 1
a111 1
    cvs_version  => '$Revision: 1.16 $' . ' sv',
d1209 1
a1209 1
                      nodeps force hostinst reinstall dodrop preconfig/;
d1235 1
d2581 4
a2584 1
           && ($cf->{selectype} || ! -f "$cf->{config_dir}/.config") ) {
d2598 1
a2598 1
    } elsif(-f "$plat_dir/preconfigs.lkc" && "$cf->{config_dir}/.config") {
@


1.16
log
@import-20080404-conflict-resolution
@
text
@d49 1
a49 1
$bdir = "/opt/freescale";
d69 1
a69 1
    lpp          => "$bdir/pkgs",
d111 1
a111 1
    cvs_version  => '$Revision$' . ' sv',
@


1.15
log
@Fixed host support package downgrade bug
@
text
@d49 1
a49 1
$bdir = "/opt";
d53 3
a55 1
    dev_image    => "$top/rootfs",
a56 1
    rpmdb        => "$top/rpmdb",
d65 2
a66 1
    tmppath      => "$top/tmp",
d69 1
a69 1
    lpp          => "$bdir/ltib/pkgs",
d107 1
d110 2
a111 2
    app_version  => "7.4.1",
    cvs_version  => '$Revision: 1.14 $' . ' sv',
d116 1
a116 1
    release_info => "$top/tmp/RELEASE_INFO",
d124 1
a124 1
    host_wait_warning => "$top/.host_wait_warning14",
d168 1
d181 1
d191 3
d240 1
d248 1
d281 1
a281 1
in the directory $cf->{dev_image} (unless overriden in the resource file)
d302 2
a303 1
            config      use with --configure to do configuration only
d306 2
a307 1
        --configure|c : run the interactive configuration
d316 1
d332 1
d356 1
d365 1
d380 1
d395 1
a395 1
    unless $cf->{mode} =~ m,^(buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell|trelease),;
d439 4
d454 1
a454 1
foreach my $sig (qw/__DIE__ INT/) {
d457 1
d462 3
d508 1
a508 1
        mk_fs_image($cf->{dev_image}, "$cf->{dev_image}.tmp",
a522 1
    print "Cleaning out target rpms:\n";
d528 1
a528 1
            unless `$cf->{rpm} --dbpath $cf->{rpmdb} -q $pkg` =~ m,^\Q$pkg\E,;
d530 2
a531 2
            if `$cf->{rpm} --dbpath $cf->{rpmdb} -q $pkg-devel` =~ m,^\Q$pkg\E,;
        my $cmd = "$cf->{sudo} $cf->{rpm} --dbpath $cf->{rpmdb} -e --allmatches $pkg";
d542 2
a543 3
    # note dev_image is not removed otherwise you need to
    # restart nfs (or run exportfs) which is a pain
    print(<<TXT);
d548 1
a548 2
$cf->{rpmdb}
$cf->{tmppath}
d551 7
a557 5
    print "To continue type in 'yes': ";
    local $_ = <STDIN>;
    print("aborted\n"), return 1 unless /^yes$/;
    die("no rpm database dir $cf->{rpmdb}\n") unless -d $cf->{rpmdb};
    f_clean() if -d $cf->{rpmdb};
d560 1
a560 1
    my @@sav_list = qw/sn force/;
d567 5
d574 1
a579 1

d583 1
a583 1
$echo find config \\( -name .config -o -name .tmpconfig.h -o -name .config.old  -o -name .config.cmd -o -name defconfig.dev \\) -exec rm {} \\;
d586 1
a586 1
$echo rm -rf $cf->{rpmdb}
d588 2
a596 1
$echo rmdir $cf->{dev_image}
d607 1
a607 1
sub f_buildrpms
d609 15
a623 6
    my($rpmbuildopts) = @@_;
    unless($rpmbuildopts) {
        $rpmbuildopts  = $cf->{keepsrpms} ? "-ba " : "-bb ";
    }
    my $ret = 1;
    my($msg, @@srpm, @@rpms, $rpm, $pkg, $subpkg, $cmd, $rebuilt, $ec, $stime);
d625 1
a625 1
    $msg = "\nProcessing platform: $pcf->{PLATFORM_COMMENT}\n";
d627 1
a627 3
    print $msg unless $cf->{nounpack};
    print "using $cf->{preconfig}\n"
              if ($cf->{preconfig} || $cf->{redirected}) && ! $cf->{nounpack};
d629 6
a634 2
    # remove any packages that are not in the build list
    remove_unselected_pkgs() unless $cf->{dltest};
d636 23
a658 46
PKG: foreach my $key (mk_buildlist()) {
        next unless $$key->{en};
        $$key->{build} = 1 if $pcf->{$key . '_FORCE'};
        my $sn = $$key->{sn};
        $msg = "\nProcessing: $sn\n";
        $msg .= '=' x length($msg) . "\n";
        print $msg;
        $rebuilt = 0;
        my $spec = get_spec($sn);
        unless( $spec ) {
            $cf->{pkg_build_failures} .= "$sn ";
            undef $ret;
            warn("specfile not found\n");
            die unless $echo || $cf->{coe} || $cf->{dltest};
            next;
        }
        my $tok = {sources => "", patches => "" };
        parse_spec($spec, $tok, 0);
        @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*");
        my $pkgfail = 0;

        # build if force, no rpms or if the spec file was updated
        if(   $cf->{force}  || $cf->{download_only}
           || (exists $$key->{build} && $$key->{build})
           || $cf->{dltest} || ! @@rpms || -M $spec < -M $rpms[0]){

            # don't do this clause if running s short-circuited mode
            if(! $cf->{nounpack})  {
                # commit to installing a new rpm (enforced if build fails)
                unlink(@@rpms) unless $cf->{dltest} || $cf->{download_only};

                foreach my $url (  split(/\s*\n/, $tok->{sources}),
                                   split(/\s*\n/, $tok->{patches})   ) {
                    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;
                            undef $ret;
                            next if $cf->{dltest};
                            warn("Can't get: $file");
                            die unless  $echo || $cf->{coe};
                            next PKG;
                        }
d660 4
d665 2
a666 2
                        # needed if the lpp moves and links break
                        unlink($tgt);
d668 2
a669 3
                        symlink($src, $tgt)
                                or die("symlink $cf->{lpp}/$file, $tgt: $!\n");
                    }
d671 3
a673 2
                next PKG if $cf->{download_only};
                next PKG if $cf->{dltest};
d675 3
a677 3
                # don't allow clobbering of existing builds
                if( -e "$cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}" ) {
                    warn(<<TXT);
d680 1
a680 1
     $cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}
d684 6
a689 17
                    if($cf->{mode} eq 'buildrpms') {
                        warn "scbuild/scdeploy already unpacked package\n";
                        my $osn = $cf->{sn};
                        $cf->{sn} = $sn;
                        pkg_iterate($cf->{sn});
                        $cf->{nounpack} = 1;
                        $ret = f_scbuild() && f_scdeploy();
                        $cf->{leavesrc} = 0;
                        $cf->{nounpack} = 0;
                        pkg_iterate();
                        $cf->{sn} = $osn; 
                    } else {
                        undef $ret;
                        $cf->{pkg_build_failures} .= "$sn ";
                    }
                    next if $cf->{coe} || $ret;
                    return $ret;
d691 1
d693 12
a704 11
            # we may not have needed to download source, so this gets
            # repeated.  Really time for a re-structure of code
            next PKG if $cf->{download_only};

            my $rpmclean;
            if($cf->{leavesrc} || $pcf->{$key . '_LEAVESRC'}) {
                $rpmclean = '';
                $ENV{$key . '_LEAVESRC'} = 'y';
            } else {
                $rpmclean = '--clean --rmsource ';
            }
d706 24
a729 23
            # build the binary rpms
            $cmd =   "$cf->{rpmbuild} --dbpath $cf->{rpmdb} "
                   . "--define '_unpackaged_files_terminate_build 0' "
                   . "--define '_target_cpu $pcf->{LINTARCH}' "
                   . "--define '__strip strip' "
                   . "--define '_topdir $cf->{rpmdir}' "
                   . "--define '_prefix $cf->{prefix}' "
                   . "--define '_tmppath $cf->{tmppath}' "
                   . "--define '_mandir $cf->{prefix}/$cf->{mandir}' "
                   . "--define '_sysconfdir $cf->{sysconfdir}' "
                   . "--define '_localstatedir $cf->{localstatedir}' "
                   . "$rpmbuildopts $rpmclean $spec";
            print "$cmd\n";
            $stime = time();
            $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 ";
                undef $ret;
                return $ret unless $echo || $cf->{coe};
            }
d731 3
a733 1
        return $ret if $rpmbuildopts =~ m,--short-circuit,;
d735 3
a737 3
        # if anything got build, try to install it
        if(    (! -f $cf->{host_wait_warning} && rpm_needs_update($tok))
            || ( -f $cf->{host_wait_warning}  && 
d740 4
a743 1
                  || `$cf->{rpm} --dbpath $cf->{rpmdb} -q $tok->{name}-$tok->{version}-$tok->{release} 2>/dev/null` =~ m,is not installed,) ) ) {
d745 24
a768 2
            # make a note that something got built
            $cf->{something_got_built} = 1;
d770 16
a785 18
            # 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 $rpm ( glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*") ) {
                # 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
                ($subpkg) = $rpm =~ m,/([^/]+)-[^-]+-[^-]+\.\w+\.rpm$,;
                die(  "Error: could not match rpm with pattern: "
                    . "$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$tok->{name}-"
                    . "$tok->{version}-$tok->{release}*\n") unless $subpkg;
                $cmd  = "$cf->{sudo} $cf->{rpm} ";
                $cmd .= "--dbpath $cf->{rpmdb} ";
                $cmd .= "-e --allmatches --nodeps ";
                $cmd .= "$subpkg 2>/dev/null";
                print "$cmd\n";
d787 4
a790 25

                # install the new package
                $cmd  = "$cf->{sudo} $cf->{rpm} ";
                $cmd .= "--dbpath $cf->{rpmdb} ";
                $cmd .= "--prefix $cf->{dev_image} " if $cf->{dev_image};
                $cmd .= "--ignorearch -ivh ";
                $cmd .= "--force "  unless $cf->{conflicts} || $cf->{hostinst};
                $cmd .= "--replacepkgs --replacefiles " if $cf->{hostinst};
                $cmd .= "--nodeps " if $cf->{nodeps};
                $cmd .= "--excludedocs ";
                $cmd .= "$rpm";
                print "$cmd\n";

                # make sure we're not going to clobber host files
                check_host_clobber($rpm);

                # in dry-run mode (echo), don't actually install)
                unless($echo) {
                    system_nb($cmd);
                    my $ec = ($? & 0xffff) >> 8;
                    # a return code of 2 indicates a newer package installed
                    if($ec != 0 && $ec != 2) {
                        undef $ret;
                        return $ret unless $cf->{coe};
                    }
d792 1
d794 2
a795 3
                # the install of this package may cause others to install
                process_pkg_triggers($key);
            }
d798 26
d830 5
a834 5
    validate_sn();
    my $key = get_key_by_sn($cf->{sn});
    $$key->{build}  = 1;
    $cf->{leavesrc} = 1;
    return f_buildrpms("-bp");
d839 6
a844 6
    validate_sn();
    my $key = get_key_by_sn($cf->{sn});
    $$key->{build}  = 1;
    $cf->{leavesrc} = 1;
    $cf->{nounpack} = 1;
    return f_buildrpms("-bc --short-circuit");
d849 6
a854 6
    validate_sn();
    my $key = get_key_by_sn($cf->{sn});
    $$key->{build}  = 1;
    $cf->{leavesrc} = 1;
    $cf->{nounpack} = 1;
    return f_buildrpms("-bi --short-circuit");
d860 10
a869 4
    my $sn = $cf->{sn};
    my $key = get_key_by_sn($sn);
    #$$key->{build}  = 1;

d874 2
a875 2
    # f_scbuild()   or die();
    f_scinstall() or return;
d878 1
a878 2
    my $tok = {sources => "", patches => "", prep => "" };
    parse_spec($spec, $tok, 1);
d909 1
d918 3
a920 1
    my $ret = f_buildrpms("-bb");
d927 2
a928 18
die "not implemented yet";
    my ($packages, $srpm, $pkg);
    # ??? should this be spec name, or package name (name:<> in specfile)
    foreach my $key (mk_buildlist()) {
         $packages->{$$key->{sn}} = 1;
    }
    for $srpm (@@ARGV) {
        warn("skipping: $srpm, doesn't look like an srpm\n"), next
                                               unless $srpm =~ m,\.src\.rpm$,;
        ($pkg) = $srpm =~ m,/([^/]+)-[^-]+-[^-]+\.\w+\.rpm$,;
        warn("skipping: $srpm, $pkg is already in the package list\n"),next
                                               if $packages->{$pkg};
        print "importing $srpm to $cf->{rpmdir}\n";
        system_nb(<<TXT) == 0 or die;
set -x -e
echo rpm --dbpath $cf->{rpmdb} --define '_topdir $cf->{rpmdir}' -ivh $srpm
TXT
    }
d947 1
a947 2
    my $tok = {sources => "", patches => "", prep => "" };
    parse_spec($spec, $tok, 0);
d991 1
a991 1
$cf->{rpmbuild} --dbpath $cf->{rpmdb} --define '_target_cpu $pcf->{LINTARCH}' --define '_topdir $cf->{rpmdir}' --define '_prefix $cf->{prefix}' --define '_tmppath $cf->{tmppath}' --define '_mandir $cf->{prefix}/$cf->{mandir}' --define '_sysconfdir $cf->{sysconfdir}' -bp $specout >/dev/null || exit 1
d1085 1
a1085 2
       $tok = {sources => "", patches => "" };
       parse_spec($spec, $tok, 0);
d1116 1
a1116 1
    return release_main();
d1122 1
a1122 1
    return release_main(warnonly => 1);
d1134 1
a1134 1
    foreach $var (qw/dev_image rpmdir rpmdb bin_path
d1208 2
a1209 2
    my @@sav_list = qw/dev_image prefix sysconfdir rpmdir rpmdb nodeps force
                      reinstall dodrop preconfig hostinst/;
d1214 2
a1215 1
    $cf->{dev_image}     = '/';                  # install prefix
d1220 1
d1222 2
a1223 2
    $cf->{force}         = 0 unless $allow_hostcf;
    $cf->{hostinst}      = 1 unless $allow_hostcf;
d1316 2
a1321 2
    check_platform_config($pcf);
    setup_env_vars($cf, $pcf);
d1334 1
a1334 1
    my $qo = `$cf->{rpm} --dbpath -q $cf->{rpmdb} bogus-package 2>&1`;
d1339 25
a1363 2
    # this allows you to have entries like: /home/seh/rpmdb_$PLATFORM
    $cf->{rpmdb} =~ s,\$([\w]+),$pcf->{$1},g;
d1366 1
a1366 1
    mk_rpm_dirs($cf->{rpmdir}, $cf->{rpmdb}, $cf->{dev_image}, $cf->{tmppath});
a1398 3
    # this allows you to have entries like: /home/seh/rpmdb_$PLATFORM
    $cf->{rpmdb} =~ s,\$([\w]+),$pcf->{$1},g;

a1405 8
    # these are "special cases"
    $pcf->{GNUTARCH} = $cf->{buildarch} if $pcf->{GNUTARCH} eq "buildarch";
    $pcf->{LINTARCH} = g2larch($cf->{buildarch})
                                        if $pcf->{LINTARCH} eq "buildarch";
    $pcf->{CFGHOST} = "$cf->{buildarch}-linux"
                                        if $pcf->{CFGHOST} eq "buildarch";


d1417 1
a1417 1
    $ENV{DEV_IMAGE} = $cf->{dev_image};
d1447 1
a1447 2
    $ENV{RPMDB} = $cf->{rpmdb};
    $ENV{PKG_CONFIG_PATH} = "$cf->{dev_image}/usr/lib/pkgconfig" || "";
d1487 3
a1489 2
        f_clean() if -d $cf->{rpmdb};
        system_nb("rm -f $cf->{rpmdir}/RPMS//$pcf->{LINTARCH}/*");
d1492 1
a1492 1
    system_nb("cp $cf->{preconfig} $cf->{preconfig}.old") unless $cf->{dry};
d1587 7
d1620 1
a1620 1
    open(MAP, $map) or die("open($map): $!\n");
d1623 3
a1625 1
        m,$pre,o or next;
d1646 1
a1646 1
    $map = "$cf->{platforms_dir}/$pcf->{PLATFORM}/$cf->{pkg_map}";
a1651 2
            $fn = "$cf->{config_dir}/userspace/$fn"
                                               unless substr($fn, 0, 1) eq '/';
d1664 3
a1666 1
            m,$pre,o or next;
d1669 1
a1669 1
                read_pkg_map($2);
d1743 1
d1778 1
a1778 3
    my $tok = {};
    parse_spec($spec, $tok, 0, 'name');
    die("$spec does not contain an entry for Name:") unless $tok->{name};
d1788 1
a1788 1
    my @@installed = split(/[\s\n]+/, `$cf->{rpm}  --dbpath $cf->{rpmdb} -qa --queryformat "%{name} "`);
d1828 5
a1832 2
        my $cmd =   "$cf->{sudo} $cf->{rpm} --dbpath $cf->{rpmdb} "
               . "-e --allmatches $rpmname --nodeps";
d1866 1
a1866 1
       || $plat_specs ne "$cf->{platforms_dir}/$pcf->{PLATFORM}" ) {
d1870 1
a1870 1
        $plat_specs  = "$cf->{platforms_dir}/$pcf->{PLATFORM}";
d1887 1
a1887 1
            $specpath   = "$cf->{tmppath}/$spec";
d1890 2
d1899 1
d1903 10
d1995 1
a1995 1
                   GNUTARCH LINTARCH CFGHOST/) {
d2005 23
d2032 2
a2033 1
    my($rpmdir, $rpmdb, $dev_image, $tmppath) = @@_;
d2039 1
a2039 1
    mkdir -p $rpmdir/\$i
d2041 1
a2041 1
for i in $dev_image $rpmdb $tmppath
d2049 1
a2049 5
    # IMPORTANT: make sure users don't install in /
    if( $dev_image =~ m,^\s*//\s*$, ) {
        die "dev_image cannot be set to '$dev_image'";
    }
    # make sure dev_image is a directory and has write permissions
d2051 1
a2051 3
    die "dev_image: $dev_image is not a directory" unless -d $dev_image;
    die "dev_image: $dev_image is not writable by the user"
                                                   unless -W $dev_image;
d2055 1
a2055 1
        my $fstype = cmd_w_to(5, "df -PT $cf->{rpmdb} |tail -1") || "fake nfs";
d2065 1
a2065 5
You may move the database to a local disk by changing the entry in your
rcfile ($cf->{rcfile}) from $rpmdb
to somewhere that is not on an NFS filesystem

Do you want to continue and attempt to use this NFS area for your rpmdb (y|n)?
a2067 1
            die "Goodbye\n" unless /^y/i;
d2073 10
a2082 1
    if(! -e "$rpmdb/Packages") {
d2085 6
a2090 1
$cf->{rpm} --dbpath $rpmdb --initdb
d2111 1
d2116 3
a2118 2
    my @@sav_list = qw/dev_image nodeps sn force reinstall dodrop ldirs
                     prefix sysconfdir rpmbuild rpm rpmdir rpmdb lpp tmppath/;
d2120 2
a2121 1
    $cf->{dev_image}     = "";
d2134 2
a2135 1
    $cf->{tmppath}       = "/tmp";
d2142 3
a2144 1
    mk_rpm_dirs($cf->{rpmdir}, $cf->{rpmdb}, "$cf->{rpmdir}/rootfs",$cf->{tmppath});
d2147 1
a2147 1
    my @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$cf->{sn}-*");
d2149 4
a2152 2
                        . "$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$cf->{sn}-*";
    my $cmd  = "$cf->{sudo} $sav->{rpm} --dbpath $cf->{defpfx}/var/lib/rpm ";
d2160 1
a2160 1
    system_nb("rm -f $cf->{defpfx}/usr/src/rpm/RPMS/$pcf->{LINTARCH}/*");
d2251 4
a2254 1
    $tcname =~ s,i\d86,$cf->{buildarch}, if $cf->{buildarch} eq 'ppc';
a2260 1

d2267 1
a2267 1
        my $tc_rpm = $pcf->{TOOLCHAIN};
d2354 1
a2354 1
# it will scribble of the host's installation.  For this
d2366 1
a2366 1
    $inst_pfx = $cf->{dev_image};
d2369 1
a2369 1
    # if a relocatable package, and were installing in our project area
d2371 3
a2373 2
    $len = length($cf->{top});
    if($pkg_prefix && unpack("A$len", $inst_pfx) eq $cf->{top}) {
d2383 1
a2383 1
    open(CMD, "$cmd |") or die("can't fork $cmd: $!\n");
d2391 1
a2391 1
            die("ERROR: $rpm\nwould clobber $path\n");
d2394 1
d2430 7
d2438 6
d2458 1
a2463 2
PLATFORM=$pcf->{PLATFORM}
PLATFORM=\${PLATFORM:-unknown}
d2466 1
a2466 1
    if [ -f \${PLATFORM}.config ]
d2468 1
a2468 1
        cp \${PLATFORM}.config .config
d2479 1
a2479 1
    cp .config \${PLATFORM}.config
d2495 4
a2498 1
    my ($plat_dir, $atime, $mtime);
d2505 1
d2509 2
a2510 1
            if(-M "$plat_dir/.config" <=  -M "$plat_dir/defconfig") {
d2540 1
d2572 49
d2624 1
a2624 1
    $plat_dir ||= $cf_main->{PLATFORM_DIR};
d2629 2
a2630 1
    if( ($cf->{preconfig} || $cf->{profile}) && -f $oldconfig ) {
d2637 1
a2637 1
if [ ! -f "$plat_dir/.config" -a -f "$plat_dir/defconfig" ]
d2639 5
a2643 5
    cp $plat_dir/defconfig $plat_dir/.config
fi
if [ -n "$cf->{preconfig}" ]
then
    cp -f $cf->{preconfig} $plat_dir/.config
d2651 1
a2651 1
$cf->{conf} main.lkc
d2654 1
d2661 1
a2661 1
    $cf->{mode} eq 'config' ? exit 0 : return 1;
d2687 1
a2687 1
    open(MCF, ">$cf->{mainlkc}") or die "open $cf->{mainlkc} : $!\n";
d2736 1
d2740 1
d2743 7
a2749 1
alias rpm="rpm --dbpath $cf->{rpmdb}"
d2831 1
a2831 1
    my ($ver) = `$cf->{rpm} --dbpath $cf->{rpmdb} -q --queryformat %{VERSION}.%{RELEASE} $tok->{name} 2>&1`;
@


1.14
log
@change Uvh back to ivh until I can resolve properly
@
text
@d108 1
a108 1
    cvs_version  => '$Revision: 1.13 $' . ' sv',
d720 6
a725 4
        if(   $rebuilt || $cf->{reinstall}
           || (exists $$key->{install} && $$key->{install})
           || `$cf->{rpm} --dbpath $cf->{rpmdb} -q $tok->{name}-$tok->{version}-$tok->{release} 2>/dev/null
                                                  ` =~ m,is not installed,) {
d2632 19
@


1.13
log
@rename noredirect to noredir to be consistent
dltest implied noredir
apply dltest to host packages too
export PKG_DIRECTFB
exitt if key is mapping from subr using return not next
@
text
@d108 1
a108 1
    cvs_version  => '$Revision: 1.12 $' . ' sv',
d730 1
d732 14
d751 1
a751 1
                $cmd .= "--ignorearch -Uvh ";
@


1.12
log
@import-20071105 conflig resolution commit
@
text
@d108 1
a108 1
    cvs_version  => '$Revision: 1.11 $' . ' sv',
d170 1
a170 1
    noredirect   => 0,
d422 3
d1210 1
a1210 1
    return 1 if -f $cf->{host_wait_warning} || $cf->{dltest};
d1384 1
d1599 1
a1599 1
                warn("$key in $map is not selectable\n"), next
@


1.11
log
@add fix to mkisofs for joliet long
@
text
@d1 1
d5 1
a5 1

d8 1
a8 1
# Copyright  Freescale Semiconductor, Inc. 2004-2005. All rights reserved.
d41 2
d50 1
d69 1
d76 2
d79 1
a79 1
    configured   => "", 
a85 1
            libstdc++-devel 0
d107 2
a108 2
    app_version  => "6.4.1",
    cvs_version  => '$Revision: 1.10 $' . ' sv',
d113 1
d121 1
a121 1
    host_wait_warning => "$top/.host_wait_warning2",
d135 1
a161 1
    verbose      => 0,
d174 1
d177 1
a177 1
    
d183 1
a183 1
            $echo $pcf $ppcf $rev_install_deps $pcac);
d191 10
a200 3
                                PKG_KERNEL_WANT_CF PKG_KERNEL_LEAVESRC/ ],
           PKG_LIBC     => [ qw/PKG_LIBC_WANT_LOCALES PKG_LIBC_WANT_HEADERS
                                PKG_LIBC_WANT_STATIC_LIBS PKG_LIBC_WANT_CF/ ],
d203 1
a203 1
                                PKG_GDB_SERVER_WANT_ED 
d208 3
a210 2
                                PKG_DROPBEAR_WANT_NO_X11FWD/ ],
           PKG_SYSCONFIG=> [ qw/SYSCFG_HOSTNAME 
d216 1
a216 1
                          SYSCFG_START_NETWORK
d237 2
d258 3
a260 1
                  PKG_LIBC  => [ qw/PKG_GCC/ ],
d278 1
a278 1
        --mode|m 
d291 1
d315 1
d318 1
d322 2
d346 2
a347 2
        "verbose|v"  => \$cf->{verbose},
        "batch|b"    => \$cf->{batch}, 
d359 1
d363 1
d377 2
a378 2
die "invalid mode $cf->{mode}\n", $usage 
    unless $cf->{mode} =~ m,^(buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell),;
d387 1
a387 1
The options: --profile cannot be used when 
d422 1
d461 1
a461 1
write_release_info("$cf->{top}/RELEASE_INFO");
d464 1
a464 1
&{"f_" . $cf->{mode}}() 
d481 1
a481 1
                    "$cf->{bin_path}/device_table.txt", $pcf) 
d493 2
a494 1
{ 
d500 1
a500 1
        print("$pkg is not installed\n"), next 
d502 1
a502 1
        $pkg .= " $pkg-devel" 
d511 1
a511 1
}   
a557 1
$echo find $cf->{rpmdir}/SPECS -type l -exec rm {} \\;
d565 1
a565 1
$echo rm -f $cf->{rpmdb_nfs_warning}
d567 1
d569 1
a569 1
$echo for i in faked fakeroot mkimage gdb tmake; do rm -rf $cf->{top}/bin/\$i ; done
d579 1
a579 1
    } 
a584 1
    $msg .= "(see logfile: $cf->{redirected})\n" if $cf->{redirected};
d586 1
a586 1
    print "using $cf->{preconfig}\n" 
d594 1
d600 8
a607 2
        my $spec = get_spec($sn) or warn("skipping $sn, specfile not found\n"),
                                                               undef $ret, next;
d610 1
a610 2
        @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$tok->{name}-*");

d614 1
a614 1
        if(   $cf->{force}
d621 1
a621 1
                unlink(@@rpms) unless $cf->{dltest};
d623 1
a623 1
                foreach my $url (  split(/\s*\n/, $tok->{sources}), 
d627 1
a627 1
                    if(! -e $tgt || $cf->{dltest}) {
d639 1
a639 1
                        
d659 1
a659 1
                    if($cf->{mode} eq 'buildrpms') { 
d669 1
a669 1
                        $cf->{sn} = $osn;
d685 1
a685 1
                $ENV{$key . '_LEAVESRC'} = 'y'; 
d689 1
a689 1
           
d719 1
a719 1
           || `$cf->{rpm} --dbpath $cf->{rpmdb} -q $tok->{name} 2>/dev/null
d725 3
a727 12
            foreach $rpm ( glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$tok->{name}-*") ) {
                # We need to removed 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
                ($subpkg) = $rpm =~ m,/([^/]+)-[^-]+-[^-]+\.\w+\.rpm$,;
                $cmd  = "$cf->{sudo} $cf->{rpm} ";
                $cmd .= "--dbpath $cf->{rpmdb} ";
                $cmd .= "-e --allmatches --nodeps ";
                $cmd .= "$subpkg 2>/dev/null";
                print "$cmd\n";
                system_nb($cmd);
d733 3
a735 2
                $cmd .= "--ignorearch -ivh ";
                $cmd .= "--force "  unless $cf->{conflicts};
d746 4
a749 1
                    if(system_nb($cmd) != 0) {
d799 1
a799 1
    
d814 1
d862 1
a862 1
        warn("skipping: $srpm, doesn't look like an srpm\n"), next 
d908 2
a909 2
already exists.  You need to move this out the way before running 
patchmerge.  Patchmerge will preserve your working copy of the 
d941 1
a941 1
    
d958 1
a958 1
due to and incomplete "make distclean" 
d972 1
a972 1
	return f_listpkgs('eula');
d981 6
a986 6
	if ($mode eq "eula") {
		# Set large FORMAT_LINES_PER_PAGE so there is only one page
		$= = 10000;
		# Disable page break characters
		#$^L = "";
	}
d988 1
a988 2
   $mode ||= 'text';
	# Set FORMAT_NAME
d1026 1
d1033 1
a1033 1
   } 
d1042 1
a1042 1

d1049 1
d1061 2
a1062 220
    # For now, don't allow batch mode releases until we've figured out
    # all the details of passing in the information needed.
    die("Batch mode is enabled, cannot make iso release!!\n") if $cf->{batch};

    local $_;

    print <<TXT;

You are about to create an iso image from this working project.
This will include all sources and built rpms for the target platform,
as well as the LTIB source code.

Before doing this, you should have done the following:

 1. Make sure you have checked in any changes (cvs commit) 
 2. Make sure your source code is up to date (cvs up -dP)
 3. Configured ltib for the target
 4. Run ltib to build all the selected packages

Do you want to continue: Y|n ?
TXT
    if(! $cf->{batch} ) {
        $_ = <STDIN>;
        print("aborted\n"), return 1 if /^n/;
    }

    # Normally everything is driven from CVS but there are some secret
    # tagnames that let you do releases from working copies, or just 
    # the HEAD of cvs.
    # HEAD : normal, except no tagging and just use the cvs HEAD for the export
    # localdir : use the content of the local dir using a list in file MANIFEST
    # localdir_nobuild : same as localdir, but don't do the package build
    my $cvstags;
    my $tag = "rel-$pcf->{PLATFORM}-$cf->{stime}";
    my $date = gm_yyyymmdd();
    my $rel = "ltib-$pcf->{PLATFORM}-$date";
    print <<TXT;

Please enter the cvs tag name for this release, or
if you just type enter, the timestamp $tag will be used

TXT
    if(! $cf->{batch} ) {
        while(1) {
            $_ = <STDIN>;
            if ( !defined $_ ) {
                # Prevent infinite loop if tag is from here file in script.
                die("STDIN is not defined, exiting\n");
            }
            chomp($_);
            $tag = $_ if $_;
            last if $tag eq 'localdir' || $tag eq 'localdir_nobuild' 
                                       || $tag eq 'HEAD';
            if($tag !~ m,^[a-zA-Z][\w-]+$,) {
                print(<<TXT);
Illegal tag name, tags need to be specified as follows:

* Start with an uppercase or lowercase letter
* Subsequently and can also contain uppercase and lowercase letters, 
  digits, `-', and `_'
TXT
                next;
            }
            unless($cvstags) {
                print("gathering a list of cvs tags used so far, pls wait\n");
                %$cvstags = map { $_ => 1 } get_cvs_tags();
            }
            last unless exists $cvstags->{$tag};
            print(  "The tag you've chosen is already in cvs, "
                  . "please choose another\n");
        }
    }

    # check for unsaved config changes
    print "\nChecking for unsaved config changes:\n\n";
    my @@devs = glob("$cf->{platforms_dir}/$pcf->{PLATFORM}/*.dev");
    system_nb(<<TXT) == 0 or die "\nPlease save your changes before continuing\n";
set -e
diff -qN  $cf->{platforms_dir}/$pcf->{PLATFORM}/defconfig $cf->{platforms_dir}/$pcf->{PLATFORM}/.config
for i in @@devs
do
    diff -qN $cf->{platforms_dir}/$pcf->{PLATFORM}/`basename \$i .dev` \$i
done
TXT
    if($tag ne 'localdir' && $tag ne 'localdir_nobuild') {
        print "\nChecking that cvs is up to date\n";
        my $cvs_state = `cvs -nq up 2>&1`;
        if($cvs_state =~ m,^(?:C|M|U|A|R),m) {
            die(<<TXT);

$cvs_state

Your working directory is not in sync with cvs (see above), please do a:
cvs up -dP
cvs commit

TXT
        }
    }

    system_nb(<<TXT) ==  0 or die;
set -x -e
rm -rf stage
mkdir -p stage

if [ "$tag" != "HEAD" -a "$tag" != "localdir" -a "$tag" != "localdir_nobuild" ]
then
    cvs tag -c $tag .
fi

if [ "$tag" != "localdir" -a "$tag" != "localdir_nobuild" ]
then
    cvs export -kv -d stage -r $tag ltib
    rm -rf stage/CVS
    for i in `ls stage/config/platform | grep -E -v '($pcf->{PLATFORM}|host)'`
    do
        rm -rf stage/config/platform/\$i
    done
    rm -rf stage/dist/FC-2
    rm -rf stage/internal
    rm -rf $rel
else
    rsync -av --files-from=MANIFEST . stage
    if [ -d overlay -a -f overlay/MANIFEST ]
    then
        rsync -av --files-from=overlay/MANIFEST overlay stage
    fi
fi
mkdir $rel
mv stage $rel
mv $rel/stage $rel/$rel
cp $rel/$rel/bin/ltib_install $rel/install
mkdir $rel/pkgs


# do a dltest to make sure that all files have been uploaded
if [ "$tag" != "localdir" -a "$tag" != "localdir_nobuild" ]
then
    ./ltib --dltest
fi

# work in the release staging area
cd $rel/$rel

# built to make sure all generated pieces make it onto the iso
if [  "$tag" != "localdir_nobuild" ]
then 
    ./ltib --preconfig config/platform/$pcf->{PLATFORM}/defconfig --configure --batch
fi

# remove the rootfs components
./ltib -m clean

# remove unwanted log files and host package install check files
rm -f .host_wait_warning* host_config.log
rm -f $cf->{rpmdb_nfs_warning}
rm -rf rpm/BUILD/*

cd -

TXT
    
    print("copy all sources\n");
    copy_all_sources("$rel/pkgs/") or die;

    print("copy all toolchain rpm/srpms\n");
    foreach my $rpm (list_all_toolchains()) { 
        my $path = get_file($rpm, $cf, 1) or die "can't get $rpm";
        system_nb("cp -af $path $rel/pkgs/") == 0 or die;
        $rpm =~ s,\.[^.]+\.rpm,.src.rpm,;
        $path = get_file($rpm, $cf, 1);
        system_nb("cp -af $path $rel/pkgs/") == 0 or die;
    }

    print("copy host support package sources\n");
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{hostconfig});
    copy_sources("$rel/pkgs/") or die;

    print("copy rpm-fs sources\n");
    copy_spec_sources("rpm-fs", "$rel/pkgs/") or die;

    # output some helpful release information
    write_release_info("$rel/$rel/RELEASE_INFO", $tag, $rel) or die;

    system_nb(<<TXT) ==  0 or die;
set -x -e
cp $rel/$rel/RELEASE_INFO $rel/RELEASE_INFO
cd $rel
tar zcf ltib.tar.gz $rel
rm -rf $rel
cd -
if mkisofs -help 2>&1 | grep -q joliet-long
then
    mkisofs -A "$rel" -J -allow-leading-dots -l -publisher "Freescale" -o $rel.iso -r -v -V "ltib" -joliet-long $rel
else
    mkisofs -A "$rel" -J -L -l -P "Freescale" -o $rel.iso -r -v -V "ltib" $rel
fi
rm -rf $rel

TXT

    return 1;
}

sub copy_spec_sources
{
    my ($sn, $dest) = @@_;
    my $spec = get_spec($sn) or warn("skipping $sn\n"), return;
    my $tok = {sources => "", patches => "" };
    parse_spec($spec, $tok, 0);
    foreach my $url (  split(/\s*\n/, $tok->{sources}),
                       split(/\s*\n/, $tok->{patches})   ) {
        my $src = get_file($url, $cf, 1) or warn("can't get: $url"), return;
        system_nb("set -x ; cp -af $src $dest") == 0 or die;
        if(-f "$src.md5") {
            system_nb("set -x ; cp -af $src.md5 $dest") == 0 or die;
        }
    }
    return 1;
d1065 1
a1065 1
sub copy_all_sources
d1067 2
a1068 6
    my ($dest) = @@_;

    foreach my $key ( mk_buildlist()  ) {
        copy_spec_sources($$key->{sn}, $dest) or die;
    }
    return 1;
a1070 26
sub copy_sources
{
    my ($dest) = @@_;

    foreach my $key ( mk_buildlist()  ) {
        next unless $$key->{en};
        copy_spec_sources($$key->{sn}, $dest) or die;
    }
    return 1;
}

sub list_all_toolchains
{
    my $lkc = "$cf->{platforms_dir}/$pcf->{PLATFORM}/main.lkc";
    my @@tcs;
    my $scan = 0;
    local $_;
    open(LKC, $lkc) or die("open $lkc : $!");
    while(<LKC>) {
        next unless $scan || m,^\s*config\s+TOOLCHAIN\s*$,;
        $scan = 1, next unless $scan;
        last if m,^\s*config\s+,;
        push(@@tcs, $1) if m,([\S]+\.rpm),;
    }
    return @@tcs;
}
d1109 8
d1130 1
a1130 1
            parse_config($rc, $cf, { strip_blank => 1, 
d1155 1
a1155 1
                      reinstall dodrop preconfig/;
d1167 1
d1186 1
a1186 1
    # we can get here at install time, or later config of host packages 
d1205 1
a1205 1
    # do not attempt to re-install host packages once 
d1208 1
a1208 1
    
d1233 1
a1233 1
    redirect($cf->{logfile});
d1235 1
a1235 1
    # use the host's rpm to bootstrap a known version of rpm 
d1245 1
a1245 1
    redirect($cf->{logfile});
d1268 1
a1268 1
    $ENV{DISTCC_HOSTS} = $cf->{DISTCC_HOSTS} 
d1270 1
a1270 1
    $ENV{DISTCC_TCP_CORK} = $cf->{DISTCC_TCP_CORK} 
d1272 1
a1272 1
    $ENV{MAKEFLAGS} = $cf->{MAKEFLAGS} 
d1334 1
a1334 1
    $pcf->{CFGHOST} = "$cf->{buildarch}-linux" 
d1338 1
a1338 1
    $ENV{UNSPOOF_PATH} = 
d1340 1
a1340 1
                 . "$cf->{defpfx}/usr/bin:" 
d1343 3
a1345 1
    $ENV{SPOOF_PATH} = ($pcf->{TOOLCHAIN_PREFIX} ? "$cf->{spoof_path}:" : "")
d1364 1
d1376 2
d1380 1
d1382 1
a1382 1
    if($cf->{verbose}) {
d1391 1
a1391 1
     
d1394 1
a1394 1
        warn("setting ENV{$k}=$pcf->{$k}\n") if $cf->{verbose};
d1409 1
a1409 1
    foreach my $dep (qw/PLATFORM GNUTARCH LINTARCH CFGHOST TOOLCHAIN DISTRO/) {
d1418 6
a1423 2
    system_nb("rm -f $cf->{rpmdir}/RPMS//$pcf->{LINTARCH}/*") if $need_frb;
    touch("$cf->{preconfig}.old");
d1437 1
a1437 1
    return 1 if -M $spec <= -M $cf->{preconfig};    
d1440 1
d1444 2
a1445 1
            warn "$dep has changed, $spec_name needs a rebuild\n";
d1507 1
a1507 1
    return unless $key;          
d1510 1
d1532 1
a1532 1
sub mk_buildlist 
d1543 1
a1543 1
    my $map = "$cf->{top}/$pcf->{DISTRO}/common/$cf->{pkg_map}";
d1548 1
a1548 1
        my $key = $1;
d1562 1
a1562 1
                                                            if $cf->{verbose};
d1570 17
a1586 2
        open(MAP, $map) or die("open($map): $!\n");
        while(<MAP>) {
d1590 4
d1601 2
a1602 1
        }
a1603 1
    close MAP;
d1615 1
a1615 1
            my ($key, $lu_pkg, $pkg, $pkg_len, $found);
d1619 1
a1619 1
                $lu_pkg = get_pkg_name($key) or die;
d1628 1
a1628 1
If necessary please give the whole spec file name (with the    
d1640 1
a1640 1
    } 
d1727 1
a1727 1
        
d1735 1
a1735 1
            }    
d1738 2
a1739 2
    warn("installed = ", join(", ", @@installed), "\n") if $cf->{verbose};
    warn("drop_list = ", join(", ", @@drop_list), "\n") if $cf->{verbose};
d1756 1
a1756 1
    } 
d1776 1
d1802 1
a1802 1
    foreach my $dir ( @@dirs ) { 
d1813 1
a1813 1
               $tmplpath = "$tdir/$tmpl", last if -e "$tdir/$tmpl"; 
d1816 3
a1818 3
            warn("template: $tmplpath\n") if $cf->{verbose};
            if(! -f $specpath  || (-M $specinpath < -M $specpath) 
                               || (-M $tmplpath   < -M $specpath)   ) {  
d1823 1
a1823 1
           warn("spec files: [ $specpath, $specinpath ]\n") if $cf->{verbose};
d1856 1
a1856 1
        warn "pkg=$pkg, min=$min, got: $ver, $info\n" if $cf->{verbose};
d1861 1
a1861 1
        push @@failed, [ $pkg, $min, $info ];         
d1903 1
a1903 1
        $ndef .= "$k " unless exists $pcf->{$k};    
d1940 1
a1940 1
                                                   unless -W $dev_image; 
d1949 1
a1949 1
Ideally the rpm database should not be located in an NFS mounted filesystem. 
d1957 1
a1957 1
 
d1965 1
a1965 1
    
d1981 1
a1981 1
  
d2015 1
a2015 1
    $cf->{rpmdir} = "/tmp/rpm-$cf->{username}";    
d2067 1
a2067 1
To configure this, as root using the command "/usr/sbin/visudo", 
d2105 1
a2105 1
            ($fn) = $path =~ m,([^/]+)$,;  
d2120 7
d2131 2
d2143 1
a2143 2
           $pcf->{TOOLCHAIN} =~ s,i\d86,$cf->{buildarch}, 
                                                  if $cf->{buildarch} eq 'ppc';
d2145 1
a2145 1
            my $tc = get_file("$pcf->{TOOLCHAIN}", $cf, 1);
d2157 1
a2157 1
            if($? && $err !~ m,is already installed,) { 
d2164 1
a2164 1
    my $gcc_path = `which $pcf->{TOOLCHAIN_PREFIX}gcc 2>/dev/null` 
d2216 1
a2216 1
        warn "newer than $spec: $_\n" if $_ && $cf->{verbose};
d2244 1
a2244 1
                                                              if $cf->{verbose};
d2287 1
a2287 1
    my $desc = $cf->{dltest} ? "would not have complete downloads available" 
d2323 1
a2323 1
    then 
d2347 2
a2348 1
    return if $cf->{preconfig} && $cf->{dltest};
d2388 2
d2406 1
a2406 1
        } 
d2423 1
a2423 1
    
d2428 5
a2432 4
    # from mconf/conf.  We save .config to restore it later as .config.old
    if( ($cf->{preconfig} || $cf->{profile}) && -f "$plat_dir/.config") {
        ($atime, $mtime) = (stat("$plat_dir/.config"))[8,9];
        system_nb("cp $plat_dir/.config $plat_dir/.config.$cf->{stime}");
d2437 4
d2443 1
a2443 1
    cp $cf->{preconfig} $plat_dir/.config
d2447 2
a2448 1
    cat  $cf->{profile} >> $plat_dir/.config
d2455 4
a2458 4
    if(-f "$plat_dir/.config.$cf->{stime}") {
        rename("$plat_dir/.config.$cf->{stime}", "$plat_dir/.config.old");
        utime($atime, $mtime, "$cf->{preconfig}.old")
                   or warn "could not reset times on $cf->{preconfig}.old: $!";
d2466 1
a2466 1
    my $platforms = (); 
d2470 1
a2470 1
        next if $ent eq 'CVS' || $ent eq '.' || $ent eq '..';
d2476 1
a2476 1
        open(CF, "$dir/$mcf/main.lkc") 
d2558 1
a2559 2
    my ($file) = @@_;
    local $^W = 0;
a2563 4
            if(0) {
              print SAVEOUT "hack to prevent used only once warning\n";
              print SAVEERR "hack to prevent used only once warning\n";
            }
d2565 1
a2565 1
        open(STDOUT, ">>$file") or die("can't redirect stderr to $file: $!");
d2569 6
d2578 2
d2581 4
d2587 3
a2589 1
    $cf->{redirected} = "";
@


1.10
log
@restore the spec name after doing a continued package build
fix the jffs2 padding option
update the helloworld spec file to the latest
@
text
@d102 1
a102 1
    cvs_version  => '$Revision: 1.9 $' . ' sv',
d1222 6
a1227 1
mkisofs -A "$rel" -J -L -l -P "Freescale" -o $rel.iso -r -v -V "ltib" $rel
@


1.9
log
@quote any '\' in the username when use as part of a path (rpm-fs)
@
text
@d102 1
a102 1
    cvs_version  => '$Revision: 1.8 $' . ' sv',
d627 1
d635 1
a635 1
                        $cf->{sn} = "";
@


1.8
log
@fixups from import-20070116
@
text
@d102 1
a102 1
    cvs_version  => '$Revision: 1.7 $' . ' sv',
d2185 1
@


1.7
log
@Improved proxy handling
@
text
@d102 1
a102 1
    cvs_version  => '$Revision: 1.6 $' . ' sv',
a522 1
$echo rm -rf $cf->{top}/bin/{faked,fakeroot,mkimage}
d527 2
a528 1
$echo rm -rf $cf->{rpmdir}/{RPMS,SRPMS}
d540 1
a540 1
$echo rm -f bin/{gdb,tmake}
d595 1
a595 1
                        unless( $src = get_file($url, $cf) ) {
d1196 1
a1196 1
        my $path = get_file($rpm, $cf) or die "can't get $rpm";
d1199 1
a1199 1
        $path = get_file($rpm, $cf);
d2089 4
a2092 1
mkdir -p $rpmdir/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
d2305 1
a2305 1
            my $tc = get_file("$pcf->{TOOLCHAIN}", $cf);
@


1.6
log
@.ltibrc: add /opt/freescale/pkgs to ldirs.  Add a commented out lpp entry as an example. ltib: remove a commented out bdirs
@
text
@d39 1
d102 1
a102 1
    cvs_version  => '$Revision: 1.5 $' . ' sv',
@


1.5
log
@changed default base dir so ltib lives under /opt instead of /opt/freescale
@
text
@a45 1
#$bdir = "/opt/freescale";
d101 1
a101 1
    cvs_version  => '$Revision: 1.4 $' . ' sv',
@


1.4
log
@post freescale import-20061124 alignment
@
text
@d45 2
a46 1
$bdir = "/opt/freescale";
d63 1
a63 1
    lpp          => "$bdir/pkgs",
d102 1
a102 1
    cvs_version  => '$Revision: 1.3 $' . ' sv',
@


1.3
log
@fix conflicts from fsl import-20061124
@
text
@d101 1
a101 1
    cvs_version  => '$Revision: 1.1.1.12 $',
@


1.2
log
@set app_version to rel-6-2-2-sv
@
text
@d33 1
a33 1
use 5.006_001;
d57 1
d73 1
a73 1
            glibc           2.2.5
d76 1
a76 1
            binutils        2.11.93
d91 1
d100 2
a101 1
    app_version  => "6.2.2-sv",
a119 1
    quiet        => 0,
d135 1
d146 1
a146 1
    pkg          => "",
d174 1
a174 1
            $echo $pcf $ppcf $rev_install_deps);
d187 2
a188 1
                                PKG_GDB_SERVER_WANT_ED/ ],
d212 5
a216 1
                          SYSCFG_READONLY_FS/ ],
d219 1
d238 1
a238 1
                                      PKG_WHICH/],
d267 2
d314 1
a314 1
        "pkg|p:s"    => \$cf->{pkg},
d340 7
a346 1
die "$cf->{app_version}\n" if $cf->{version};
d350 1
a350 1
    unless $cf->{mode} =~ m,^(buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell)$,;
d352 6
a357 7
if($cf->{mode} eq 'scbuild' && $cf->{pkg} && $cf->{configure}) {
    $cf->{configure} = '';
    $ENV{SCB_WANT_CF} = 'y';
}
if($cf->{pkg}) {
    #### TODO: temporarily allow preconfig until lkc bug is fixed
    if($cf->{configure} || $cf->{profile}) {
d359 1
a359 1
The options: --configure, --preconfig and --profile cannot be used when 
d431 3
d444 2
a445 1
        || ($cf->{mode} eq 'buildrpms' && ! $cf->{pkg}) ) {
d503 1
a503 1
    my @@sav_list = qw/pkg force/;
d508 1
a508 1
    $cf->{pkg} = "mkdistclean";
d520 1
a520 4
for i in .wget_warning .rpm_warning .sudo_warning .config .tmpconfig.h .config.old .config.cmd
do
    $echo rm -f \$i
done
d551 2
a552 2
    $cf->{something_got_built} = 0;
    my($msg, @@srpm, @@rpms, $rpm, $pkg, $subpkg, $cmd, $gcc, $rebuilt);
d556 1
a556 1
    print $msg;
d558 1
a558 1
                 if $cf->{preconfig} && ! $cf->{quiet} || $cf->{redirected};
d568 1
a568 1
        print $msg if ! $cf->{quiet} || $cf->{redirected};
d579 1
a579 1
        if(   ( $cf->{force} && ! $cf->{pkg} ) 
d584 1
a584 1
            if($cf->{mode} !~ m,^sc,) {
d624 12
a635 1
                    if($cf->{coe}) {
a636 2
                        undef $ret;
                        next;
d638 2
a639 1
                    die;
d645 8
a652 2
            my $rpmclean = $cf->{leavesrc} || $pcf->{$key . '_LEAVESRC'} ?
                            '' :  '--clean --rmsource ';
d664 1
d667 5
a671 3
            if( system_nb("$echo $cf->{fakeroot} $cmd") == 0 ) {
                $rebuilt = 1;
            } else {
d674 2
a675 1
                return unless $echo || $cf->{coe};
d715 8
a722 1
                system_nb($cmd) == 0 or return unless $echo;
d735 2
a736 2
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
d744 2
a745 2
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
d748 1
d754 2
a755 2
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
d758 1
d764 4
a767 3
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
    $$key->{build}  = 1;
d774 1
a774 1
    f_scinstall() or die();
d787 1
a787 1
Release         : $tok->{release} 
d809 1
a809 2
%Files
$tok->{files}
d816 1
a816 1
    my $ret = f_buildrpms("-bb") or die;
d850 1
a850 1
    die(<<TXT) unless $cf->{pkg};
d856 2
a857 1
    my ($specout, $specin) = get_spec($cf->{pkg}) or die();
d938 8
d948 7
d956 4
a959 3
   my $opt_f = "text";
   $~ = $opt_f;
   $^ = $opt_f . "_top";
d971 1
a971 1
"$tok->{name}-$tok->{version}-$tok->{release}", $sn, $en, $tok->{license}, $tok->{summary}
d974 2
a975 2
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<@@<@@||||||||@@<@@<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<
'|','*Package*','|','*Spec Name*','|','*Enabled*','|','*License*','|','*Summary*','|'
d978 12
a989 2
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<@@<@@||||||||@@<@@<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<
'|',"$tok->{name}-$tok->{version}-$tok->{release}",'|',$sn,'|',$en,'|',$tok->{license},'|',$tok->{summary},'|'
a1000 1
       
d1005 21
d1072 6
a1077 1
            chomp($_ = <STDIN>);
d1211 1
a1211 12
    open(RI, ">$rel/$rel/RELEASE_INFO")
                       or die("open: >$rel/$rel/RELEASE_INFO : $!\n");
    print RI <<TXT;
Release date = $cf->{gmsdate} UTC
Release user = $cf->{username}
Release host = $cf->{hostname}
Release dir  = $cf->{top}
CVS tag      = $tag
Release tag  = $rel
App version  = $cf->{app_version}
TXT
    close RI;
d1356 1
a1356 1
    my @@sav_list = qw/dev_image prefix sysconfdir rpmdir rpmdb nodep force
d1388 1
a1388 1
    if($cf->{hostcf}) {
d1468 8
d1478 1
d1502 3
d1551 1
d1564 1
a1703 2
my $pcac;

d1706 2
d1749 2
d1755 1
a1755 1
    # It makes no sense it have u-boot or kernels in them
d1774 4
a1777 2
    # When -p <pkg> is specified at the command line, this means
    # actually the spec file name (without .spec).  This is needed
d1780 15
a1794 2
    if($cf->{pkg}) {
        $key = 'userpkg';
d1796 6
a1801 11
        # turn off all packages from build list
        # see if we can find a key that matches the spec name
        foreach my $tkey (@@{$pcac->{mk_buildlist}}) {
            $$tkey->{was_en} = $$tkey->{en};
            $$tkey->{en} = 0;
            $key = $tkey if $$tkey->{sn} eq $cf->{pkg};
        }
        # if this spec name is unknown, fabricate a key
        unless(exists $$key->{sn}) {
            push @@{$pcac->{mk_buildlist}}, $key;
            $$key->{sn} = $cf->{pkg};
d1803 1
a1803 2
        $$key->{en} = 1;
        $$key->{build} = 1 if $cf->{force};
d1814 33
d1866 2
a1867 1
    my $spec = get_spec($$key->{sn}) or return;
d1869 1
a1869 1
    parse_spec($spec, $tok, 0, 'nvr');
a1874 1

d1878 1
a1878 2
    return 1 if $cf->{pkg} || $cf->{dodrop} eq 'no';

d1880 1
a1880 1
    my @@installed = split(/[\s\n]+/, `$cf->{rpm}  --dbpath $cf->{rpmdb} -qa`);
d1890 3
a1892 3
            $pkg = get_pkg_name($key) or die;
            $len = length $pkg;
            next INST if unpack("A" . $len, $inst) eq $pkg;
d1901 1
a1901 1
            if( unpack("A" . $len, $inst) eq $pkg ) {
d1911 1
d1913 1
a1913 1
        next if $rpmname =~ m,^(?:rpm-fs|tc-mtwk-|mtwk-lnx-|ppc-uclibc-tc|tc-fsl-),;
d1915 1
a1915 4
            print <<TXT if $cf->{dodrop} eq 'ask';

Drop package $rpmname ? (y|N) 
TXT
d1941 4
d2040 1
a2040 1
'Package',             'Mininum ver', 'Installed info'
d2054 1
a2054 1
Please install/ugrade these packages and then re-try.
d2160 1
a2160 1
    my @@sav_list = qw/dev_image nodeps pkg force reinstall dodrop ldirs
d2166 1
a2166 1
    $cf->{pkg}           = "rpm-fs";
d2185 1
a2185 1
    my @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$cf->{pkg}-*");
d2187 1
a2187 1
                        . "$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$cf->{pkg}-*";
d2467 1
a2467 1
   
d2688 7
@


1.1
log
@Initial revision
@
text
@d7 1
a7 1
# Copyright  Freescale Semicondutor, Inc. 2004-2005. All rights reserved.
d33 1
d44 2
a45 1
$top = $FindBin::Bin;
d51 1
a51 1
    rpm          => "/var/tmp/freescale/usr/bin/rpm",
d54 1
a54 1
    nodrop       => 0,
d56 2
a57 1
    mandir       => "/usr/share/man",
d60 3
a62 3
    defpfx       => "/var/tmp/freescale",
    lpp          => "/var/tmp/pkgs",
    spoof_path   => "/var/tmp/freescale/usr/spoof",
d64 1
d69 1
a69 3
    proxy_user   => "",
    proxy_passwd => "",
    wget_opts    => "--passive-ftp -nc --tries=1 --timeout=4",
d71 26
a96 8
    build_deps   => "
            binutils   2.11.93
            gcc        2.96
            ncurses    5.1
            rpm        0
            wget       0
            sudo       0
            texinfo    0",
d98 1
a98 1
    app_version  => "5.2.3",
d101 2
a102 3
    profile_dir  => "$top/config/profile",
    platform_dir => "$top/config/platform",
    mainconfig   => "$top/config/main.lkc",
d109 2
d116 1
d121 1
a121 1
    abnormal_exit => 'no',
d161 5
d169 5
d175 16
a190 14
$pkg_deps = {
    PKG_U_BOOT    => [ qw/PKG_U_BOOT_CONFIG_TYPE PKG_U_BOOT_BUILD_ARGS/ ],
    PKG_KERNEL    => [ qw/PKG_KERNEL_PRECONFIG PKG_KERNEL_WANT_HEADERS
                          PKG_KERNEL_WANT_CF/ ],
    PKG_LIBC      => [ qw/PKG_LIBC_WANT_LOCALES PKG_LIBC_WANT_HEADERS 
                          PKG_LIBC_WANT_STATIC_LIBS/ ],
    PKG_BUSYBOX   => [ qw/PKG_BUSYBOX_PRECONFIG PKG_BUSYBOX_WANT_CF/ ],
    PKG_GDB       => [ qw/PKG_GDB_NATIVE_WANT_CF PKG_GDB_CROSS_WANT_CF 
                          PKG_GDB_SERVER_WANT_CF/ ],
    PKG_OPENSSL   => [ qw/PKG_OPENSSL_WANT_SEC/ ],
    PKG_DROPBEAR  => [ qw/PKG_DROPBEAR_WANT_URANDOM_DEV
                          PKG_DROPBEAR_WANT_NO_REV_DNS
                          PKG_DROPBEAR_WANT_NO_X11FWD/ ],
    PKG_SYSCONFIG => [ qw/SYSCFG_HOSTNAME SYSCFG_MODLIST SYSCFG_START_SYSLOG
a191 3
                          SYSCFG_START_NETWORK SYSCFG_DHCPC SYSCFG_NET_INTERFACE
                          SYSCFG_IPADDR SYSCFG_NET_MASK SYSCFG_NET_BROADCAST
                          SYSCFG_NET_GATEWAY SYSCFG_NAMESERVER 
d195 13
d209 27
a235 5
};

# this is a cached list of the specnames, needs to be invalidated
# if a new platform config is loaded
@@sns = ();
d237 1
a237 1
$usage =<<TXT;
d250 1
a250 1
            buildrpms   build rpms (default)
a253 1
            prep        just prep the package
d255 1
a255 1
            clean       clean the build area and generated files
a256 5
            install     install but don't attempt to upgrade/replace
            uninstall   uninstall all packages
            upgrade     upgrade or install new packages (not forced)
            addsrpms    install an srpm(s) into the build area
                        you need provide a list of srpms on the command line 
d260 1
d263 5
a267 5
        --preconfig   : pre-config to build from (defaults to .config)
        --profile     : Used only with -m configure.  Ths sets the userspace
                        platform profile to use, this will override your
                        current package settings (e.g --profile max.config)
        --rcfile|r    : use this resource file
d275 1
a275 1
        --dry-run     : mostly a dry run (calls to system are just echos)
d280 4
d320 5
d333 1
a333 1
    unless $cf->{mode} =~ m,^(install|uninstall|upgrade|buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config)$,;
d335 15
a349 2
if($cf->{mode} =~m,^(scbuild|scinstall|prep|scdeploy)$, && ! $cf->{pkg}) {
    die <<TXT;
d353 7
d361 4
a364 2
$cf->{logfile} ||= "$top/host_config.log";
unlink($cf->{logfile});
a368 5
# some modes imply --force
$cf->{force} = 1 if $cf->{batch} || $cf->{mode} eq 'prep';
$cf->{force} = 1 if $cf->{batch} || $cf->{mode} eq 'scbuild';
$cf->{force} = 1 if $cf->{batch} || $cf->{mode} eq 'scinstall';

d385 1
a385 1
foreach $sig (qw/__DIE__ INT/) {
d390 5
a394 1
$ENV{PATH} =  "$cf->{defpfx}/usr/bin:$cf->{path_orig}";
d400 1
a400 1
    $ret = &{"f_" . $cf->{mode}}() || 0;
d409 3
d416 5
a420 1
&{"f_" . $cf->{mode}}() or die;
a422 5
    # check and run post-build deployment stuff
    $msg = "\nChecking for deployment operations\n";
    $msg .= '=' x length($msg) . "\n";
    print $msg if ! $cf->{quiet} || $cf->{redirected};
    
d426 8
a433 3
        mk_uboot_kernel("$cf->{dev_image}/boot/vmlinux.gz", $pcf) or die;
        mk_fs_image($cf->{dev_image}, "$cf->{top}/rootfs.tmp",
                    "$cf->{bin_path}/device_table.txt", $pcf) or die;
d443 1
a443 1
sub f_uninstall
d445 5
a449 1
    foreach my $pkg (reverse get_pkg_list()) {
d454 1
a454 1
        $cmd = "$cf->{sudo} $cf->{rpm} --dbpath $cf->{rpmdb} -e --allmatches $pkg";
a462 7
sub f_clean
{
    print "Cleaning out target rpms:\n";
    f_uninstall();
    return 1;
}

d477 1
a477 1
    $_ = <STDIN>;
a481 1
    @@sns = ();
d487 1
a495 1
    @@sns = ();
d500 1
a500 1
for i in .wget_warning .rpm_warning .sudo_warning .config .tmpconfig.h .config.old .config.cmd .host_wait_warning
d504 1
a504 1
$echo find config \\( -name .config -o -name .tmpconfig.h -o -name .config.old  -o -name .config.cmd  \\) -exec rm {} \\;
d518 5
a526 10

# The logic is:
# build the rpm and (re)install it:
# if 
#    the spec file is newer than the output rpm
# 
# The last condition catches problems where a package builds but
# fails to install due to some dependancy problem.  Re-building 
# makes sure that the dependancies fixes get seen
#
a531 1
        $rpmbuildopts .= "--clean --rmsource";
d544 1
a544 1
    remove_unselected_pkgs();
d546 3
a548 1
    foreach my $sn (get_specname_list()) {
d553 2
a554 1
        my $spec = get_spec($sn) or warn("skipping $sn\n"), undef $ret, next;
d556 1
a556 1
        parse_spec($spec, $tok);
d559 2
d562 4
a565 1
        if( $cf->{force} || ! @@rpms || -M $spec < -M $rpms[0] ) {
d568 3
d575 13
a587 3
                    if(! -e $tgt) {
                        my $src = get_file($url, $cf) or die "Can't get: $file";

d595 3
d615 5
a620 3
            # commit to installing a new rpm (enforced if build fails)
            unlink(@@rpms);

d629 3
a631 2
                   . "--define '_mandir $cf->{mandir}' "
                   . "$rpmbuildopts $spec";
d641 1
d645 1
d675 3
d679 3
d688 10
d700 4
d709 4
d718 4
a721 1
    my ($sn) = get_specname_list(); 
a725 1
    $cf->{force} = 1;
a728 1
    # store the first array ref returned by get_specname_list
d732 1
a732 1
    open(SPEC, ">$tspec") or die("can't open $tspec for write: $!\n");
d734 1
d740 1
a740 1
Release         : test
d752 2
d770 1
a770 1
    my $ret = f_buildrpms("-bb");
a774 5
sub f_prep
{
    return f_buildrpms("-bp");
}

d777 1
d780 3
a782 2
    %$packages = map { $_ => 1 } get_specname_list();

d810 2
a811 1
    my $spec = get_spec($cf->{pkg}) or die();
d813 1
a813 1
    parse_spec($spec, $tok);
a836 4
    # re-parse the spec file without token reduction so we can susbsitute
    $tok = {sources => "", patches => "", prep => "" };
    parse_spec($spec, $tok, 1);

d840 1
a840 1
    open(SPEC, $spec) or die("Can't open $spec : $!\n");
d844 1
a844 1
    @@p = sort @@p;
d857 1
a857 1
$cf->{rpmbuild} --dbpath $cf->{rpmdb} --define '_target_cpu $pcf->{LINTARCH}' --define '_topdir $cf->{rpmdir}' --define '_tmppath $cf->{tmppath}' --define '_mandir $cf->{mandir}' -bp $spec >/dev/null || exit 1
d863 1
a863 1
    open(SPEC, ">$spec.bak") or die("Can't open $spec.bak for writing: $!\n");
d867 1
a867 1
    s,$tok->{prep},$tok->{prep}%patch$num -p1\n,;
d869 1
a869 1
    open(SPEC, ">$spec") or die("Can't open $spec for writing : $!\n");
d879 1
a879 1
due to and incompete "make distclean" 
d899 1
a899 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d901 1
a901 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d903 1
a903 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d907 1
a907 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d911 1
a911 1
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<@@<@@||||||||@@<@@<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<
d915 1
a915 1
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<@@<@@||||||||@@<@@<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<
d919 5
a923 4
   my @@snlist = get_all_specname_list();
   @@snlist = sort { $a->[0] cmp $b->[0] } @@snlist;
   foreach my $aref ( @@snlist  ) {
       ($sn, $en) = @@$aref;
d926 1
a926 1
       parse_spec($spec, $tok);
d935 6
d963 1
a963 1
    # the head of cvs.
d967 1
d978 23
a1000 2
        chomp($_ = <STDIN>);
        $tag = $_ if $_;
d1005 2
a1006 2
    my @@devs = glob("$cf->{platform_dir}/$pcf->{PLATFORM}/*.dev");
    system(<<TXT) == 0 or die "\nPlease save your changes before continuing\n";
d1008 1
a1008 1
diff -qN  $cf->{platform_dir}/$pcf->{PLATFORM}/defconfig $cf->{platform_dir}/$pcf->{PLATFORM}/.config
d1011 1
a1011 1
    diff -qN $cf->{platform_dir}/$pcf->{PLATFORM}/`basename \$i .dev` \$i
a1029 5
    if($tag ne 'localdir_nobuild') {
        print "\nMaking sure built rpms are up to date\n";
        f_buildrpms() or die;
    }

a1033 5
cp -a $cf->{top}/.config stage
mkdir -p stage/config/platform/$pcf->{PLATFORM}
cp -a $cf->{platform_dir}/$pcf->{PLATFORM}/.config stage/config/platform/$pcf->{PLATFORM}/.config
cp -a $cf->{platform_dir}/$pcf->{PLATFORM}/.config stage/config/platform/$pcf->{PLATFORM}/.config.old
cp -r $cf->{rpmdir} stage
d1060 2
a1061 2
mv $rel/stage $rel/ltib
cp $rel/ltib/bin/ltib_install $rel/install
d1063 27
d1092 1
d1094 8
a1101 3
    if($pcf->{TOOLCHAIN}) {
        my $tc = get_file("$pcf->{TOOLCHAIN}", $cf);
        system("cp -a $tc $rel/pkgs/") == 0 or die;
d1103 4
a1106 3
    $pcf = {};
    @@sns = ();
    parse_dotconfig($cf->{hostconfig}, $pcf);
d1108 2
d1113 2
a1114 2
    open(RI, ">$rel/ltib/RELEASE_INFO")
                                 or die("open: >$rel/ltib/RELEASE_INFO : $!\n");
d1122 1
d1128 1
a1128 1
cp $rel/ltib/RELEASE_INFO $rel/RELEASE_INFO
d1130 2
a1131 2
tar zcf ltib.tar.gz ltib
rm -rf ltib
d1133 1
a1133 1
mkisofs -A "$rel" -J -L -l -P "Frescale" -o $rel.iso -r -v -V "ltib" $rel
a1137 1

d1146 1
a1146 1
    parse_spec($spec, $tok);
d1150 4
a1153 1
        system("set -x ; cp -af $src $dest") == 0 or die;
a1160 1
    my (@@aref, $sn, $en);
d1162 2
a1163 4
    my @@snlist = get_all_specname_list();
    foreach $aref ( @@snlist  ) {
        ($sn, $en) = @@$aref;
        copy_spec_sources($sn, $dest) or die;
a1164 1
    system("set -x ; cp -a $cf->{lpp}/MD5SUMS $dest") == 0 or die;
d1172 3
a1174 2
    foreach my $sn ( get_specname_list()  ) {
        copy_spec_sources($sn, $dest) or die;
d1179 15
d1204 4
a1207 4
                     defpfx lpp spoof_path gpp_url config_dir profile_dir
                     platform_dir mainconfig conf defdist pfx buildarch
                     pkg_map top home username path_orig
                     build_deps/ ) {
d1263 1
a1263 1
sub host_checks
d1265 2
a1266 4
    # do not attempt to re-install host packages once 
    # we have got through here completely once
    return 1 if -f "$cf->{top}/.host_wait_warning";
    
d1269 2
a1270 2
    my @@sav_list = qw/dev_image rpmdir rpmdb nodeps pkg force 
                   reinstall wget_opts preconfig nodrop quiet/;
d1272 1
a1272 1
        $sav->{$k} = $cf->{$k}
d1274 4
a1277 2
    # override with suitable host values
    $cf->{dev_image}     = $cf->{defpfx};
d1281 1
a1281 2
    $cf->{pkg}           = "";
    $cf->{force}         = 0;
a1282 2
    $cf->{wget_opts}     = "--passive-ftp -nc --tries=1 --timeout=10";
    $cf->{nodrop}        = 1;  # this is a shared area
d1285 11
a1295 4
    $cf->{preconfig} = $cf->{hostconfig};
    $pcf = {};
    @@sns = ();
    parse_dotconfig($cf->{preconfig}, $pcf);
d1298 15
d1314 9
d1324 1
a1324 1
    check_basic_deps();
a1329 3
    # check/create required directories
    check_dirs();

d1331 1
a1331 4
    if(-f "$cf->{top}/.host_wait_warning") {
        $cf->{quiet} = 1 unless $cf->{verbose};
    } else {
        print <<TXT;
d1342 5
a1346 2
    }
    # redirect output
d1352 3
d1358 1
a1358 3
    # make sure we can build packages, this is here as it needs our rpm
    check_toolchain_setup($pcf);

a1359 2
    f_buildrpms() or die;
    redirect();
d1361 2
a1362 3
    # restore
    foreach my $k (@@sav_list) { $cf->{$k} = $sav->{$k} }
    undef $sav;
d1364 2
a1365 5
    # from here on use fakeroot for builds (we know it's installed now)
    # 22mar05 we no longer use fakeroot due to problems on amd64
    # $cf->{fakeroot} = "fakeroot";

    touch("$cf->{top}/.host_wait_warning");
d1372 2
a1373 3
    $pcf = {};
    @@sns = ();
    parse_dotconfig($cf->{preconfig}, $pcf);
d1375 1
a1375 2
        $ppcf = {};
        parse_dotconfig("$cf->{preconfig}.old", $ppcf);
a1380 3
    # check/create required directories
    check_dirs();

d1403 3
d1414 2
a1415 2
    $pcf = {};
    parse_dotconfig($cf->{preconfig}, $pcf);
d1436 1
a1436 1
    $pcf->{CFGHOST} = "$cf->{buildarch}-linux"
d1444 1
a1444 1
                 .  $cf->{path_orig};
d1464 2
a1465 1
    $ENV{PLATFORM_PATH} = "$cf->{platform_dir}/$pcf->{PLATFORM}";
d1469 1
d1474 1
d1481 1
a1481 1
                          UCLIBC/ ) {
d1526 2
a1527 2
    # assume done if the specfile post-dates the .config file
    return 1 if -M $spec < -M $cf->{preconfig};    
d1529 1
a1529 1
    foreach my $dep ( @@{$pkg_deps->{$key}} ) {
d1540 70
d1611 7
a1617 1
# get attributes about all spec names
d1619 1
a1619 1
sub get_all_specname_list
d1621 3
a1623 2
    my ($sn, $en);
    my @@allsns;
d1625 22
a1646 15
    if($cf->{pkg}) {
        push @@allsns, [ $cf->{pkg}, 'y' ] if $cf->{pkg};
    } else {
        my $pre = '[\S]+';
        # first load up the override map if present
        my $ovmap = {};
        my $map = "$cf->{platform_dir}/$pcf->{PLATFORM}/$cf->{pkg_map}";
        if( -f $map ) {
            open(MAP, $map) or die("open($map): $!\n");
            while(<MAP>) {
                chomp;
                m,^([\w]+)\s*=\s*($pre),o or next;
                $ovmap->{$1} = $2;
            }
            close MAP;
d1648 7
a1654 2
        # load up the main map
        $map = "$cf->{top}/$pcf->{DISTRO}/common/$cf->{pkg_map}";
d1658 7
a1664 9
            m,^([\w]+)\s*=\s*($pre),o or next;
            next unless defined $pcf->{$1};

            if($pcf->{$1} eq 'y' || $pcf->{$1} eq 'n' || ! $pcf->{$1}) {
                $sn = $2;    
                $en = $pcf->{$1} || 'n';
            } else {
                $sn = $pcf->{$1};
                $en = 'y';
d1666 1
a1666 3
            $sn = $ovmap->{$1} if $ovmap->{$1};
            process_pkg_deps($1, $sn) if $en ne 'n';
            push @@allsns, [ $sn, $en ];
a1667 1
        close MAP;
d1669 1
a1669 8
    return @@allsns;
}
# Return a build ordered list of specfile names (without .spec suffix)
# Note: the main pkg_map is in build order and must be preserved
sub get_specname_list
{
    # caching
    return @@sns if @@sns;
d1671 6
a1676 1
    @@sns = map { $_->[1] ne 'n' ? $_->[0] : () } get_all_specname_list();
d1678 14
a1691 2
    if($cf->{verbose}) {
        warn("package list is: ", join(", ",@@sns), "\n") if $cf->{verbose};
d1693 7
a1699 2
    die("no packages found") unless @@sns;
    return @@sns;
d1702 1
a1702 1
sub get_pkg_list
d1704 3
a1706 11
    my ($name, $pkg, $spec);
    my @@list = ();
    foreach $pkg ( get_specname_list() ) {
        $spec = get_spec($pkg) or next;
        open(F, $spec) or next;
        while(<F>) {
            ($name) = m,^name\s*:\s*(.+),i;
            last if $name;
        }
        close F;
        push @@list, $name if $name;
d1708 1
a1708 1
    return @@list;
d1711 19
d1733 1
a1733 1
    return 1 if $cf->{pkg} || $cf->{nodrop};
d1735 1
d1737 26
a1762 13
    my ($name);
    my @@pkg_list =  get_pkg_list();
    my @@drop_list = grep {
                            my $found = 0;
                            foreach my $wanted ( @@pkg_list ) {
                                if(m,^\Q$wanted\E,) {
                                    $found = 1;
                                    last;
                                }
                            } 
                            $found ? "" : $_;

                         } @@installed;
a1763 1
    warn("pkg_list = ", join(", ", @@pkg_list), "\n") if $cf->{verbose};
d1766 14
a1779 4
    print "Removing de-selected packages:\n";
    foreach my $pkg ( reverse(@@drop_list) ) {
        $cmd =   "$cf->{sudo} $cf->{rpm} --dbpath $cf->{rpmdb} "
               . "-e --allmatches $pkg --nodeps";
d1782 1
d1808 1
a1808 1
       || $plat_specs ne "$cf->{platform_dir}/$pcf->{PLATFORM}" ) {
d1812 1
a1812 1
        $plat_specs  = "$cf->{platform_dir}/$pcf->{PLATFORM}";
d1818 4
a1821 1
    return $cache->{$sn} if exists $cache->{$sn};
d1825 23
a1847 5
        my $path = "$dir/$spec";
        if(-e $path) {
           warn("using specfile: $path\n") if $cf->{verbose};
           $cache->{$sn} = $path;
           return $path;
d1850 1
a1850 1
    $cache->{$sn} = undef;
d1853 2
a1854 1
Can't find spec file $spec
a1856 1

d1860 1
d1863 1
a1863 1
    return;
d1867 1
d1870 3
a1872 2
    # check the most basic host services are available
    foreach my $dep ( split(/\n/, $cf->{build_deps}) ) {
d1874 1
a1874 1
        next if $dep =~ m,\s*#,;
d1877 27
a1903 5
        my $ver = get_ver($pkg) || '-1';
        warn "pkg=$pkg, min=$min, got: $ver\n" if $cf->{verbose};
        next if cmp_ver($ver, $min) >= 0;
        $ver = 'none' if $ver eq '-1';
        die(<<TXT);
d1905 2
a1906 1
Your $pkg is too old:
d1908 1
a1908 2
Minimum needed is $min
Installed version $ver
a1909 1
Please install/ugrade this package before re-trying
d1911 2
d1914 1
a1914 1
    return 1;
d1923 1
a1923 1
    foreach $k (qw/TOOLCHAIN_PREFIX TOOLCHAIN_PATH
d1952 1
a1952 1
    if( $dev_image =~ m,^\s*/\s*$, ) {
d1961 15
a1975 8
    # make sure the rpmdb directory is not an nfs mount
    my $fstype = cmd_w_to(5, "df -PT $cf->{rpmdb} |tail -1") || "fake nfs";
    $fstype = (split(/\s+/, $fstype))[1];
    die(<<TXT) if $fstype eq 'nfs';

The rpm database cannot be in an nfs mounted filesystem. Please change
the entry in your rcfile ($cf->{rcfile})
from $rpmdb to somewhere that is not on an nfs filesystem
d1977 1
d1979 6
d2002 11
d2014 2
a2015 2
    my @@sav_list = qw/dev_image nodeps pkg force reinstall nodrop
                     prefix rpmbuild rpm rpmdir rpmdb/;
d2019 1
d2023 1
a2023 1
    $cf->{nodrop}        = 1;
d2025 1
d2028 3
d2042 1
a2042 1
    my $cmd  = "$cf->{sudo} $sav->{rpm} --dbpath $sav->{rpmdb} ";
d2049 3
a2056 1
    @@sns = ();
d2068 1
a2068 1
    my ($hostrpm) = `PATH=$cf->{path_orig} ; which rpm`;
d2109 1
a2109 1
    $lpp_mode = (stat("$cf->{lpp}"))[2];
d2119 1
a2119 1
    if( -d "$top/pkgs" ) {
d2121 7
a2127 2
        system("rsync -a --ignore-existing $top/pkgs/* $cf->{lpp}") == 0 or die;
        system("rm -rf $top/pkgs 2>/dev/null");
a2137 11
sub check_sb_bstrap
{
    if(! -f "$cf->{defpfx}/usr/bin/rpm") {
        my $bs = get_file($cf->{sb_bstrap_tarfile}, $cf);
        $cmd = "tar -C / -zxvf $bs";
        print "$cmd\n";
        system_nb($cmd) == 0 or die "Failed to install: $bs\n";
    }
    return 1;
}

d2148 12
a2159 9
        my $qo = `$cf->{rpm} -q $tc_rpm 2>/dev/null`;
        if(! -e  "$pcf->{TOOLCHAIN_PATH}/bin/$pcf->{TOOLCHAIN_PREFIX}gcc" ) {
            print "Installing: $pcf->{TOOLCHAIN}\n";
            if($cf->{buildarch} ne 'x86_64') {
                $pcf->{TOOLCHAIN} =~ s,i686,$cf->{buildarch},;
            }
            $tc = get_file("$pcf->{TOOLCHAIN}", $cf)
                                       or die "Can't get: $pcf->{TOOLCHAIN}";
            $cmd =   "$cf->{sudo} $cf->{rpm} "
d2161 1
a2161 1
                   . "-Uvh --force --ignorearch $tc";
d2163 7
a2169 1
            system_nb($cmd) == 0 or die"Failed to install: $pcf->{TOOLCHAIN}\n";
a2217 1

d2221 1
a2221 1
    my $spec = get_spec("merge");
d2224 1
d2232 43
d2280 3
a2282 3
    $edate = localtime();
    $elapsed  = time() - $cf->{stime};
    $cf->{abnormal_exit} = 'yes' if $cf->{pkg_build_failures};
d2284 1
a2284 2

print <<TXT;
d2290 1
a2290 2
Build failures  : $cf->{pkg_build_failures}
Abnormal exit   : $cf->{abnormal_exit}
d2292 2
a2293 1
TXT
d2295 8
d2309 1
a2309 1
    $cf->{abnormal_exit} = 'yes';
d2318 35
d2356 2
a2357 2
    # bypass if passed a preconfig and we don't want to configure
    return if $cf->{preconfig} && ! $cf->{configure} && ! $cf->{profile};
d2360 1
d2363 25
a2387 5
    if(! $cf->{configure} && ! $cf->{profile} ) {
        if(-f "$cf->{top}/.config") {
            parse_dotconfig("$cf->{top}/.config", $cf_main);
            $cf->{preconfig} = "$cf_main->{PLATFORM_DIR}/.config";
            return 1;
d2396 3
a2398 1
        ( $cf_main->{PLATFORM_DIR} = $cf->{preconfig} ) =~ s,/[^/]+$,,;
d2407 1
a2407 1
        open(MC, $cf->{mainconfig}) or die "open $cf->{mainconfig} : $!";
d2409 2
a2410 2
            if( m,$cf_main->{PLATFORM_DIR}"\s+if\s+(\w+), ) {
                $platform = "CONFIG_$1=y";
d2415 6
a2420 8
        die "No match for $cf_main->{PLATFORM_DIR} in $cf->{mainconfig}"
                                                            unless $platform;
        system_nb(<<TXT) == 0 or die;
set -e
cp $cf->{preconfig} $cf_main->{PLATFORM_DIR}/.config
echo "${platform}=y" > $cf->{top}/.config
echo 'CONFIG_PLATFORM_DIR="$cf_main->{PLATFORM_DIR}"' >> $cf->{top}/.config
TXT
d2425 1
a2425 1
            system_nb("$cf->{conf} $cf->{mainconfig}") == 0 or die;
d2428 1
a2428 1
        parse_dotconfig(".config", $cf_main);
d2430 11
a2440 1
    # Run the system specific config
d2443 1
a2443 2
cd $cf_main->{PLATFORM_DIR}
if [ -n "$cf->{profile}" -a -e "$cf->{profile_dir}/$cf->{profile}" ]
d2445 1
a2445 1
    cat  $cf->{profile_dir}/$cf->{profile} >> .config
d2447 5
d2453 1
d2455 6
a2460 2
    $cf->{preconfig} = "$cf_main->{PLATFORM_DIR}/.config";
    die("No config saved") unless $cf->{preconfig};
d2466 1
a2466 1
    my ($dir, $ent, $p) = ("config/platform", "", {});
d2468 1
a2468 1
    opendir(DIR, $dir) or warn("can't open $dir: $!\n"), return;
d2487 1
a2487 1
    open(MCF, ">$cf->{mainconfig}") or die "open $cf->{mainconfig} : $!\n";
d2501 1
a2501 1
    foreach my $mcf (sort keys %$p) {
d2512 1
a2512 1
    foreach my $mcf (keys %$p) {
d2520 29
d2577 19
@


1.1.1.1
log
@LTIB external initial import
@
text
@@


1.1.1.2
log
@Import from fsl 6sep05
@
text
@a60 1
    ppp_url      => "",
d67 1
a67 1
    wget_opts    => "--passive-ftp -nc --tries=1 --timeout=4 --non-verbose",
a138 2
    download_only=> 0,
    
d214 1
a214 1
        --dry-run|d   : mostly a dry run (calls to system are just echos)
a218 1
        --dlonly      : just download the packages only
a254 1
        "dlonly"     => \$cf->{download_only},
d265 2
a266 10
if($cf->{pkg}) {
    if($cf->{configure} || $cf->{preconfig} || $cf->{profile}) {
        die <<TXT;
The options: --configure, --preconfig and --profile cannot be used when 
passing the --pkg|-p option.
TXT
    }
} else {
    if($cf->{mode} =~m,^(scbuild|scinstall|prep|scdeploy)$, ) {
        die <<TXT;
a269 1
    }
d278 3
a280 4
$cf->{force} = 1 if $cf->{batch};
$cf->{force} = 1 if $cf->{mode} eq 'prep';
$cf->{force} = 1 if $cf->{mode} eq 'scbuild';
$cf->{force} = 1 if $cf->{mode} eq 'scinstall';
a320 10
# TODO this is a temporary debug
if(1) {
    warn "verifying LTIB's host package database\n";
    foreach $i (qw/rpm-fs mkspooflinks zlib autoconf libtool lkc wget
                  uclinux-cksum genext2fs u-boot-tools mtd-utils sysconfig/ ) {
        $_ =  `/var/tmp/freescale/usr/bin/rpm -V --nodeps $i`;
        die "Host package $i has missing files:\n$_" if /^missing/m;
    }
}

d458 1
a458 1
PKG: foreach my $sn (get_specname_list()) {
d477 2
a478 9
                        my $src;
                        unless( $src = get_file($url, $cf) ) {
                            warn("Can't get: $file");
                            $cf->{pkg_build_failures} .= "$sn ";
                            undef $ret;
                            die unless  $echo || $cf->{coe};
                            next PKG;
                        }
                        
a485 2
                next PKG if $cf->{download_only};

a502 3
            # we may not have needed to download source, so this gets
            # repeated.  Really time for a re-structure of code
            next PKG if $cf->{download_only};
d995 1
a995 1
                     defpfx lpp spoof_path config_dir profile_dir
d1075 1
a1075 1
    $cf->{wget_opts}     = "--passive-ftp -nc --tries=1 --timeout=10 --non-verbose";
@


1.1.1.3
log
@Import from fsl 6feb06
@
text
@d43 1
a43 2
$top  = $FindBin::Bin;
$bdir = "/opt/freescale";
d49 1
a49 1
    rpm          => "$bdir/ltib/usr/bin/rpm",
d57 3
a59 3
    defpfx       => "$bdir/ltib",
    lpp          => "$bdir/pkgs",
    spoof_path   => "$bdir/ltib/usr/spoof",
d66 3
a68 1
    wget_opts    => "--passive-ftp -nc --tries=1 --timeout=4 -nv",
d79 1
a79 1
    app_version  => "5.3.1",
d82 2
a83 1
    platforms_dir => "$top/config/platform",
a90 1
    host_wait_warning => "$top/.host_wait_warning2",
a140 1
    dltest       => 0,
d151 1
a151 1
                          PKG_LIBC_WANT_STATIC_LIBS PKG_LIBC_WANT_CF/ ],
d153 2
a154 2
    PKG_GDB       => [ qw/PKG_GDB_NATIVE_WANT_ED PKG_GDB_CROSS_WANT_ED
                          PKG_GDB_SERVER_WANT_ED/ ],
a202 1
            shell       enter ltib shell mode (sets up spoofing etc)
d205 4
a208 4
        --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)
a222 1
        --dltest      : test that the BSP's packaes are available
a259 1
        "dltest"     => \$cf->{dltest},
d268 1
a268 1
    unless $cf->{mode} =~ m,^(install|uninstall|upgrade|buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell)$,;
a269 4
if($cf->{mode} eq 'scbuild' && $cf->{pkg} && $cf->{configure}) {
    $cf->{configure} = '';
    $ENV{SCB_WANT_CF} = 'y';
}
d271 1
a271 3
    #### TODO: temporarily allow preconfig util lkc bug is fixed
    ###if($cf->{configure} || $cf->{preconfig} || $cf->{profile}) {
    if($cf->{configure} || $cf->{profile}) {
a284 6
if($cf->{preconfig} && ! -e $cf->{preconfig}) {
    die "preconfig file: $cf->{preconfig} does not exist\n";
}
if($cf->{profile} && ! -e $cf->{profile}) {
    die "profile file: $cf->{profile} does not exist\n";
}
d336 10
a348 3
# clear transient configuration flags
clear_transient_configs();

d431 1
a431 1
for i in .wget_warning .rpm_warning .sudo_warning .config .tmpconfig.h .config.old .config.cmd
a448 1
$echo rm -f .host_wait_warning*
a492 2
        my $pkgfail = 0;

d494 1
a494 1
        if($cf->{force} || $cf->{dltest} || ! @@rpms || -M $spec < -M $rpms[0]){
a496 3
                # commit to installing a new rpm (enforced if build fails)
                unlink(@@rpms) unless $cf->{dltest};

d501 1
a501 1
                    if(! -e $tgt || $cf->{dltest}) {
d505 1
a505 1
                            $cf->{pkg_build_failures} .= "$sn " unless $pkgfail;
a506 2
                            $pkgfail = 1;
                            next if $cf->{dltest};
a509 1
                        next if $cf->{dltest};
a518 1
                next PKG if $cf->{dltest};
d541 3
a562 1
        return $ret if $rpmbuildopts =~ m,--short-circuit,;
d742 1
a742 1
    @@p = sort { $a <=> $b } @@p;
d797 1
a797 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d799 1
a799 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d801 1
a801 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d805 1
a805 1
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<< @@|||||| @@<<<<<<<<<< @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
d809 1
a809 1
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<@@<@@||||||||@@<@@<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<
d813 1
a813 1
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<@@<@@||||||||@@<@@<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<
d874 1
a874 1
    my @@devs = glob("$cf->{platforms_dir}/$pcf->{PLATFORM}/*.dev");
d877 1
a877 1
diff -qN  $cf->{platforms_dir}/$pcf->{PLATFORM}/defconfig $cf->{platforms_dir}/$pcf->{PLATFORM}/.config
d880 1
a880 1
    diff -qN $cf->{platforms_dir}/$pcf->{PLATFORM}/`basename \$i .dev` \$i
d910 2
a911 2
cp -a $cf->{platforms_dir}/$pcf->{PLATFORM}/.config stage/config/platform/$pcf->{PLATFORM}/.config
cp -a $cf->{platforms_dir}/$pcf->{PLATFORM}/.config stage/config/platform/$pcf->{PLATFORM}/.config.old
d939 2
a940 2
mv $rel/stage $rel/$rel
cp $rel/$rel/bin/ltib_install $rel/install
d956 2
a957 2
    open(RI, ">$rel/$rel/RELEASE_INFO")
                       or die("open: >$rel/$rel/RELEASE_INFO : $!\n");
a964 1
App version  = $cf->{app_version}
d970 1
a970 1
cp $rel/$rel/RELEASE_INFO $rel/RELEASE_INFO
d972 2
a973 2
tar zcf ltib.tar.gz $rel
rm -rf $rel
d975 1
a975 1
mkisofs -A "$rel" -J -L -l -P "Freescale" -o $rel.iso -r -v -V "ltib" $rel
d980 1
a993 3
        if(-f "$src.md5") {
            system("set -x ; cp -af $src.md5 $dest") == 0 or die;
        }
d1008 1
d1032 2
a1033 2
                     defpfx lpp spoof_path config_dir
                     platforms_dir mainconfig conf defdist pfx buildarch
d1095 1
a1095 1
    return 1 if -f $cf->{host_wait_warning} || $cf->{dltest};
d1112 1
a1112 1
    $cf->{wget_opts}     = "--passive-ftp -nc --tries=1 --timeout=10 -nv";
d1134 1
a1134 1
    if(-f $cf->{host_wait_warning}) {
d1173 1
a1173 1
    touch($cf->{host_wait_warning});
d1191 3
d1246 1
a1246 1
    chomp($pcf->{CFGHOST} = `rpm --eval %_build` )
d1274 1
a1274 1
    $ENV{PLATFORM_PATH} = "$cf->{platforms_dir}/$pcf->{PLATFORM}";
a1315 1
            $pcf->{TOOLCHAIN_CHANGED} = 1 if $dep eq 'TOOLCHAIN';
d1361 1
a1361 1
        my $map = "$cf->{platforms_dir}/$pcf->{PLATFORM}/$cf->{pkg_map}";
d1481 1
a1481 1
       || $plat_specs ne "$cf->{platforms_dir}/$pcf->{PLATFORM}" ) {
d1485 1
a1485 1
        $plat_specs  = "$cf->{platforms_dir}/$pcf->{PLATFORM}";
d1616 1
a1616 1
                     prefix rpmbuild rpm rpmdir rpmdb lpp tmppath/;
a1626 2
    $cf->{lpp}           = "/tmp";
    $cf->{tmppath}       = "/tmp";
d1749 1
a1749 2
        if(! -e  "$pcf->{TOOLCHAIN_PATH}/bin/$pcf->{TOOLCHAIN_PREFIX}gcc"
           ||    $pcf->{TOOLCHAIN_CHANGED} ) {
d1755 1
a1755 4
                                       or warn("Can't get: $pcf->{TOOLCHAIN}");
            return if $cf->{dltest};
            die unless $tc;

d1758 1
a1758 1
                   . "-ivh --force --ignorearch $tc";
d1760 1
a1760 5
            # switch stdout with stderr and run the command to capture stderr
            $_ = `$cmd 3>&1 1>&2 2>&3 3>&-`;
            if($? && ! m,is already installed,) { 
                die "Failed to install: $pcf->{TOOLCHAIN}:\n$_\n"
            }
a1862 1
    # TODO: 20oct05: put this back for now until the lkc bug is fixed
d1868 1
a1868 1
    if(! $cf->{configure} && ! $cf->{profile} && ! $cf->{preconfig}) {
d1881 1
a1881 4
        my $th = {};
        parse_dotconfig($cf->{preconfig}, $th);
        $cf_main->{PLATFORM_DIR} = "config/platform/$th->{PLATFORM}";
        undef $th;
d1918 2
a1919 1
if [ -n "$cf->{profile}" ]
d1921 1
a1921 1
    cat  $cf->{profile} >> $cf_main->{PLATFORM_DIR}/.config
a1922 1
cd $cf_main->{PLATFORM_DIR}
a1923 4
if [ -f .config ]
then
    cp .config defconfig
fi
d1926 1
a1926 1
    die("No config saved") unless -f $cf->{preconfig};
a1985 20
sub clear_transient_configs
{
    my $file = $cf->{preconfig};
    my ($atime, $mtime) = (stat($file))[8,9];
    local $^I = '.bak';
    @@ARGV = $file;
    while(<>) {
        s,^(\w+WANT_CF)=y,# $1 is not set,;
        print;
    }
    utime($atime, $mtime, $file) or warn "could not reset times on $file: $!";
}

sub f_shell
{
    print "Entering ltib shell mode, type 'exit' to quit\n";
    system("/bin/sh");
    exit 0;
}

@


1.1.1.4
log
@Import from fsl 14feb06
@
text
@d99 1
a99 1
    normal_exit  => 'yes',
d161 3
d167 1
a167 14
                          SYSCFG_START_NETWORK
                          SYSCFG_NET_GATEWAY SYSCFG_NAMESERVER
                          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/ 
                          ],
a334 4
# turn off timestamps in the lkc menu system to prevent constant
# cvs checkings of unchanged files
$ENV{KCONFIG_NOTIMESTAMP} = "no";

d1148 3
a1175 3
    # check/create required directories
    check_dirs();

a1289 1
    $ENV{CONFIG_DIR}    = $cf->{config_dir};
d1303 1
a1303 1
                          UCLIBC CONFIG_DIR/ ) {
d1856 1
a1856 1
    $cf->{normal_exit} = 'no' if $cf->{pkg_build_failures};
d1866 1
a1866 1
Normal exit     : $cf->{normal_exit}
d1876 1
a1876 1
    $cf->{normal_exit} = 'no';
d1888 3
d1895 1
a1895 1
    if(! $cf->{preconfig} && ! $cf->{configure} && ! $cf->{profile}) {
d1898 2
a1899 18
            if(     -M "$cf_main->{PLATFORM_DIR}/.config"
                <=  -M "$cf_main->{PLATFORM_DIR}/defconfig" ) {

                $cf->{preconfig} = "$cf_main->{PLATFORM_DIR}/.config";
                return 1;
            }
            # the defconfig is newer than the .config, this is normally
            # because someone else has updated cvs.  In this case, use
            # the new defconfig
            warn("Using update $cf_main->{PLATFORM_DIR}/defconfig\n");
            my $date = gm_yyyymmdd();
            system_nb(<<TXT) == 0 or die;
set -x -e
mv -f $cf_main->{PLATFORM_DIR}/.config $cf_main->{PLATFORM_DIR}/.config.$date
cp $cf_main->{PLATFORM_DIR}/defconfig $cf_main->{PLATFORM_DIR}/.config
sleep 2
TXT
            $cf->{batch} = 1;
a1900 4
    } else {
        # bypass if passed a preconfig and we don't want to configure
        # TODO: 20oct05: put this back for now until the lkc bug is fixed
        return if $cf->{preconfig} && ! $cf->{configure} && ! $cf->{profile};
d1956 1
a1956 1
    cp .config defconfig.dev
@


1.1.1.5
log
@Import from fsl 13mar06
@
text
@a37 2
use vars qw($PKG_SYSCONFIG $PKG_LIBC $PKG_OPENSSL $PKG_U_BOOT $PKG_DROPBEAR
            $PKG_BUSYBOX $PKG_KERNEL $PKG_GDB);
a94 1
    path_std     => "/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin",
d99 1
a99 1
    normal_exit  => 1,
a140 1
    prof         => 0,
d146 14
a159 14
$PKG_U_BOOT->{deps}  = [ qw/PKG_U_BOOT_CONFIG_TYPE PKG_U_BOOT_BUILD_ARGS
                            PKG_U_BOOT_LEAVESRC/ ];
$PKG_KERNEL->{deps}  = [ qw/PKG_KERNEL_PRECONFIG PKG_KERNEL_WANT_HEADERS
                            PKG_KERNEL_WANT_CF PKG_KERNEL_LEAVESRC/ ];
$PKG_LIBC->{deps}    = [ qw/PKG_LIBC_WANT_LOCALES PKG_LIBC_WANT_HEADERS
                            PKG_LIBC_WANT_STATIC_LIBS PKG_LIBC_WANT_CF/ ];
$PKG_BUSYBOX->{deps} = [ qw/PKG_BUSYBOX_PRECONFIG PKG_BUSYBOX_WANT_CF/ ];
$PKG_GDB->{deps}     = [ qw/PKG_GDB_NATIVE_WANT_ED PKG_GDB_CROSS_WANT_ED
                            PKG_GDB_SERVER_WANT_ED/ ];
$PKG_OPENSSL->{deps} = [ qw/PKG_OPENSSL_WANT_SEC/ ];
$PKG_DROPBEAR->{deps}= [ qw/PKG_DROPBEAR_WANT_URANDOM_DEV
                            PKG_DROPBEAR_WANT_NO_REV_DNS
                            PKG_DROPBEAR_WANT_NO_X11FWD/ ];
$PKG_SYSCONFIG->{deps}=[ qw/SYSCFG_HOSTNAME SYSCFG_MODLIST SYSCFG_START_SYSLOG
d176 3
a178 2
                          SYSCFG_READONLY_FS/
                          ];
d180 3
a182 3
# This hash is used to control caching of expensive functions that
# only need to be properly run once per platform.  
$pcac = {};
d234 1
a234 2
        --dltest      : test that the BSP's packages are available
        --leavesrc|l  : leave the sources unpacked (only valid for pkg mode)
a272 2
        "prof"       => \$cf->{prof},
        "leavesrc|l" => \$cf->{leavesrc},
d289 1
a302 3
    if($cf->{leaverc}) {
        die "--leavesrc|l only work on a single package, use -p <pkg>\n";
    }
d317 1
d343 1
a343 1
$ENV{PATH} =  "$cf->{defpfx}/usr/bin:$cf->{path_std}";
a361 3
# invalidate the cache
$pcac = {};

d381 1
a381 1
        mk_fs_image($cf->{dev_image}, "$cf->{dev_image}.tmp",
d434 1
a434 2
    # invalidate the cache
    $pcac = {};
d448 1
d457 1
a457 1
$echo find config \\( -name .config -o -name .tmpconfig.h -o -name .config.old  -o -name .config.cmd -o -name defconfig.dev \\) -exec rm {} \\;
d491 1
d506 1
a506 3
PKG: foreach my $key (mk_buildlist()) {
        next unless $$key->{en};
        my $sn = $$key->{sn};
a571 2
            my $rpmclean = $cf->{leavesrc} || $pcf->{$key . '_LEAVESRC'} ?
                            '' :  '--clean --rmsource ';
d582 1
a582 1
                   . "$rpmbuildopts $rpmclean $spec";
a631 6
sub f_prep
{
    $cf->{leavesrc} = 1;
    return f_buildrpms("-bp");
}

a633 1
    $cf->{leavesrc} = 1;
a638 1
    $cf->{leavesrc} = 1;
d644 1
a644 3
    my @@keys = mk_buildlist();
    my $sn = ${$keys[0]}->{sn};
    
d653 1
d697 5
a703 1
die "not implemented yet";
d706 2
a707 3
    foreach my $key (mk_buildlist()) {
         $packages->{$$key->{sn}} = 1;
    }
d847 4
a850 5
   # sort the keylist by alphabetic spec name
   my @@keylist = sort { $$a->{sn} cmp $$b->{sn} } mk_buildlist();
   foreach my $key ( @@keylist  ) {
       $sn = $$key->{sn};
       $en = $$key->{en} ? 'y' : 'n';
d884 1
a884 1
    # the HEAD of cvs.
a887 1
    my $cvstags;
d898 2
a899 23
        while(1) {
            chomp($_ = <STDIN>);
            $tag = $_ if $_;
            last if $tag eq 'localdir' || $tag eq 'localdir_nobuild' 
                                       || $tag eq 'HEAD';
            if($tag !~ m,^[a-zA-Z][\w-]+$,) {
                print(<<TXT);
Illegal tag name, tags need to be specified as follows:

* Start with an uppercase or lowercase letter
* Subsequently and can also contain uppercase and lowercase letters, 
  digits, `-', and `_'
TXT
                next;
            }
            unless($cvstags) {
                print("gathering a list of cvs tags used so far, pls wait\n");
                %$cvstags = map { $_ => 1 } get_cvs_tags();
            }
            last unless exists $cvstags->{$tag};
            print(  "The tag you've chosen is already in cvs, "
                  . "please choose another\n");
        }
d929 5
d938 5
a971 23

cd $rel/$rel

# do a dltest to make sure that all files have been uploaded
if [ "$tag" != "localdir" -a "$tag" != "localdir_nobuild" ]
then
    ./ltib --dltest
fi

# built to make sure all generated pieces make it onto the iso
if [  "$tag" != "localdir_nobuild" ]
then 
    ./ltib --preconfig config/platform/qs875s/defconfig --configure --batch
fi

# remove the rootfs components
./ltib -m clean

# remove unwanted log files and host package install check files
rm -f .host_wait_warning* host_config.log

cd -

d975 3
a977 6
    foreach my $rpm (list_all_toolchains()) { 
        my $path = get_file($rpm, $cf);
        system("cp -af $path $rel/pkgs/") == 0 or die;
        $rpm =~ s,\.[^.]+\.rpm,.src.rpm,;
        $path = get_file($rpm, $cf);
        system("cp -af $path $rel/pkgs/") == 0 or die;
d980 1
d1034 1
d1036 4
a1039 2
    foreach my $key ( mk_buildlist()  ) {
        copy_spec_sources($$key->{sn}, $dest) or die;
d1048 2
a1049 3
    foreach my $key ( mk_buildlist()  ) {
        next unless $$key->{en};
        copy_spec_sources($$key->{sn}, $dest) or die;
a1053 14
sub list_all_toolchains
{
    my $lkc = "$cf->{platforms_dir}/$pcf->{PLATFORM}/main.lkc";
    my @@tcs;
    my $scan = 0;
    open(LKC, $lkc) or die("open $lkc : $!");
    while(<LKC>) {
        next unless $scan || m,^\s*config\s+TOOLCHAIN\s*$,;
        $scan = 1, next unless $scan;
        last if m,^\s*config\s+,;
        push(@@tcs, $1) if m,([\S]+\.rpm),;
    }
    return @@tcs;
}
d1066 1
a1066 1
                     pkg_map top home username path_std
d1150 1
d1184 3
a1189 3
    # turn on output again as the user may have to interact
    redirect();

d1213 1
d1283 1
a1283 1
                 .  $cf->{path_std};
a1307 1
    $ENV{ENDIAN}        = $pcf->{endian} || "big";
d1318 1
a1318 1
                          UCLIBC CONFIG_DIR ENDIAN/ ) {
d1367 1
a1367 1
    foreach my $dep ( @@{$$key->{deps}} ) {
d1379 1
a1379 7
# Process build list.
# Cycle through all packages and build a list of keys for each package,
# these keys are placed in a build ordered array.
# For a key to be added, it needs to be in both the platforms .config
# file and in one of the pkg_map files.
# As the keys are process, attributes for that key are saved into
# a hash that is referenced using a soft reference to the key name
d1381 1
a1381 1
sub mk_buildlist 
d1383 2
a1384 2
    return @@{$pcac->{mk_buildlist}} if exists $pcac->{mk_buildlist};
    warn("PROFILE:: mk_buildlist(): ", join(":",caller()), "\n") if $cf->{prof};
a1385 4
    # When -p <pkg> is specified at the command line, this means
    # actually the spec file name (without .spec).  This is needed
    # so we can ask to build a specific package without regard to
    # whether it's part of our current platform configuration
d1387 17
a1403 13
        push @@{$pcac->{mk_buildlist}}, 'userpkg';
        $userpkg->{sn} = $cf->{pkg};
        $userpkg->{en} = 'y';
        return @@{$pcac->{mk_buildlist}}
    }
    my $pre = '^([\w]+)\s*=\s*([\S]+)';

    # load up the override map if present.  These values must exist
    # the main package map, and are used to override them
    # it makes no sense it have u-boot or kernels in them
    my $ovmap = {};
    my $map = "$cf->{platforms_dir}/$pcf->{PLATFORM}/$cf->{pkg_map}";
    if( -f $map ) {
d1407 13
a1419 2
            m,$pre,o or next;
            $ovmap->{$1} = $2;
d1421 1
d1423 10
a1432 1
    close MAP;
d1434 2
a1435 21
    # load up the main map
    $map = "$cf->{top}/$pcf->{DISTRO}/common/$cf->{pkg_map}";
    open(MAP, $map) or die("open($map): $!\n");
    while(<MAP>) {
        chomp;
        m,$pre,o or next;
        my $key = $1;
        next unless defined $pcf->{$key};
        push @@{$pcac->{mk_buildlist}}, $key;

        # if the package name is in the .config use that name, otherwise
        # use the one from the package map
        if($pcf->{$key} && $pcf->{$key} ne 'y') {
            $$key->{sn} = $pcf->{$key};
            $$key->{en} = 1;
        } else {
            $$key->{sn} = $2;
            $$key->{en} = $pcf->{$key} eq 'y' ? 1 : 0;
        }
        $$key->{sn} = $ovmap->{$1} if $ovmap->{$1};
        process_pkg_deps($key, $$key->{sn}) if $$key->{en};
d1437 2
a1438 3
    close MAP;

    return @@{$pcac->{mk_buildlist}};
a1440 3
# return a build ordered list of enabed packages
# this is from the Name: field in the spec file, which
# may be different from the spec file name
d1443 4
a1446 7
    return @@{$pcac->{get_pkg_list}} if exists $pcac->{get_pkg_list};

    warn("PROFILE:: get_pkg_list(): ", join(":",caller()), "\n") if $cf->{prof};
    my ($name, $key, $pkg, $spec);
    foreach $key ( mk_buildlist()) {
        next unless $$key->{en};
        $spec = get_spec($$key->{sn}) or next;
d1449 1
a1449 1
            ($name) = m,^name\s*:\s*([\S]+),i;
d1453 1
a1453 1
        push @@{$pcac->{get_pkg_list}}, $name if $name;
d1455 1
a1455 1
    return @@{$pcac->{get_pkg_list}};
a1523 2
    warn("PROFILE:: get_spec ($sn): ", join(":",caller()), "\n") if $cf->{prof};

a1644 3

    # invalidate the cache
    $pcac = {};
d1683 1
a1683 2
    # invalidate the cache
    $pcac = {};
d1695 1
a1695 1
    my ($hostrpm) = `PATH=$cf->{path_std} ; which rpm`;
d1748 2
a1749 7
        my ($path, $fn);
        foreach $path ( glob("$top/pkgs/*") ) {
            ($fn) = $path =~ m,([^/]+)$,;  
            next if -f "$cf->{lpp}/$fn";
            system_nb("set -x; cp -dp $path $cf->{lpp}/$fn") == 0 or die;
        }
        system_nb("rm -rf $top/pkgs 2>/dev/null");
d1854 1
a1854 1
    my $spec;
a1856 1
        $spec = get_spec("merge") unless $spec;
d1871 1
a1871 1
    $cf->{normal_exit} = 0 if $cf->{pkg_build_failures};
d1873 2
a1874 1
    print <<TXT;
d1880 3
a1883 3

if( $cf->{normal_exit} ) {
    print "Build Succeeded\n\n";
a1884 6
}
if( $cf->{pkg_build_failures}) {
    print "These packages failed to build:\n$cf->{pkg_build_failures}\n";
}
print "Build Failed\n\n";
    return;
d1891 1
a1891 1
    $cf->{normal_exit} = 0;
a1905 5

    # if not asking to configure and we have a preconfig, just return it
    # TODO: 20oct05: put this back for now until the lkc bug is fixed
    return if $cf->{preconfig} && ! $cf->{configure} && ! $cf->{profile};

d1907 1
a1907 1
    if(! $cf->{configure} && ! $cf->{preconfig} && ! $cf->{profile}) {
d1910 2
a1911 4
            if(-f "$cf_main->{PLATFORM_DIR}/.config") {
                # The normal case where the .config is new than the defconfig
                if(     -M "$cf_main->{PLATFORM_DIR}/.config"
                    <=  -M "$cf_main->{PLATFORM_DIR}/defconfig" ) {
d1913 9
a1921 10
                    $cf->{preconfig} = "$cf_main->{PLATFORM_DIR}/.config";
                    return 1;
                }

                # the defconfig is newer than the .config, this is normally
                # because someone else has updated cvs.  In this case, use
                # the new defconfig
                warn("Using update $cf_main->{PLATFORM_DIR}/defconfig\n");
                my $date = gm_yyyymmdd();
                system_nb(<<TXT) == 0 or die;
d1927 1
a1927 6
                $cf->{batch} = 1;
            } else {
                # the platform's .config is missing, need to re-select the
                # platform again
                unlink "$cf->{top}/.config";
            }
d1929 4
d1955 1
a1955 1
                $platform = "CONFIG_$1";
a2059 1
        s,^(\w+LEAVESRC)=y,# $1 is not set,;
@


1.1.1.6
log
@Import from fsl 14mar06
@
text
@d1005 1
a1012 3
# work in the release staging area
cd $rel/$rel

d1016 1
a1016 1
    ./ltib --preconfig config/platform/$pcf->{PLATFORM}/defconfig --configure --batch
@


1.1.1.7
log
@Import from fsl 29mar06
@
text
@d319 1
a881 4
    # For now, don't allow batch mode releases until we've figured out
    # all the details of passing in the information needed.
    die("Batch mode is enabled, cannot make iso release!!\n") if $cf->{batch};

d947 1
a947 1
    system_nb(<<TXT) == 0 or die "\nPlease save your changes before continuing\n";
a1030 1
    print("copy all sources\n");
a1031 2

    print("copy all toolchain rpm/srpms\n");
d1034 1
a1034 1
        system_nb("cp -af $path $rel/pkgs/") == 0 or die;
d1037 1
a1037 1
        system_nb("cp -af $path $rel/pkgs/") == 0 or die;
a1038 3

    print("copy host support package sources\n");
    $pcac = {};
a1041 2

    print("copy rpm-fs sources\n");
d1082 1
a1082 1
        system_nb("set -x ; cp -af $src $dest") == 0 or die;
d1084 1
a1084 1
            system_nb("set -x ; cp -af $src.md5 $dest") == 0 or die;
d1233 4
a1236 1
    print <<TXT;
d1247 1
a1247 4

    # remove the previous logfile
    unlink($cf->{logfile});

d1377 1
a1377 1
    $ENV{ENDIAN}        = $pcf->{ENDIAN} || "big";
d1434 2
a1435 2
    # assume done if the specfile was touched after the .config file
    return 1 if -M $spec <= -M $cf->{preconfig};    
d1877 2
a1878 2
            if($cf->{buildarch} eq 'ppc') {
                $pcf->{TOOLCHAIN} =~ s,i\d86,$cf->{buildarch},;
d2176 1
a2176 9
    my $rc = 'ltib_bashrc';
    open(RC, ">$rc") or die("can't open $rc for write: $!\n");
    print RC <<TXT;
export PS1="LTIB> "
alias rpm="rpm -dbpath $cf->{rpmdb}"
TXT
    close RC;
    system_nb("/bin/bash --rcfile $rc");
    unlink $rc;
@


1.1.1.8
log
@Import from fsl 20060406
@
text
@d39 1
a39 1
            $PKG_BUSYBOX $PKG_KERNEL $PKG_GDB $PKG_NCURSES $PKG_BASH);
d80 1
a80 1
    app_version  => "6.2.1",
a181 2
$PKG_NCURSES->{deps} = [ qw/PKG_NCURSES_WANT_REDUCED_SET/ ];
$PKG_BASH->{deps}    = [ qw/PKG_BASH_WANT_NO_SH_SYMLINK/  ];
d375 1
a375 2
&{"f_" . $cf->{mode}}() 
                    or die("\n\nf_$cf->{mode}() returned an error, exiting\n");
d512 1
a512 1
    remove_unselected_pkgs() unless $cf->{dltest};
d542 1
d544 1
a545 1
                            undef $ret;
a546 1
                            warn("Can't get: $file");
d1891 2
a1892 1
            $tc = get_file("$pcf->{TOOLCHAIN}", $cf);
d1894 1
a1894 1
            warn("Can't get: $pcf->{TOOLCHAIN}"), die unless $tc;
d1990 1
a1990 3
    my $desc = $cf->{dltest} ? "would not have complete downloads available" 
                             : "failed to build";
    print "These packages $desc:\n$cf->{pkg_build_failures}\n";
@


1.1.1.9
log
@Import from fsl 20060516
@
text
@d7 1
a7 1
# Copyright  Freescale Semiconductor, Inc. 2004-2005. All rights reserved.
d38 2
d55 1
a55 1
    dodrop       => 'yes',
d57 1
a57 2
    sysconfdir   => "/etc",
    mandir       => "share/man",
d69 1
a69 1
    wget_opts    => "--passive-ftp -nc --tries=1 --timeout=5 -nv",
d84 1
a84 1
    mainlkc      => "$top/config/main.lkc",
a144 1
    hostcf       => 0,
d150 14
a163 16
$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/ ],
           PKG_LIBC     => [ qw/PKG_LIBC_WANT_LOCALES PKG_LIBC_WANT_HEADERS
                                PKG_LIBC_WANT_STATIC_LIBS PKG_LIBC_WANT_CF/ ],
           PKG_BUSYBOX  => [ qw/PKG_BUSYBOX_PRECONFIG PKG_BUSYBOX_WANT_CF/ ],
           PKG_GDB      => [ qw/PKG_GDB_NATIVE_WANT_ED PKG_GDB_CROSS_WANT_ED
                                PKG_GDB_SERVER_WANT_ED/ ],
           PKG_OPENSSL  => [ qw/PKG_OPENSSL_WANT_SEC/ ],
           PKG_DROPBEAR => [ qw/PKG_DROPBEAR_WANT_URANDOM_DEV
                                PKG_DROPBEAR_WANT_NO_REV_DNS
                                PKG_DROPBEAR_WANT_NO_X11FWD/ ],
           PKG_SYSCONFIG=> [ qw/SYSCFG_HOSTNAME 
                          SYSCFG_MODLIST SYSCFG_START_SYSLOG
d180 8
a187 13
                          SYSCFG_READONLY_FS/ ],
           PKG_NCURSES  => [ qw/PKG_NCURSES_WANT_REDUCED_SET/ ],
           PKG_BASH     => [ qw/PKG_BASH_WANT_NO_SH_SYMLINK/  ],
               };

# package build dependencies
$build_deps = { PKG_KERNEL => [ qw/PKG_SYSCONFIG/ ] };

# packages install dependencies
$install_deps = { PKG_SKELL => [ qw/PKG_SYSCONFIG/ ],
                  PKG_BUSYBOX => [ qw/PKG_INETUTILS PKG_SYSKLOGD
                                      PKG_SYSVINIT/ ]
                };
d202 1
a202 1
            prep        just prep the package
d206 1
d208 1
a208 1
            clean       clean/uninstall target packages
d210 5
d225 1
a225 1
        --rcfile|r <f>: use this resource file
a240 1
        --hostcf      : (re)configure/build/install the host support package set
a280 1
        "hostcf"     => \$cf->{hostcf},
d289 1
a289 1
    unless $cf->{mode} =~ m,^(buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell)$,;
d325 5
d370 3
a375 3
# if doing host stuff, run that command
build_host_rpms(1) if $cf->{hostcf};

d384 5
d392 1
a392 5

        $msg = "\nProcessing deployment operations\n";
        $msg .= '=' x length($msg) . "\n";
        print $msg;

d404 1
a404 1
sub f_clean
d406 1
a406 4
    print "Cleaning out target rpms:\n";
    my @@pkg_list = map { $$_->{en} ? get_pkg_name($_) : () } mk_buildlist();

    foreach my $pkg (reverse @@pkg_list) {
d420 7
d446 2
a452 1
    pkg_cache_init();
d488 10
d524 1
a524 2
        my $spec = get_spec($sn) or warn("skipping $sn, specfile not found\n"),
                                                               undef $ret, next;
d532 1
a532 4
        if(   ( $cf->{force} && ! $cf->{pkg} ) 
           || (exists $$key->{build} && $$key->{build})
           || $cf->{dltest} || ! @@rpms || -M $spec < -M $rpms[0]){
     
d596 1
a596 2
                   . "--define '_mandir $cf->{prefix}/$cf->{mandir}' "
                   . "--define '_sysconfdir $cf->{sysconfdir}' "
a610 1
           || (exists $$key->{install} && $$key->{install})
a639 3

                # make sure we're not going to clobber host files
                check_host_clobber($rpm);
a640 3

                # the install of this package may cause others to install
                process_pkg_triggers($key);
a646 1

a648 3
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
    $$key->{build}  = 1;
a654 3
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
    $$key->{build}  = 1;
a660 3
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
    $$key->{build}  = 1;
d667 2
a668 3
    my $sn = $cf->{pkg};
    my $key = get_key_by_sn($cf->{pkg});
    $$key->{build}  = 1;
d674 1
d681 1
a681 1
    open(SPEC, ">$tspec") or die("can't open $tspec for write: $!");
d688 1
a688 1
Release         : $tok->{release} 
a699 2
From an scdeploy !!!!

d716 1
a716 1
    my $ret = f_buildrpms("-bb") or die;
d756 1
a756 2
    my ($specout, $specin) = get_spec($cf->{pkg}) or die();
    my $spec = $specin || $specout;
d789 1
a789 1
    open(SPEC, $spec) or die("can't open $spec : $!");
d806 1
a806 1
$cf->{rpmbuild} --dbpath $cf->{rpmdb} --define '_target_cpu $pcf->{LINTARCH}' --define '_topdir $cf->{rpmdir}' --define '_prefix $cf->{prefix}' --define '_tmppath $cf->{tmppath}' --define '_mandir $cf->{prefix}/$cf->{mandir}' --define '_sysconfdir $cf->{sysconfdir}' -bp $specout >/dev/null || exit 1
d812 1
a812 1
    open(SPEC, ">$spec.bak") or die("can't open $spec.bak for writing: $!");
d816 1
a816 1
    s,\Q$tok->{prep}\E,$tok->{prep}%patch$num -p1\n,;
d818 1
a818 1
    open(SPEC, ">$spec") or die("can't open $spec for writing : $!");
d828 1
a828 1
due to and incomplete "make distclean" 
a1031 1
rm -rf rpm/BUILD/*
d1042 1
a1042 1
        my $path = get_file($rpm, $cf) or die "can't get $rpm";
d1050 3
a1052 2
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{hostconfig});
d1150 1
a1150 1
                     platforms_dir mainlkc conf defdist pfx buildarch
d1208 1
a1208 1
sub build_host_rpms
d1210 4
a1213 2
    my ($allow_hostcf) = @@_;

d1216 2
a1217 2
    my @@sav_list = qw/dev_image prefix sysconfdir rpmdir rpmdb nodep force
                      reinstall dodrop preconfig/;
d1219 1
a1219 1
        $sav->{$k} = $cf->{$k};
d1221 2
a1222 4
    # override with suitable host values (some host pkgs are not relocatable)
    $cf->{dev_image}     = '/';                  # install prefix
    $cf->{prefix}        = "$cf->{defpfx}/usr";  # build prefix
    $cf->{sysconfdir}    = "$cf->{defpfx}/etc";  # config files
d1226 1
d1229 2
d1233 3
a1235 12
    if($allow_hostcf == 1) {
        # in this case, we have installed base host packages and have
        # also got a target config setup
        ltib_host_config();
        $cf->{dodrop} = 'ask';
    } else {
        # this is the case where we are doing just the basic host packages
        $cf->{dodrop} = 'no';
        $cf->{preconfig} = $cf->{hostconfig};
    }
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{preconfig});
a1237 1
    check_toolchain_setup($pcf);
a1238 23
    # we can get here at install time, or later config of host packages 
    if($cf->{hostcf}) {
        &{"f_" . $cf->{mode}}()
                    or die("\n\nf_$cf->{mode}() returned an error, exiting\n");
        exit 0;
    }

    # build host rpms
    f_buildrpms() or die;

    # restore
    foreach my $k (@@sav_list) { $cf->{$k} = $sav->{$k} }
    undef $sav;

    return 1;
}

sub host_checks
{
    # do not attempt to re-install host packages once 
    # we have got through here completely once
    return 1 if -f $cf->{host_wait_warning} || $cf->{dltest};
    
d1262 1
a1262 1
    # redirect output to logfile
d1274 3
a1276 1
    # redirect output to logfile
d1278 2
d1281 7
a1287 2
    # build and install rpms for the host
    build_host_rpms(0);
a1288 1
    redirect();
d1296 2
a1297 2
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{preconfig});
d1299 2
a1300 1
        $ppcf = parse_dotconfig("$cf->{preconfig}.old");
a1327 3
    # clean up stale rpm-tmp files
    system("rm -f $cf->{tmppath}/rpm-tmp.*");

d1336 2
a1337 2
    pkg_cache_init();
    $pcf = parse_dotconfig($cf->{preconfig});
d1358 1
a1358 1
    $pcf->{CFGHOST} = "$cf->{buildarch}-linux" 
a1395 1
    $ENV{RPMDB} = $cf->{rpmdb};
d1451 1
a1451 1
    foreach my $dep ( @@{$config_deps->{$key}} ) {
a1461 41
sub process_pkg_triggers
{
    my ($key) = @@_;
    return unless exists $build_deps->{$key} || $install_deps->{$key};
    foreach my $dep ( @@{$build_deps->{$key}} ) {
        warn "$$dep->{sn} rebuild forced by $$key->{sn}\n";
        enable_pkg_if_was_en($dep, 'build');
    }
    foreach my $dep ( @@{$install_deps->{$key}} ) {
        warn "$$dep->{sn} install forced by $$key->{sn}\n";
        enable_pkg_if_was_en($dep, 'install');
    }
}

sub process_pkg_rev_triggers
{
    my ($key) = @@_;

    # it is valid that a package may not have a key during development
    return unless $key;          

    unless(defined $rev_install_deps) {
        foreach my $hr ($build_deps, $install_deps) {
            foreach my $k ( keys %$hr ) {
                foreach my $dep ( @@{$hr->{$k}} ) {
                    push @@{$rev_install_deps->{$dep}}, $k;
                }
            }
        }
    }
    foreach my $k (@@{$rev_install_deps->{$key}}) {
        warn("re-installing $$k->{sn} because $$key->{sn} was dropped\n");
        $$k->{install} = 1;
    }
}

sub pkg_cache_init
{
    $pcac = {};
}

a1473 1

d1476 10
d1487 15
a1501 1
    local $_;
d1522 1
a1526 44
    # load up the override map if present.  These should be bools.
    # It makes no sense it have u-boot or kernels in them
    my $map = "$cf->{platforms_dir}/$pcf->{PLATFORM}/$cf->{pkg_map}";
    if( -f $map ) {
        open(MAP, $map) or die("open($map): $!\n");
        while(<MAP>) {
            chomp;
            m,$pre,o or next;
            my $key = $1;
            unless(exists $$key->{sn}) {
                warn("$key in $map is not selectable\n"), next
                                                    unless exists $pcf->{$key};
                push @@{$pcac->{mk_buildlist}}, $key;
                $$key->{en} = $pcf->{$key} eq 'y' ? 1 : 0;
            }
            $$key->{sn} = $2;
        }
        process_pkg_deps($key, $$key->{sn}) if $$key->{en};
    }
    close MAP;

    # When -p <pkg> is specified at the command line, this means
    # actually the spec file name (without .spec).  This is needed
    # so we can ask to build a specific package without regard to
    # whether it's part of our current platform configuration
    if($cf->{pkg}) {
        my $key = 'userpkg';

        # turn off all packages from build list
        # see if we can find a key that matches the spec name
        foreach my $tkey (@@{$pcac->{mk_buildlist}}) {
            $$tkey->{was_en} = $$tkey->{en};
            $$tkey->{en} = 0;
            $key = $tkey if $$tkey->{sn} eq $cf->{pkg};
        }
        # if this spec name is unknown, fabricate a key
        unless(exists $$key->{sn}) {
            push @@{$pcac->{mk_buildlist}}, $key;
            $$key->{sn} = $cf->{pkg};
        }
        $$key->{en} = 1;
        $$key->{build} = 1 if $cf->{force};
    }

d1530 1
a1530 19
sub get_key_by_sn
{
    my ($sn) = @@_;
    foreach my $key ( mk_buildlist() ) {
        return $key if $$key->{sn} eq $sn;
    }
    return 'userpkg';
}

sub enable_pkg_if_was_en
{
    my ($key, $action) = @@_;
    if(exists $$key->{was_en} && $$key->{was_en}) {
        $$key->{en} = 1;
    }
    $$key->{$action} = 1;
}

# return the name of a package referenced by key
d1533 1
a1533 1
sub get_pkg_name
d1535 1
a1535 2
    my ($key) = @@_;
    return $$key->{pkg} if exists $$key->{pkg};
d1537 14
a1550 14
    warn("PROFILE:: get_pkg_name(): ", join(":",caller()), "\n") if $cf->{prof};

    local $_;
    my ($spec, $pkg);
    $spec = get_spec($$key->{sn}) or die("can't find $$key->{sn}.spec");
    open(F, $spec) or die("can't open $spec: $!");
    while(<F>) {
        ($pkg) = m,^name\s*:\s*([\S]+),i;
        last if $pkg;
    }
    close F;
    die("$spec does not contain an entry for Name:") unless $pkg;
    $$key->{pkg} = $pkg;
    return $pkg;
a1552 1

d1556 1
a1556 1
    return 1 if $cf->{pkg} || $cf->{dodrop} eq 'no';
d1559 13
a1571 17
    my @@drop_list = ();
    my $pkg2key   = {};
    foreach (@@installed) {
        my $not_wanted = 1;
        foreach my $key ( mk_buildlist() ) {
            next unless $$key->{en};
            my $pkg = get_pkg_name($key);
            $not_wanted = 0, last if m,^\Q$pkg\E,;
        }
        if($not_wanted) {
            push(@@drop_list, $_);
            foreach my $key ( mk_buildlist() ) {
                my $pkg = get_pkg_name($key);
                $pkg2key->{$_} = $key, last if m,^\Q$pkg\E,;
            }    
        }
    }
d1573 1
d1576 2
a1577 12

    foreach my $rpmname ( reverse(@@drop_list) ) {
        next if $rpmname =~ m,^(?:rpm-fs|tc-mtwk-|mtwk-lnx-|ppc-uclibc-tc),;
        if($cf->{dodrop} eq 'ask') {
            print <<TXT if $cf->{dodrop} eq 'ask';

Drop package $rpmname ? (y|N) 
TXT
            $_ = <STDIN>;
            next unless m,^y,;
        }
        print "Dropping de-selected package $rpmname\n";
d1579 1
a1579 1
               . "-e --allmatches $rpmname --nodeps";
a1581 1
        process_pkg_rev_triggers($pkg2key->{$rpmname});
d1617 2
a1618 3
    if(exists $cache->{$sn}) {
        return wantarray ? @@{$cache->{$sn}} : $cache->{$sn}[0];
    }
d1623 5
a1627 23
        my $specpath = "$dir/$spec";
        my $specinpath = "";
        if(-e "$specpath.in") {
            $specinpath = "$specpath.in";
            $specpath   = "$cf->{tmppath}/$spec";
            open(SPECIN, $specinpath) or die("can't open $specinpath: $!");
            $_ = <SPECIN>;
            my $tmplpath;
            my ($tmpl) = m,template\s*=\s*([\S]+),i or die("no template");
            foreach my $tdir ( $dir, @@dirs ) {
               $tmplpath = "$tdir/$tmpl", last if -e "$tdir/$tmpl"; 
            }
            die("no template") unless $tmplpath;
            warn("template: $tmplpath\n") if $cf->{verbose};
            if(! -f $specpath  || (-M $specinpath < -M $specpath) 
                               || (-M $tmplpath   < -M $specpath)   ) {  
                expand_spec($specpath, $specinpath, $tmplpath);
            }
        }
        if(-e $specpath) {
           warn("spec files: [ $specpath, $specinpath ]\n") if $cf->{verbose};
           $cache->{$sn} = [ $specpath, $specinpath ];
           return wantarray ? @@{$cache->{$sn}} : $cache->{$sn}[0];
d1630 1
a1630 1
    undef $cache->{$sn};
d1642 1
a1642 1
    return wantarray ? () : undef;
d1706 1
a1706 1
    if( $dev_image =~ m,^\s*//\s*$, ) {
a1741 9
    # at this point we haven't parsed any pcf (platform config)
    # so we write our own
    $pcf = {};
    $pcf->{PLATFORM_COMMENT} = 'host support';
    $pcf->{DISTRO}   = 'dist/lfs-5.1';
    $pcf->{PLATFORM} = 'host';
    $pcf->{GNUTARCH} = $cf->{buildarch};
    $pcf->{LINTARCH} = g2larch($cf->{buildarch});
    $pcf->{CFGHOST}  = "$cf->{buildarch}-linux";
d1744 1
d1746 2
a1747 2
    my @@sav_list = qw/dev_image nodeps pkg force reinstall dodrop
                     prefix sysconfdir rpmbuild rpm rpmdir rpmdb lpp tmppath/;
a1750 1
    pkg_cache_init();
d1754 1
a1754 1
    $cf->{dodrop}        = 'no';
a1755 1
    $cf->{sysconfdir}    = "$cf->{defpfx}/etc";
d1771 1
a1771 1
    my $cmd  = "$cf->{sudo} $sav->{rpm} --dbpath $cf->{defpfx}/var/lib/rpm ";
d1779 1
a1779 1
    foreach $k (@@sav_list) {
d1783 2
d1866 11
d1955 1
a1969 43
# we have to be very careful with packages that have a
# prefix of effectively /, if the package builds wrongly
# it will scribble of the host's installation.  For this
# reason we check carefully that this cannot happen
# This is to handle building packages that need to be installed
# on the host under {defpfx}
sub check_host_clobber
{
    my ($rpm) = @@_;
    my ($len, $cmd, $pkg_prefix, $inst_pfx, $path, $line);

    $pkg_prefix = `$cf->{rpm} -qp --queryformat "%{PREFIXES}\n" $rpm`;
    chomp($pkg_prefix);
    $pkg_prefix  = '' if $pkg_prefix eq '(none)';
    $inst_pfx = $cf->{dev_image};
    $inst_pfx =~ s,/+,/,g;

    # if a relocatable package, and were installing in our project area
    # then we can bypass this strict test
    $len = length($top);
    if($pkg_prefix && unpack("A$len", $inst_pfx) eq $top) {
       warn("skip host clobber check, pkg_prefix=$pkg_prefix inst=$inst_pfx\n")
                                                              if $cf->{verbose};
       return 1;
    }

    # if removing the install prefix results in anything in getting installed
    # under anything except /opt, /tmp, /home exit in a big hurry.
    $len = length($pkg_prefix);
    $cmd = "$cf->{rpm} -qlp $rpm";
    open(CMD, "$cmd |") or die("can't fork $cmd: $!\n");
    while(defined($line = <CMD>)) {
        chomp($line);
        last if $line eq '(contains no files)';
        ($path) = unpack ("x$len A*", $line);
        $path   = $inst_pfx . $path;
        $path   =~ s,/+,/,g;
        if( $path !~ m,^/(?:opt|tmp|home), ) {
            die("ERROR: $rpm\nwould clobber $path\n");
        }
    }
    return 1;
}
d2013 2
a2014 1
sub ltib_host_config
d2016 1
a2017 28
   
    my $hostpath = "$top/config/platform/host";

    # so you want to add some new host packages
    system_nb(<<TXT) == 0 or die;
set -ex
cd $hostpath
PLATFORM=$pcf->{PLATFORM}
PLATFORM=\${PLATFORM:-unknown}
if [ ! -f .config ]
then
    if [ -f \${PLATFORM}.config ]
    then 
        cp \${PLATFORM}.config .config
    else
        cp $cf->{hostconfig} .config
    fi
fi
mconf main.lkc
if [ -f .config ]
then
    cp .config \${PLATFORM}.config
fi
TXT
    $cf->{preconfig} = "$hostpath/.config";
    die("No config saved") unless -f $cf->{preconfig};
    return 1;
}
d2020 3
a2022 4
sub ltib_config
{
    my $cf_main = {};
    my $plat_dir;
d2025 7
a2031 11
    if( ! $cf->{configure} && ! $cf->{preconfig} && ! $cf->{profile}
                                                 && -f "$cf->{top}/.config" ) {
        $cf_main = parse_dotconfig("$cf->{top}/.config");
        $plat_dir = $cf_main->{PLATFORM_DIR} or die "no PLATFORM_DIR";

        if(-f "$plat_dir/.config") {
            # The normal case where the .config is new than the defconfig
            if(-M "$plat_dir/.config" <=  -M "$plat_dir/defconfig") {
                $cf->{preconfig} = "$plat_dir/.config";
                return 1;
            }
d2033 3
a2035 8
            # the defconfig is newer than the .config, this is normally
            # because someone else has updated cvs.  In this case, use
            # the new defconfig.  Note mconf/conf use defconfig if .config
            # is missing.
            warn("Using update $plat_dir/defconfig\n");
            rename("$plat_dir/.config", "$plat_dir/.config.$cf->{stime}")
                                                     if -f "$plat_dir/.config";
            $cf->{batch} = 1;
d2037 17
a2053 4
        } else {
            # the platform's .config is missing, need to re-select the
            # platform again
            unlink "$cf->{top}/.config";
d2062 3
a2064 2
        my $th = parse_dotconfig($cf->{preconfig});
        $plat_dir = "config/platform/$th->{PLATFORM}";
d2074 1
a2074 1
        open(MC, $cf->{mainlkc}) or die "open $cf->{mainlkc} : $!";
d2076 1
a2076 1
            if( m,$plat_dir"\s+if\s+(\w+), ) {
d2082 8
a2089 6
        die "No match for $plat_dir in $cf->{mainlkc}" unless $platform;
        open(TOPCF, ">$cf->{top}/.config") or die("open $cf->{top}/.config:$!");
        print TOPCF "$platform=y\n";
        print TOPCF "CONFIG_PLATFORM_DIR=\"$plat_dir\"\n";
        close TOPCF;

d2094 1
a2094 1
            system_nb("$cf->{conf} $cf->{mainlkc}") == 0 or die;
d2097 1
a2097 10
        $cf_main = parse_dotconfig(".config");
    }
    
    # Run the platform specific config
    $plat_dir ||= $cf_main->{PLATFORM_DIR};

    # preconfigs/profiles effectively invalidate the .config.old output
    # from mconf/conf.  We save .config to restore it later as .config.old
    if( ($cf->{preconfig} || $cf->{profile}) && -f "$plat_dir/.config") {
        rename("$plat_dir/.config", "$plat_dir/.config.$cf->{stime}");
d2099 1
a2099 1

d2102 1
a2102 1
if [ -n "$cf->{preconfig}" ]
d2104 1
a2104 1
    cp $cf->{preconfig} $plat_dir/.config
d2106 3
a2108 1
if [ -n "$cf->{profile}" ]
d2110 1
a2110 1
    cat  $cf->{profile} >> $plat_dir/.config
a2111 3
cd $plat_dir
$cf->{conf} main.lkc
cp .config defconfig.dev
d2113 2
a2114 4
    $cf->{preconfig} = "$plat_dir/.config";
    if(-f "$plat_dir/.config.$cf->{stime}") {
        rename("$plat_dir/.config.$cf->{stime}", "$plat_dir/.config.old");
    }
d2122 1
a2122 1
    opendir(DIR, $dir) or warn("can't open $dir: $!"), return;
d2141 1
a2141 1
    open(MCF, ">$cf->{mainlkc}") or die "open $cf->{mainlkc} : $!\n";
d2155 1
a2155 1
    foreach $mcf (sort keys %$p) {
d2166 1
a2166 1
    foreach $mcf (keys %$p) {
d2192 1
a2192 1
    open(RC, ">$rc") or die("can't open $rc for write: $!");
d2195 1
a2195 1
alias rpm="rpm --dbpath $cf->{rpmdb}"
a2230 19

sub expand_spec
{
    my ($specpath, $specinpath, $tmplpath) = @@_;
    open(SPECIN, "$specinpath")   or die("can't open $specpath.in: $!");
    open(TMPL, $tmplpath)         or die("can't open $tmplpath: $!");
    open(SPEC, ">$specpath")      or die("can't open $specpath for write: $!");
    while(<SPECIN>) {
        print SPEC;
    }
    close(SPECIN);
    while(<TMPL>) {
        print SPEC;
    }
    close(TMPL);
    close(SPEC);

    return 1;
}
@


1.1.1.10
log
@Import from fsl 20060530
@
text
@a89 1
    rpmdb_nfs_warning => "$top/.rpmdb_nfs_warning",
a90 1
    force_rebuild_host_rpms => "$top/.force_rebuild_host_rpms",
d299 1
a299 1
    #### TODO: temporarily allow preconfig until lkc bug is fixed
d368 3
a373 3
# do setup before target building
pre_build_checks();

a403 1
    local $_;
d434 1
a434 1
    local $_ = <STDIN>;
a475 4
$echo rm -f $cf->{rpmdb_nfs_warning}
$echo rm -f rootfs.jffs2 rootfs.ext2.gz
$echo find $cf->{platforms_dir} \\( -name *.dev -o -name *.bak \\) -exec rm {} \\;
$echo rm -f bin/{gdb,tmake}
d509 1
a509 1
        parse_spec($spec, $tok, 0);
d765 1
a765 1
    parse_spec($spec, $tok, 0);
d789 4
d823 1
a823 1
    s,^(%[Pp]rep.+?)(?=\s*(^%[Bb]uild|\Z)),$1\n%patch$num -p1,sm;
d882 1
a882 1
       parse_spec($spec, $tok, 0);
a894 2
    local $_;

a1038 1
rm -f $cf->{rpmdb_nfs_warning}
d1099 1
a1099 1
    parse_spec($spec, $tok, 0);
a1136 1
    local $_;
d1233 1
a1233 2
    $cf->{force}         = 0 unless $allow_hostcf;
    $cf->{force}         = 1 if -f $cf->{force_rebuild_host_rpms};
d1238 2
a1239 1
        # we are working on host packages
d1264 1
a1264 1
    foreach $k (@@sav_list) { $cf->{$k} = $sav->{$k} }
a1318 1
    unlink($cf->{force_rebuild_host_rpms});
d1502 1
a1502 1
    foreach $dep ( @@{$install_deps->{$key}} ) {
d1524 1
a1524 1
    foreach $k (@@{$rev_install_deps->{$key}}) {
d1584 1
a1584 1
            $key = $1;
d1602 1
a1602 1
        $key = 'userpkg';
d1641 1
a1641 1
# Return the name of a package referenced by key
a1643 2
# This is an ugly optimisation as the cost of parsing the spec files
# and reducing the macros is quite high
d1649 14
a1662 6
    my $spec = get_spec($$key->{sn}) or die("can't find $$key->{sn}.spec");
    my $tok = {};
    parse_spec($spec, $tok, 0, 'nvr');
    die("$spec does not contain an entry for Name:") unless $tok->{name};
    $$key->{pkg} = $tok->{name};
    return $$key->{pkg};
a1670 1
    local $_;
d1674 4
a1677 6
    my @@buildlist = mk_buildlist();
    my @@wanted    = grep { $$_->{en} } @@buildlist;

INST:
    foreach my $inst ( @@installed ) {
        foreach my $key ( @@wanted ) {
d1679 1
a1679 2
            my $len = length $pkg;
            next INST if unpack("A" . $len, $inst) eq $pkg;
d1681 5
a1685 8
        # this clause is to catch temporarily installed package via -m scdeploy
        push(@@drop_list, $inst);
        foreach $key ( @@buildlist ) {
            $pkg = get_pkg_name($key);
            $len = length $pkg;
            if( unpack("A" . $len, $inst) eq $pkg ) {
                $pkg2key->{$inst} = $key;
                last;
d1694 1
a1694 1
        next if $rpmname =~ m,^(?:rpm-fs|tc-mtwk-|mtwk-lnx-|ppc-uclibc-tc|tc-fsl-),;
d1757 1
a1757 1
            local $_ = <SPECIN>;
d1861 8
a1868 14
    if(! -f $cf->{rpmdb_nfs_warning} ) {
        # make sure the rpmdb directory is not an nfs mount
        my $fstype = cmd_w_to(5, "df -PT $cf->{rpmdb} |tail -1") || "fake nfs";
        $fstype = (split(/\s+/, $fstype))[1];
        if($fstype eq 'nfs') {
            warn(<<TXT);

The rpm database should not be located in an NFS mounted filesystem. 
On some systems this may cause cause problems due to filesystem locking
and this application.

You may move the database to a local disk by changing the entry in your
rcfile ($cf->{rcfile}) from $rpmdb to somewhere that is not on an
NFS filesystem
a1869 1
Do you want to continue and attempt to use this NFS area for your rpmdb (y|n)?
a1870 6
            local $_ = <STDIN>;
            die "Goodbye\n" unless /^y/i;
            touch($cf->{rpmdb_nfs_warning});
        }
    }
    
a1886 3
    # signal that the existing host rpms are possibly invalid
    touch($cf->{force_rebuild_host_rpms});

d2046 3
a2048 3
            my $err = `$cmd 3>&1 1>&2 2>&3 3>&-`;
            if($? && $err !~ m,is already installed,) { 
                die "Failed to install: $pcf->{TOOLCHAIN}:\n$err\n"
d2219 1
a2219 4
if [ "$cf->{configure}" = "1" ]
then
    mconf main.lkc
fi
a2232 3
    # this is a special case that should not really exist
    return if $cf->{preconfig} && $cf->{dltest};

@


1.1.1.11
log
@Import from fsl 20060615
@
text
@a32 1
use 5.006_001;
d68 1
a68 1
    wget_opts    => "--passive-ftp -nc --tries=1 --timeout=12 -nv",
d70 8
a77 26
    pre_install_deps   => "
            glibc           2.2.5
            glibc-headers   0
            glibc-devel     0
            binutils        2.11.93
            libstdc++       0
            libstdc++-devel 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
#            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
            ",
d92 1
a150 5
use strict 'vars';
use vars qw($cf $config_deps $build_deps $install_deps
            $echo $pcf $ppcf $rev_install_deps);


d173 1
a173 2
                          SYSCFG_NET_GATEWAY0 SYSCFG_NAMESERVER0
                          SYSCFG_NET_GATEWAY1 SYSCFG_NAMESERVER1
d195 1
a195 16
                                      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_LIBC  => [ 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/ ],
d198 1
a198 1
my $usage =<<TXT;
d325 1
a325 1
$cf->{logfile} ||= "$cf->{top}/host_config.log";
d346 1
a346 1
foreach my $sig (qw/__DIE__ INT/) {
d361 1
a361 1
    my $ret = &{"f_" . $cf->{mode}}() || 0;
d388 1
a388 1
        my $msg = "\nProcessing deployment operations\n";
d393 1
a393 2
                    "$cf->{bin_path}/device_table.txt", $pcf) 
                                                          or die unless $echo;
d414 1
a414 1
        my $cmd = "$cf->{sudo} $cf->{rpm} --dbpath $cf->{rpmdb} -e --allmatches $pkg";
d525 1
a525 1

a693 1
${\( exists $tok->{base} ? "%define base $tok->{base}" : '' )}
d1166 1
a1166 1
                     pre_install_deps/ ) {
d1241 1
d1271 1
a1271 1
    foreach my $k (@@sav_list) { $cf->{$k} = $sav->{$k} }
d1284 1
a1284 1
    check_basic_deps() or die;
d1326 1
d1470 1
d1507 2
a1508 12
        if(exists $$dep->{was_en} && $$dep->{was_en}) {
            $$dep->{en} = 1;
        }
        $$dep->{build} = 1;
        warn "$$dep->{sn} rebuild forced by $$key->{sn}\n" if $$dep->{en};
    }
    foreach my $dep ( @@{$install_deps->{$key}} ) {
        if(exists $$dep->{was_en} && $$dep->{was_en}) {
            $$dep->{en} = 1;
        }
        $$dep->{install} = 1;
        warn "$$dep->{sn} install forced by $$key->{sn}\n" if $$dep->{en};
d1510 3
a1512 12
}

sub build_rev_triggers
{
    return if defined $rev_install_deps;

    foreach my $hr ($build_deps, $install_deps) {
        foreach my $k ( keys %$hr ) {
            foreach my $dep ( @@{$hr->{$k}} ) {
                push @@{$rev_install_deps->{$dep}}, $k;
            }
        }
a1515 15
sub has_rev_trigger
{
    my ($key) = @@_;

    build_rev_triggers();

    return exists $rev_install_deps->{$key} ? 1: 0;
}

sub get_rev_triggers
{
    build_rev_triggers();
    return keys %$rev_install_deps;
}

a1519 2
    build_rev_triggers();

d1523 10
a1532 1
    foreach my $k (@@{$rev_install_deps->{$key}}) {
a1537 2
my $pcac;

d1556 1
a1556 1
    warn("PROFILE:: mk_buildlist():\n", caller_stack(), "\n") if $cf->{prof};
a1558 1
    my $key;
d1562 1
a1562 1
    my $map = "$cf->{top}/$pcf->{DISTRO}/common/$cf->{pkg_map}";
d1580 1
d1586 1
a1586 1
    $map = "$cf->{platforms_dir}/$pcf->{PLATFORM}/$cf->{pkg_map}";
d1601 1
a1627 5
    # process the package dependencies
    foreach $key ( @@{$pcac->{mk_buildlist}} ) {
        process_pkg_deps($key, $$key->{sn}) if $$key->{en};
    } 

d1640 9
d1659 1
a1659 1
    my $spec = get_spec($$key->{sn}) or return;
a1678 1
    my ($key, $pkg, $len);
d1682 3
a1684 3
        foreach $key ( @@wanted ) {
            $pkg = get_pkg_name($key) or die;
            $len = length $pkg;
d1687 1
a1687 1
        # the installed package is not in the list of enabled packages
d1689 2
a1690 4
        
        # check to see if this package has any reverse triggers
        foreach $key ( get_rev_triggers() ) {
            $pkg = get_pkg_name($key) or next;
d1713 1
a1713 1
        my $cmd =   "$cf->{sudo} $cf->{rpm} --dbpath $cf->{rpmdb} "
d1756 1
a1756 1
    warn("PROFILE:: get_spec ($sn):\n", caller_stack(), "\n") if $cf->{prof};
d1788 1
d1790 1
a1790 1
get_spec: can't find spec file $spec
a1791 1
in search any of the directories:
a1794 1

a1800 1
# check the most basic host services are available
d1803 2
a1804 3
    my @@failed = ();

    foreach my $dep ( split(/\n/, $cf->{pre_install_deps}) ) {
d1806 1
a1806 1
        next if $dep =~ m,^\s*#,;
d1809 5
a1813 25
        my ($ver, $info) = get_ver($pkg);
        warn "pkg=$pkg, min=$min, got: $ver, $info\n" if $cf->{verbose};
        if($ver ne -1) {
            next if cmp_ver($ver, $min) >= 0;
            $info = $ver;
        }
        push @@failed, [ $pkg, $min, $info ];         
    }
    return 1 unless @@failed;

    no strict 'vars';
    $~ = 'inst';
    $^ = 'inst_top';
    my @@ar;

format inst_top =
@@<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<  @@<<<<<<<<<<<<<<<
'Package',             'Mininum ver', 'Installed info'
@@<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<  @@<<<<<<<<<<<<<<<
'-------',             '-----------','---------------'
.
format inst =
@@<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<<  @@*
$ar->[0],              $ar->[1],     $ar->[2]
.
d1815 1
a1815 1
    print(<<TXT);
d1817 2
a1818 4
ltib cannot be run because one or more of the host packages needed
to run it are either missing or out of date.

Please install/ugrade these packages and then re-try.
d1820 1
a1821 2
    foreach $ar ( @@failed ) {
       write;
d1823 1
a1823 1
    return;
d1832 1
a1832 1
    foreach my $k (qw/TOOLCHAIN_PREFIX TOOLCHAIN_PATH
d1877 1
a1877 1
Ideally the rpm database should not be located in an NFS mounted filesystem. 
d1879 1
a1879 2
and this application.  If you have this problem, you'll see error
messages like: "error: cannot get exclusive lock on ..../Packages"
d1882 2
a1883 2
rcfile ($cf->{rcfile}) from $rpmdb
to somewhere that is not on an NFS filesystem
d1909 3
d1925 1
a1925 1
    my @@sav_list = qw/dev_image nodeps pkg force reinstall dodrop ldirs
a1939 1
    $cf->{ldirs}         = $cf->{lpp};
a1958 3
    # The existing host rpms are possibly invalid now so remove them
    system_nb("rm -f $cf->{defpfx}/usr/src/rpm/RPMS/$pcf->{LINTARCH}/*");

d1960 1
a1960 1
    foreach my $k (@@sav_list) {
d2016 1
a2016 1
    my $lpp_mode = (stat("$cf->{lpp}"))[2];
d2026 1
a2026 1
    if( -d "$cf->{top}/pkgs" ) {
d2029 1
a2029 1
        foreach $path ( glob("$cf->{top}/pkgs/*") ) {
d2034 1
a2034 1
        system_nb("rm -rf $cf->{top}/pkgs 2>/dev/null");
d2055 1
a2055 1
        `$cf->{rpm} -q $tc_rpm 2>/dev/null`;
d2057 7
a2063 7
           || `$cf->{rpm} -q $tc_rpm 2>/dev/null` =~ m,is not installed,
           || $cf->{dltest}) {
           $pcf->{TOOLCHAIN} =~ s,i\d86,$cf->{buildarch}, 
                                                  if $cf->{buildarch} eq 'ppc';
            print "Installing: $pcf->{TOOLCHAIN}\n" unless $cf->{dltest};
            my $tc = get_file("$pcf->{TOOLCHAIN}", $cf);
            return 1 if $cf->{dltest};
d2066 1
a2066 1
            my $cmd =   "$cf->{sudo} $cf->{rpm} "
a2069 2
            return 1 if $echo;

d2156 2
a2157 2
    $len = length($cf->{top});
    if($pkg_prefix && unpack("A$len", $inst_pfx) eq $cf->{top}) {
d2185 2
a2186 2
    my $edate = localtime();
    my $elapsed  = time() - $cf->{stime};
d2227 1
a2227 1
    my $hostpath = "$cf->{top}/config/platform/host";
d2265 1
a2265 1
    my ($plat_dir, $atime, $mtime);
d2342 1
a2342 2
        ($atime, $mtime) = (stat("$plat_dir/.config"))[8,9];
        system_nb("cp $plat_dir/.config $plat_dir/.config.$cf->{stime}");
a2361 2
        utime($atime, $mtime, "$cf->{preconfig}.old")
                   or warn "could not reset times on $cf->{preconfig}.old: $!";
d2368 1
a2368 1
    my ($dir, $ent, $p, $mcf) = ("config/platform", "", {});
@


1.1.1.12
log
@Import from fsl 20061124
@
text
@d33 1
a33 1
use 5.006_000;  # now known to work on 5.6.0, don't know the oldest ver yet
a56 1
    localstatedir=> "/var",
d72 1
a72 1
            glibc           2.2.4
d75 1
a75 1
            binutils        2.11.90
a89 1
            patch           0
d98 1
a98 2
    app_version  => "6.4.1",
    cvs_version  => '$Revision: 1.247 $',
d117 1
a132 1
    buildcxx     => "/usr/bin/g++ -B/usr/bin//",
d143 1
a143 1
    sn           => "",
d171 1
a171 1
            $echo $pcf $ppcf $rev_install_deps $pcac);
d184 1
a184 2
                                PKG_GDB_SERVER_WANT_ED 
                                PKG_GDB_M68K_BDM_WANT_ED/ ],
d208 1
a208 5
                          SYSCFG_READONLY_FS SYSCFG_START_DEVFSD
                          SYSCFG_DEPLOYMENT_STYLE SYSCFG_INETD_ARGS
                          SYSCFG_START_DHCPD SYSCFG_DHCPC_CMD
                          CONFIG_SYSCFG_START_SAMBA CONFIG_SYSCFG_SMBD_ARGS
                          CONFIG_SYSCFG_NMBD_ARGS/ ],
a210 1
           PKG_DHCP     => [ qw/PKG_DHCP_WANT_SERVER PKG_DHCP_WANT_CLIENT/ ],
d229 1
a229 1
                                      PKG_WHICH PKG_DEVFSD/],
a257 2
            listpkgseula list package names and licenses
            listpkgstw  list packages in twiki format
d303 1
a303 1
        "pkg|p:s"    => \$cf->{sn},
d329 1
a329 7
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
d333 1
a333 1
    unless $cf->{mode} =~ m,^(buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell),;
d335 7
a341 6
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
d343 1
a343 1
The options: --profile cannot be used when 
a414 3
# write out a release info file
write_release_info("$cf->{top}/RELEASE_INFO");

d425 1
a425 2
        || $cf->{do_deploy}
        || ($cf->{mode} eq 'buildrpms' && ! $cf->{sn}) ) {
d483 1
a483 1
    my @@sav_list = qw/sn force/;
d488 1
a488 1
    $cf->{sn} = "mkdistclean.spec";
d500 4
a503 1
$echo rm -f .wget_warning .rpm_warning .sudo_warning .config .tmpconfig.h .config.old .config.cmd
d534 2
a535 2
    my($msg, @@srpm, @@rpms, $rpm, $pkg, $subpkg, $cmd, $rebuilt, $ec, $stime);

d539 1
a539 1
    print $msg unless $cf->{nounpack};
d541 1
a541 1
              if ($cf->{preconfig} || $cf->{redirected}) && ! $cf->{nounpack};
d551 1
a551 1
        print $msg;
d562 1
a562 1
        if(   $cf->{force}
d567 1
a567 1
            if(! $cf->{nounpack})  {
d607 2
a608 11
                    if($cf->{mode} eq 'buildrpms') { 
                        warn "scbuild/scdeploy already unpacked package\n";
                        $cf->{sn} = $sn;
                        pkg_iterate($cf->{sn});
                        $cf->{nounpack} = 1;
                        $ret = f_scbuild() && f_scdeploy();
                        $cf->{leavesrc} = 0;
                        $cf->{nounpack} = 0;
                        pkg_iterate();
                        $cf->{sn} = "";
                    } else {
d610 1
a610 1
                        $cf->{pkg_build_failures} .= "$sn ";
d612 1
a612 2
                    next if $cf->{coe} || $ret;
                    return $ret;
d618 2
a619 8

            my $rpmclean;
            if($cf->{leavesrc} || $pcf->{$key . '_LEAVESRC'}) {
                $rpmclean = '';
                $ENV{$key . '_LEAVESRC'} = 'y'; 
            } else {
                $rpmclean = '--clean --rmsource ';
            }
a630 1
                   . "--define '_localstatedir $cf->{localstatedir}' "
d633 3
a635 5
            $stime = time();
            $ec    = system_nb("$echo $cf->{fakeroot} $cmd");
            print "Build time for $sn: ${\( time() - $stime )} seconds\n\n";
            $rebuilt = 1;
            if($ec) {
d638 1
a638 2
                undef $ret;
                return $ret unless $echo || $cf->{coe};
d678 1
a678 8

                # in dry-run mode (echo), don't actually install)
                unless($echo) {
                    if(system_nb($cmd) != 0) {
                        undef $ret;
                        return $ret unless $cf->{coe};
                    }
                }
d691 2
a692 2
    validate_sn();
    my $key = get_key_by_sn($cf->{sn});
d700 2
a701 2
    validate_sn();
    my $key = get_key_by_sn($cf->{sn});
a703 1
    $cf->{nounpack} = 1;
d709 2
a710 2
    validate_sn();
    my $key = get_key_by_sn($cf->{sn});
a712 1
    $cf->{nounpack} = 1;
d718 3
a720 4
    validate_sn();
    my $sn = $cf->{sn};
    my $key = get_key_by_sn($sn);
    #$$key->{build}  = 1;
d727 1
a727 1
    f_scinstall() or return;
d740 1
a740 1
Release         : $tok->{release}
d762 2
a763 1
%Files$tok->{files}
d770 1
a770 1
    my $ret = f_buildrpms("-bb");
d804 1
a804 1
    die(<<TXT) unless $cf->{sn};
d810 1
a810 2
    validate_sn();
    my ($specout, $specin) = get_spec($cf->{sn}) or die();
a890 8
sub f_listpkgseula
{
	return f_listpkgs('eula');
}
sub f_listpkgstw
{
    return f_listpkgs('twiki');
}
a892 7
   my ($mode) = @@_;
	if ($mode eq "eula") {
		# Set large FORMAT_LINES_PER_PAGE so there is only one page
		$= = 10000;
		# Disable page break characters
		#$^L = "";
	}
d894 3
a896 4
   $mode ||= 'text';
	# Set FORMAT_NAME
   $~ = $mode;
   $^ = $mode . "_top";
d908 1
a908 1
$tok->{name}.'-'.$tok->{version}.'-'.$tok->{release}, $sn, $en, $tok->{license}, $tok->{summary}
d911 2
a912 2
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<@@<@@|||||@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@*@@<
'|','*Package*','|','*Spec Name*','|','*En*','|','*Summary*','|','*License*','|'
d915 2
a916 12
@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@<<<<<<<<<<<<<<<<<<<<<<@@<@@|||||@@<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<@@*@@<
'|',$tok->{name}.'-'.$tok->{version}.'-'.$tok->{release},'|',$sn,'|',$en,'|',$tok->{summary},'|',$tok->{license},'|'
.
format eula_top =
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<
'Package', 'License'
@@<<<<<<<<<<<<<<<<<<<<<<< @@<<<<<<<<<<
'-----------------------','-------'
.
format eula =
@@<<<<<<<<<<<<<<<<<<<<<<< @@*
"$tok->{name}-$tok->{version}-$tok->{release}", $tok->{license}
d928 1
a932 21
sub write_release_info
{
    my ($file, $cvs, $rel) = @@_;
    $cvs ||= 'none';
    $rel ||= 'none';

    open(RI, ">$file") or warn("open: >$file : $!"), return;
    print RI <<TXT;
Release date = $cf->{gmsdate} UTC
Release user = $cf->{username}
Release host = $cf->{hostname}
Release dir  = $cf->{top}
CVS tag      = $cvs
Release tag  = $rel
App version  = $cf->{app_version}
CVS version  = $cf->{cvs_version}
TXT
    close RI;
    return 1;
}

d979 1
a979 6
            $_ = <STDIN>;
            if ( !defined $_ ) {
                # Prevent infinite loop if tag is from here file in script.
                die("STDIN is not defined, exiting\n");
            }
            chomp($_);
d1113 12
a1124 1
    write_release_info("$rel/$rel/RELEASE_INFO", $tag, $rel) or die;
d1269 1
a1269 1
    my @@sav_list = qw/dev_image prefix sysconfdir rpmdir rpmdb nodeps force
d1301 1
a1301 1
    if($cf->{hostcf} && $cf->{mode} ne 'config' ) {
a1380 8
    # add distcc hosts if this has been setup
    $ENV{DISTCC_HOSTS} = $cf->{DISTCC_HOSTS} 
                       if ! defined $ENV{DISTCC_HOSTS} && $cf->{DISTCC_HOSTS};
    $ENV{DISTCC_TCP_CORK} = $cf->{DISTCC_TCP_CORK} 
         if ! defined $ENV{DISTCC_TCP_CORK} && defined $cf->{DISTCC_TCP_CORK};
    $ENV{MAKEFLAGS} = $cf->{MAKEFLAGS} 
                       if ! defined $ENV{MAKEFLAGS} && $cf->{MAKEFLAGS};

a1382 1
    die "$cf->{rpm} has gone missing" unless -f $cf->{rpm};
a1405 3
    # we only want to record something go built for target packages
    $cf->{something_got_built} = 0;

a1451 1
    $ENV{BUILDCXX}  = $cf->{buildcxx};
a1463 1
    $ENV{TOOLCHAIN_PATH} = $pcf->{TOOLCHAIN_PATH};
d1603 2
a1606 2
    # this was changed from an outer lexical to global to keep older
    # version from warning about 'not staying shared'
a1647 2
        warn "mk_buildlist: key=$key, sn=$$key->{sn}, en=$$key->{en}\n"
                                                            if $cf->{verbose};
d1652 1
a1652 1
    # It makes no sense to have u-boot or kernels in them
d1671 2
a1672 4
    # A user can specifiy -p <pkg>.  Without the '.spec' extention
    # means we should lookup the specfile name from the package.
    # If the '.spec' extension is passed, then the user means
    # the actual spec file name.  This is needed
d1675 2
a1676 15
    if($cf->{sn}) {
        if( substr($cf->{sn}, -5, 5) eq ".spec" ) {
            substr($cf->{sn}, -5, 5) = "";
        } else {
            my ($key, $lu_pkg, $pkg, $pkg_len, $found);
            $pkg     = $cf->{sn};
            $pkg_len = length($cf->{sn});
            foreach $key ( @@{$pcac->{mk_buildlist}} ) {
                $lu_pkg = get_pkg_name($key) or die;
                if( unpack("A" . $pkg_len, $lu_pkg) eq $pkg ) {
                    $found = $$key->{sn};
                    last;
                }
            }
            die <<TXT unless $found;
d1678 11
a1688 6
Cannot find spec file that contains the package name $pkg.
If necessary please give the whole spec file name (with the    
.spec extension).

TXT
            $cf->{sn} = $found;
d1690 2
a1691 1
        pkg_iterate($cf->{sn});
a1701 33
# If a spec name is passed, turn off all packages except that one
# if no spec name is passed, restore all packages to their previous state
sub pkg_iterate
{
    my ($sn) = @@_;
    my $key = 'userpkg';

    foreach my $tkey (@@{$pcac->{mk_buildlist}}) {
        if($sn) {
            $$tkey->{was_en} = $$tkey->{en};
            $$tkey->{en} = 0;
            $key = $tkey if $$tkey->{sn} eq $sn;
        } else {
            $$tkey->{en} = $$tkey->{was_en};
        }
    }
    return 1 unless $sn;

    # if this spec name is unknown, fabricate a key
    unless(exists $$key->{sn}) {
        push @@{$pcac->{mk_buildlist}}, $key;
        $$key->{sn} = $sn;
    }
    $$key->{en} = 1;
    $$key->{build} = 1 if $cf->{force};
    return 1;
}

sub validate_sn
{
    mk_buildlist();
}

d1721 1
a1721 2
    my $sn = $$key->{sn} or return;
    my $spec = get_spec($sn) or return;
d1723 1
a1723 1
    parse_spec($spec, $tok, 0, 'name');
d1729 1
d1733 2
a1734 1
    return 1 if $cf->{sn} || $cf->{dodrop} eq 'no';
d1736 1
a1736 1
    my @@installed = split(/[\s\n]+/, `$cf->{rpm}  --dbpath $cf->{rpmdb} -qa --queryformat "%{name} "`);
d1746 3
a1748 3
            $pkg = get_pkg_name($key) or next;
            $len = length $inst;
            next INST if $inst eq $pkg;
d1757 1
a1757 1
            if( $inst eq $pkg ) {
a1766 1
    print "\n" if @@drop_list;
d1768 1
a1768 1
        next if $rpmname =~ m,^(?:rpm-fs|tc-mtwk-|mtwk-lnx-|ppc-uclibc-tc|tc-fsl-|freescale-coldfire-),;
d1770 4
a1773 1
            print "Drop package $rpmname ? (y|N)" if $cf->{dodrop} eq 'ask';
a1798 4
    unless($sn) {
        warn("get_spec():\n", caller_stack(), "\n");
        return;
    }
d1894 1
a1894 1
'Package',             'Minimum ver', 'Installed info'
d1908 1
a1908 1
Please install/upgrade these packages and then re-try.
d2014 1
a2014 1
    my @@sav_list = qw/dev_image nodeps sn force reinstall dodrop ldirs
d2020 1
a2020 1
    $cf->{sn}            = "rpm-fs.spec";
d2039 1
a2039 1
    my @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$cf->{sn}-*");
d2041 1
a2041 1
                        . "$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$cf->{sn}-*";
d2321 1
a2321 1

a2541 7

# Target man pages
function tman()
{
    export MANPATH=\$DEV_IMAGE/man:\$DEV_IMAGE/usr/man:\$DEV_IMAGE/usr/share/man:\$DEV_IMAGE/usr/local/man
    man \$1
}
@


1.1.1.13
log
@Import from fsl 20070116
@
text
@a38 1
#use LWP::Debug qw(+);
d101 1
a101 1
    cvs_version  => '$Revision$',
d522 1
d527 1
a527 2
$echo rm -rf $cf->{rpmdir}/RPMS
$echo rm -rf $cf->{rpmdir}/SRPMS
d539 1
a539 1
$echo for i in faked fakeroot mkimage gdb tmake; do rm -rf $cf->{top}/bin/\$i ; done
d594 1
a594 1
                        unless( $src = get_file($url, $cf, 1) ) {
d1195 1
a1195 1
        my $path = get_file($rpm, $cf, 1) or die "can't get $rpm";
d1198 1
a1198 1
        $path = get_file($rpm, $cf, 1);
d2088 1
a2088 4
for i in BUILD RPMS SOURCES SPECS SRPMS
do
    mkdir -p $rpmdir/\$i
done
d2301 1
a2301 1
            my $tc = get_file("$pcf->{TOOLCHAIN}", $cf, 1);
@


1.1.1.14
log
@Import from fsl 20071105
@
text
@a0 1
#!/usr/bin/perl -w
d4 1
a4 1
$ENV{LANG} = 'C';
d7 1
a7 1
# Copyright  Freescale Semiconductor, Inc. 2004-2007. All rights reserved.
a39 2
use IO::File;

a46 1
$verbose = 0;
a64 1
    pps          => "ppp gpp",
a70 2
    force_md5get => "",
    quiet        => "",
d72 1
a72 1
    configured   => "",
d79 1
d101 1
a101 1
    app_version  => "7.2.1",
a106 1
    release_info => "$top/tmp/RELEASE_INFO",
d114 1
a114 1
    host_wait_warning => "$top/.host_wait_warning14",
a127 1
    hostinst     => 0,
d154 1
a166 1
    external     => 0,
d169 1
a169 1

d175 1
a175 1
            $echo $pcf $ppcf $rev_install_deps $pcac $verbose);
d183 3
a185 10
                                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/ ],
d188 1
a188 1
                                PKG_GDB_SERVER_WANT_ED
d193 2
a194 3
                                PKG_DROPBEAR_WANT_NO_X11FWD
                                PKG_DROPBEAR_WANT_HACKABLE_KEY/ ],
           PKG_SYSCONFIG=> [ qw/SYSCFG_HOSTNAME
d200 1
a200 1
                          SYSCFG_START_NETWORK SYSCFG_TMPFS_SIZE
a220 2
           PKG_PPP      => [ qw/PKG_PPP_WANT_FILTER/ ],
           PKG_SKELL    => [ qw/PKG_SKELL_WANT_TERMINFO/ ],
d240 1
a240 3
                  PKG_UCLIBC => [ qw/PKG_GCC/ ],
                  PKG_GLIBC  => [ qw/PKG_GCC/ ],
                  PKG_BASE_LIBS => [ qw/PKG_GCC/ ],
d258 1
a258 1
        --mode|m
a270 1
            trelease    make a non-distributable test iso release
a293 1
        --external    : check against external staging repositories
a295 1
        --enabled     : use with package listings
a298 2
# set stdout to autoflush
$| = 1;
d321 2
a322 2
        "verbose|v"  => \$verbose,
        "batch|b"    => \$cf->{batch},
a333 1
        "external"   => \$cf->{external},
a336 1
        "enabled"    => \$cf->{enabled},
d350 2
a351 2
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),;
d360 1
a360 1
The options: --profile cannot be used when
a394 1

d433 1
a433 1
write_release_info($cf->{release_info});
d436 1
a436 1
&{"f_" . $cf->{mode}}()
d453 1
a453 1
                    "$cf->{bin_path}/device_table.txt", $pcf)
d465 1
a465 2
{
    remove_unselected_pkgs();
d471 1
a471 1
        print("$pkg is not installed\n"), next
d473 1
a473 1
        $pkg .= " $pkg-devel"
d482 1
a482 1
}
d529 1
d537 1
a537 1
$echo rm -f $cf->{rpmdb_nfs_warning} $cf->{release_info}
a538 1
$echo rm -rf rootfs.tmp
d540 1
a540 1
$echo for i in faked fakeroot mkimage gdb tmake .gdbinit mpc.init; do rm -rf $cf->{top}/bin/\$i ; done
d550 1
a550 1
    }
d556 1
d558 1
a558 1
    print "using $cf->{preconfig}\n"
a565 1
        $$key->{build} = 1 if $pcf->{$key . '_FORCE'};
d571 2
a572 8
        my $spec = get_spec($sn);
        unless( $spec ) {
            $cf->{pkg_build_failures} .= "$sn ";
            undef $ret;
            warn("specfile not found\n");
            die unless $echo || $cf->{coe} || $cf->{dltest};
            next;
        }
d575 2
a576 1
        @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*");
d580 1
a580 1
        if(   $cf->{force}  || $cf->{download_only}
d587 1
a587 1
                unlink(@@rpms) unless $cf->{dltest} || $cf->{download_only};
d589 1
a589 1
                foreach my $url (  split(/\s*\n/, $tok->{sources}),
d593 1
a593 1
                    if(! -e $tgt || $cf->{dltest} || $cf->{download_only}) {
d605 1
a605 1

d625 1
a625 1
                    if($cf->{mode} eq 'buildrpms') {
a626 1
                        my $osn = $cf->{sn};
d634 1
a634 1
                        $cf->{sn} = $osn; 
d650 1
a650 1
                $ENV{$key . '_LEAVESRC'} = 'y';
d654 1
a654 1

d684 1
a684 1
           || `$cf->{rpm} --dbpath $cf->{rpmdb} -q $tok->{name}-$tok->{version}-$tok->{release} 2>/dev/null
d690 12
a701 3
            # seh: 20070312: sub-packages have not ever really worked.
            # seh: 20071030: remove rpm -e as using Uvh, not ivh
            foreach $rpm ( glob("$cf->{rpmdir}/RPMS/$pcf->{LINTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*") ) {
d707 2
a708 3
                $cmd .= "--ignorearch -Uvh ";
                $cmd .= "--force "  unless $cf->{conflicts} || $cf->{hostinst};
                $cmd .= "--replacepkgs --replacefiles " if $cf->{hostinst};
d719 1
a719 4
                    system_nb($cmd);
                    my $ec = ($? & 0xffff) >> 8;
                    # a return code of 2 indicates a newer package installed
                    if($ec != 0 && $ec != 2) {
d769 1
a769 1

a783 1
%define __os_install_post %{nil}
d831 1
a831 1
        warn("skipping: $srpm, doesn't look like an srpm\n"), next
d877 2
a878 2
already exists.  You need to move this out the way before running
patchmerge.  Patchmerge will preserve your working copy of the
d910 1
a910 1

d927 1
a927 1
due to and incomplete "make distclean"
d941 1
a941 1
        return f_listpkgs('eula');
d950 7
d958 1
a958 7
   $^L = '';
        if ($mode eq "eula") {
                # Set large FORMAT_LINES_PER_PAGE so there is only one page
                $= = 10000;
        }
   my ($tok, $en, $sn);
   # Set FORMAT_NAME
a995 1
       next if $cf->{enabled} && $$key->{en} == 0;
d1002 1
a1002 1
   }
d1011 1
a1011 1
    my $wtag = get_cvs_tag() || 'none';
a1017 1
CVS wtag     = $wtag
d1029 215
a1243 2
    require Ltibrelease;
    return release_main();
d1246 1
a1246 1
sub f_trelease
d1248 6
a1253 2
    require Ltibrelease;
    return release_main(warnonly => 1);
d1256 26
a1319 8
    if($cf->{external}) {
        $cf->{pp_list} = [ 'gpp_stage', 'cpp_stage' ];
    } else {
        @@{$cf->{pp_list}} = grep { ! m,^\s*$, && ! m,\s*#, }
                                                      split(/\s+/, $cf->{pps});
    }
    warn "No remote package pools defined\n" unless @@{$cf->{pp_list}};

d1333 1
a1333 1
            parse_config($rc, $cf, { strip_blank => 1,
d1358 1
a1358 1
                      reinstall dodrop preconfig hostinst/;
a1369 1
    $cf->{hostinst}      = 1 unless $allow_hostcf;
d1388 1
a1388 1
    # we can get here at install time, or later config of host packages
d1407 1
a1407 1
    # do not attempt to re-install host packages once
d1410 1
a1410 1

d1435 1
a1435 1
    redirect(">> $cf->{logfile}");
d1437 1
a1437 1
    # use the host's rpm to bootstrap a known version of rpm
d1447 1
a1447 1
    redirect(">> $cf->{logfile}");
d1470 1
a1470 1
    $ENV{DISTCC_HOSTS} = $cf->{DISTCC_HOSTS}
d1472 1
a1472 1
    $ENV{DISTCC_TCP_CORK} = $cf->{DISTCC_TCP_CORK}
d1474 1
a1474 1
    $ENV{MAKEFLAGS} = $cf->{MAKEFLAGS}
d1536 1
a1536 1
    $pcf->{CFGHOST} = "$cf->{buildarch}-linux"
d1540 1
a1540 1
    $ENV{UNSPOOF_PATH} =
d1542 1
a1542 1
                 . "$cf->{defpfx}/usr/bin:"
d1545 1
a1545 3
    $ENV{SPOOF_PATH} =
                 "$cf->{bin_path}:"
                 .  ($pcf->{TOOLCHAIN_PREFIX} ? "$cf->{spoof_path}:" : "")
a1563 1
    $ENV{TOOLCHAIN} = $pcf->{TOOLCHAIN} || "";
a1574 2
    $ENV{DYNAMIC_LINKER} = $pcf->{DYNAMIC_LINKER} || "";
    $ENV{LIBC_HACKING} = $pcf->{LIBC_HACKING} || "";
a1576 1
    $ENV{PKG_CONFIG_PATH} = "$cf->{dev_image}/usr/lib/pkgconfig" || "";
d1578 1
a1578 1
    if($verbose) {
d1587 1
a1587 1

d1590 1
a1590 1
        warn("setting ENV{$k}=$pcf->{$k}\n") if $verbose;
d1605 1
a1605 1
    foreach my $dep (qw/PLATFORM GNUTARCH LINTARCH CFGHOST TOOLCHAIN DISTRO PKG_UCLIBC PKG_GLIBC LIBC_HACKING/) {
d1614 2
a1615 6
    if($need_frb) {
        f_clean() if -d $cf->{rpmdb};
        system_nb("rm -f $cf->{rpmdir}/RPMS//$pcf->{LINTARCH}/*");
        $ENV{LTIB_FULL_REBUILD} = "y";
    }
    system_nb("cp $cf->{preconfig} $cf->{preconfig}.old") unless $cf->{dry};
d1629 1
a1629 1
    return 1 if -M $spec <= -M $cf->{preconfig};
a1631 1
        next unless $pcf->{$key} && $ppcf->{$key};
d1635 1
a1635 2
            warn "$dep has changed, $spec_name needs a rebuild\n"
                                            unless $cf->{mode} eq 'release';
d1697 1
a1697 1
    return unless $key;
a1699 1
        next unless defined $$k->{sn};
d1721 1
a1721 1
sub mk_buildlist
d1732 1
a1732 1
    my $map = "$cf->{config_dir}/userspace/$cf->{pkg_map}";
d1737 1
a1737 1
        $key = $1;
d1751 1
a1751 1
                                                            if $verbose;
d1759 2
a1760 17
        my $seen = {};
        local *read_pkg_map =
        sub {
            my ($fn) = shift;
            $fn = "$cf->{config_dir}/userspace/$fn"
                                               unless substr($fn, 0, 1) eq '/';
            return if $seen->{$fn};
            $seen->{$fn} = 1;
            my $FH = IO::File->new($fn) or die("open $fn : $!");
            while(<$FH>) {
                proc_pkg_map($_)
            }
            delete($seen->{fn});
        };
        local *proc_pkg_map =
        sub {
            local $_ = shift;
a1763 4
            if($key eq 'source') {
                read_pkg_map($2);
                return;
            }
d1771 1
a1771 2
        };
        read_pkg_map($map);
d1773 1
d1785 1
a1785 1
            my ($lu_pkg, $pkg, $pkg_len, $found);
d1789 1
a1789 1
                $lu_pkg = get_pkg_name($key) or next;
d1798 1
a1798 1
If necessary please give the whole spec file name (with the
d1810 1
a1810 1
    }
d1897 1
a1897 1

d1905 1
a1905 1
            }
d1908 2
a1909 2
    warn("installed = ", join(", ", @@installed), "\n") if $verbose;
    warn("drop_list = ", join(", ", @@drop_list), "\n") if $verbose;
d1926 1
a1926 1
    }
a1945 1
    warn "get_spec($sn)\n" if $verbose;
d1971 1
a1971 1
    foreach my $dir ( @@dirs ) {
d1982 1
a1982 1
               $tmplpath = "$tdir/$tmpl", last if -e "$tdir/$tmpl";
d1985 3
a1987 3
            warn("template: $tmplpath\n") if $verbose;
            if(! -f $specpath  || (-M $specinpath < -M $specpath)
                               || (-M $tmplpath   < -M $specpath)   ) {
d1992 1
a1992 1
           warn("spec files: [ $specpath, $specinpath ]\n") if $verbose;
d2025 1
a2025 1
        warn "pkg=$pkg, min=$min, got: $ver, $info\n" if $verbose;
d2030 1
a2030 1
        push @@failed, [ $pkg, $min, $info ];
d2072 1
a2072 1
        $ndef .= "$k " unless exists $pcf->{$k};
d2109 1
a2109 1
                                                   unless -W $dev_image;
d2118 1
a2118 1
Ideally the rpm database should not be located in an NFS mounted filesystem.
d2126 1
a2126 1

d2134 1
a2134 1

d2150 1
a2150 1

d2184 1
a2184 2
    $cf->{rpmdir} = "/tmp/rpm-$cf->{username}";
    $cf->{rpmdir} =~ s,[\\],-,g;
d2235 1
a2235 1
To configure this, as root using the command "/usr/sbin/visudo",
d2273 1
a2273 1
            ($fn) = $path =~ m,([^/]+)$,;
a2287 7
sub tc_name
{
    my ($tcname) = @@_;
    $tcname =~ s,i\d86,$cf->{buildarch}, if $cf->{buildarch} eq 'ppc';
    return $tcname;
}

a2291 2
    return if $cf->{mode} =~ m,^listpkgs,;

d2302 2
a2303 1
            $pcf->{TOOLCHAIN} = tc_name($pcf->{TOOLCHAIN});
d2305 1
a2305 1
            my $tc = get_file($pcf->{TOOLCHAIN}, $cf, 1);
d2317 1
a2317 1
            if($? && $err !~ m,is already installed,) {
d2324 1
a2324 1
    my $gcc_path = `which $pcf->{TOOLCHAIN_PREFIX}gcc 2>/dev/null`
d2376 1
a2376 1
        warn "newer than $spec: $_\n" if $_ && $verbose;
d2404 1
a2404 1
                                                              if $verbose;
d2447 1
a2447 1
    my $desc = $cf->{dltest} ? "would not have complete downloads available"
d2483 1
a2483 1
    then
d2507 1
a2507 2
    return if $cf->{preconfig} && (    $cf->{dltest}
                                    || $cf->{mode} =~ m,^listpkgs,);
a2546 2
        die "ERROR: attempting to use a non-LTIB preconfig"
                                                        unless $th->{PLATFORM};
d2563 1
a2563 1
        }
d2580 1
a2580 1

d2585 4
a2588 5
    # from mconf/conf.  We save it and restore it later as .config.old
    my $oldconfig = "$plat_dir/.config.old";
    if( ($cf->{preconfig} || $cf->{profile}) && -f $oldconfig ) {
        ($atime, $mtime) = (stat($oldconfig))[8,9];
        system_nb("cp $oldconfig $oldconfig.$cf->{stime}");
a2592 4
if [ ! -f "$plat_dir/.config" -a -f "$plat_dir/defconfig" ]
then
    cp $plat_dir/defconfig $plat_dir/.config
fi
d2595 1
a2595 1
    cp -f $cf->{preconfig} $plat_dir/.config
d2599 1
a2599 2
    $cf->{top}/bin/splice_profile $plat_dir/.config $cf->{profile} > .config.tmp
    mv -f .config.tmp $plat_dir/.config
d2606 4
a2609 4
    if(-f "$oldconfig.$cf->{stime}") {
        rename("$oldconfig.$cf->{stime}", $oldconfig);
        utime($atime, $mtime, $oldconfig)
                   or warn "could not reset times on $oldconfig : $!";
d2617 1
a2617 1
    my $platforms = ();
d2621 1
a2621 1
        next if $ent eq 'CVS' || $ent eq '.' || $ent eq '..' || $ent eq 'host';
d2627 1
a2627 1
        open(CF, "$dir/$mcf/main.lkc")
d2709 1
d2711 1
a2711 1

d2716 4
d2721 1
a2721 1
        open(STDOUT, $file) or die("can't redirect stderr to $file: $!");
a2724 6
        # prevent: Filehandle STDERR reopened as only for input on later opens
        open(JUNK1, ">/dev/null");
        if(0) {
           my $msg = "hack to prevent used only once warning\n";
           print SAVEOUT $msg; print SAVEERR $msg; print JUNK1 $msg;
        }
a2727 2

    # if we get here and we're not redirected, just return
a2728 4

    # we are redirected, so restore the original STDOUT/STDERR
    close STDERR;
    close STDOUT;
d2731 1
a2731 3
    close SAVEOUT;
    close SAVEERR;
    $cf->{redirected} = '';
@


1.1.1.15
log
@Import from fsl 20080404
@
text
@d53 1
a53 3
    rfsbase      => "$top",
    rpmipfx      => '/',
    rpmdb        => '/var/lib/rpm',
d55 1
d64 1
a64 2
    tmppath      => "/tmp/ltib",
    projtmp      => "$top/tmp",
a104 1
            make            0
d107 1
a107 1
    app_version  => "8.1.2",
d113 1
a113 1
    release_info => "$top/RELEASE_INFO",
d121 1
a121 1
    host_wait_warning => "$top/.host_wait_warning16",
a164 1
    erase        => 0,
d170 1
a170 1
    noredir      => 0,
a176 1
    fullbsp      => 0,
a185 3
# make sure the root prefix for rpm is never set to / by the user
$cf->{rpmroot} = "$cf->{rfsbase}/rootfs";

a231 1
                          SYSCFG_START_WATCHDOG
a238 1
           PKG_HELLOWORLD_MOD => [ qw/PKG_KERNEL/ ],
d271 1
a271 1
in the directory $cf->{rpmroot} (unless overriden in the resource file)
d292 1
a292 2
            config      configure selected platform (no build)
            selectype   sub-platform selection (no build)
d295 1
a295 2
        --configure|c : run the interactive configuration and build
        --selectype   : run the sub-platform configuration and build
a303 1
        --erase|E     : remove (erase) rpm
a318 1
        --fullbsp     : used with -m release to copy additional content
a341 1
        "selectype"  => \$cf->{selectype},
a349 1
        "erase|E"    => \$cf->{erase},
a363 1
        "fullbsp"    => \$cf->{fullbsp},
d378 1
a378 1
    unless $cf->{mode} =~ m,^(buildrpms|addsrpms|clean|distclean|scbuild|scinstall|prep|patchmerge|scdeploy|listpkgs|release|config|shell|trelease|selectype),;
a421 7
# mode 'selectype' implies --selectype and --configure
$cf->{selectype} = 1 if $cf->{mode} eq 'selectype';
$cf->{configure} = 1 if $cf->{selectype};

# dltest implied noredir(ect)
$cf->{noredir} = 1 if $cf->{dltest};

d430 1
a430 1
foreach my $sig (qw/INT/) {
a432 1
$SIG{__DIE__} = \&die_handler;
a436 3
# remove possible CROSS_COMPILE prefix that could mess up spoofing
delete $ENV{CROSS_COMPILE};

d480 1
a480 1
        mk_fs_image($cf->{rpmroot}, "$cf->{rpmroot}.tmp",
d495 1
d501 1
a501 1
            unless `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -q $pkg` =~ m,^\Q$pkg\E,;
d503 2
a504 2
            if `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -q $pkg-devel` =~ m,^\Q$pkg\E,;
        my $cmd = "$cf->{sudo} $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -e --allmatches --define '_tmppath $cf->{tmppath}' $pkg";
d515 3
a517 2
    if(! $cf->{batch}) {
        print(<<TXT);
d522 2
a523 1
$cf->{rpmroot}
d526 5
a530 7
        print "To continue type in 'yes': ";
        local $_ = <STDIN>;
        print("aborted\n"), return 1 unless /^yes$/;
    }
    my $rpmdb = "$cf->{rpmroot}/$cf->{rpmdb}";
    die("no rpm database dir $rpmdb") unless -d $rpmdb;
    f_clean();
d533 1
a533 1
    my @@sav_list = qw/sn force rpmipfx rpmroot rpmdb tmppath/;
a539 5
    $cf->{rpmipfx} = $cf->{rpmroot};
    $cf->{rpmroot} = '/';
    $cf->{rpmdb}   = "$cf->{top}/cleanupdb";
    $cf->{tmppath} = $cf->{projtmp};
    mk_rpm_dirs();
a541 1
    system_nb("rm -rf $cf->{rpmdb} $cf->{tmppath}");
d547 1
d551 1
a551 1
$echo find config \\( -name .config -o -name .tmpconfig.h -o -name .config.old  -o -name .config.cmd \\) -exec rm {} \\;
d554 1
a554 1
$echo rm -rf $cf->{projtmp}
a555 2
$echo rm -rf $cf->{rpmroot}
$echo rm -rf $cf->{top}/rpmdb
d563 1
d574 1
a574 1
sub build_rpm
d576 6
a581 15
    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}|| '';
    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};
d583 1
a583 1
    my $msg = "\nProcessing: $sn\n";
d585 3
a587 1
    print $msg;
d589 2
a590 6
    my $spec = get_spec($sn);
    unless( $spec ) {
        $cf->{pkg_build_failures} .= "$sn ";
        warn("specfile not found\n");
        return;
    }
d592 46
a637 23
    my $tok = parse_spec($spec) or die();
    my @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*");
    my $pkgfail = 0;

    # build if force, no rpms or if the spec file was updated
    if(   $cf->{force}  || $cf->{download_only}
       || (exists $$key->{build} && $$key->{build})
       || $cf->{dltest} || ! @@rpms || -M $spec < -M $rpms[0]){

        # don't do this clause if running s short-circuited mode
        if( $unpack eq 'yes' )  {
            # commit to installing a new rpm (enforced if build fails)
            unlink(@@rpms) unless $cf->{dltest} || $cf->{download_only};

            foreach my $url (  split(/\s*\n/, $tok->{sources}),
                               split(/\s*\n/, $tok->{patches})   ) {
                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;
a638 4
                        warn("Can't get: $file");
                        return;
                    }
                    next if $cf->{dltest};
d640 2
a641 2
                    # needed if the lpp moves and links break
                    unlink($tgt);
d643 3
a645 2
                    symlink($src, $tgt)
                            or die("symlink $cf->{lpp}/$file, $tgt: $!");
d647 2
a648 3
            }
            return 1 if $cf->{download_only};
            return 1 if $cf->{dltest};
d650 3
a652 3
            # don't allow clobbering of existing builds
            if( -e "$cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}" ) {
                warn(<<TXT);
d655 1
a655 1
 $cf->{rpmdir}/BUILD/$tok->{pkg_dir_name}
d659 17
a675 6
                my $ret;
                if($cf->{mode} eq 'buildrpms') {
                    warn "scbuild/scdeploy already unpacked package\n";
                    $ret = f_scbuild($key) && f_scdeploy($key);
                } else {
                    $cf->{pkg_build_failures} .= "$sn ";
a676 1
                return $ret;
d678 11
a688 12
        }
        # 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 ';
        }
d690 23
a712 24
        # 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 '_mandir $cf->{prefix}/$cf->{mandir}' "
               . "--define '_sysconfdir $cf->{sysconfdir}' "
               . "--define '_localstatedir $cf->{localstatedir}' "
               . "$rpmopts $rpmclean $spec";
        print "$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;
d714 1
a714 3
    }
    # short circuited rpm modes don't install rpms
    return 1 if $rpmopts =~ m,--short-circuit,;
d716 38
a753 48
    # 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}/RPMS/$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}/RPMS/$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";
d755 2
a756 8
            # 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;
                }
a757 3

            # the install of this package may cause others to install
            process_pkg_triggers($key);
a759 26
    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} || $cf->{redirected};

    # remove any packages that are not in the build list
    remove_unselected_pkgs() unless $cf->{dltest};

    foreach my $key( mk_buildlist() ) {
       build_rpm(key => $key) or do {
           undef $ret;
           return unless $echo || $cf->{coe} || $cf->{dltest};
       };
    }
d766 5
a770 5
    my ($key) = @@_ or ();
    return build_rpm( key      => $key,
                      leavesrc => 1,
                      force    => 1,
                      rpmopts  => '-bp');
d775 6
a780 6
    my ($key) = @@_ or ();
    return build_rpm( key      => $key,
                      leavesrc => 1,
                      force    => 1,
                      unpack   => 'no',
                      rpmopts  => '-bc --short-circuit');
d785 6
a790 6
    my ($key) = @@_ or ();
    return build_rpm( key      => $key,
                      leavesrc => 1,
                      force    => 1,
                      unpack   => 'no',
                      rpmopts  => '-bi --short-circuit');
d796 4
a799 10
    my ($key) = @@_;
    my $sn;
    if($key) {
        $sn    = $$key->{sn};
        die("f_scdeploy: $key has no spec name set") unless $sn;
    } else {
        die("f_scdeploy: no spec name passed") unless $cf->{sn};
        $sn    = $cf->{sn};
        $key   = get_key_by_sn($sn);
    }
d804 2
a805 2
    # f_scbuild($key) or die();
    f_scinstall($key) or return;
d808 2
a809 1
    my $tok = parse_spec($spec, 1) or die();
a839 1
rm -rf \$RPM_BUILD_ROOT
d848 1
a848 3
    my $ret = build_rpm( key     => $key,
                         unpack  => 'no',
                         rpmopts => '-bb');
d855 18
a872 2
    require Ltibaddsrpms;
    return  addsrpms();
d891 2
a892 1
    my $tok = parse_spec($spec) or die();
d936 1
a936 1
$cf->{rpmbuild} --dbpath $cf->{rpmroot}/$cf->{rpmdb} --define '_target_cpu $pcf->{RPMTARCH}' --define '_topdir $cf->{rpmdir}' --define '_prefix $cf->{prefix}' --define '_tmppath $cf->{projtmp}' --define '_mandir $cf->{prefix}/$cf->{mandir}' --define '_sysconfdir $cf->{sysconfdir}' -bp $specout >/dev/null || exit 1
d1030 2
a1031 1
       $tok = parse_spec($spec) or die();
d1062 1
a1062 1
    return release_main(fullbsp => $cf->{fullbsp});
d1068 1
a1068 1
    return release_main(fullbsp => $cf->{fullbsp}, warnonly => 1);
d1080 1
a1080 1
    foreach $var (qw/rpmroot rpmdir rpmdb bin_path
d1154 2
a1155 2
    my @@sav_list = qw/rpmroot rpmipfx prefix sysconfdir rpmdir rpmdb tmppath
                      nodeps force hostinst reinstall dodrop preconfig/;
d1160 1
a1160 2
    $cf->{rpmroot}       = '/';                  # rpm (ch)root path
    $cf->{rpmipfx}       = '/';                  # install prefix
a1164 1
    $cf->{tmppath}       = $cf->{projtmp};
d1166 2
a1167 2
    $cf->{force}         = 0 if $allow_hostcf == 0;
    $cf->{hostinst}      = 1 if $allow_hostcf == 0;
d1207 1
a1207 1
    return 1 if -f $cf->{host_wait_warning} && ! $cf->{dltest};
a1259 2
    check_platform_config($pcf);
    setup_env_vars($cf, $pcf);
d1264 2
d1278 1
a1278 1
    my $qo = `$cf->{rpm} --root $cf->{rpmroot} --dbpath -q $cf->{rpmdb} bogus-package 2>&1`;
d1283 2
a1284 25
    # auto-migrate old rpmdb
    if(-e "$cf->{top}/rpmdb") {
        print "Updating to new rpm database placement, running a clean\n";
        my $sav = {};
        my @@sav_list   = qw/sn force rpmipfx rpmroot rpmdb tmppath/;
        foreach my $k (@@sav_list) {
            $sav->{$k} = $cf->{$k}
        }
        $cf->{rpmipfx} = $cf->{rpmroot};
        $cf->{rpmroot} = '/';
        $cf->{rpmdb}   = "$cf->{top}/rpmdb";
        $cf->{tmppath} = $cf->{projtmp};
        f_clean();
        pkg_cache_init();
        $cf->{sn}      = "mkdistclean.spec";
        $cf->{force}   = 1;
        mk_rpm_dirs();
        f_buildrpms() or die;
        f_clean();
        pkg_cache_init();
        system_nb("rm -rf $cf->{rpmdb}");
        foreach my $k (@@sav_list) {
            $cf->{$k} = $sav->{$k}
        }
    }
d1287 1
a1287 1
    mk_rpm_dirs();
d1320 3
d1330 8
d1349 1
a1349 1
    $ENV{DEV_IMAGE} = $cf->{rpmroot};
d1379 2
a1380 2
    $ENV{PKG_CONFIG_PATH} = "$cf->{rpmroot}/usr/lib/pkgconfig" || "";
    $ENV{PKG_DIRECTFB}    = $pcf->{PKG_DIRECTFB} || "";
d1419 2
a1420 3
        f_clean() if -d "$cf->{rpmroot}/$cf->{rpmdb}";
        my $oldarch = g2larch($ppcf->{LINTARCH});
        system_nb("rm -f $cf->{rpmdir}/RPMS/$oldarch/*");
d1423 1
a1423 1
    system_nb("cp -f $cf->{preconfig} $cf->{preconfig}.old") unless $cf->{dry};
a1517 7
    return unless exists $pcac->{mk_buildlist};

    # clear any pre-existing keys so package maps work on multiple runs
    foreach my $key (mk_buildlist()) {
        undef $$key
    }

d1544 1
a1544 1
    open(MAP, $map) or die("open($map): $!");
d1547 1
a1547 3
        next if m,^\s*$,;
        next if m,^\s*#,;
        m,$pre,o or warn("invalid token: $_"), next;
d1568 1
a1568 1
    $map = "$cf->{plat_dir}/$cf->{pkg_map}";
d1574 2
d1588 1
a1588 3
            return if m,^\s*$,;
            return if m,^\s*#,;
            m,$pre,o or warn("invalid token: $_"), return;
d1591 1
a1591 1
                read_pkg_map("$cf->{config_dir}/userspace/$2");
d1595 1
a1595 1
                warn("$key in $map is not selectable\n"), return
a1664 1
        # this is not nice as pcac should be private to mk_buildlist
d1699 3
a1701 1
    my $tok = parse_spec($spec, 0, 'name') or die();
d1711 1
a1711 1
    my @@installed = split(/[\s\n]+/, `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -qa --queryformat "%{name} "`);
d1751 2
a1752 5
        my $cmd =   "$cf->{sudo} $cf->{rpm} "
               . "--root $cf->{rpmroot} --dbpath $cf->{rpmdb} "
               . "-e --allmatches --nodeps "
               . "--define '_tmppath $cf->{tmppath}' "
               . "$rpmname";
d1786 1
a1786 1
       || $plat_specs ne $cf->{plat_dir} ) {
d1790 1
a1790 1
        $plat_specs  = $cf->{plat_dir};
d1807 1
a1807 1
            $specpath   = "$cf->{projtmp}/$spec";
a1809 2
            close(SPECIN);

a1816 1

a1819 10

            } elsif( -f $specpath ) {
                expand_spec("$specpath.new", $specinpath, $tmplpath);
                if( md5sum("$specpath.new") ne md5sum($specpath) ) {
                    unlink($specpath) or die("unlink $specpath : $!");
                    rename("$specpath.new", $specpath)
                             or die("rename $specpath.new, $specpath: $!");
                } else {
                    unlink("$specpath.new") or die("unlink $specpath.new : $!");
                }
d1902 1
a1902 1
                   GNUTARCH LINTARCH CFGHOST PLATFORM/) {
a1911 23
    # these are "special cases"
    $pcf->{GNUTARCH} = $cf->{buildarch} if $pcf->{GNUTARCH} eq "buildarch";
    $pcf->{LINTARCH} = g2larch($cf->{buildarch})
                                        if $pcf->{LINTARCH} eq "buildarch";
    $pcf->{CFGHOST} = "$cf->{buildarch}-linux"
                                        if $pcf->{CFGHOST} eq "buildarch";

    # RPM wants a value of ppc for powerpc platforms for its architecture
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH});

    $cf->{plat_dir} = "$cf->{platforms_dir}/$pcf->{PLATFORM}"
                                                    unless $cf->{plat_dir};
}

sub check_rpm_ipfx()
{
    # IMPORTANT: make sure users don't install in /
    my $ipath = $cf->{rpmroot};
    $ipath   .= $cf->{rpmipfx} if $cf->{rpmipfx};
    if($ipath =~ m,^\s*/+[^/]*\s*$, && $cf->{prefix} !~ m,/+[^/]+/+[^/]+,) {
        die "Install path cannot be set to '$ipath'\n",
            "rpmroot = $cf->{rpmroot}, rpmipfx = $cf->{rpmipfx}";
    }
d1916 1
a1916 2
    # check the install prefix is safe
    check_rpm_ipfx();
d1922 1
a1922 1
    mkdir -p $cf->{rpmdir}/\$i
d1924 1
a1924 1
for i in "$cf->{rpmroot}/$cf->{rpmdb}"
d1932 5
a1936 1
    # make sure rootfs is a directory and ipath has write permissions
d1938 3
a1940 1
    die "rpmroot: $cf->{rpmroot} is not a directory" unless -d $cf->{rpmroot};
d1944 1
a1944 1
        my $fstype = cmd_w_to(5, "df -PT $cf->{rpmroot}/$cf->{rpmdb} |tail -1") || "fake nfs";
d1954 5
a1958 1
Press <enter to continue>
d1961 1
d1967 1
a1967 10
    # otherwise rebuilt it if the target has run and altered it.  This
    # is needed as I think different endianesses store data differently
    # so a rpm database build on an x86 host is not readable on a ppc 
    # machine until you run rpm --rebuilddb, similarly once that's been
    # done you can no longer read it properly on an x86 machine
    my $do_rebuild = 1 unless -e "$cf->{rpmroot}/$cf->{tmppath}";
    system_nb("mkdir -p $cf->{rpmroot}/$cf->{tmppath}");
    system_nb("mkdir -p $cf->{projtmp}");

    if(! -e "$cf->{rpmroot}/$cf->{rpmdb}/Packages") {
d1970 1
a1970 6
$cf->{sudo} $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --initdb
TXT
    } elsif($do_rebuild) {
        system_nb(<<TXT) == 0 or die;
set -e
$cf->{sudo} $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --define '_tmppath $cf->{tmppath}' --rebuilddb
a1990 1
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH});
d1995 2
a1996 3
    my @@sav_list = qw/rpmroot rpmipfx nodeps sn force reinstall
                      dodrop ldirs prefix sysconfdir rpmbuild 
                      rpm rpmdir rpmdb lpp tmppath sudo plat_dir/;
d1998 1
a1998 2
    $cf->{rpmroot}       = '/';
    $cf->{rpmipfx}       = "";
d2011 1
a2011 2
    $cf->{tmppath}       = $cf->{projtmp};
    $cf->{plat_dir}      = "$cf->{platforms_dir}/$pcf->{PLATFORM}";
d2018 1
a2018 3
    $cf->{sudo}   = "";
    mk_rpm_dirs();
    $cf->{sudo}   = $sav->{sudo};
d2021 1
a2021 1
    my @@rpms = glob("$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$cf->{sn}-*");
d2023 2
a2024 4
                        . "$cf->{rpmdir}/RPMS/$pcf->{RPMTARCH}/$cf->{sn}-*";
    my $cmd  = "$cf->{sudo} $sav->{rpm} ";
       $cmd .= "--root $cf->{rpmroot} ";
       $cmd .= "--dbpath $cf->{defpfx}/var/lib/rpm ";
d2032 1
a2032 1
    system_nb("rm -f $cf->{defpfx}/usr/src/rpm/RPMS/$pcf->{RPMTARCH}/*");
d2123 1
a2123 4
    if($cf->{buildarch} =~ m,^ppc,) {
        $tcname =~ s,i\d86,ppc,;
        $tcname =~ s,-x86,-ppc,;
    }
d2130 1
d2137 1
a2137 1
        my $tc_rpm = tc_name($pcf->{TOOLCHAIN});
d2224 1
a2224 1
# it will scribble over the host's installation.  For this
d2236 1
a2236 1
    $inst_pfx = "$cf->{rpmroot}/$cf->{rpmipfx}";
d2239 1
a2239 1
    # if a relocatable package, and we are installing in our project area
d2241 2
a2242 3
    my $rootfs = "$cf->{top}/rootfs";
    $len = length($rootfs);
    if($pkg_prefix && unpack("A$len", $inst_pfx) eq $rootfs) {
d2252 1
a2252 1
    open(CMD, "$cmd |") or die("can't fork $cmd: $!");
d2260 1
a2260 1
            die("ERROR: $rpm\nwould clobber '$path'\n");
a2262 1
    close CMD;
a2297 7
    my $sig = shift;
    warn("killed by SIG$sig\n");
    bad_exit_handler();
}

sub die_handler
{
a2298 6
    warn("traceback:\n", caller_stack(1), "\n");
    bad_exit_handler();
}

sub bad_exit_handler
{
a2312 1
    my $PLATFORM = $pcf->{PLATFORM} || 'host';
d2318 2
d2322 1
a2322 1
    if [ -f ${PLATFORM}.config ]
d2324 1
a2324 1
        cp ${PLATFORM}.config .config
d2335 1
a2335 1
    cp .config ${PLATFORM}.config
d2351 1
a2351 4
    my $cf_plat = {};
    my ($plat_dir, $atime, $mtime, $pcf, $pcfname, $kconfig);
    $kconfig = "main.lkc";
    $pcfname = "defconfig";
a2357 1
        $cf->{plat_dir} = $plat_dir;
d2361 1
a2361 2
            if(   ! -e "$plat_dir/defconfig"
               ||   -M "$plat_dir/.config" <= -M "$plat_dir/defconfig") {
a2390 1
        $cf->{plat_dir} = $plat_dir;
a2421 49

        # set the platform directory
        $plat_dir = $cf_main->{PLATFORM_DIR};
        $cf->{plat_dir} = $plat_dir;

        # If there is a preconfigs.lkc file and user passes --selectype
        # or there is no .config file at all run mconf
        if(     -f "$plat_dir/preconfigs.lkc"
           && ($cf->{selectype} || ! -f "$cf->{config_dir}/.config") ) {
        system_nb(<<TXT) == 0 or die;
set -ex
cd $cf->{config_dir}
$cf->{conf} ../$plat_dir/preconfigs.lkc
cd -
TXT
        }
    }

    if($cf->{preconfig}) {
        # user provided preconfigs override anything else
        unlink("$plat_dir/.config");

    } elsif(-f "$plat_dir/preconfigs.lkc" && "$cf->{config_dir}/.config") {
        # For platforms with preconfigs.lkc, the $kconfig lets us change
        # the kconfig file use for configuration of the platform
        $cf_plat   = parse_dotconfig("$cf->{config_dir}/.config");
        $kconfig   = $cf_plat->{PCF_KCONFIG}   if $cf_plat->{PCF_KCONFIG};
        if($cf_plat->{PCF_PRECONFIG}) {
            $pcfname         = $cf_plat->{PCF_PRECONFIG};
            $cf->{preconfig} = "$plat_dir/$pcfname";
        }
        # If the platform has not been configured or the a new preconfig
        # has been selected (selectype) the remove the current platform
        # .config, this triggers a copy of the selected preconfig to
        # the platforms .config
        if(    ! -f "$plat_dir/.config"
            || (-M "$cf->{config_dir}/.config" < -M "$plat_dir/.config") ){
            unlink("$plat_dir/.config");
            if($cf_plat->{PCF_PROFILE}) {
                foreach my $dir ($plat_dir, "$cf->{config_dir}/profile",
                                                                 $cf->{top}){
                    my $path = "$dir/$cf_plat->{PCF_PROFILE}";
                    if(-f $path) {
                        $cf->{profile} = $path;
                        last;
                    }
                }
            }
        }
d2425 1
a2425 1
    die "No platform directory set" unless $plat_dir;
d2430 1
a2430 2
    if(($cf->{selectype} || $cf->{preconfig} || $cf->{profile})
        && -f $oldconfig ) {
d2437 1
a2437 1
if [ -n "$cf->{preconfig}" -a ! -f "$plat_dir/.config" ]
d2439 5
a2443 5
    cp $cf->{preconfig} $plat_dir/.config
    if [ -f "$cf->{config_dir}/.config" ]
    then
        cat $cf->{config_dir}/.config | perl -ne 'print if m,^CONFIG_(?!PCF),' >> $plat_dir/.config
    fi
d2451 1
a2451 1
$cf->{conf} $kconfig
a2453 1
    # we probably changed it, so now this becomes the new user selection
d2460 1
a2460 1
    $cf->{mode} =~ m,(?:config|selectype), ? exit 0 : return 1;
d2486 1
a2486 1
    open(MCF, ">$cf->{mainlkc}") or die "open $cf->{mainlkc} : $!";
a2534 1
    check_rpm_ipfx();    
a2537 1

d2540 1
a2540 7
alias rpm="$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb}"
alias rpme="sudo $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --define '_tmppath $cf->{tmppath}' -e "
alias rpmi="sudo $cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} --prefix $cf->{rpmipfx} --ignorearch -ivh  --define '_tmppath $cf->{tmppath}' "
alias rpm-host="$cf->{rpm}"
alias rpme-host="sudo $cf->{rpm} --dbpath $cf->{defpfx}/var/lib/rpm -e "
# seh: I've remove the rpm aliases for rpmi-host as it's too dangerous
#      without running the check_host_clobber test first
a2610 19

sub rpm_needs_update
{
    my ($tok) = @@_;
    # In this case we're installing the host support package (clean install).
    # The policy here is that packages should only be upgraded (never down).
    # The idea is to prevent the install of an old BSP downgrading a
    # host support package.  The added wrinkle is that in cases where
    # the normal version comparision fails (e.g dtc version went
    # from 20070307 to 1.0.0) needs to be taken care of as exceptions
    # for now it's been left.
    my ($ver) = `$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -q --queryformat %{VERSION}.%{RELEASE} $tok->{name} 2>&1`;
    return 1 if $ver =~  m,is not installed,;
    warn   "installed version=$ver, "
         . "new version = $tok->{version}.$tok->{release}\n" if $verbose;
    my $ret = cmp_ver("$tok->{version}.$tok->{release}", $ver);
    warn "ret = $ret\n" if $verbose;
    return ($ret > 0) ? 1 : 0;
}
@


1.1.1.16
log
@Import from fsl 20081205
@
text
@d53 1
a53 1
    bldbase      => $top,
a107 1
            tcl             0       # needed by git for internal work
d109 2
a110 4
    frb_deps      => "PLATFORM GNUTARCH LINTARCH CFGHOST TOOLCHAIN
                      TOOLCHAIN_CFLAGS DISTRO PKG_UCLIBC PKG_GLIBC
                      LIBC_HACKING",
    app_version  => "8.4.1",
a114 1
    plat_dir     => "",
d122 1
d124 1
a124 1
    host_wait_warning => "$top/.host_wait_warning27",  # update .ltibrc now!
a138 4
    enrootn      => 1,
    oneroot      => 0,
    root_cf      => "$top/.root_cf",
    lock_file    => "$top/.lock_file",
a150 1
    buildranlib  => "/usr/bin/ranlib",
a159 1
    upreconfig   => "",
a175 1
    no_deploy    => 0,
a178 1
    leavesrc     => 0,
a181 1
    no_sudo_check => 0,  # fc9 work-around
d190 4
a194 1
# re-build the key (lhs) if any of the dependents (rhs) in the list have changed
a209 2
           PKG_DIRECTFB => [ qw/PKG_DIRECTFB_WANT_TS/ ],
           PKG_DTC      => [ qw/PKG_DTC_WANT_FDT/ ],
a213 1
           PKG_OPENSSH  => [ qw/PKG_OPENSSH_WANT_HACKABLE_KEYS/ ],
a237 1
                          SYSCFG_START_UDEV SYSCFG_START_MDEV
d240 3
a242 2
                          SYSCFG_START_WATCHDOG SYSCFG_START_SSHD
                          SYSCFG_START_SAMBA SYSCFG_SMBD_ARGS SYSCFG_NMBD_ARGS/ ],
d248 1
d252 1
a252 7
# 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/ ]
              };
a254 1
# re-install all the pkgs in the list (rhs) if the key (lhs) has been installed
d280 2
a281 1
root filesystems.
d283 2
a284 4
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.
a299 1
            listpkgcsv  list packages in a format for import into spreadsheet
a304 2
            addsrpms    import srpms into ltib (semi-automatic)
        --rootn|R     : Root context number (0 is the primary and implicit)
a325 1
        --no-deploy   : disabled deployment (even with -p <pkg>
a329 2
        --sticky      : Make the selected root number sticky
        --no-sticky   : Remove root stickiness
a331 1
        --ignorelock  : use if you really want to ignore any locks (careful!)
a332 1
        --no-sudo     : don't check sudo, work around for broken sudo (fc9)
d351 1
a351 1
Getopt::Long::Configure("no_ignore_case", "bundling");
a353 1
        "rootn|R:i"  => \$cf->{rootn},
d357 1
a357 1
        "preconfig:s"=> \$cf->{upreconfig},
a372 1
        "no-deploy"  => \$cf->{no_deploy},
a377 1
        "sticky!"    => \$cf->{sticky},
a379 1
        "ignorelock" => \$cf->{ignorelock},
a380 1
        "no-sudo"    => \$cf->{no_sudo_check},
d419 2
a420 2
if($cf->{upreconfig} && ! -e $cf->{upreconfig}) {
    die "preconfig file: $cf->{upreconfig} does not exist\n";
a434 1
$cf->{conf} = $cf->{batch} ? "yes '' | conf" : "mconf";
a441 3
if($cf->{selectype} && ($cf->{upreconfig} || $cf->{profile}) ) {
    die "selectype can't be used with preconfig and/or profiles\n";
}
a445 16
# 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;
}
a449 3
# make sure the root prefix for rpm is never set to / by the user
$cf->{rpmroot} = $cf->{rfsbase} = "$cf->{bldbase}/rootfs";

d469 6
a474 4
# do distclean before other modes to prevent re-installing parts
if($cf->{mode} eq 'distclean') {
    f_distclean() or die;
    exit(0);
d485 2
a486 8
# get/set the platorm 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;
d488 2
a489 2
    # do setup before target building
    pre_build_checks();
d491 2
a492 2
    # run the requested mode
    &{"f_" . $cf->{mode}}()
d495 2
a496 29
    # 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;
d498 13
a510 3
    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;
d527 5
a531 11
        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";
d540 1
a540 1
sub remove_rfsbase
d542 4
a545 2
    die("Request to remove too filesystem denied, expected .../rootfs")
                                           unless $cf->{rfsbase} =~ m,rootfs$,;
d547 2
a548 1
    print("Removing target root filesystem\n");
d550 8
a557 11
    # 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});
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH});
    $pcf->{CFGHOST}  = "$cf->{buildarch}-linux";
    my $di = $ENV{DEV_IMAGE} || '';
d560 1
a560 1
    my @@sav_list = qw/sn force rpmipfx rpmroot rpmdb tmppath enrootn/;
d567 1
a567 1
    $ENV{DEV_IMAGE} = $cf->{rpmipfx} = $cf->{rfsbase};
d569 1
a569 1
    $cf->{rpmdb}   = "$cf->{bldbase}/cleanupdb";
d571 3
a573 5
    $cf->{enrootn} = 0;
    setup_rpmdb();

    build_rpm() or die;
    f_clean() or die;
a578 10
    $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:
d580 1
a580 11
$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);
d583 1
a583 1
$echo find config \\( -name .config\\* -o -name .tmpconfig.h \\) -exec rm {} \\;
d588 1
a588 1
$echo rm -rf $cf->{rfsbase}
d595 1
a595 1
$echo rm -f $cf->{logfile} $cf->{lock_file} $cf->{root_cf}
d597 1
a597 1
$echo rm -f .host_wait_warning* .tc_test_*
d602 1
a602 1
$echo for i in faked fakeroot mkimage gdb tmake .gdbinit mpc.init netperf netserver; do rm -rf $cf->{top}/bin/\$i ; done
d618 1
a618 1
    my $leavesrc   = $args->{leavesrc}|| $cf->{leavesrc};
d630 1
a630 3
    die("can't find spec file for $sn\n") unless $spec && -e $spec;

    unless( $spec && -e $spec ) {
d641 3
a643 9
    my $r = '';
    $r   .= "force set, "                if $cf->{force};
    $r   .= "build key set, "            if $$key->{build};
    $r   .= "dltest mode, "              if $cf->{dltest};
    $r   .= "no prebuilt rpm, "          if ! @@rpms;
    $r   .= "spec file newer than rpm, " if @@rpms && (-M $spec < -M $rpms[0])
                                                  && ! $cf->{hostinst};
    if($r) {
        warn("Build path taken because: $r\n\n");
d645 1
a645 1
        # don't do this clause if running in short-circuited mode
d648 1
a648 2
            unlink(@@rpms) unless $cf->{dltest} || $cf->{download_only}
                                               || $cf->{dry};
d659 1
a659 4
                        if($cf->{dltest}) {
                            push @@{$cf->{dlfails}{$sn}}, $url;
                            next;
                        }
d685 1
a685 1
                if($cf->{hostinst} == 0 && $cf->{mode} eq 'buildrpms') {
d784 1
a784 1
            # in dry-run mode (echo), don't actually install
d813 1
a813 1
    print "using $cf->{preconfig}\n" if $cf->{preconfig};
a817 5
    # process the package dependencies
    foreach my $key ( mk_buildlist()  ) {
        process_pkg_deps($key, $$key->{sn}) if $$key->{en};
    }

d877 1
a877 1
    my $spec = get_spec($sn) or die("can't find spec file for $sn");
d916 1
a916 1
    get_spec($sn, 'del') or die("can't find spec file for $sn");
d945 1
a945 2
    my ($specout, $specin) = get_spec($cf->{sn})
                                   or die("can't find spec file for $cf->{sn}");
d1027 1
a1027 1
    return f_listpkgs('eula');
a1028 1

d1033 1
a1033 2

sub f_listpkgscsv
d1035 42
a1076 2
    return f_listpkgs('csv');
}
d1078 11
a1088 5
sub f_listpkgs
{
    my $mode = shift || '';
    require Ltiblistpkgs;
    return listpkgs($mode);
a1096 2
    my $gv   = -d "$cf->{top}/.git" ? `setlocalversion` : 'none';

a1107 1
git version  = $gv
d1134 1
a1134 1
    foreach $var (qw/rfsbase rpmdir rpmdb bin_path
d1137 1
a1137 1
                     top home username path_std
d1184 4
a1187 5
            my $hr = parse_config(fn => $rc) or die;
            $hr->{rcfile} = $rc;
            while( my($k,$v) = each(%$hr) ) {
                $cf->{$k} = $v;
            }
d1204 1
a1204 1
    my ($host_pkg_dev) = @@_;
d1209 1
a1209 2
                      nodeps force hostinst reinstall dodrop sn
                      preconfig enrootn something_got_built plat_dir/;
d1222 2
a1223 2
    $cf->{force}         = 0 if $host_pkg_dev == 0;
    $cf->{hostinst}      = 1 if $host_pkg_dev == 0;
a1224 2
    $cf->{enrootn}       = 0;
    $cf->{plat_dir}      = "config/platform/host";
d1227 1
a1227 1
    if($host_pkg_dev == 1) {
a1234 1
        $cf->{sn} = '';
d1263 1
a1263 1
    return 1 if -f $cf->{host_wait_warning} && (! $cf->{dltest} || $cf->{sn});
d1270 1
a1270 1
    check_sudo_setup() unless $cf->{no_sudo_check};
a1316 1
    setup_rpmdb();
d1318 51
a1368 2
    process_full_rebuild();
    legacy_rpm_fixups();
d1370 2
d1373 2
d1376 2
d1380 19
a1424 1
    $ENV{BUILDRANLIB} = $cf->{buildranlib};
d1435 1
a1435 1
    $ENV{PLATFORM_PATH} = "$cf->{top}/$cf->{plat_dir}";
a1448 18
    $ENV{LTIB_BATCH}      = $cf->{batch} || "";
    $ENV{PKG_BUSYBOX}    = $pcf->{PKG_BUSYBOX} || "";
    $ENV{PKG_SYSVINIT}    = $pcf->{PKG_SYSVINIT} || "";
    $ENV{INITTAB_LINE}    = $pcf->{INITTAB_LINE} || "";

    if($cf->{enrootn}) {
        $ENV{DISTCC_HOSTS} = $cf->{DISTCC_HOSTS}
                       if ! defined $ENV{DISTCC_HOSTS} && $cf->{DISTCC_HOSTS};
        $ENV{DISTCC_TCP_CORK} = $cf->{DISTCC_TCP_CORK}
         if ! defined $ENV{DISTCC_TCP_CORK} && defined $cf->{DISTCC_TCP_CORK};
    	$ENV{MAKEFLAGS} = $cf->{MAKEFLAGS}
                             if ! defined $ENV{MAKEFLAGS} && $cf->{MAKEFLAGS};
        if(! defined $ENV{CCACHE_DIR} && $cf->{CCACHE_DIR}) {
            # For this variable, interpolate 
            $cf->{CCACHE_DIR} =~ s,\$([\w]+),$cf->{$1},g;
            $ENV{CCACHE_DIR} = $cf->{CCACHE_DIR}; 
        }
    }
d1452 1
a1452 1
                          BUILDARCH BUILDRANLIB GNUTARCH LINTARCH CFGHOST
d1461 3
a1463 6
        if($pcf->{$k}) {
            warn("setting ENV{$k}=$pcf->{$k}\n") if $verbose;
            $ENV{$k} = $pcf->{$k};
        } else {
            delete $ENV{$k};
        }
d1470 1
a1470 15
    # lock ltib
    if(! try_lock_file($cf->{lock_file}, $$) ) {
        warn("$cf->{lock_file} locked\n");
        die unless $cf->{ignorelock};
    }

    # process any toolchain switch
    save_binary_rpms();

    return 1 unless -f "$cf->{preconfig}.old";

    $ppcf = parse_dotconfig("$cf->{preconfig}.old");
    if(-M "$cf->{preconfig}.old" <= -M $cf->{preconfig}) {
        return 1;
    }
d1477 1
a1477 1
    foreach my $dep (split(/[\s\n]+/,$cf->{frb_deps})) {
d1482 1
a1482 1
            print("CONFIG_$dep forced a full rebuild\n");
d1486 4
a1489 2
    if($need_frb && ! $cf->{dry}) {
        f_clean() if -e "$cf->{rpmroot}/$cf->{rpmdb}/Name";
a1495 94
sub save_binary_rpms
{
    die("pcf  not defined") unless $pcf;

    my $newarch = g2larch($pcf->{LINTARCH});
    my $cfn     = '.config';
    my $dir     = "$cf->{rpmdir}/RPMS";
    my $nset    = gen_build_setup($pcf);
    my $ts      = "$cf->{stime}.00";
    my $oset    = '';
    my $oldarch;

    # figure out if there has been a change that invalidates the current rpms
    if(-f "$dir/$cfn") {
        my $lcf  = parse_dotconfig("$dir/$cfn");
        $oldarch = g2larch($lcf->{LINTARCH});
        local $/ = undef;
        open(F, "$dir/$cfn") or die("open $dir/$cfn : $!");
        $oset = <F> || '';
        close F;
    } else {
        # fresh install or legacy updated project, assume okay
        $oset = $nset;
    }
    write_file("$dir/$cfn", $nset);

    return 1 if $oset eq $nset;

    die("old LINTARCH not defined in $dir/$cfn") unless $oldarch;

    print "Flushing old rpm set\n";

    # This is used to signal u-boot/kernel to do distcleans as their
    # sources are commonly left unpacked.  The only alternative is
    # to deny continuing unpacked builds (clobber).
    $ENV{LTIB_FULL_REBUILD} = 'y';

    # we need to switch to a new set of rpms (or remove)
    if($pcf->{FEAT_CACHE_RPMS} || ! defined($pcf->{FEAT_CACHE_RPMS}) ) {
        if(glob("$dir/$oldarch/*.rpm")) {
            if(! -f "$dir/$oldarch/$cfn") {
                write_file("$dir/$oldarch/$cfn", $oset);
            }
            while(-d "$dir/$ts") { $ts += 0.01; }
            print("Saving rpms from $oldarch to $dir/$ts\n");
            rename("$dir/$oldarch", "$dir/$ts")
                       or die("rename $dir/$oldarch", "$dir/$ts : $!");
        } else {
            print "No binary rpms to save\n";
            system_nb("rm -rf $dir/$oldarch") if -e "$dir/$oldarch";
        }

        # look for an existing set of binary rpms matching the new settings
        opendir(DIR, $dir) or die("opendir: $dir: $!");
        while( defined(my $ent = readdir(DIR)) ) {
            next unless -d "$dir/$ent";
            next if $ent eq '.' || $ent eq '..' || $ent eq $newarch;
            next unless -f "$dir/$ent/$cfn";
            system_nb("rm -rf $dir/$ent"), next
                                             unless glob("$dir/$ent/*.rpm");
            local $/ = undef;
            open(F, "$dir/$ent/$cfn") or die("open $dir/$ent/$cfn : $!");
            my $ck = <F> || '';
            close F;
            if($ck eq $nset) {
                print "Using cached pre-built packages for $pcf->{PLATFORM} ",
                      "from rpm/$ent\n";
                die "$dir/$newarch already exists" if -d "$dir/$newarch";
                rename("$dir/$ent", "$dir/$newarch")
                     or die "rename: $dir/$ent, $dir/$newarch : $!";
                last;
            }
        }
        closedir DIR;
        mkdir("$dir/$newarch", 0755);
        write_file("$dir/$newarch/$cfn", $nset);

    } else {
        print "Removing binary rpms\n";
        system_nb("rm -f $dir/$oldarch");
    }
    return 1;
}

sub gen_build_setup
{
    my $hr = shift or die;
    my $buf = '';
    foreach my $k (split(/[\s\n]+/, $cf->{frb_deps})) {
        $buf .= "CONFIG_$k=" . ($hr->{$k} || '') . "\n";
    }
    return $buf;
}

a1531 9
    if($key eq 'PKG_KERNEL') {
        foreach my $mod ( grep { m,PKG_[\w_]+_MOD$, } mk_buildlist() ){
            if(exists $$mod->{was_en} && $$mod->{was_en}) {
                $$mod->{en} = 1;
            }
            $$mod->{build} = 1;
            warn "$$mod->{sn} rebuild forced by $$key->{sn}\n" if $$mod->{en};
        }
    }
d1619 1
a1619 1
    my $map = "$cf->{config_dir}/userspace/pkg_map";
d1627 1
a1627 1
        $pcf->{$key} ||= '';
a1638 1
        $cf->{pkg_map}{$2} = $$key->{en};
d1646 1
a1646 1
    $map = "$cf->{plat_dir}/pkg_map";
d1672 4
a1675 12
            if(! exists $$key->{sn}) {
                if(! exists $pcf->{$key}) {
                    warn("$key in $map is not selectable\n") if $verbose;
                    $pcf->{$key} = '';
                }
                # insert packages not in the main pkg_map before
                # merge and modep
                # For a minimal system (lwe) it may not have these
                my $pos = defined($pcf->{PKG_MODEPS})
                                                   + defined($pcf->{PKG_MERGE});
                $pos = $pos ? -$pos : $#{$pcac->{mk_buildlist}}+1;
                splice(@@{$pcac->{mk_buildlist}}, $pos, 0, $key);
a1677 1
            $cf->{pkg_map}{$2} = $$key->{en};
a1678 2
            warn "mk_buildlist (plat/pkg_map): key=$key, sn=$$key->{sn}, en=$$key->{en}\n"
                                                            if $verbose;
a1689 1
        # bug alert: this is a one-shot, you can't later run pkg_cache_init
d1706 2
a1707 1
If necessary please give the whole spec file name (with the .spec extension).
d1715 5
d1788 1
a1788 5
    my $cmd = "$cf->{rpm} --root $cf->{rpmroot} --dbpath $cf->{rpmdb} -qa "
            . "--queryformat '%{name} '";
    $_ = qx($cmd);
    die $cmd if $?;
    my @@installed = split(/[\s\n]+/);
d1791 3
a1793 1
    my ($key, $pkg);
d1795 1
a1795 1
    mk_buildlist();
d1797 15
a1811 10
        if(exists($cf->{pkg_map}{$inst}) && ! $cf->{pkg_map}{$inst}) {
            push(@@drop_list, $inst);

            # check to see if this package has any reverse triggers
            foreach $key ( get_rev_triggers() ) {
                $pkg = get_pkg_name($key) or next;
                if( $inst eq $pkg ) {
                    $pkg2key->{$inst} = $key;
                    last;
                }
d1876 1
a1876 1
    if(exists $cache->{$sn} && -e $cache->{$sn}) {
d1900 2
a1901 2
            my @@dlist = sort { -M $a <=> -M $b } ($specinpath, $tmplpath);
            if(! -f $specpath  || (-M $dlist[0] < -M $specpath) ) {
d1903 1
a1903 2
                my ($atime, $mtime) = (stat($dlist[0]))[8,9];
                utime($atime, $mtime, $specpath);
d1921 1
a1921 1
    delete $cache->{$sn};
d1923 1
a1923 1
    my $msg = <<TXT;
d1933 1
a1933 2
    $msg .= "    $defdist\n" if $defdist ne $pcf_distro;
    warn $msg if $verbose;
d1976 2
a1977 4
ltib cannot be run because one or more of the host packages needed to run it
are either missing or out of date or not in ltib's standard path.  Please
install/upgrade these packages on your host.  If you have your own utilities
in non-standard paths, please add an entry into the .ltibrc file for example:
d1979 1
a1979 2
%path_std
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/my/own/exes
a1984 1
    print "\n";
a2013 11
}

sub legacy_rpm_fixups
{
    # this is to catch mangled databases before we had a known rpm
    # once this has rippled through all users it could come out
    die "$cf->{rpm} has gone missing" unless -f $cf->{rpm};
    my $qo = `$cf->{rpm} --root $cf->{rpmroot} --dbpath -q $cf->{rpmdb} bogus-package 2>&1`;
    if($qo =~ m,unsupported hash version:,m) {
        system_nb("rm -rf $cf->{rpmdb}/*") == 0 or die;
    }
d2015 2
a2016 26
    # auto-migrate old rpmdb
    if(-e "$cf->{top}/rpmdb") {
        print "Updating to new rpm database placement, running a clean\n";
        my $sav = {};
        my @@sav_list   = qw/sn force rpmipfx rpmroot rpmdb tmppath enrootn/;
        foreach my $k (@@sav_list) {
            $sav->{$k} = $cf->{$k}
        }
        $cf->{rpmipfx} = $cf->{rpmroot};
        $cf->{rpmroot} = '/';
        $cf->{rpmdb}   = "$cf->{top}/rpmdb";
        $cf->{tmppath} = $cf->{projtmp};
        $cf->{enrootn} = 0;
        f_clean();
        pkg_cache_init();
        $cf->{sn}      = "mkdistclean.spec";
        $cf->{force}   = 1;
        f_buildrpms() or die;
        f_clean();
        pkg_cache_init();
        system_nb("rm -rf $cf->{rpmdb}");
        foreach my $k (@@sav_list) {
            $cf->{$k} = $sav->{$k}
        }
    }
    return 1;
a2021 5
    # Note:      rpmipfx is not set, this indicate a non-relocatable install
    #            even in this case the prefix must be at least /a/b/c
    #            for example: /opt/freescale/pkgs or /opt/ltib/pkgs

    die  "rpmroot undefined" if ! $cf->{rpmroot};
d2024 2
a2025 3
    if($ipath =~ m,^\s*/+[^/]*/*\s*$, && $cf->{prefix} !~ m,^/+[^/]+/+[^/]+,) {
        die "Install path cannot be set to '$ipath' ",
            "with prefix: '$cf->{prefix}'\n",
d2030 1
a2030 1
sub setup_rpmdb
a2031 5
    if($cf->{enrootn}) {
        $cf->{rpmroot}  = $cf->{rfsbase};
        $cf->{rpmroot} .= "/R$cf->{rootn}" if $cf->{rootn};
    }

a2048 1

d2050 1
a2050 1
    # by the real user id unless in host/clean mode
a2051 2
    die "rpmroot: $cf->{rpmroot} is not writable by $cf->{username}"
                              if ! -w $cf->{rpmroot} && $cf->{rpmroot} ne '/';
d2075 1
a2075 1
    # so a rpm database build on an x86 host is not readable on a ppc
d2117 2
a2118 2
                      dodrop ldirs prefix sysconfdir rpmbuild
                      rpm rpmdir rpmdb lpp tmppath sudo enrootn/;
a2119 1
    pkg_cache_init();
d2123 1
d2135 1
a2135 1
    $cf->{enrootn}       = 0;
d2143 1
a2143 1
    setup_rpmdb();
d2145 1
a2145 1
    f_buildrpms();
d2181 3
a2183 4
    my $bre = '(?:\(root\)|\(ALL\))\s+(?:ROLE=\s+)?NOPASSWD:';
    my $hostrpm_ok = $s =~ /$bre.*[\s,]$hostrpm/m;
    my $fsrpm_ok   = $s =~ /$bre.*[\s,]$cf->{rpm}/m;
    my $all_ok     = $s =~ /$bre\s+ALL/m,;
d2265 1
a2265 1
    # note: deal with x86-isms in a crude way (subst)
a2334 16
    # If we just installed a toolchain, check that we can compile something
    if($pcf->{TOOLCHAIN} && ! -f ".tc_test_$pcf->{TOOLCHAIN}") {
        my $cmd = <<TXT;
echo '#include <stdio.h>
int main() { printf("hello world"); }' | $gcc_path -x c - -c -o /dev/null
TXT

        die(<<TXT) if system_nb($cmd) != 0;

Error $gcc_path can't compile a simple hello world test program:

$cmd

TXT
        touch(".tc_test_$pcf->{TOOLCHAIN}");
    }
d2341 1
a2341 5
    my $spec = get_spec("merge");
    if( ! -w "$cf->{rfsbase}/etc/ltib-release") {
        touch($spec);
        return 1;
    }
d2344 1
d2390 1
a2390 1
        if( $path !~ m,^(?:/opt|/tmp|/home|$cf->{rfsbase}), ) {
d2414 10
a2423 20
    if( $cf->{normal_exit} ) {
        print "Build Succeeded\n\n";
        return 1;
    }
    if( $cf->{pkg_build_failures}) {
        if($cf->{dltest}) {
            print "These packages would not have complete downloads ",
                                                                "available:\n";
            foreach my $sn (split(/\s+/, $cf->{pkg_build_failures})) {
                print "$sn:\n";
                foreach my $fn (@@{$cf->{dlfails}{$sn}}) {
                    print "    $fn\n";
                }
            }
        } else {
            print "These packages failed to build:\n",
                  "$cf->{pkg_build_failures}\n";
        }
    }
    print "\nBuild Failed\n\n";
d2425 1
d2455 2
d2475 1
a2475 1
    $cf->{conf} main.lkc
d2490 9
a2498 5
    my $plat_dir = $cf->{plat_dir};
    my $kconfig  = "main.lkc";
    my $rootn    = $cf->{rootn} || '';
    my $plat_cf  = "$plat_dir/.config$rootn";
    my $conf_cf  = "$cf->{config_dir}/.config$rootn";
d2501 7
a2507 3
    if(   ! $cf->{configure} && ! $cf->{upreconfig} && ! $cf->{profile}
       && ! $cf->{selectype} && -f "$cf->{top}/.config" ) {
        if(-f $plat_cf) {
d2509 3
a2511 3
            if(   ! -e "$plat_dir/defconfig$rootn"
               ||   -M $plat_cf <= -M "$plat_dir/defconfig$rootn") {
                $cf->{preconfig} = $plat_cf;
d2519 3
a2521 3
            warn("Using updated $plat_dir/defconfig$rootn\n");
            rename($plat_cf, "$plat_cf.$cf->{stime}") if -f $plat_cf;
            system_nb("cp $plat_dir/defconfig$rootn $plat_cf") == 0 or die;
d2523 5
d2534 48
a2581 5
    if(    -f "$plat_dir/preconfigs.lkc"
       && ($cf->{selectype}
            || (! -f $plat_cf && ! -f $conf_cf && ! $cf->{upreconfig})) ) {
        do {
            system_nb(<<TXT) == 0 or die;
d2584 1
a2584 1
$cf->{conf} ../$plat_dir/preconfigs.lkc $conf_cf
d2587 1
a2587 1
        } while(! -f $conf_cf);
d2589 21
a2609 8
    if(-f $conf_cf) {
        my $cf_plat = parse_dotconfig($conf_cf);
        $kconfig    = $cf_plat->{PCF_KCONFIG} if $cf_plat->{PCF_KCONFIG};

        # something changed in selectype or never copied
        if(! -f $plat_cf || (-M $conf_cf < -M $plat_cf) ) {
            $cf->{upreconfig} = "$plat_dir/$cf_plat->{PCF_PRECONFIG}"
                                                 if $cf_plat->{PCF_PRECONFIG};
a2621 7
    return run_plat_config($plat_dir, $kconfig);
}

sub run_plat_config
{
    my ($plat_dir, $kconfig) = @@_;
    my ($atime, $mtime);
d2624 1
a2624 6
    die "No platform directory set" unless $plat_dir && -d $plat_dir;

    my $rootn   = $cf->{rootn} || '';
    my $plat_cf = "$plat_dir/.config$rootn";
    my $pdef_cf = "$plat_dir/defconfig$rootn";
    my $conf_cf = "$cf->{config_dir}/.config$rootn";
d2628 2
a2629 2
    my $oldconfig = "$plat_cf.old";
    if(($cf->{selectype} || $cf->{upreconfig} || $cf->{profile})
d2637 1
a2637 1
if [ -n "$cf->{upreconfig}" ]
d2639 2
a2640 4
    cp $cf->{upreconfig} $plat_cf
    chmod +w $plat_cf
else
    if [ -f $conf_cf ]
d2642 1
a2642 1
        cat $conf_cf | perl -ne 'print if m,^CONFIG_(?!PCF),' >> $plat_cf
a2644 4
if [ ! -f $plat_cf -a -f $pdef_cf ]
then
    cp $pdef_cf $plat_cf
fi
d2647 2
a2648 2
    $cf->{top}/bin/splice_profile $plat_cf $cf->{profile} > .config.tmp
    mv -f .config.tmp $plat_cf
d2651 2
a2652 2
$cf->{conf} $kconfig .config$rootn
    cp .config$rootn defconfig$rootn.dev
d2654 2
a2655 1
    $cf->{preconfig} = $plat_cf;
a2663 64
sub get_plat_dir
{
    my $plat_dir;
    my $hr;

    mk_main_conf() unless -f $cf->{mainlkc};

    if($cf->{upreconfig}) {
        if(-d $cf->{upreconfig}) {
            if($cf->{upreconfig} =~ m,(config/platform/[^/]+)$,) {
                $plat_dir = $1;
                $cf->{upreconfig} = '';
            }
        } else {
            $hr = parse_dotconfig($cf->{upreconfig});
            die "ERROR: $cf->{upreconfig} is non-ltib" unless $hr->{PLATFORM};

            # Balancing correctness against backward compatibility
            if($cf->{upreconfig} =~ m,(config/platform/[^/]+)/[^/]+\s*$,) {
                $plat_dir = $1;
            } else {
                $plat_dir = $hr->{PLATFORM_SUBDIR} || $hr->{PLATFORM};
                $plat_dir = "config/platform/$plat_dir";
            }
        }
        die "can't derive a platform directory from $cf->{upreconfig}"
                                                              unless $plat_dir;

        # set in the platform .config for subsequent runs
        my $choice;
        open(MC, $cf->{mainlkc}) or die "open $cf->{mainlkc} : $!";
        while(<MC>) {
            if( m,$plat_dir"\s+if\s+(\w+), ) {
                $choice = "CONFIG_$1";
                last;
            }
        }
        close MC;
        die "No match for $plat_dir in $cf->{mainlkc}" unless $choice;
        open(TOPCF, ">$cf->{top}/.config") or die "open $cf->{top}/.config:$!";         print TOPCF "$choice=y\n";
        print TOPCF "CONFIG_PLATFORM_DIR=\"$plat_dir\"\n";
        close TOPCF;

        return $plat_dir;
    }

CHOOSE_TOP_PLATFORM:
    while(! -f "$cf->{top}/.config") {
        system_nb("$cf->{conf} $cf->{mainlkc}") == 0 or die;
    }

    # extract the choice
    $hr = parse_dotconfig("$cf->{top}/.config");
    $plat_dir = $hr->{PLATFORM_DIR};
    if(! -d $plat_dir) {
        warn("Platform choice rejected as: '$plat_dir' doesn't exist\n");
        unlink "$cf->{top}/.config";
        die if $cf->{batch};
        goto CHOOSE_TOP_PLATFORM;
    }

    return $plat_dir;
}

d2668 1
a2668 1
    opendir(DIR, $dir) or die("can't open $dir: $!");
a2719 17
sub build_root_list
{
    my @@rl;
    if( $cf->{oneroot} || $cf->{sn} ) {
        @@rl = $cf->{rootn};
    } else {
        @@rl = (0);
        opendir(DIR, $cf->{plat_dir}) or die("opendir $cf->{plat_dir} : $!");
        while(defined(my $ent = readdir(DIR)) ) {
            next unless $ent =~ m,defconfig(\d\d?)$,;
            push(@@rl, $1);
        }
        closedir(DIR);
    }
    return @@rl;
}

d2736 1
a2736 1
    check_rpm_ipfx();
@


1.1.1.17
log
@Import from fsl 20090318
@
text
@a56 1
    _rpmdir      => "$top/rpm/RPMS",
d113 1
a113 1
    app_version  => "9.1.1",
d252 1
a252 1
                          SYSCFG_START_DHCPD SYSCFG_DHCPC_CMD SYSCFG_DHCP_ARG
d254 1
a254 2
                          SYSCFG_START_SAMBA SYSCFG_SMBD_ARGS SYSCFG_NMBD_ARGS
                          SYSCFG_BOA_ARGS SYSCFG_DROPBEAR_ARGS/ ],
d319 1
a319 1
            listpkgscsv list packages in a format for import into spreadsheet
d467 1
a467 1
$cf->{conf} = $cf->{batch} ? "yes '' | conf >&2" : "mconf";
d518 1
a518 1
$ENV{CROSS_COMPILE} = "";
d521 1
a521 1
# check-ins of unchanged files
a528 4
if($cf->{mode} =~ m,listpkgs,) {
    &{"f_" . $cf->{mode}}();
    exit(0);
}
d538 1
a538 1
# get/set the platform directory
d636 2
a637 2
    $pcf->{LINTARCH} = g2larch($cf->{buildarch}) or die;
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH}) or die;
a704 1
$echo rm -f config/platform/host/host.config
d743 1
a743 1
    my @@rpms = glob("$cf->{_rpmdir}/$pcf->{RPMTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*");
d746 1
a746 4
    # 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};
a747 1
    $r   .= "directory build, "          if $dir_bld;
a750 1
    $r   .= "download only, "            if $cf->{download_only};
d752 2
a753 1
    $r   .= "spec file newer than rpm, " if $spec_upd;
d755 1
a755 1
        warn("Build path taken because: $r\n") unless $cf->{dltest};
d760 2
a761 1
            unlink(@@rpms) if $cf->{force} || $$key->{build} || $spec_upd;
a764 1
                (undef, $url) = split(/:\s*/, $url, 2);
d791 3
a793 4
            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';
d800 5
a805 1
                    return;
a806 27

                # 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);
a832 1
               . "--define '_rpmdir $cf->{_rpmdir}'  "
d837 1
a837 1
        print "\n$cmd\n";
d865 1
a865 1
        foreach my $rpm ( glob("$cf->{_rpmdir}/$pcf->{RPMTARCH}/$tok->{name}-$tok->{version}-$tok->{release}*") ) {
d875 1
a875 1
                . "$cf->{_rpmdir}/$pcf->{RPMTARCH}/$tok->{name}-"
a939 1
       next unless $$key->{sn};
d1115 1
a1115 1
diff --exclude CVS --exclude .git -uNr $pkg_dir_name $pkg_dir_name.modified > $cf->{lpp}/$pname
d1171 2
a1172 2
    my ($file, $tag, $rel) = @@_;
    $tag ||= get_scm_tag() || 'none';
d1174 2
a1175 1
    my $wtag = get_scm_branch() || 'none';
d1183 2
a1184 2
SCM wtag     = $wtag
SCM tag      = $tag
d1187 2
a1269 6
            # Do a one pass, simple expansion for a few config items
            use warnings FATAL => 'uninitialized';
            foreach my $k (qw/CCACHE_DIR _rpmdir/) {
                next unless $cf->{$k};
                $cf->{$k} =~ s,\$([\w]+),$cf->{$1},g;
            }
d1291 1
a1291 1
                      nodeps force hostinst reinstall dodrop sn _rpmdir
a1301 1
    $cf->{_rpmdir}       = "$cf->{rpmdir}/RPMS";
d1349 1
a1349 2
    return 1 if -f $cf->{host_wait_warning} && (! $cf->{dltest} 
                                                  || $cf->{sn} || $cf->{batch});
d1359 1
a1359 1
    print <<TXT unless $cf->{dltest};
a1466 2
    $ENV{SOFT_FP_ARCH} = $pcf->{SOFT_FP_ARCH} || "";
    $ENV{GLIBC_WANT_KERNEL_HEADERS} = $pcf->{GLIBC_WANT_KERNEL_HEADERS} || "";
d1476 2
d1547 1
a1547 1
    my $newarch = g2larch($pcf->{LINTARCH}) or die;
d1549 1
a1549 1
    my $dir     = $cf->{_rpmdir};
a1553 1
    my $pon     = ! $cf->{dltest};
a1558 2
        unlink("$dir/$cfn"), die("old LINTARCH not in $dir/$cfn, removing\n")
                                                               unless $oldarch;
d1571 1
d1573 1
a1573 1
    print "Flushing old rpm set\n" if $pon;
d1587 1
a1587 1
            print("Saving rpms from $oldarch to $dir/$ts\n") if $pon;
d1591 1
a1591 1
            print "No binary rpms to save\n" if $pon;
d1609 1
a1609 1
                      "from rpm/$ent\n" if $pon;
d1621 1
a1621 1
        print "Removing binary rpms\n" if $pon;
a1759 2
    die("no platform config has been parsed (\$pcf)") unless defined $pcf;

d1764 1
a1764 1
    my $pre = '^([\w]+)\s*=\s*([\S]*)';
d1782 7
a1788 2
        $$key->{sn} = $pcf->{$key} && $pcf->{$key} ne 'y' ?  $pcf->{$key} : $2;
        $$key->{en} = $pcf->{$key} ? 1 : 0;
d1795 2
a1796 1
    # load up the override map if present.
d1828 8
a1835 2
                # insert just before sysconfig (3rd from last)
                splice(@@{$pcac->{mk_buildlist}}, -3, 0, $key);
a1836 2
            $$key->{sn} = $pcf->{$key} && $pcf->{$key} ne 'y' ?  $pcf->{$key} : $2;
            $$key->{en} = $pcf->{$key} ? 1 : 0;
d1838 1
d2006 4
a2009 2
    return unless $sn;

d2016 1
d2167 1
a2167 1
    $pcf->{LINTARCH} = g2larch($cf->{buildarch}) or die
d2173 1
a2173 1
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH}) or die;
d2243 1
a2243 1
for i in BUILD SOURCES SPECS SRPMS
a2246 1
mkdir -p $cf->{_rpmdir}
d2289 1
d2319 2
a2320 2
    $pcf->{LINTARCH} = g2larch($cf->{buildarch}) or die;
    $pcf->{RPMTARCH} = g2larch($pcf->{LINTARCH}) or die;
d2327 1
a2327 1
                      rpm rpmdir _rpmdir rpmdb lpp tmppath sudo enrootn/;
a2349 1
    $cf->{_rpmdir} = "$cf->{rpmdir}/RPMS";
d2356 1
a2356 1
    my @@rpms = glob("$cf->{_rpmdir}/$pcf->{RPMTARCH}/$cf->{sn}-*");
d2358 1
a2358 1
                        . "$cf->{_rpmdir}/$pcf->{RPMTARCH}/$cf->{sn}-*";
d2369 1
a2369 1
    system_nb("rm -f $cf->{_rpmdir}/$pcf->{RPMTARCH}/*");
a2416 3
    # create the project tmp directory
    system_nb("mkdir -p $cf->{projtmp}") unless -e $cf->{projtmp};

a2725 4
    if($cf->{upreconfig} && $cf->{dltest}) {
        $cf->{preconfig} = $cf->{upreconfig};
        return 1;
    }
d2744 1
a2744 1
            # because someone else has updated the scm.  In this case, use
d2755 1
a2755 1
    $cf->{conf} = $cf->{batch} ? "yes '' | conf >&2" : "mconf";
d2853 2
a2874 4
        die "invalid platform directory: $plat_dir in $cf->{upreconfig}"
                                                           unless -d $plat_dir;

        return $plat_dir if $cf->{dltest} || $cf->{mode} =~ m,^listpkgs,;
d2877 11
a2887 3
        my ($platform) = $plat_dir =~ m,([^/]+)\s*$,;
        open(TOPCF, ">$cf->{top}/.config") or die "open $cf->{top}/.config:$!";
        print TOPCF "CONFIG_PLATFORM_$platform=y\n";
a2893 2
    mk_main_conf() unless -f $cf->{mainlkc};

a2919 1
        next if $ent eq 'git';
@


