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";
101 if (not -d "ext/$pname") {
102 print "\tSkipping $extspec (directory does not exist)\n";
103 exit(0); # not an error ?
106 if ($Config{osname} eq 'catamount') {
107 # Snowball's chance of building extensions.
108 print "This is $Config{osname}, not building $mname, sorry.\n";
112 print "\tMaking $mname ($target)\n";
116 # check link type and do any preliminaries. Valid link types are
117 # 'dynamic', 'static', and 'static_pic' (the last one respects
118 # CCCDLFLAGS such as -fPIC -- see static_target in the main Makefile.SH)
119 if ($target eq 'dynamic') {
120 $passthru = "LINKTYPE=dynamic $passthru";
123 elsif ($target eq 'static') {
124 $passthru = "LINKTYPE=static CCCDLFLAGS= $passthru";
127 elsif ($target eq 'static_pic') {
128 $passthru = "LINKTYPE=static $passthru";
131 elsif ($target eq 'nonxs') {
134 elsif ($target =~ /clean$/) {
136 elsif ($target eq '') {
137 print "make_ext: no make target specified (eg static or dynamic)\n";
141 # for the time being we are strict about what make_ext is used for
142 print "make_ext: unknown make target '$target'\n";
147 if (not -f $makefile) {
148 if (-f "Makefile.PL") {
149 my $cross = $opts{cross} ? ' -MCross' : '';
150 system("${run}../$depth/miniperl -I../$depth/lib$cross Makefile.PL INSTALLDIRS=perl INSTALLMAN3DIR=none PERL_CORE=1 $passthru");
152 # Right. The reason for this little hack is that we're sitting inside
153 # a program run by ./miniperl, but there are tasks we need to perform
154 # when the 'realclean', 'distclean' or 'veryclean' targets are run.
155 # Unfortunately, they can be run *after* 'clean', which deletes
157 # So we do our best to leave a set of instructions identical to what
158 # we would do if we are run directly as 'realclean' etc
159 # Whilst we're perfect, unfortunately the targets we call are not, as
160 # some of them rely on a $(PERL) for their own distclean targets.
161 # But this always used to be a problem with the old /bin/sh version of
164 foreach my $clean_target ('realclean', 'veryclean') {
165 my $file = "../$depth/$clean_target$suffix";
166 open my $fh, '>>', $file or die "open $file: $!";
167 # Quite possible that we're being run in parallel here.
168 # Can't use Fcntl this early to get the LOCK_EX
169 flock $fh, 2 or warn "flock $file: $!";
172 } elsif ($^O eq 'MSWin32') {
173 # Might not need anything here.
177 if test ! -f $makefile -a -f Makefile.old; then
178 echo "Note: Using Makefile.old"
179 make -f Makefile.old $clean_target MAKE=$make $passthru
181 if test ! -f $makefile ; then
182 echo "Warning: No Makefile!"
184 make $clean_target MAKE=$make $passthru
189 close $fh or die "close $file: $!";
193 if (not -f $makefile) {
194 print "Warning: No Makefile!\n";
197 if ($target eq 'clean') {
199 elsif ($target eq 'realclean') {
202 # Give makefile an opportunity to rewrite itself.
203 # reassure users that life goes on...
204 system( "$run$make config MAKE=$make $passthru" )
205 and print "$make config failed, continuing anyway...\n";
208 system "$run$make $target MAKE=$make $passthru" and exit $?;