Commit | Line | Data |
7e050124 |
1 | =head1 NAME |
2 | |
3 | buildext.pl - build extensions |
4 | |
5 | =head1 SYNOPSIS |
6 | |
a24cc0c0 |
7 | buildext.pl make [-make_opts] dep directory [target] [--static|--dynamic] +ext2 !ext1 |
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 | |
a24cc0c0 |
22 | If any extensions are listed with a '+' char then only those |
23 | extensions will be built, but only if they arent countermanded |
24 | by an '!ext' and are appropriate to the type of building being done. |
25 | |
d2b25974 |
26 | If '--static' specified, only static extensions will be built. |
27 | If '--dynamic' specified, only dynamic extensions will be built. |
28 | |
7e050124 |
29 | =cut |
30 | |
17af6fb0 |
31 | use Cwd; |
8e232993 |
32 | use FindExt; |
d2b25974 |
33 | use Config; |
fefd7080 |
34 | |
35 | # @ARGV with '!' at first position are exclusions |
a24cc0c0 |
36 | # @ARGV with '+' at first position are inclusions |
4feb7f09 |
37 | # -- are long options. |
38 | |
39 | my %excl, %incl, |
40 | my @argv; |
41 | |
42 | foreach (@ARGV) { |
43 | if (/^!(.*)$/) { |
44 | $excl{$1} = 1; |
45 | } elsif (/^\+(.*)$/) { |
46 | $incl{$1} = 1; |
47 | } elsif (/^--([\w\-]+)$/) { |
48 | $opts{$1} = 1; |
49 | } else { |
50 | push @argv, $_; |
51 | } |
d2b25974 |
52 | } |
d2b25974 |
53 | |
4feb7f09 |
54 | my $static = $opts{static}; |
55 | my $dynamic = $opts{dynamic}; |
56 | |
57 | $static = $dynamic = 1 unless $static or $dynamic; |
58 | |
8ed969f8 |
59 | my $makecmd = shift @argv; |
4feb7f09 |
60 | my $dep = shift @argv; |
61 | my $dir = shift @argv; |
62 | my $targ = shift @argv; |
63 | |
8ed969f8 |
64 | my $make; |
65 | if (defined($makecmd) and $makecmd =~ /^MAKE=(.*)$/) { |
66 | $make = $1; |
67 | } |
68 | else { |
69 | print "ext/util/make_ext: WARNING: Please include MAKE=\$(MAKE)\n"; |
70 | print "\tin your call to make_ext. See ext/util/make_ext for details.\n"; |
71 | exit(1); |
72 | } |
73 | |
74 | |
a1f2e719 |
75 | (my $here = getcwd()) =~ s{/}{\\}g; |
17af6fb0 |
76 | my $perl = $^X; |
a1f2e719 |
77 | if ($perl =~ m#^\.\.#) { |
78 | $perl = "$here\\$perl"; |
79 | } |
200dcf2d |
80 | (my $topdir = $perl) =~ s/\\[^\\]+$//; |
3a7016a8 |
81 | # miniperl needs to find perlglob and pl2bat |
82 | $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}"; |
3a7016a8 |
83 | my $pl2bat = "$topdir\\win32\\bin\\pl2bat"; |
84 | unless (-f "$pl2bat.bat") { |
85 | my @args = ($perl, ("$pl2bat.pl") x 2); |
86 | print "@args\n"; |
fefd7080 |
87 | system(@args) unless defined $::Cross::platform; |
3a7016a8 |
88 | } |
4feb7f09 |
89 | |
17af6fb0 |
90 | my $dmod = -M $dep; |
17af6fb0 |
91 | chdir($dir) || die "Cannot cd to $dir\n"; |
a1f2e719 |
92 | (my $ext = getcwd()) =~ s{/}{\\}g; |
fefd7080 |
93 | my $code; |
8e232993 |
94 | FindExt::scan_ext($ext); |
3fd041e4 |
95 | FindExt::set_static_extensions(split ' ', $Config{static_ext}) if $ext ne "ext"; |
17af6fb0 |
96 | |
3fd041e4 |
97 | my @ext; |
98 | push @ext, FindExt::static_ext() if $static; |
99 | push @ext, FindExt::dynamic_ext(), FindExt::nonxs_ext() if $dynamic; |
8e232993 |
100 | |
a24cc0c0 |
101 | |
d2b25974 |
102 | foreach $dir (sort @ext) |
17af6fb0 |
103 | { |
a24cc0c0 |
104 | if (%incl and !exists $incl{$dir}) { |
105 | #warn "Skipping extension $ext\\$dir, not in inclusion list\n"; |
106 | next; |
107 | } |
fefd7080 |
108 | if (exists $excl{$dir}) { |
109 | warn "Skipping extension $ext\\$dir, not ported to current platform"; |
110 | next; |
111 | } |
17af6fb0 |
112 | if (chdir("$ext\\$dir")) |
113 | { |
114 | my $mmod = -M 'Makefile'; |
115 | if (!(-f 'Makefile') || $mmod > $dmod) |
116 | { |
0026721a |
117 | print "\nRunning Makefile.PL in $dir\n"; |
e7d8b26b |
118 | my @perl = ($perl, "-I$here\\..\\lib", 'Makefile.PL', |
d2b25974 |
119 | 'INSTALLDIRS=perl', 'PERL_CORE=1', |
3fd041e4 |
120 | (FindExt::is_static($dir) |
121 | ? ('LINKTYPE=static') : ()), # if ext is static |
d2b25974 |
122 | ); |
fefd7080 |
123 | if (defined $::Cross::platform) { |
124 | @perl = (@perl[0,1],"-MCross=$::Cross::platform",@perl[2..$#perl]); |
125 | } |
e7d8b26b |
126 | print join(' ', @perl), "\n"; |
fefd7080 |
127 | $code = system(@perl); |
d2b25974 |
128 | warn "$code from $dir\'s Makefile.PL" if $code; |
17af6fb0 |
129 | $mmod = -M 'Makefile'; |
130 | if ($mmod > $dmod) |
131 | { |
132 | warn "Makefile $mmod > $dmod ($dep)\n"; |
133 | } |
134 | } |
7e050124 |
135 | if ($targ) |
136 | { |
137 | print "Making $targ in $dir\n$make $targ\n"; |
fefd7080 |
138 | $code = system("$make $targ"); |
139 | die "Unsuccessful make($dir): code=$code" if $code!=0; |
7e050124 |
140 | } |
141 | else |
142 | { |
143 | print "Making $dir\n$make\n"; |
fefd7080 |
144 | $code = system($make); |
145 | die "Unsuccessful make($dir): code=$code" if $code!=0; |
7e050124 |
146 | } |
17af6fb0 |
147 | chdir($here) || die "Cannot cd to $here:$!"; |
148 | } |
149 | else |
150 | { |
151 | warn "Cannot cd to $ext\\$dir:$!"; |
152 | } |
153 | } |
154 | |