2002-02-28 08:11:51 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
#
|
|
|
|
# First attempt at using module-graph.pl to generate
|
|
|
|
# a cvs checkout list, and building the resulting tree.
|
|
|
|
#
|
2002-04-03 00:48:03 +00:00
|
|
|
# bootstrap.pl starts with an "all.dot" requires map file
|
|
|
|
# and nothing else, and does the following:
|
|
|
|
# * Figures out the module dependencies for the module
|
|
|
|
# you want to build, via module-graph.pl.
|
|
|
|
# * Creates a list of directories from the modules via
|
|
|
|
# modules2dir.pl.
|
|
|
|
# * Checks out core config files, nspr, and module directories.
|
|
|
|
# * Based on this resulting tree, allmakefiles.sh is generated
|
2002-05-09 08:39:46 +00:00
|
|
|
# on the fly with a module name "bootstrap". modules.mk file
|
|
|
|
# generated with DIRS in leaf-first order.
|
2002-05-10 01:28:44 +00:00
|
|
|
# * A build is attempted with this configure option:
|
|
|
|
# --enable-standalone-modules=bootstrap --disable-ldap --disable-tests
|
2002-04-03 00:48:03 +00:00
|
|
|
#
|
2002-05-10 01:28:44 +00:00
|
|
|
# Example usage, to build xpcom:
|
|
|
|
#
|
|
|
|
# cvs co mozilla/tools/module-deps/bootstrap.pl
|
|
|
|
# mozilla/tools/module-deps/bootstrap.pl --module=xpcom
|
2002-04-03 00:48:03 +00:00
|
|
|
#
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-05-10 01:28:44 +00:00
|
|
|
|
2002-03-30 04:29:40 +00:00
|
|
|
use strict;
|
2002-04-02 23:13:35 +00:00
|
|
|
use File::Find();
|
2002-03-30 04:29:40 +00:00
|
|
|
|
|
|
|
# For --option1, --option2, ...
|
|
|
|
use Getopt::Long;
|
|
|
|
Getopt::Long::Configure("bundling_override");
|
|
|
|
Getopt::Long::Configure("auto_abbrev");
|
|
|
|
|
2002-02-28 08:11:51 +00:00
|
|
|
use Cwd;
|
|
|
|
|
2002-03-30 04:29:40 +00:00
|
|
|
my $debug = 1;
|
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
sub PrintUsage {
|
|
|
|
die <<END_USAGE
|
2002-04-02 23:13:35 +00:00
|
|
|
usage: $0 --modules=mod1,mod2,.. --skip-cvs
|
2002-05-09 08:27:52 +00:00
|
|
|
(Assumes you can check out a new cvs tree here)
|
2002-03-02 00:04:47 +00:00
|
|
|
END_USAGE
|
2002-02-28 08:11:51 +00:00
|
|
|
}
|
|
|
|
|
2002-04-02 23:13:35 +00:00
|
|
|
# Globals.
|
2002-04-01 23:43:44 +00:00
|
|
|
my $root_modules = 0; # modules we want to build.
|
2002-04-02 23:13:35 +00:00
|
|
|
my $skip_cvs = 0;
|
2002-03-30 04:29:40 +00:00
|
|
|
|
|
|
|
sub parse_args() {
|
|
|
|
PrintUsage() if $#ARGV < 0;
|
|
|
|
|
|
|
|
# Stuff arguments into variables.
|
|
|
|
# Print usage if we get an unknown argument.
|
2002-05-09 08:27:52 +00:00
|
|
|
PrintUsage() if !GetOptions('module=s' => \$root_modules,
|
|
|
|
'modules=s' => \$root_modules,
|
|
|
|
'skip-cvs' => \$skip_cvs);
|
2002-04-01 23:43:44 +00:00
|
|
|
if ($root_modules) {
|
|
|
|
print "root_modules = $root_modules\n";
|
|
|
|
|
|
|
|
# Test for last tree, or remember what tree we're doing.
|
|
|
|
if (-e "last_module.txt") {
|
|
|
|
open LAST_MODULE, "last_module.txt";
|
|
|
|
|
|
|
|
while(<LAST_MODULE>) {
|
|
|
|
# Assume module name is first line
|
|
|
|
unless($_ eq $root_modules) {
|
|
|
|
print "Error: Last module pulled ($_) doesn't match \"$root_modules\", remove last_module.txt and mozilla tree, then try again.\n";
|
|
|
|
exit 1;
|
|
|
|
} else {
|
|
|
|
print "Checking out same module...\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close LAST_MODULE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
# Save off file to remember which tree we're using
|
|
|
|
open LAST_MODULE, ">last_module.txt";
|
|
|
|
print LAST_MODULE $root_modules;
|
|
|
|
close LAST_MODULE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-30 04:29:40 +00:00
|
|
|
}
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
sub get_system_cwd {
|
|
|
|
my $a = Cwd::getcwd()||`pwd`;
|
|
|
|
chomp($a);
|
|
|
|
return $a;
|
|
|
|
}
|
2002-02-28 08:11:51 +00:00
|
|
|
|
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
# Run shell command, return output string.
|
|
|
|
sub run_shell_command {
|
2002-03-30 04:29:40 +00:00
|
|
|
my ($shell_command, $echo) = @_;
|
2002-03-02 00:04:47 +00:00
|
|
|
local $_;
|
|
|
|
|
|
|
|
my $status = 0;
|
|
|
|
my $output = "";
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
chomp($shell_command);
|
2002-03-30 04:29:40 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
print "cmd = $shell_command\n";
|
2002-03-30 04:29:40 +00:00
|
|
|
|
2002-05-09 23:23:10 +00:00
|
|
|
open CMD, "$shell_command 2>&1|" or die "command failed: $!";
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
while(<CMD>) {
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-03-30 04:29:40 +00:00
|
|
|
if($echo) {
|
2002-03-02 00:04:47 +00:00
|
|
|
print $_;
|
|
|
|
}
|
|
|
|
chomp($_);
|
|
|
|
$output .= "$_ ";
|
|
|
|
}
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
close CMD or $status = 1;
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
if($status) {
|
2002-05-09 23:19:05 +00:00
|
|
|
print "Warning, cmd exited with status $status.\n";
|
2002-03-02 00:04:47 +00:00
|
|
|
}
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
return $output;
|
|
|
|
}
|
2002-02-28 08:11:51 +00:00
|
|
|
|
2002-04-20 02:15:40 +00:00
|
|
|
# Global and Compare routines for Find()
|
2002-04-02 23:13:35 +00:00
|
|
|
my @foundMakefiles;
|
|
|
|
|
2002-04-20 02:15:40 +00:00
|
|
|
sub FindMakefiles {
|
|
|
|
# Don't descend into CVS dirs.
|
|
|
|
/CVS/ and $File::Find::prune = 1;
|
|
|
|
|
|
|
|
if($_ eq "Makefile.in") {
|
|
|
|
#print "$File::Find::dir $_\n";
|
2002-04-02 23:13:35 +00:00
|
|
|
|
2002-04-20 02:15:40 +00:00
|
|
|
$_ =~ s/.in//; # Strip off the ".in"
|
|
|
|
|
|
|
|
$File::Find::dir =~ s/^mozilla\///; # Strip off mozilla/
|
|
|
|
|
|
|
|
#$_ =~ s/mozilla//;
|
|
|
|
push(@foundMakefiles, "$File::Find::dir/$_");
|
|
|
|
} else {
|
|
|
|
#print " $File::Find::dir $_\n";
|
|
|
|
}
|
|
|
|
}
|
2002-02-28 08:11:51 +00:00
|
|
|
|
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
# main
|
|
|
|
{
|
|
|
|
my $rv = 0; # 0 = success.
|
|
|
|
|
2002-03-30 04:29:40 +00:00
|
|
|
# Get options.
|
|
|
|
parse_args();
|
|
|
|
|
2002-05-09 08:27:52 +00:00
|
|
|
# Module map file is currently mozilla/tools/module-deps/all.dot
|
2002-03-02 00:04:47 +00:00
|
|
|
|
|
|
|
# Pull core build stuff.
|
2002-04-02 23:13:35 +00:00
|
|
|
unless($skip_cvs) {
|
|
|
|
print "\n\nPulling core build files...\n";
|
2002-04-04 07:48:26 +00:00
|
|
|
my $core_build_files = "mozilla/client.mk mozilla/config mozilla/configure mozilla/configure.in mozilla/aclocal.m4 mozilla/Makefile.in mozilla/build mozilla/include mozilla/tools/module-deps";
|
2002-04-02 23:13:35 +00:00
|
|
|
$rv = run_shell_command("cvs co $core_build_files");
|
|
|
|
}
|
2002-03-02 00:04:47 +00:00
|
|
|
|
|
|
|
# Pull nspr
|
2002-04-02 23:13:35 +00:00
|
|
|
unless($skip_cvs) {
|
|
|
|
print "\n\nPulling nspr...\n";
|
|
|
|
my $nspr_cvs_cmd = "cvs co -rNSPRPUB_PRE_4_2_CLIENT_BRANCH mozilla/nsprpub";
|
|
|
|
$rv = run_shell_command("$nspr_cvs_cmd");
|
|
|
|
}
|
2002-03-02 00:04:47 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Pull modules.
|
2002-03-30 04:29:40 +00:00
|
|
|
# Only one root/start module to start.
|
2002-03-02 00:04:47 +00:00
|
|
|
#
|
|
|
|
print "\n\nPulling modules...\n";
|
2002-04-02 23:13:35 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
|
|
|
|
# Figure out the modules list.
|
|
|
|
my @modules;
|
|
|
|
my $modules_string = "";
|
|
|
|
my $num_modules = 0;
|
2002-05-09 08:27:52 +00:00
|
|
|
my $modules_cmd = "mozilla/tools/module-deps/module-graph\.pl --file mozilla/tools/module-deps/all\.dot --start-module $root_modules --list-only";
|
2002-03-30 04:29:40 +00:00
|
|
|
$modules_string = run_shell_command($modules_cmd, 0);
|
2002-05-15 19:21:29 +00:00
|
|
|
|
|
|
|
# Yank modules we know we don't want.
|
|
|
|
$modules_string =~ s/mozldap //; # no ldap.
|
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
@modules = split(' ', $modules_string);
|
|
|
|
$num_modules = $#modules + 1;
|
|
|
|
print "modules = $num_modules\n";
|
|
|
|
|
|
|
|
|
|
|
|
# Map modules list to directories list.
|
|
|
|
my @dirs;
|
|
|
|
my $dirs_string = "";
|
2002-04-20 02:15:40 +00:00
|
|
|
my $dirs_string_no_mozilla = ""; # dirs_string, stripping off mozilla/
|
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
my $dirs_cmd = "echo $modules_string | mozilla/config/module2dir\.pl --list-only";
|
2002-04-02 23:13:35 +00:00
|
|
|
|
|
|
|
print "\nGenerating directories list...\n";
|
2002-03-30 04:29:40 +00:00
|
|
|
$dirs_string = run_shell_command($dirs_cmd, 0);
|
2002-03-02 00:04:47 +00:00
|
|
|
#print "dirs_string = $dirs_string\n";
|
|
|
|
|
2002-04-02 23:13:35 +00:00
|
|
|
@dirs = split(' ', $dirs_string); # Create dirs array for find command.
|
2002-03-02 00:04:47 +00:00
|
|
|
|
2002-04-20 02:15:40 +00:00
|
|
|
$dirs_string_no_mozilla = $dirs_string;
|
|
|
|
$dirs_string_no_mozilla =~ s/mozilla\/+//g;
|
|
|
|
|
|
|
|
print "dirs_string_no_mozilla = $dirs_string_no_mozilla\n";
|
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
# Checkout directories.
|
2002-04-02 23:13:35 +00:00
|
|
|
unless($skip_cvs) {
|
|
|
|
print "\nChecking out directories...\n";
|
|
|
|
my $dirs_cvs_cmd = "cvs co $dirs_string";
|
|
|
|
run_shell_command($dirs_cvs_cmd);
|
|
|
|
}
|
2002-03-02 00:05:54 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
# Try a build.
|
2002-04-05 02:08:37 +00:00
|
|
|
my $basedir = get_system_cwd();
|
2002-03-02 00:04:47 +00:00
|
|
|
|
2002-03-30 04:29:40 +00:00
|
|
|
#
|
2002-04-02 23:13:35 +00:00
|
|
|
# Construct an allmakefiles.sh file
|
2002-03-30 04:29:40 +00:00
|
|
|
#
|
2002-04-02 23:13:35 +00:00
|
|
|
|
|
|
|
# Look for previously generated allmakefiles.sh file.
|
|
|
|
my $generated_allmakefiles_file = 0;
|
|
|
|
if(-e "mozilla/allmakefiles.sh") {
|
|
|
|
open ALLMAKEFILES, "mozilla/allmakefiles.sh";
|
|
|
|
while(<ALLMAKEFILES>) {
|
|
|
|
if(/# Generated by bootstrap.pl/) {
|
|
|
|
$generated_allmakefiles_file = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close ALLMAKEFILES;
|
|
|
|
|
|
|
|
if($generated_allmakefiles_file == 0) {
|
|
|
|
print "Error: non-generated mozilla/allmakefiles.sh found.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Stomp on generated file, or open a new one.
|
2002-04-20 02:15:40 +00:00
|
|
|
print "\nGenerating allmakefiles.sh ...\n";
|
|
|
|
my $allmakefiles_cmd = "cp mozilla/tools/module-deps/allmakefiles.stub mozilla/allmakefiles.sh";
|
|
|
|
print "$allmakefiles_cmd\n";
|
|
|
|
system("$allmakefiles_cmd");
|
2002-04-06 00:27:40 +00:00
|
|
|
|
|
|
|
# Open copy of stub file.
|
|
|
|
open ALLMAKEFILES, ">>mozilla/allmakefiles.sh";
|
2002-04-02 23:13:35 +00:00
|
|
|
|
|
|
|
# Add in our hack
|
|
|
|
print ALLMAKEFILES "MAKEFILES_bootstrap=\"\n";
|
|
|
|
|
|
|
|
# Recursively decend the tree looking for Makefiles
|
|
|
|
File::Find::find(\&FindMakefiles, @dirs);
|
|
|
|
|
|
|
|
# Write Makefiles out to allmakefiles.sh.
|
|
|
|
foreach (@foundMakefiles) {
|
|
|
|
print ALLMAKEFILES "$_\n";
|
|
|
|
}
|
2002-03-30 04:29:40 +00:00
|
|
|
|
2002-04-04 08:49:14 +00:00
|
|
|
print ALLMAKEFILES "\"\n\n";
|
|
|
|
print ALLMAKEFILES "add_makefiles \"\$MAKEFILES_bootstrap\"";
|
2002-04-02 23:13:35 +00:00
|
|
|
close ALLMAKEFILES;
|
2002-03-30 04:29:40 +00:00
|
|
|
|
2002-03-02 00:04:47 +00:00
|
|
|
#print "Configuring nspr ... \n";
|
2002-04-05 02:08:37 +00:00
|
|
|
#chdir("$basedir/mozilla/nsprpub");
|
2002-03-02 00:04:47 +00:00
|
|
|
#my $nspr_configure_cmd = "./configure";
|
|
|
|
#system("$nspr_configure_cmd");
|
|
|
|
|
2002-04-20 02:15:40 +00:00
|
|
|
print "\nConfiguring ... \n";
|
2002-04-05 02:08:37 +00:00
|
|
|
unlink("$basedir/mozilla/config.cache");
|
|
|
|
chdir("$basedir/mozilla");
|
2002-04-20 02:17:23 +00:00
|
|
|
my $configure_cmd = "./configure --enable-standalone-modules=$root_modules --disable-ldap --disable-tests";
|
2002-03-02 00:04:47 +00:00
|
|
|
$rv = run_shell_command("$configure_cmd");
|
|
|
|
|
2002-04-20 02:15:40 +00:00
|
|
|
#
|
|
|
|
# Construct a build/unix/modules.mk file, this let's us do
|
|
|
|
# a top-level build instead of n gmake -C <dir> commands.
|
|
|
|
#
|
|
|
|
|
|
|
|
chdir("$basedir");
|
|
|
|
|
|
|
|
# Look for previously generated modules.mk file.
|
|
|
|
my $generated_modulesmk_file = 0;
|
|
|
|
if(-e "mozilla/build/unix/modules.mk") {
|
|
|
|
open MODULESMK, "mozilla/allmakefiles.sh";
|
|
|
|
while(<MODULESMK>) {
|
|
|
|
if(/# Generated by bootstrap.pl/) {
|
|
|
|
$generated_modulesmk_file = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close MODULESMK;
|
|
|
|
|
|
|
|
if($generated_modulesmk_file == 0) {
|
|
|
|
print "Error: non-generated mozilla/build/unix/modules.mk found.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Stomp on generated file, or open a new one.
|
|
|
|
print "\nGenerating modules.mk ...\n";
|
|
|
|
my $modulesmk_cmd = "cp mozilla/tools/module-deps/modules.mk.stub mozilla/build/unix/modules.mk";
|
|
|
|
print "$modulesmk_cmd\n";
|
|
|
|
system("$modulesmk_cmd");
|
|
|
|
|
|
|
|
# Open copy of stub file.
|
|
|
|
open MODULESMK, ">>mozilla/build/unix/modules.mk";
|
|
|
|
|
|
|
|
# Add in our hack
|
|
|
|
print MODULESMK "BUILD_MODULE_DIRS := config build include $dirs_string_no_mozilla\n";
|
|
|
|
|
|
|
|
close MODULESMK;
|
|
|
|
|
2002-04-05 02:08:37 +00:00
|
|
|
# Now try and build.
|
|
|
|
# Not a top-level build, but build each directory.
|
2002-04-20 02:15:40 +00:00
|
|
|
print "\nBuilding ... \n";
|
2002-04-05 02:08:37 +00:00
|
|
|
|
|
|
|
print "basedir = $basedir\n";
|
|
|
|
chdir($basedir);
|
|
|
|
my $dir;
|
|
|
|
|
2002-04-06 00:27:40 +00:00
|
|
|
#
|
|
|
|
# Inherent build dependencies, we need to build some inital
|
|
|
|
# tools & directories first before attacking the modules.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Build nspr
|
|
|
|
print "gmake -C mozilla/nsprpub\n";
|
|
|
|
system("gmake -C mozilla/nsprpub");
|
|
|
|
|
|
|
|
# Build config
|
|
|
|
print "gmake -C mozilla/config\n";
|
|
|
|
system("gmake -C mozilla/config");
|
|
|
|
|
|
|
|
# Build xpidl
|
|
|
|
print "gmake -C mozilla/xpcom/typelib\n";
|
|
|
|
system("gmake -C mozilla/xpcom/typelib");
|
2002-05-07 07:05:10 +00:00
|
|
|
|
2002-04-06 00:27:40 +00:00
|
|
|
# Now try the modules.
|
2002-04-05 02:08:37 +00:00
|
|
|
|
2002-05-07 07:05:10 +00:00
|
|
|
chdir("$basedir/mozilla");
|
2002-04-05 02:08:37 +00:00
|
|
|
|
2002-05-07 07:05:10 +00:00
|
|
|
# Export-phase first. Export IDL stuff first to avoid IDL order problems.
|
|
|
|
# system("gmake export-idl"); # testing, not part of make system yet.
|
|
|
|
system("gmake export"); # run_shell_command("gmake export");
|
2002-04-05 02:08:37 +00:00
|
|
|
|
2002-05-07 07:05:10 +00:00
|
|
|
# Libs-phase next.
|
|
|
|
system("gmake libs"); # run_shell_command("gmake libs");
|
2002-02-28 08:11:51 +00:00
|
|
|
}
|