summaryrefslogtreecommitdiff
path: root/do_build.pl
blob: f29b1eb566ee4a55be9664b0caf3501a159e9269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/perl

use warnings;
use strict;

use FindBin;
use lib "$FindBin::Bin";
use do_common;

#
##
###
#### Initialization
###
##
#
my $type = shift @ARGV;
die "Bad arguments" unless defined($type);

my $resume = shift @ARGV;
my $config_only = defined($resume) && ($resume eq 'configonly');
my $clean_only = defined($resume) && ($resume eq 'cleanonly');
$resume = undef if $config_only || $clean_only;

chdir($basedir) or die "Failed to change directory to $basedir: $!\n";

open(LOG, '>', 'build.log') or die "Failed to open log file for writing: $!\n";
open(FH, '>&', STDOUT) or die "Failed to reopen STDOUT: $!\n";
open(STDOUT, '>&', LOG) or die "Failed to redirect STDOUT: $!\n";
open(STDERR, '>&', LOG) or die "Failed to redirect STDERR: $!\n";

#
##
###
#### Set up Environment Variables
###
##
#
$ENV{ACLOCAL_LOCALDIR} = "$prefix/share/aclocal";
system("mkdir -p $ENV{ACLOCAL_LOCALDIR}") and do { print FH "Failed to make aclocal directory.\n"; die };

if (defined($ENV{ACLOCAL}) && $ENV{ACLOCAL}) {
    $ENV{ACLOCAL} = "$ENV{ACLOCAL} -I $ENV{ACLOCAL_LOCALDIR}";
} else {
    $ENV{ACLOCAL} = "aclocal -I $ENV{ACLOCAL_LOCALDIR}";
}

if (defined($ENV{PKG_CONFIG_PATH}) && $ENV{PKG_CONFIG_PATH}) {
    $ENV{PKG_CONFIG_PATH} = "$prefix/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}";
} else {
    $ENV{PKG_CONFIG_PATH} = "$prefix/lib/pkgconfig";
}

unless (defined($ENV{FONTPATH}) && $ENV{FONTPATH}) {
    $ENV{FONTPATH}="$prefix/lib/X11/fonts/misc/,$prefix/lib/X11/fonts/Type1/,$prefix/lib/X11/fonts/75dpi/,$prefix/lib/X11/fonts/100dpi/,$prefix/lib/X11/fonts/cyrillic/,$prefix/lib/X11/fonts/TTF/";
}

system("mkdir -p $prefix/var/log") and do { print FH "Failed to make var/log directory.\n"; die };

#
##
###
#### Read configuration and perform build
###
##
#
my $ref = &read_config($basedir, "$FindBin::Bin/do_build.conf", $type);

for (@$ref) {
    my ($dir, $args) = @$_;

    # Check resume (second argument)
    if (defined($resume) && $resume eq $dir) {
	$resume = undef;
    } elsif (defined($resume)) {
	next;
    }

    # Change directories
    chdir("$basedir/$dir") or do { print FH "Failed to change directory to $basedir/$dir: $!\n"; die };
    chomp(my $pwd = `pwd`);
    my $cmd;

    # Clean/configure
    unless ($args =~ /noclean/) {
	print FH "CLEAN in $pwd...\n";
	$cmd = "sh autogen.sh --prefix=$prefix ";
	if (defined($mod_specific_configuration{$dir})) {
	    $cmd .= $mod_specific_configuration{$dir};
	}
	system($cmd) and do { print FH "ERROR: Autogen of '$dir' was UNSUCCESSFUL!!!\n"; die };
	exit if $config_only;
	if ($clean_only) {
	    system('make distclean') and do { print FH "ERROR: Clean of '$dir' was UNSUCCESSFUL!!!\n"; die };
	    next;
	}
	system('make clean') and do { print FH "ERROR: Clean of '$dir' was UNSUCCESSFUL!!!\n"; die };
    }

    # Build
    print FH "MAKE in $pwd...\n";
    system('make') and do { print FH "ERROR: Make of '$dir' was UNSUCCESSFUL!!!\n"; die };

    # Install
    print FH "INSTALL in $pwd...\n";
    my $target = 'install';
    if ($args =~ /install:([\w-]+)/) {
	$target = $1;
    }
    system("make $target") and do { print FH "ERROR: Install of '$dir' was UNSUCCESSFUL!!!\n"; die };

    if ($args =~ /distcheck/) {
	print FH "MAKE-DISTCHECK\n";
	system('make distcheck') and do { print FH "ERROR: Make-Distcheck of libxcb was UNSUCCESSFUL!!!\n"; die };
    }
}

close(FH);
close(LOG);
close(STDOUT);
close(STDERR);

exec("/sbin/fixfiles restore $prefix/bin");