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