chiark / gitweb /
switch tools and volume_id from LGPL to GPLv2
[elogind.git] / klibc / makeklcc.pl
1 #!/usr/bin/perl
2 #
3 # Combine klibc.config, klcc.in to produce a klcc script
4 #
5 # Usage: makeklcc klcc.in klibc.config perlpath
6 #
7
8 use File::Spec;
9
10 ($klccin, $klibcconf, $perlpath) = @ARGV;
11
12 sub pathsearch($) {
13     my($file) = @_;
14     my(@path);
15     my($p,$pp);
16
17     if ( $file =~ /\// ) {
18         return File::Spec->rel2abs($file);
19     }
20     
21     foreach $p ( split(/\:/, $ENV{'PATH'}) ) {
22         $pp = File::Spec->rel2abs(File::Spec->catpath(undef, $p, $file));
23         return $pp if ( -x $pp );
24     }
25
26     return undef;
27 }
28
29 print "#!${perlpath}\n";
30
31 open(KLIBCCONF, '<', $klibcconf) or die "$0: cannot open $klibcconf: $!\n";
32 while ( defined($l = <KLIBCCONF>) ) {
33     chomp $l;
34     if ( $l =~ /^([^=]+)\=(.*)$/ ) {
35         $n = $1;  $s = $2;
36
37         if ( $n eq 'CC' || $n eq 'LD' || $n eq 'STRIP' ) {
38             $s1 = pathsearch($s);
39             die "$0: Cannot find $n: $s\n" unless ( defined($s1) );
40             $s = $s1;
41         }
42
43         print "\$$n = \"\Q$s\E\";\n";
44         print "\@$n = qw($s);\n";
45         print "\$conf{\'\L$n\E\'} = \\\$$n;\n";
46     }
47 }
48 close(KLIBCCONF);
49
50 open(KLCCIN, '<', $klccin) or die "$0: cannot open $klccin: $!\n";
51 while ( defined($l = <KLCCIN>) ) {
52     print $l;
53 }
54 close(KLCCIN);
55