This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add OpenZaurus cross-compilation patches.
[perl5.git] / Cross / generate_config_sh
CommitLineData
6a809565
JH
1#!/usr/bin/perl
2
3##############################################################################
4#
5# Ok, so there is this buildsystem that has variables set in shell
6# like this:
7#
8# cc='gcc'
9#
10# This means we can go
11#
12# if test "${CC+set}" != set; then
13# ar='arm-linux-ar'
14# else
15# ar=${AR}
16# fi
17#
18# Right??? WRONG!
19#
20# Damn perl installation *PARSES* and *PATTERN MATCHES* this file.
21#
22##############################################################################
23
24my $config = shift;
25
26my $sys = $ENV{SYS};
27
28my $callbacks = {};
29$callbacks->{'ar'} = [\&simple_process, ["AR", "arm-linux-ar"]];
30$callbacks->{'archname'} = [\&simple_process, ["SYS", "armv4l-linux"]];
31$callbacks->{'cc'} = [\&simple_process, ["CC", "arm-linux-gcc"]];
32$callbacks->{'cccdlflags'} = [\&simple_process, ["CFLAGS", ""]];
33$callbacks->{'ccdlflags'} = [\&simple_process, ["CFLAGS", ""]];
34$callbacks->{'ccflags'} = [\&simple_process, ["CFLAGS", "-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"]];
35$callbacks->{'ccflags_uselargefiles'} = [\&simple_process, ["CFLAGS", "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"]];
36$callbacks->{'ccname'} = [\&simple_process, ["CC", "arm-linux-gcc"]];
37$callbacks->{'cpp'} = [\&simple_process, ["CCP", "arm-linux-cpp"]];
38$callbacks->{'cppflags'} = [\&simple_process, ["CCPFLAGS", "-fno-strict-aliasing"]];
39$callbacks->{'cpprun'} = [\&simple_process_append, ["CC", "arm-linux-gcc -E", "-E"]];
40$callbacks->{'cppstdin'} = [\&simple_process_append, ["CC", "arm-linux-gcc -E", "-E"]];
41$callbacks->{'full_ar'} = [\&backtick, ["AR", "which $ENV{AR}", "/usr/local/arm/2.95.3/bin/arm-linux-ar"]];
42$callbacks->{'ld'} = [\&simple_process, ["LD", "arm-linux-ld"]];
43$callbacks->{'ldflags'} = [\&simple_process, ["LDFLAGS", ""]];
44$callbacks->{'ldflags_uselargefiles'} = [\&simple_process, ["LDFLAGS", ""]];
45$callbacks->{'myarchname'} = [\&simple_process, ["SYS", "armv4l-linux"]];
46$callbacks->{'archlib'} = [\&library_munge, ["SYS", "armv4l-linux"]];
47$callbacks->{'archlibexp'} = [\&library_munge, ["SYS", "armv4l-linux"]];
48$callbacks->{'installarchlib'} = [\&library_munge, ["SYS", "armv4l-linux"]];
49$callbacks->{'installsitearch'} = [\&library_munge, ["SYS", "armv4l-linux"]];
50$callbacks->{'sitearch'} = [\&library_munge, ["SYS", "armv4l-linux"]];
51$callbacks->{'sitearchexp'} = [\&library_munge, ["SYS", "armv4l-linux"]];
52
53if ($config eq "") {
54 die("Please run me as generate_config_sh path/to/original/config.sh");
55}
56
57open(FILE, "$config") || die("Unable to open $config");
58
59my $line_in;
60while ($line_in = <FILE>) {
61 if ($line_in =~ /^#/) {
62 next;
63 }
64
65 if ($line_in !~ /./) {
66 next;
67 }
68
69 $line_in =~ /^([^=]+)=(.*)/;
70 my $key = $1;
71 my $value = $2;
72 if (ref($callbacks->{$key}) eq "ARRAY") {
73 ($callbacks->{$key}[0])->($key,$value);
74 } else {
75 print($line_in);
76 }
77}
78
79sub backtick {
80 my $key = shift;
81 my $value = shift;
82 my $envvar = $callbacks->{$key}->[1][0];
83
84 if ($ENV{$envvar}) {
85 my $rawtext = `$callbacks->{$key}->[1][1]`;
86 chomp($rawtext);
87 print("$key=\'$rawtext\'\n");
88 } else {
89 print("$key=\'$callbacks->{$key}->[1][2]\'\n");
90 }
91}
92
93
94sub simple_process {
95 my $key = shift;
96 my $envvar = $callbacks->{$key}->[1][0];
97
98 if ($ENV{$envvar}) {
99 print("$key=\"$ENV{$envvar}\"\n");
100 } else {
101 print("$key=\'$callbacks->{$key}->[1][1]\'\n");
102 }
103
104}
105
106sub simple_process_append {
107 my $key = shift;
108 my $envvar = $callbacks->{$key}->[1][0];
109
110 if ($ENV{$envvar}) {
111 print("$key=\"$ENV{$envvar} $callbacks->{$key}->[1][2]\"\n");
112 } else {
113 print("$key=\'$callbacks->{$key}->[1][1]\'\n");
114 }
115
116}
117
118sub library_munge {
119 my $key = shift;
120 my $value = shift;
121 my $envvar = $callbacks->{$key}->[1][0];
122
123 if ($ENV{$envvar}) {
124 $value =~ s/$callbacks->{$key}->[1][1]/$ENV{$envvar}/g;
125 print("$key=$value\n");
126 } else {
127 print("$key=$value\n");
128 }
129
130}
131