Remove DOS line endings
[p5sagit/p5-mst-13.2.git] / win32 / buildext.pl
CommitLineData
7e050124 1=head1 NAME
2
3buildext.pl - build extensions
4
5=head1 SYNOPSIS
6
a24cc0c0 7 buildext.pl make [-make_opts] dep directory [target] [--static|--dynamic] +ext2 !ext1
7e050124 8
9E.g.
10
11 buildext.pl nmake -nologo perldll.def ..\ext
12
13 buildext.pl nmake -nologo perldll.def ..\ext clean
14
15 buildext.pl dmake perldll.def ..\ext
16
17 buildext.pl dmake perldll.def ..\ext clean
18
fefd7080 19Will skip building extensions which are marked with an '!' char.
20Mostly because they still not ported to specified platform.
21
a24cc0c0 22If any extensions are listed with a '+' char then only those
23extensions will be built, but only if they arent countermanded
24by an '!ext' and are appropriate to the type of building being done.
25
d2b25974 26If '--static' specified, only static extensions will be built.
27If '--dynamic' specified, only dynamic extensions will be built.
28
29--create-perllibst-h
30 creates perllibst.h file for inclusion from perllib.c
31--list-static-libs:
32 prints libraries for static linking and exits
33
7e050124 34=cut
35
17af6fb0 36use Cwd;
8e232993 37use FindExt;
d2b25974 38use Config;
fefd7080 39
40# @ARGV with '!' at first position are exclusions
41my %excl = map {$_=>1} map {/^!(.*)$/} @ARGV;
42@ARGV = grep {!/^!/} @ARGV;
a24cc0c0 43# @ARGV with '+' at first position are inclusions
44my %incl = map {$_=>1} map {/^\+(.*)$/} @ARGV;
45@ARGV = grep {!/^\+/} @ARGV;
fefd7080 46
d2b25974 47# --static/--dynamic
48my %opts = map {$_=>1} map {/^--([\w\-]+)$/} @ARGV;
49@ARGV = grep {!/^--([\w\-]+)$/} @ARGV;
50my ($static,$dynamic) = ((exists $opts{static}?1:0),(exists $opts{dynamic}?1:0));
51if ("$static,$dynamic" eq "0,0") {
52 ($static,$dynamic) = (1,1);
53}
54if ($opts{'list-static-libs'} || $opts{'create-perllibst-h'}) {
3fd041e4 55 my @statics = split /\s+/, $Config{static_ext};
d2b25974 56 if ($opts{'create-perllibst-h'}) {
a24cc0c0 57 open my $fh, ">perllibst.h"
58 or die "Failed to write to perllibst.h:$!";
d2b25974 59 my @statics1 = map {local $_=$_;s/\//__/g;$_} @statics;
60 my @statics2 = map {local $_=$_;s/\//::/g;$_} @statics;
61 print $fh "/*DO NOT EDIT\n this file is included from perllib.c to init static extensions */\n";
62 print $fh "#ifdef STATIC1\n",(map {" \"$_\",\n"} @statics),"#undef STATIC1\n#endif\n";
63 print $fh "#ifdef STATIC2\n",(map {" EXTERN_C void boot_$_ (pTHX_ CV* cv);\n"} @statics1),"#undef STATIC2\n#endif\n";
64 print $fh "#ifdef STATIC3\n",(map {" newXS(\"$statics2[$_]::bootstrap\", boot_$statics1[$_], file);\n"} 0 .. $#statics),"#undef STATIC3\n#endif\n";
a24cc0c0 65 close $fh;
d2b25974 66 }
67 else {
8bcd5811 68 my %extralibs;
69 for (@statics) {
70 open my $fh, "<..\\lib\\auto\\$_\\extralibs.ld" or die "can't open <..\\lib\\auto\\$_\\extralibs.ld: $!";
71 $extralibs{$_}++ for grep {/\S/} split /\s+/, join '', <$fh>;
72 }
9506093e 73 print map {s|/|\\|g;m|([^\\]+)$|;"..\\lib\\auto\\$_\\$1$Config{_a} "} @statics;
8bcd5811 74 print map {"$_ "} sort keys %extralibs;
d2b25974 75 }
a24cc0c0 76 exit(0);
d2b25974 77}
78
17af6fb0 79my $here = getcwd();
80my $perl = $^X;
81$here =~ s,/,\\,g;
82if ($perl =~ m#^\.\.#)
83 {
84 $perl = "$here\\$perl";
85 }
200dcf2d 86(my $topdir = $perl) =~ s/\\[^\\]+$//;
3a7016a8 87# miniperl needs to find perlglob and pl2bat
88$ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}";
200dcf2d 89#print "PATH=$ENV{PATH}\n";
3a7016a8 90my $pl2bat = "$topdir\\win32\\bin\\pl2bat";
91unless (-f "$pl2bat.bat") {
92 my @args = ($perl, ("$pl2bat.pl") x 2);
93 print "@args\n";
fefd7080 94 system(@args) unless defined $::Cross::platform;
3a7016a8 95}
17af6fb0 96my $make = shift;
f76dcffd 97$make .= " ".shift while $ARGV[0]=~/^-/;
17af6fb0 98my $dep = shift;
99my $dmod = -M $dep;
100my $dir = shift;
101chdir($dir) || die "Cannot cd to $dir\n";
7e050124 102my $targ = shift;
17af6fb0 103(my $ext = getcwd()) =~ s,/,\\,g;
fefd7080 104my $code;
8e232993 105FindExt::scan_ext($ext);
3fd041e4 106FindExt::set_static_extensions(split ' ', $Config{static_ext}) if $ext ne "ext";
17af6fb0 107
3fd041e4 108my @ext;
109push @ext, FindExt::static_ext() if $static;
110push @ext, FindExt::dynamic_ext(), FindExt::nonxs_ext() if $dynamic;
8e232993 111
a24cc0c0 112
d2b25974 113foreach $dir (sort @ext)
17af6fb0 114 {
a24cc0c0 115 if (%incl and !exists $incl{$dir}) {
116 #warn "Skipping extension $ext\\$dir, not in inclusion list\n";
117 next;
118 }
fefd7080 119 if (exists $excl{$dir}) {
120 warn "Skipping extension $ext\\$dir, not ported to current platform";
121 next;
122 }
17af6fb0 123 if (chdir("$ext\\$dir"))
124 {
125 my $mmod = -M 'Makefile';
126 if (!(-f 'Makefile') || $mmod > $dmod)
127 {
0026721a 128 print "\nRunning Makefile.PL in $dir\n";
e7d8b26b 129 my @perl = ($perl, "-I$here\\..\\lib", 'Makefile.PL',
d2b25974 130 'INSTALLDIRS=perl', 'PERL_CORE=1',
3fd041e4 131 (FindExt::is_static($dir)
132 ? ('LINKTYPE=static') : ()), # if ext is static
d2b25974 133 );
fefd7080 134 if (defined $::Cross::platform) {
135 @perl = (@perl[0,1],"-MCross=$::Cross::platform",@perl[2..$#perl]);
136 }
e7d8b26b 137 print join(' ', @perl), "\n";
fefd7080 138 $code = system(@perl);
d2b25974 139 warn "$code from $dir\'s Makefile.PL" if $code;
17af6fb0 140 $mmod = -M 'Makefile';
141 if ($mmod > $dmod)
142 {
143 warn "Makefile $mmod > $dmod ($dep)\n";
144 }
145 }
7e050124 146 if ($targ)
147 {
148 print "Making $targ in $dir\n$make $targ\n";
fefd7080 149 $code = system("$make $targ");
150 die "Unsuccessful make($dir): code=$code" if $code!=0;
7e050124 151 }
152 else
153 {
154 print "Making $dir\n$make\n";
fefd7080 155 $code = system($make);
156 die "Unsuccessful make($dir): code=$code" if $code!=0;
7e050124 157 }
17af6fb0 158 chdir($here) || die "Cannot cd to $here:$!";
159 }
160 else
161 {
162 warn "Cannot cd to $ext\\$dir:$!";
163 }
164 }
165