Radix cross Linux Build System

Cross-platform build system is designed to build distributions of different operating systems for a set of target devices

39 Commits   2 Branches   2 Tags
     5         kx #!/bin/env perl
     5         kx 
     5         kx #
     5         kx # Generate .REQUIRES file for package.
     5         kx #
     5         kx # usage:
     5         kx #   $0 [options] dir dir outfile
     5         kx #
     5         kx # where: 'dir'     - is directory where made required package
     5         kx #        'outfile' - output file with following format:
     5         kx #
     5         kx # _kxLibc=1.0.7
     5         kx # pkgtool=0.0.1
     5         kx #
     5         kx # empty version is allowed:
     5         kx #
     5         kx # pkg=
     5         kx #
     5         kx 
     5         kx my ($toolchain, $hardware, $flavour);
     5         kx 
     5         kx sub read_requires
     5         kx {
     5         kx   my %requires;
     5         kx   my ( $name, $version, $group );
     5         kx 
     5         kx   my ( $file_name, $makefile );
     5         kx 
     5         kx   my $ptype = shift;
     5         kx 
     5         kx   if( $ptype eq "bin" )
     5         kx   {
     5         kx     $name    = "BIN_PKG_NAME";
     5         kx     $version = "BIN_PKG_VERSION";
     5         kx     $group   = "BIN_PKG_GROUP";
     5         kx   }
     5         kx   elsif( $ptype eq "dev" )
     5         kx   {
     5         kx     $name    = "DEV_PKG_NAME";
     5         kx     $version = "DEV_PKG_VERSION";
     5         kx     $group   = "DEV_PKG_GROUP";
     5         kx   }
     5         kx   else
     5         kx   {
     5         kx     $name    = "PKG_NAME";
     5         kx     $version = "PKG_VERSION";
     5         kx     $group   = "PKG_GROUP";
     5         kx   }
     5         kx 
     5         kx 
     5         kx   foreach my $req ( reverse @_ )
     5         kx   {
     5         kx     my $d = `echo $req | cut -f 1 -d '^'`;
     5         kx     $d =~ s/^\s+|\s+$//;
     5         kx 
     5         kx     $file_name = "${top_build_dir}/$d/Makefile";
     5         kx     $makefile = `cat $file_name`;
     5         kx     if( $makefile =~ m/^ *([_A-Za-z]*[_A-Za-z0-9]*)$name(.+= +)(.+)/gm )
     5         kx     {
     5         kx       my ( @p, @n, @v );
     5         kx       my ( $n, $v, $g );
     5         kx 
     5         kx       my $prefix = $1;
     5         kx 
     5         kx       my $cdir = "${top_build_dir}/$d";
     5         kx       my $shell_output = <<`SHELL`;
     5         kx cd $cdir
     5         kx make TOOLCHAIN=$toolchain HARDWARE=$hardware FLAVOUR=$flavour -f $file_name print-$prefix$name 2>/dev/null
     5         kx exit 0
     5         kx SHELL
     5         kx       while( $shell_output =~ m/^ *$prefix$name(.+= +)(.+)/gm ) { $n = $2; }
     5         kx 
     5         kx       $shell_output = <<`SHELL`;
     5         kx cd $cdir
     5         kx make TOOLCHAIN=$toolchain HARDWARE=$hardware FLAVOUR=$flavour -f $file_name print-$prefix$version 2>/dev/null
     5         kx exit 0
     5         kx SHELL
     5         kx       while( $shell_output =~ m/^ *$prefix$version(.+= +)(.+)/gm ) { $v = $2; }
     5         kx 
     5         kx       $shell_output = <<`SHELL`;
     5         kx cd $cdir
     5         kx make TOOLCHAIN=$toolchain HARDWARE=$hardware FLAVOUR=$flavour -f $file_name print-$prefix$group 2>/dev/null
     5         kx exit 0
     5         kx SHELL
     5         kx       while( $shell_output =~ m/^ *$prefix$group(.+= +)(.+)/gm ) { $g = $2; }
     5         kx 
     5         kx       $requires{"$d"} = \@p;
     5         kx       if( $g ) { @n = split / +/, $g . '/' . $n; }
     5         kx       else     { @n = split / +/, $n; }
     5         kx       push( @{ $requires{"$d"} }, @n );
     5         kx       @v = split / +/, $v;
     5         kx       if( $requires{"$d"} )
     5         kx       {
     5         kx         push( @{ $requires{"$d"} }, @v );
     5         kx       }
     5         kx     }
     5         kx     else
     5         kx     {
     5         kx       #
     5         kx       # The ..._PKG_NAME is not found in a Makefile then
     5         kx       # assume that this Makefile is a collection (depth=1):
     5         kx       # ---------------------------------------------------
     5         kx       # NOTE:
     5         kx       # ----
     5         kx       #   We do not allow flavours in the package .REQUIRES file.
     5         kx       #
     5         kx       my $cdir = "${top_build_dir}/$d";
     5         kx       #
     5         kx       # We read the head of Makefile until '__END_OF_REQUIRES__' keyword.
     5         kx       # The 'build-system/constants.mk' should be included before requires.
     5         kx       #
     5         kx       my $requires_output = <<`SHELL`;
     5         kx cd $cdir
     5         kx head -n `cat Makefile | grep -n "__END_OF_REQUIRES__" | cut -f 1 -d ':'` Makefile | \
     5         kx   make TOOLCHAIN=$toolchain HARDWARE=$hardware FLAVOUR=$flavour -f - -p __build_requires__ 2>/dev/null | grep "REQUIRES"
     5         kx exit 0
     5         kx SHELL
     5         kx 
     5         kx       while( $requires_output =~ m/^REQUIRES(.+= +)(.+)/gm )
     5         kx       {
     5         kx         my @r = split( " ", $2 );
     5         kx         foreach my $req ( reverse @r )
     5         kx         {
     5         kx           $d = `echo $req | cut -f 1 -d '^'`;
     5         kx           $d =~ s/^\s+|\s+$//;
     5         kx 
     5         kx           $file_name = "${top_build_dir}/$d/Makefile";
     5         kx           $makefile = `cat $file_name`;
     5         kx           if( $makefile =~ m/^ *([_A-Za-z]*[_A-Za-z0-9]*)$name(.+= +)(.+)/gm )
     5         kx           {
     5         kx             my ( @p, @n, @v );
     5         kx             my ( $n, $v, $g );
     5         kx 
     5         kx             my $prefix = $1;
     5         kx 
     5         kx             my $cdir = "${top_build_dir}/$d";
     5         kx             my $shell_output = <<`SHELL`;
     5         kx cd $cdir
     5         kx make TOOLCHAIN=$toolchain HARDWARE=$hardware FLAVOUR=$flavour -f $file_name print-$prefix$name 2>/dev/null
     5         kx exit 0
     5         kx SHELL
     5         kx             while( $shell_output =~ m/^ *$prefix$name(.+= +)(.+)/gm ) { $n = $2; }
     5         kx 
     5         kx             $shell_output = <<`SHELL`;
     5         kx cd $cdir
     5         kx make TOOLCHAIN=$toolchain HARDWARE=$hardware FLAVOUR=$flavour -f $file_name print-$prefix$version 2>/dev/null
     5         kx exit 0
     5         kx SHELL
     5         kx             while( $shell_output =~ m/^ *$prefix$version(.+= +)(.+)/gm ) { $v = $2; }
     5         kx 
     5         kx             $shell_output = <<`SHELL`;
     5         kx cd $cdir
     5         kx make TOOLCHAIN=$toolchain HARDWARE=$hardware FLAVOUR=$flavour -f $file_name print-$prefix$group 2>/dev/null
     5         kx exit 0
     5         kx SHELL
     5         kx             while( $shell_output =~ m/^ *$prefix$group(.+= +)(.+)/gm ) { $g = $2; }
     5         kx 
     5         kx             $requires{"$d"} = \@p;
     5         kx             if( $g ) { @n = split / +/, $g . '/' . $n; }
     5         kx             else     { @n = split / +/, $n; }
     5         kx             push( @{ $requires{"$d"} }, @n );
     5         kx             @v = split / +/, $v;
     5         kx             if( $requires{"$d"} )
     5         kx             {
     5         kx               push( @{ $requires{"$d"} }, @v );
     5         kx             }
     5         kx           }
     5         kx 
     5         kx         } # end of foreach ( req )
     5         kx 
     5         kx       } # End of while ( shell_output )
     5         kx 
     5         kx     }
     5         kx 
     5         kx   }
     5         kx 
     5         kx   return %requires;
     5         kx }
     5         kx 
     5         kx sub usage
     5         kx {
     5         kx   print <<EOF;
     5         kx 
     5         kx Usage: build_pkg_requires [options] dir ... dir output_file_name
     5         kx Options:
     5         kx    --toolchain={TOOLCHAIN}  - actual Toolchain name;
     5         kx    --hardware={HARDVARE}    - actual  Hardware name;
     5         kx    --flavour={FLAVOUR}      - actual   Flavour name;
     5         kx    --pkg-type={all|bin|dev} - find required packages of defined type only;
     5         kx    --all                    - find required packages of all types;
     5         kx    --bin                    - find binary packages only;
     5         kx    --dev                    - find development packages only.
     5         kx 
     5         kx EOF
     5         kx   exit;
     5         kx }
     5         kx 
     5         kx 
     5         kx my $pkg_type;
     5         kx 
     5         kx my @dirs;
     5         kx 
     5         kx foreach ( @ARGV )
     5         kx {
     5         kx   if( /--toolchain=(\S*)/ )
     5         kx   {
     5         kx     $toolchain = $1;
     5         kx   }
     5         kx   elsif( /--hardware=(\S*)/ )
     5         kx   {
     5         kx     $hardware = $1;
     5         kx   }
     5         kx   elsif( /--flavour=(\S*)/ )
     5         kx   {
     5         kx     $flavour = $1;
     5         kx   }
     5         kx   elsif( /--pkg-type=(\S*)/ )
     5         kx   {
     5         kx     $pkg_type = $1;
     5         kx   }
     5         kx   elsif( /--all/ )
     5         kx   {
     5         kx     $pkg_type = "all";
     5         kx   }
     5         kx   elsif( /--bin/ )
     5         kx   {
     5         kx     $pkg_type = "bin";
     5         kx   }
     5         kx   elsif( /--dev/ )
     5         kx   {
     5         kx     $pkg_type = "dev";
     5         kx   }
     5         kx   elsif( /--help/ )
     5         kx   {
     5         kx     usage;
     5         kx   }
     5         kx   else
     5         kx   {
     5         kx     push @dirs, $_;
     5         kx   }
     5         kx }
     5         kx 
     5         kx $reqfile = pop @dirs;
     5         kx 
     5         kx if( $pkg_type eq "" ) { $pkg_type = "all"; }
     5         kx 
     5         kx # Set up $top_build_dir
     5         kx $pwd = `pwd`;
     5         kx chomp $pwd;
     5         kx 
     5         kx if( $ENV{TOP_BUILD_DIR_ABS} eq "" )
     5         kx {
     5         kx   $p = $pwd;
     5         kx   while( ! -f "$p/build-system/core.mk" )
     5         kx   {
     5         kx     $p =~ m!(.*)/(.*)!;
     5         kx     $p = $1;
     5         kx   }
     5         kx   $top_build_dir = $p;
     5         kx }
     5         kx else
     5         kx {
     5         kx   $top_build_dir = $ENV{TOP_BUILD_DIR_ABS};
     5         kx }
     5         kx 
     5         kx # Open the output file
     5         kx open( REQUIRES_FILE, "> $reqfile" );
     5         kx 
     5         kx 
     5         kx # Read package names and versions from required Makefiles
     5         kx %requires = read_requires( $pkg_type, @dirs );
     5         kx 
     5         kx while( ($pkg, $nv) = each %requires )
     5         kx {
     5         kx    print REQUIRES_FILE "${$nv}[0]=${$nv}[1]\n";
     5         kx }
     5         kx 
     5         kx 
     5         kx # Close output file
     5         kx close REQUIRES_FILE;