summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/cygwin32/perlgcc
blob: 97d7d1a8a531c387f2e6bb9180e8f8328393f23e (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#

# Perl script be a wrapper around the gnu gcc. the exportable perl.exe
#   is built, special processing is done.
# This script is caled by the gcc2 shell script when the flag
#   -buildperl is passed to gcc2

print "perlgcc: building exportable perl...\n";

# get all libs:
my @libobs;
my @obs;
my @libFlags;
my $libstring;
foreach (@ARGV){
	if( /\.[a]$/){
		push @libobs,$_;
	}
	elsif(/^\-l/){
		push @libFlags,$_;
	}
	if( /\.[o]$/){
		push @obs,$_;
	}
}
$libstring = join(" ",@libobs);	
$obsString = join(" ",@obs);
$libflagString = join(" ",@libFlags);

# make exports file
my $command = "echo EXPORTS > perl.def";
print "$command\n";
system($command);

$command ="nm $libstring | grep '^........ [TCD] _'| grep -v _impure_ptr | sed 's/[^_]*_//' >> perl.def";
print "$command\n";
system($command);

# Build the perl.a lib to link to:
$command ="dlltool --as=as --dllname perl.exe --def perl.def --output-lib perl.a";
print "$command\n";
system($command); 

# change name of export lib to libperlexp so that is can be understood by ld2/perlld
$command ="mv perl.a libperlexp.a";  
print "$command\n";
system($command);

# get the full path name of a few libs:
my $crt0 = `gcc -print-file-name=crt0.o`;
chomp $crt0;
my $libdir = `gcc -print-file-name=libcygwin.a`;
chomp $libdir;
$libdir =~ s/libcygwin\.a//g;

# Link exe:
$command = "ld --base-file perl.base -o perl.exe $crt0 $obsString $libstring -L$libdir $libflagString";
print "$command\n";
system($command);

$command = "dlltool --as=as --dllname perl.exe --def perl.def --base-file perl.base --output-exp perl.exp";
print "$command\n";
system($command);

$command = "ld --base-file perl.base perl.exp -o perl.exe $crt0 $obsString $libstring -L$libdir $libflagString";
print "$command\n";
system($command);

$command = "dlltool --as=as --dllname perl.exe --def perl.def --base-file perl.base --output-exp perl.exp";
print "$command\n";
system($command);

$command = "ld perl.exp -o perl.exe $crt0 $obsString $libstring -L$libdir $libflagString";
print "$command\n";
system($command);

print "perlgcc: Completed\n";