This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.000 patch.0l: MakeMaker 4.085 and upgrade Configure to dist3 PL 51.
[perl5.git] / ext / util / make_ext
CommitLineData
75f92628
AD
1#!/bin/sh
2
a0d0e21e
LW
3# This script acts as a simple interface for building extensions.
4# It primarily used by the perl Makefile:
5#
6# d_dummy $(dynamic_ext): miniperl preplibrary FORCE
7# ext/util/make_ext dynamic $@
8#
9# It may be deleted in a later release of perl so try to
10# avoid using it for other purposes.
11
42793c05
TB
12target=$1; shift
13extspec=$1; shift
14passthru="$*" # allow extra macro=value to be passed through
15echo ""
a0d0e21e
LW
16
17case $CONFIG in
18'')
19 if test -f config.sh; then TOP=.;
20 elif test -f ../config.sh; then TOP=..;
21 elif test -f ../../config.sh; then TOP=../..;
22 elif test -f ../../../config.sh; then TOP=../../..;
23 elif test -f ../../../../config.sh; then TOP=../../../..;
24 else
25 echo "Can't find config.sh generated by Configure"; exit 1
26 fi
27 . $TOP/config.sh
28 ;;
29esac
30
31if test "X$extspec" = X; then
32 echo "make_ext: no extension specified"
33 exit 1;
34fi
35
75f92628
AD
36# The Perl Makefile.SH will expand all extensions to
37# lib/auto/X/X.a (or lib/auto/X/Y/Y.a is nested)
38# A user wishing to run make_ext might use
39# X (or X/Y or X::Y is nested)
40
41# canonise into X/Y form (pname)
42case "$extspec" in
43lib*) # Remove lib/auto prefix and /*.* suffix
44 pname=`echo "$extspec" | sed -e 's:^lib/auto/::' -e 's:/[^/]*\.[^/]*$::' ` ;;
45*::*) # Convert :: to /
46 pname=`echo "$extspec" | sed -e 's/::/\//g' ` ;;
47*) pname="$extspec" ;;
48esac
49# echo "Converted $extspec to $pname"
a0d0e21e 50
e1666bf5 51mname=`echo "$pname" | sed -e 's!/!::!g'`
a0d0e21e 52depth=`echo "$pname" | sed -e 's![^/][^/]*!..!g'`
42793c05 53make=${altmake-make}
75f92628 54makefile=Makefile
42793c05 55makeargs=''
75f92628 56makeopts=''
a0d0e21e
LW
57
58if test ! -d "ext/$pname"; then
42793c05
TB
59 echo " Skipping $extspec (directory does not exist)"
60 exit 0 # not an error ?
a0d0e21e
LW
61fi
62
a0d0e21e 63
42793c05 64echo " Making $mname ($target)"
a0d0e21e
LW
65
66cd ext/$pname
67
42793c05
TB
68# check link type and do any preliminaries
69case "$target" in
75f92628
AD
70 # convert 'static' or 'dynamic' into 'all LINKTYPE=XXX'
71static) makeargs="LINKTYPE=static CCCDLFLAGS="
72 target=all
73 ;;
74dynamic) makeargs="LINKTYPE=dynamic";
75 target=all
76 ;;
77
78*clean) # If Makefile has been moved to Makefile.old by a make clean
79 # then use Makefile.old for realclean rather than rebuild it
80 if test ! -f $makefile -a -f Makefile.old; then
81 makefile=Makefile.old
82 makeopts="-f $makefile"
83 echo "Note: Using Makefile.old"
84 fi
85 ;;
86
42793c05 87*) # for the time being we are strict about what make_ext is used for
75f92628
AD
88 echo "make_ext: unknown make target '$target'"; exit 1
89 ;;
90'') echo "make_ext: no make target specified (eg static or dynamic)"; exit 1
91 ;;
42793c05
TB
92esac
93
75f92628 94if test ! -f $makefile ; then
40000a8c 95 test -f Makefile.PL && ../$depth/miniperl -I../$depth/lib Makefile.PL $passthru
a0d0e21e 96fi
75f92628
AD
97if test ! -f $makefile ; then
98 if test -f Makefile.SH; then
99 echo "Warning: Writing $makefile from old-style Makefile.SH!"
100 sh Makefile.SH
101 else
102 echo "Warning: No Makefile!"
103 fi
a0d0e21e
LW
104fi
105
42793c05
TB
106case "$target" in
107clean) ;;
108realclean) ;;
75f92628
AD
109*) # Give makefile an opportunity to rewrite itself.
110 # reassure users that life goes on...
111 $make config $passthru || echo "$make config failed, continuing anyway..."
112 ;;
42793c05 113esac
a0d0e21e 114
75f92628 115$make $makeopts $target $makeargs $passthru || exit
a0d0e21e
LW
116
117exit $?