Fix malloc.c warning
[perl.git] / Cross / generate_config_sh
1 #!/usr/bin/perl
2
3 ##############################################################################
4 #
5 #       generate_config_sh
6 #               Process that takes an automatically generated config.sh
7 #               file and allows the environment to overload the values
8 #               automatically discovered by Configure on our target platform.
9 #
10 #       Author  Redvers Davies <red@criticalintegration.com>
11 #
12 ##############################################################################
13
14 my $config = shift;
15
16 my $sys = $ENV{SYS};
17
18 my $callbacks = {};
19 $callbacks->{'ar'} = [\&simple_process, ["AR", "arm-linux-ar"]];
20 $callbacks->{'archname'} = [\&simple_process, ["SYS", "armv4l-linux"]];
21 $callbacks->{'cc'} = [\&simple_process, ["CC", "arm-linux-gcc"]];
22 $callbacks->{'cccdlflags'} = [\&simple_process, ["CFLAGS", ""]];
23 $callbacks->{'ccdlflags'} = [\&simple_process, ["CFLAGS", ""]];
24 $callbacks->{'ccflags'} = [\&simple_process, ["CFLAGS", "-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"]];
25 $callbacks->{'ccflags_uselargefiles'} = [\&simple_process, ["CFLAGS", "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"]];
26 $callbacks->{'ccname'} = [\&simple_process, ["CC", "arm-linux-gcc"]];
27 $callbacks->{'cpp'} = [\&simple_process, ["CCP", "arm-linux-cpp"]];
28 $callbacks->{'cppflags'} = [\&simple_process, ["CCPFLAGS", "-fno-strict-aliasing"]];
29 $callbacks->{'cpprun'} = [\&simple_process_append, ["CC", "arm-linux-gcc -E", "-E"]];
30 $callbacks->{'cppstdin'} = [\&simple_process_append, ["CC", "arm-linux-gcc -E", "-E"]];
31 $callbacks->{'full_ar'} = [\&backtick, ["AR", "which $ENV{AR}", "/usr/local/arm/2.95.3/bin/arm-linux-ar"]];
32 $callbacks->{'ld'} = [\&simple_process, ["LD", "arm-linux-ld"]];
33 $callbacks->{'ldflags'} = [\&simple_process, ["LDFLAGS", ""]];
34 $callbacks->{'ldflags_uselargefiles'} = [\&simple_process, ["LDFLAGS", ""]];
35 $callbacks->{'myarchname'} = [\&simple_process, ["SYS", "armv4l-linux"]];
36 $callbacks->{'archlib'} = [\&library_munge, ["SYS", "armv4l-linux"]];
37 $callbacks->{'archlibexp'} = [\&library_munge, ["SYS", "armv4l-linux"]];
38 $callbacks->{'installarchlib'} = [\&library_munge, ["SYS", "armv4l-linux"]];
39 $callbacks->{'installsitearch'} = [\&library_munge, ["SYS", "armv4l-linux"]];
40 $callbacks->{'sitearch'} = [\&library_munge, ["SYS", "armv4l-linux"]];
41 $callbacks->{'sitearchexp'} = [\&library_munge, ["SYS", "armv4l-linux"]];
42
43 if ($config eq "") {
44         die("Please run me as generate_config_sh path/to/original/config.sh");
45 }
46
47 open(FILE, "$config") || die("Unable to open $config");
48
49 my $line_in;
50 while ($line_in = <FILE>) {
51         if ($line_in =~ /^#/) {
52                 next;
53         }
54
55         if ($line_in !~ /./) {
56                 next;
57         }
58
59         $line_in =~ /^([^=]+)=(.*)/;
60         my $key = $1;
61         my $value = $2;
62         if (ref($callbacks->{$key}) eq "ARRAY") {
63                 ($callbacks->{$key}[0])->($key,$value);
64         } else {
65                 print($line_in);
66         }
67 }
68
69 sub backtick {
70         my $key = shift;
71         my $value = shift;
72         my $envvar = $callbacks->{$key}->[1][0];
73
74         if ($ENV{$envvar}) {
75                 my $rawtext = `$callbacks->{$key}->[1][1]`;
76                 chomp($rawtext);
77                 print("$key=\'$rawtext\'\n");
78         } else {
79                 print("$key=\'$callbacks->{$key}->[1][2]\'\n");
80         }
81 }
82         
83
84 sub simple_process {
85         my $key = shift;
86         my $envvar = $callbacks->{$key}->[1][0];
87
88         if ($ENV{$envvar}) {
89                 print("$key=\"$ENV{$envvar}\"\n");
90         } else {
91                 print("$key=\'$callbacks->{$key}->[1][1]\'\n");
92         }
93
94 }
95
96 sub simple_process_append {
97         my $key = shift;
98         my $envvar = $callbacks->{$key}->[1][0];
99
100         if ($ENV{$envvar}) {
101                 print("$key=\"$ENV{$envvar} $callbacks->{$key}->[1][2]\"\n");
102         } else {
103                 print("$key=\'$callbacks->{$key}->[1][1]\'\n");
104         }
105
106 }
107
108 sub library_munge {
109         my $key = shift;
110         my $value = shift;
111         my $envvar = $callbacks->{$key}->[1][0];
112
113         if ($ENV{$envvar}) {
114                 $value =~ s/$callbacks->{$key}->[1][1]/$ENV{$envvar}/g;
115                 print("$key=$value\n");
116         } else {
117                 print("$key=$value\n");
118         }
119                 
120 }
121
122
123
124
125
126
127
128
129
130
131
132