summaryrefslogtreecommitdiffstats
path: root/debian/clean_config_vars
blob: 9611f9a0b3f2c1ffb3d90b967d33e4cc73868968 (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
#! /usr/bin/perl

use strict;

my %FLAGS = {
    'CFLAGS'   => $ARGV[0],
    'CPPFLAGS' => $ARGV[1],
    'LDDFLAGS' => $ARGV[2],
    'CXXFLAGS' => $ARGV[3],
};

sub clean_and_deduplicate {
    my $arg          = shift;
    my $return_flags = "";
    my @flags        = split( /\s+/, $arg );
    my %seen         = ();
    my @flags        = grep { !$seen{$_}++ } @flags;
    foreach my $flag (@flags) {

        #print("FLAG: $flag\n");
        $return_flags .= "$flag "
          unless $flag =~ m/PLATFORM/
          || $flag =~ m/-DBUILD_DATETIME/
          || $flag =~ m/-fdebug-prefix-map/
          || $flag =~ m/-ffile-prefix-map/;
    }
    return $return_flags;
}

chdir("debian/tmp/usr/share/apache2/build/") || die("$1");

open( CONFIG_VARS,     "<", "config_vars.mk" ) || die("config_vars.mk: $!");
open( TMP_CONFIG_VARS, ">", "tmp_config_vars.mk" )
  || die("tmp_config_vars.mk: $1");

while ( my $line = <CONFIG_VARS> ) {
    chomp $line;
    unless ( $line =~ m/(^|_)(LD|CPP|C|CXX)FLAGS/ ) {
        print TMP_CONFIG_VARS "$line\n";
    }
    else {
        my ( $flag, $value ) = split( /\s*=\s*/, $line, 2 );
        if ( exists $FLAGS{$flag} ) {
            $value .= ' ' . $FLAGS{$flag};
        }
        my $mangled = clean_and_deduplicate($value);
        print "mangle: $flag: '$value' => '$mangled'\n";
        printf TMP_CONFIG_VARS "%s = %s\n", $flag, $mangled;
    }
}

close(CONFIG_VARS);
close(TMP_CONFIG_VARS);

unlink("config_vars.mk") || die("unlink: config_vars.mk: $1");
rename( "tmp_config_vars.mk", "config_vars.mk" )
  || die("rename: tmp_config_vars.mk: $1");