File: makeklcc.pl

package info (click to toggle)
klibc 2.0.4-9
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,512 kB
  • sloc: ansic: 48,305; asm: 2,578; perl: 797; makefile: 200; sh: 191
file content (63 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download | duplicates (9)
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
#!/usr/bin/perl
#
# Combine klibc.config, klcc.in to produce a klcc script
#
# Usage: makeklcc klcc.in klibc.config perlpath
#

use File::Spec;

($klccin, $klibcconf, $perlpath) = @ARGV;

sub pathsearch($) {
    my($file) = @_;
    my(@path);
    my($p,$pp);

    if ( $file =~ /\// ) {
	return File::Spec->rel2abs($file);
    }

    foreach $p ( split(/\:/, $ENV{'PATH'}) ) {
	$pp = File::Spec->rel2abs(File::Spec->catpath(undef, $p, $file));
	return $pp if ( -x $pp );
    }

    return undef;
}

print "#!${perlpath}\n";

open(KLIBCCONF, "< $klibcconf\0")
    or die "$0: cannot open $klibcconf: $!\n";
while ( defined($l = <KLIBCCONF>) ) {
    chomp $l;
    if ( $l =~ /^([^=]+)\=\s*(.*)$/ ) {
	$n = $1;  $s = $2;

	if ( $n eq 'CC' || $n eq 'LD' || $n eq 'STRIP' ) {
	    $s1 = pathsearch($s);
	    die "$0: Cannot find $n: $s\n" unless ( defined($s1) );
	    $s = $s1;
	}

	print "\$$n = \"\Q$s\E\";\n";
	print "\$conf{\'\L$n\E\'} = \\\$$n;\n";

	print "\@$n = ("; $sep = '';
	while ( $s =~ /^\s*(\S+)/ ) {
	    print $sep, "\"\Q$1\E\"";
	    $sep = ', ';
	    $s = "$'";
	}
	print ");\n";
    }
}
close(KLIBCCONF);

open(KLCCIN, "< $klccin\0")
or die "$0: cannot open $klccin: $!\n";
while ( defined($l = <KLCCIN>) ) {
    print $l;
}
close(KLCCIN);