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