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