6 # This script acts as a simple interface for building extensions.
7 # It primarily used by the perl Makefile:
9 # d_dummy $(dynamic_ext): miniperl preplibrary FORCE
10 # @$(RUN) ./miniperl make_ext.pl --target=dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
12 # It may be deleted in a later release of perl so try to
13 # avoid using it for other purposes.
15 my (%excl, %incl, %opts, @extspec, @passthrough);
20 } elsif (/^\+(.*)$/) {
22 } elsif (/^--([\w\-]+)$/) {
24 } elsif (/^--([\w\-]+)=(.*)$/) {
26 } elsif (/^--([\w\-]+)=(.*)$/) {
29 push @passthrough, $_;
35 my $target = $opts{target};
36 my $extspec = $extspec[0];
37 my $makecmd = shift @passthrough; # Should be something like MAKE=make
38 my $passthru = join ' ', @passthrough; # allow extra macro=value to be passed through
41 # Previously, $make was taken from config.sh. However, the user might
42 # instead be running a possibly incompatible make. This might happen if
43 # the user types "gmake" instead of a plain "make", for example. The
44 # correct current value of MAKE will come through from the main perl
45 # makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in
46 # case third party users of this script (are there any?) don't have the
47 # MAKE=$(MAKE) argument, which was added after 5.004_03.
49 if (defined($makecmd) and $makecmd =~ /^MAKE=(.*)$/) {
53 print "ext/util/make_ext: WARNING: Please include MAKE=\$(MAKE)\n";
54 print "\tin your call to make_ext. See ext/util/make_ext for details.\n";
58 # fallback to config.sh's MAKE
59 $make ||= $Config{make} || $ENV{MAKE};
60 my $run = $Config{run};
61 $run = '' if not defined $run;
62 $run .= ' ' if $run ne '';;
64 if (!defined($extspec) or $extspec eq '') {
65 print "make_ext: no extension specified\n";
69 # The Perl Makefile.SH will expand all extensions to
70 # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested)
71 # A user wishing to run make_ext might use
72 # X (or X/Y or X::Y if nested)
74 # canonise into X/Y form (pname)
77 if ($extspec =~ /^lib/) {
78 # Remove lib/auto prefix and /*.* suffix
79 $pname =~ s{^lib/auto/}{};
80 $pname =~ s{[^/]*\.[^/]*$}{};
82 elsif ($extspec =~ /^ext/) {
83 # Remove ext/ prefix and /pm_to_blib suffix
85 $pname =~ s{/pm_to_blib$}{};
87 elsif ($extspec =~ /::/) {
91 elsif ($extspec =~ /\..*o$/) {
98 $depth =~ s![^/]+!..!g;
99 my $makefile = "Makefile";
103 if (not -d "ext/$pname") {
104 print "\tSkipping $extspec (directory does not exist)\n";
105 exit(0); # not an error ?
108 if ($Config{osname} eq 'catamount') {
109 # Snowball's chance of building extensions.
110 print "This is $Config{osname}, not building $mname, sorry.\n";
114 print "\tMaking $mname ($target)\n";
118 # check link type and do any preliminaries. Valid link types are
119 # 'dynamic', 'static', and 'static_pic' (the last one respects
120 # CCCDLFLAGS such as -fPIC -- see static_target in the main Makefile.SH)
121 if ($target eq 'dynamic') {
122 $makeargs = "LINKTYPE=dynamic";
125 elsif ($target eq 'static') {
126 $makeargs = "LINKTYPE=static CCCDLFLAGS=";
129 elsif ($target eq 'static_pic') {
130 $makeargs = "LINKTYPE=static";
133 elsif ($target eq 'nonxs') {
137 elsif ($target =~ /clean$/) {
138 # If Makefile has been moved to Makefile.old by a make clean
139 # then use Makefile.old for realclean rather than rebuild it
140 if (! -f $makefile and -f "Makefile.old") {
141 $makefile = "Makefile.old";
142 $makeopts = "-f $makefile";
143 print "Note: Using Makefile.old\n";
146 elsif ($target eq '') {
147 print "make_ext: no make target specified (eg static or dynamic)\n";
151 # for the time being we are strict about what make_ext is used for
152 print "make_ext: unknown make target '$target'\n";
157 if (not -f $makefile) {
158 if (-f "Makefile.PL") {
159 my $cross = $opts{cross} ? ' -MCross' : '';
160 system("${run}../$depth/miniperl -I../$depth/lib$cross Makefile.PL INSTALLDIRS=perl INSTALLMAN3DIR=none PERL_CORE=1 $passthru");
162 # Right. The reason for this little hack is that we're sitting inside
163 # a program run by ./miniperl, but there are tasks we need to perform
164 # when the 'realclean', 'distclean' or 'veryclean' targets are run.
165 # Unfortunately, they can be run *after* 'clean', which deletes
167 # So we do our best to leave a set of instructions identical to what
168 # we would do if we are run directly as 'realclean' etc
169 # Whilst we're perfect, unfortunately the targets we call are not, as
170 # some of them rely on a $(PERL) for their own distclean targets.
171 # But this always used to be a problem with the old /bin/sh version of
174 foreach my $clean_target ('realclean', 'veryclean') {
175 my $file = "../$depth/$clean_target$suffix";
176 open my $fh, '>>', $file or die "open $file: $!";
177 # Quite possible that we're being run in parallel here.
178 # Can't use Fcntl this early to get the LOCK_EX
179 flock $fh, 2 or warn "flock $file: $!";
182 } elsif ($^O eq 'MSWin32') {
183 # Might not need anything here.
187 if test ! -f $makefile -a -f Makefile.old; then
188 echo "Note: Using Makefile.old"
189 make -f Makefile.old $clean_target MAKE=$make $passthru
191 if test ! -f $makefile ; then
192 echo "Warning: No Makefile!"
194 make $clean_target MAKE=$make $passthru
199 close $fh or die "close $file: $!";
203 if (not -f $makefile) {
204 print "Warning: No Makefile!\n";
207 if ($target eq 'clean') {
209 elsif ($target eq 'realclean') {
212 # Give makefile an opportunity to rewrite itself.
213 # reassure users that life goes on...
214 system( "$run$make config MAKE=$make $passthru" )
215 and print "$make config failed, continuing anyway...\n";
219 "$run$make $target MAKE=$make $makeargs $passthru"