Commit | Line | Data |
---|---|---|
5aabfad6 | 1 | # |
2 | ||
3 | # Perl script be a wrapper around the gnu gcc. the exportable perl.exe | |
4 | # is built, special processing is done. | |
5 | # This script is caled by the gcc2 shell script when the flag | |
6 | # -buildperl is passed to gcc2 | |
7 | ||
8 | print "perlgcc: building exportable perl...\n"; | |
9 | ||
10 | # get all libs: | |
11 | my @libobs; | |
12 | my @obs; | |
13 | my @libFlags; | |
14 | my $libstring; | |
15 | foreach (@ARGV){ | |
16 | if( /\.[a]$/){ | |
17 | push @libobs,$_; | |
18 | } | |
19 | elsif(/^\-l/){ | |
20 | push @libFlags,$_; | |
21 | } | |
22 | if( /\.[o]$/){ | |
23 | push @obs,$_; | |
24 | } | |
25 | } | |
26 | $libstring = join(" ",@libobs); | |
27 | $obsString = join(" ",@obs); | |
28 | $libflagString = join(" ",@libFlags); | |
29 | ||
30 | # make exports file | |
31 | my $command = "echo EXPORTS > perl.def"; | |
32 | print "$command\n"; | |
e9cb6d14 | 33 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 34 | |
35 | $command ="nm $libstring | grep '^........ [TCD] _'| grep -v _impure_ptr | sed 's/[^_]*_//' >> perl.def"; | |
36 | print "$command\n"; | |
e9cb6d14 | 37 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 38 | |
39 | # Build the perl.a lib to link to: | |
40 | $command ="dlltool --as=as --dllname perl.exe --def perl.def --output-lib perl.a"; | |
41 | print "$command\n"; | |
e9cb6d14 | 42 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 43 | |
44 | # change name of export lib to libperlexp so that is can be understood by ld2/perlld | |
45 | $command ="mv perl.a libperlexp.a"; | |
46 | print "$command\n"; | |
e9cb6d14 | 47 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 48 | |
49 | # get the full path name of a few libs: | |
50 | my $crt0 = `gcc -print-file-name=crt0.o`; | |
51 | chomp $crt0; | |
52 | my $libdir = `gcc -print-file-name=libcygwin.a`; | |
53 | chomp $libdir; | |
54 | $libdir =~ s/libcygwin\.a//g; | |
55 | ||
e9cb6d14 BZ |
56 | # when $crt0 and $libdir get used in the system calls below, the \'s |
57 | # from the gcc -print-file-name get used to create special characters, | |
58 | # such as \n, \t. Replace the \'s with /'s so that this does not | |
59 | # happen: | |
60 | $crt0 =~ s:\\:/:g; | |
61 | $libdir =~ s:\\:/:g; | |
62 | ||
5aabfad6 | 63 | # Link exe: |
64 | $command = "ld --base-file perl.base -o perl.exe $crt0 $obsString $libstring -L$libdir $libflagString"; | |
65 | print "$command\n"; | |
e9cb6d14 | 66 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 67 | |
68 | $command = "dlltool --as=as --dllname perl.exe --def perl.def --base-file perl.base --output-exp perl.exp"; | |
69 | print "$command\n"; | |
e9cb6d14 | 70 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 71 | |
72 | $command = "ld --base-file perl.base perl.exp -o perl.exe $crt0 $obsString $libstring -L$libdir $libflagString"; | |
73 | print "$command\n"; | |
e9cb6d14 | 74 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 75 | |
76 | $command = "dlltool --as=as --dllname perl.exe --def perl.def --base-file perl.base --output-exp perl.exp"; | |
77 | print "$command\n"; | |
e9cb6d14 | 78 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 79 | |
80 | $command = "ld perl.exp -o perl.exe $crt0 $obsString $libstring -L$libdir $libflagString"; | |
81 | print "$command\n"; | |
e9cb6d14 | 82 | system($command) == 0 or die "system() failed.\n"; |
5aabfad6 | 83 | |
84 | print "perlgcc: Completed\n"; |