Commit 1c8cfeb2 authored by Andrey V.Kosteltsev's avatar Andrey V.Kosteltsev

building source_requires; needs patch all makefiles

git-svn-id: https://svn.radix.pro/svn/toolchains/trunk@101 0df74aab-45ad-4799-93a1-122938110d35
parent 21da16be
#!/usr/bin/perl
use FindBin;
use lib $FindBin::Bin;
use strict;
use warnings FATAL => 'all';
use IO::Handle;
use File::Basename;
use File::Temp;
use Getopt::Long;
use _kxLab;
#
# Generate .src_requires file for current directory
#
# usage:
# $0 [options] topdir
#
# where:
# 'topdir' - is a absolute path to the top directory of checked out branch
#
# global variables
my (%all_requires, $top_dir, $opt_max_depth, %requires_depend, $requires_file, %skip_dirs);
my %all_src_requires;
sub usage
{
print <<EOF;
Usage: build_requires [options] topdir toolchain hardware flavour
Options:
--max-depth=i - where 'i' is a maximal directory depth for finding requires;
--skip-dir - directory to be skipped (such as dist or TARGET_BUILD_DIR);
topdir - is a absolute path to the top of checked out branch.
EOF
exit;
}
sub requires_depend
{
my $makefile = shift;
if( ! exists $requires_depend{$makefile} )
{
print REQUIRES_DEPEND_FILE "$requires_file: $makefile\n\n";
print REQUIRES_DEPEND_FILE "$makefile:\n\n";
$requires_depend{$makefile} = "";
}
}
sub read_src_requires
{
my $makefile = shift;
# add a dependency to the Makefile
requires_depend($makefile);
my %requires;
my $shell_output = `cat $makefile`;
while( $shell_output =~ m/^SOURCE_REQUIRES(.+= +)(.+)/gm )
{
my @n = split( " ", $2 );
foreach my $d ( @n )
{
if( $d eq "ALL_DIRS" )
{
my $dirname = dirname($makefile);
opendir( DIR, "$dirname" ) or
_kxLab::error( "build_requires: Could not open directory: $dirname: $!" );
my @dirs = grep { ! /^\./ && -d "$_" && -f "$_/Makefile" } readdir( DIR );
closedir DIR;
foreach my $dir (@dirs)
{
requires_depend("$dirname/$dir/Makefile");
"$dirname/$dir" =~ m!$top_dir/(.+)!;
$requires{$1} = "";
}
}
else
{
# Print a nice error message if the REQUIRES statement points to a missing directory
_kxLab::error( "build_requires: REQUIRES '$d' in $makefile not found. Exit" ) if( ! -d "$top_dir/$d" );
if( -f "$top_dir/$d/Makefile" )
{
$requires{$d} = "";
requires_depend("$top_dir/$d/Makefile");
}
}
}
}
return %requires;
}
sub read_requires
{
my $makefile = shift;
# add a dependency to the Makefile
requires_depend($makefile);
my %requires;
my $shell_output = `cat $makefile`;
while( $shell_output =~ m/^REQUIRES(.+= +)(.+)/gm )
{
my @n = split( " ", $2 );
foreach my $d ( @n )
{
if( $d eq "ALL_DIRS" )
{
my $dirname = dirname($makefile);
opendir( DIR, "$dirname" ) or
_kxLab::error( "build_requires: Could not open directory: $dirname: $!" );
my @dirs = grep { ! /^\./ && -d "$_" && -f "$_/Makefile" } readdir( DIR );
closedir DIR;
foreach my $dir (@dirs)
{
requires_depend( "$dirname/$dir/Makefile" );
"$dirname/$dir" =~ m!$top_dir/(.+)!;
$requires{$1} = "";
my %src_requires = read_src_requires( "$dirname/$dir/Makefile" );
my @sort_src_requires = sort(keys %src_requires);
foreach my $req ( @sort_src_requires )
{
$all_src_requires{$req} = "";
}
}
}
else
{
# Print a nice error message if the REQUIRES statement points to a missing directory
_kxLab::error( "build_requires: REQUIRES '$d' in $makefile not found. Exit" ) if( ! -d "$top_dir/$d" );
if( -f "$top_dir/$d/Makefile" )
{
$requires{$d} = "";
my %src_requires = read_src_requires( "$top_dir/$d/Makefile" );
my @sort_src_requires = sort(keys %src_requires);
foreach my $req ( @sort_src_requires )
{
$all_src_requires{$req} = "";
}
}
}
}
}
return %requires;
}
sub start_depend
{
my $req = shift;
print REQUIRES_FILE "$req:";
}
sub depend
{
my $req = shift;
print REQUIRES_FILE " $req";
}
sub end_depend
{
print REQUIRES_FILE "\n\n";
}
sub make_sub_requires
{
my $req = shift;
if( ! exists $all_requires{$req} )
{
$all_requires{$req} = "";
# Read sub requires
my $makefile = "$top_dir/$req/Makefile";
my %sub_requires = read_requires( $makefile );
if( scalar(%sub_requires) )
{
# Make sub sub requires
my @sorted_sub_requires = sort(keys %sub_requires);
foreach my $sub_req ( @sorted_sub_requires )
{
make_sub_requires( $sub_req );
}
}
}
}
#
# Parse the command line options
#
$opt_max_depth = 10;
my @opt_skip_dirs;
GetOptions( "max-depth=i" => \$opt_max_depth, "skip-dir=s" => \@opt_skip_dirs );
%skip_dirs = map { $_ => "" } @opt_skip_dirs;
# get the rest of the command line
my $topdir = shift;
my $makefile = "Makefile";
if( ! defined $topdir or $topdir eq "" ) { usage; }
_kxLab::error( "build_requires: $topdir is not a directory" ) if( ! -d $topdir );
_kxLab::error( "build_requires: Makefile missing: $makefile" ) if ( ! -f $makefile );
# setup $top_build_dir
$top_dir = $topdir;
$requires_file = ".src_requires";
my $requires_depend_file = $requires_file . "_depend";
# open the output files
open(REQUIRES_FILE, "> $requires_file") or
_kxLab::error( "build_requires: Could not open $requires_file file: $!" );
open(REQUIRES_DEPEND_FILE, "> $requires_depend_file") or
_kxLab::error( "build_requires: Could not open $requires_depend_file file: $!" );
# root component
my $pwd = `pwd`;
chomp $pwd;
$pwd =~ m!$top_dir(.*)!;
my $root;
if( $1 eq "" )
{
$root = "all";
}
else
{
$1 =~ m!/(.+)!;
$root = $1;
}
print REQUIRES_FILE "# ROOT=$root\n\n";
print REQUIRES_DEPEND_FILE "\n";
# read the makefile
%all_src_requires = read_src_requires( "$pwd/$makefile" );
my %requires = read_requires( "$pwd/$makefile" );
# check the "build-system" sub dependencies implicitly (excluding sources directories)
#$requires{"build-system"} = "";
# build sub dependencies
my @sorted_requires = sort(keys %requires);
foreach my $req ( @sorted_requires )
{
make_sub_requires( $req );
}
# build the all: rule
start_depend( "all" );
my @sorted_src_requires = sort(keys %all_src_requires);
foreach my $req ( @sorted_src_requires )
{
depend( $req );
}
end_depend();
# Finish by including tree.mk
print REQUIRES_FILE "TREEDIRS = ", join(" ", sort(keys %all_src_requires)), "\n\n";
print REQUIRES_FILE "include \$(BUILDSYSTEM)/tree-src.mk\n";
# close output files
close REQUIRES_FILE;
close REQUIRES_DEPEND_FILE;
......@@ -227,7 +227,7 @@ endif
CLEANUP_FILES += .dist.*
CLEANUP_FILES += $(addprefix ., $(TOOLCHAIN_NAMES))
CLEANUP_FILES += .*requires
CLEANUP_FILES += .*requires*
CLEANUP_FILES += $(SRC_DIR)
CLEANUP_FILES += $(SRC_DIR).back.??????
......@@ -327,28 +327,37 @@ install: .install
.install: .src_requires .install_builds .install_products
.src_requires: $(SOURCE_REQUIRES)
ifdef SOURCE_REQUIRES
#######
####### Build directory dependencies into .src_requires which
####### is used as a Makefile for srource tarballs downloading
#######
.sources: .src_requires
.src_requires_depend: .src_requires ;
.src_requires: .makefile
ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
@rm -f $(TARGET_BUILD_DIR)/.src_requires
@touch $(TARGET_BUILD_DIR)/.src_requires
@for part in $(SOURCE_REQUIRES) ; do \
echo $$part >> $(TARGET_BUILD_DIR)/.src_requires ; \
done
@echo "======="
@echo "======= Start of building source requires for: `pwd`:"
@echo "=======" ; \
$(foreach part,$(SOURCE_REQUIRES),\
$(MAKE) -C $(part) TOOLCHAIN=$(TOOLCHAIN_NOARCH) FLAVOUR= local_all &&) true
@if [ ! -s $(TARGET_BUILD_DIR)/.src_requires ]; then \
echo -e "======= ... Nothing to be done (there are no source requires) ..." ; \
fi
@echo "======="
@echo "======= End of building source requires for `pwd`."
@echo "======="
ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
@echo ""
@shtool echo -e "%B################################################################%b"
@shtool echo -e "%B#######%b"
@shtool echo -e "%B#######%b %BStart of building source requires for%b `pwd`%B:%b"
@shtool echo -e "%B#######%b"
@$(BUILDSYSTEM)/build_src_requires $(TOP_BUILD_DIR_ABS)
TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN_NOARCH) -f .src_requires
@shtool echo -e "%B#######%b"
@shtool echo -e "%B#######%b %BEnd of building source requires for%b `pwd`%B.%b"
@shtool echo -e "%B#######%b"
@shtool echo -e "%B################################################################%b"
@echo ""
@touch $@
@touch .src_requires_depend
endif
endif
.install_builds: $(BUILD_TARGETS)
# Do nothing
......
# Generic rule used for source directories
all $(TREEDIRS):
$(TREEDIRS):
@$(MAKE) -C $(TOP_BUILD_DIR_ABS)/$@ $(TREE_RULE)
.PHONY: all $(TREEDIRS)
......@@ -4,10 +4,15 @@ COMPONENT_TARGETS = $(TOOLCHAIN_HOST)
include ../../../build-system/config.mk
SOURCE_REQUIRES = $(SRC_PACKAGE_DIR)/GNU/gcc/gcc-4.9.2
SOURCE_REQUIRES += $(SRC_PACKAGE_DIR)/GNU/gmp
SOURCE_REQUIRES += $(SRC_PACKAGE_DIR)/GNU/mpfr
SOURCE_REQUIRES += $(SRC_PACKAGE_DIR)/GNU/mpc
#SOURCE_REQUIRES = $(SRC_PACKAGE_DIR)/GNU/gcc/gcc-4.9.2
#SOURCE_REQUIRES += $(SRC_PACKAGE_DIR)/GNU/gmp
#SOURCE_REQUIRES += $(SRC_PACKAGE_DIR)/GNU/mpfr
#SOURCE_REQUIRES += $(SRC_PACKAGE_DIR)/GNU/mpc
SOURCE_REQUIRES = sources/GNU/gcc/gcc-4.9.2
SOURCE_REQUIRES += sources/GNU/gmp
SOURCE_REQUIRES += sources/GNU/mpfr
SOURCE_REQUIRES += sources/GNU/mpc
tar_bz2_archive = $(SRC_PACKAGE_DIR)/GNU/gcc/gcc-4.9.2/gcc-4.9.2.tar.bz2
tar_bz2_archive_gmp = $(SRC_PACKAGE_DIR)/GNU/gmp/gmp-6.0.0a.tar.bz2
......@@ -66,7 +71,9 @@ $(mpc_src_done): $(src_done)
$(build_dir): $(src_done)
@mkdir -p $@
$(build_target): $(build_dir) $(gmp_src_done) $(mpfr_src_done) $(mpc_src_done)
$(build_target): $(src_done) $(gmp_src_done) $(mpfr_src_done) $(mpc_src_done)
@mkdir -p $(build_dir)
exit 1
@cd $(build_dir) && ../$(src_dir)/configure \
--prefix=$(GNATTOOLS_DEST_DIR) \
--build=$(shell $(BUILDSYSTEM)/canonical-build) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment