perl5.000 patch.0k: MakeMaker 4.06 and to fix minor portability and build problems...
[p5sagit/p5-mst-13.2.git] / makeaperl
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 makeaperl - create a new perl binary from static extensions
6
7 =head1 SYNOPSIS
8
9 C<makeaperl -l library -m makefile -o target -t tempdir [object_files] [static_extensions] [search_directories]>
10
11 =head1 DESCRIPTION
12
13 This utility is designed to build new perl binaries from existing
14 extensions on the fly. Called without any arguments it produces a new
15 binary with the name C<perl> in the current directory. Intermediate
16 files are produced in C</tmp>, if that is writeable, else in the
17 current directory. The most important intermediate file is a Makefile,
18 that is used internally to call C<make>. The new perl binary will consist
19
20 The C<-l> switch lets you specify the name of a perl library to be
21 linked into the new binary. If you do not specify a library, makeaperl
22 writes targets for any C<libperl*.a> it finds in the search path. The
23 topmost target will be the one related to C<libperl.a>.
24
25 With the C<-m> switch you can provide a name for the Makefile that
26 will be written (default C</tmp/Makefile.$$>). Likewise specifies the
27 C<-o> switch a name for the perl binary (default C<perl>). The C<-t>
28 switch lets you determine, in which directory the intermediate files
29 should be stored.
30
31 All object files and static extensions following on the command line
32 will be linked into the target file. If there are any directories
33 specified on the command line, these directories are searched for
34 C<*.a> files, and all of the found ones will be linked in, too. If
35 there is no directory named, then the contents of $INC[0] are
36 searched.
37
38 If the command fails, there is currently no other mechanism to adjust
39 the behaviour of the program than to alter the generated Makefile and
40 run C<make> by hand.
41
42 =head1 AUTHORS
43 Tim Bunce <Tim.Bunce@ig.co.uk>, Andreas Koenig
44 <koenig@franz.ww.TU-Berlin.DE>; 
45
46 =head2 STATUS
47 First version, written 5 Feb 1995, is considered alpha.
48
49 =cut
50
51 use ExtUtils::MakeMaker;
52 use Getopt::Long;
53 use strict qw(subs refs);
54
55 $Version = 1.0;
56 $Verbose = 0;
57
58 sub usage{
59     warn <<END;
60 $0 version $Version
61
62 $0: [options] [object_files] [static_extensions ...] [directories to search through]
63  -l perllibrary     perl library to link from (the first libperl.a found)
64  -m makefilename    name of the makefile to be written (/tmp/Makefile.$$)
65  -o name            name for perl executable (perl)
66  -t directory       directory where intermediate files reside (/tmp)
67 END
68     exit 1;
69 }
70
71 if (-w "/tmp") {
72     $opt_t = "/tmp";
73 } else {
74     $opt_t = ".";
75 }
76 $opt_l = '';
77 $opt_m = "$opt_t/Makefile.$$";
78 $opt_o = 'perl';
79
80 $Getopt::Long::ignorecase=0;
81
82 GetOptions('t=s', 'l=s', 'm=s', 'o=s') || die &usage;
83
84 @dirs = grep -d $_, @ARGV;
85 @fils = grep -f $_, @ARGV;
86
87 @dirs = $INC[0] unless @dirs;
88
89 open MAKE, ">$opt_m";
90 MM->init_main();
91 MM->init_others();
92 print MAKE MM->makeaperl('MAKE'    => $opt_m,
93                          'TARGET'  => $opt_o,
94                          'TMP'     => $opt_t,
95                          'LIBPERL' => $opt_l,
96                          'DIRS'    => [@dirs], 
97                          'STAT'    => [@fils], 
98                          'INCL'    => [@dirs]
99 );
100 close MAKE;
101 (system "make -f $opt_m") == 0 or die "$0 failed: Please check file $opt_m and run make -f $opt_m\n";