[asperl] integrate mainline changes
[p5sagit/p5-mst-13.2.git] / ext / util / make_ext
CommitLineData
75f92628 1#!/bin/sh
2
a0d0e21e 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
fb73857a 7# @sh ext/util/make_ext dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL)
a0d0e21e 8#
9# It may be deleted in a later release of perl so try to
10# avoid using it for other purposes.
11
42793c05 12target=$1; shift
13extspec=$1; shift
fb73857a 14makecmd=$1; shift # Should be something like MAKE=make
42793c05 15passthru="$*" # allow extra macro=value to be passed through
16echo ""
a0d0e21e 17
fb73857a 18# Previously, $make was taken from config.sh. However, the user might
19# instead be running a possibly incompatible make. This might happen if
20# the user types "gmake" instead of a plain "make", for example. The
21# correct current value of MAKE will come through from the main perl
22# makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in
23# case third party users of this script (are there any?) don't have the
24# MAKE=$(MAKE) argument, which was added after 5.004_03.
25case "$makecmd" in
26MAKE=*)
27 eval $makecmd
28 ;;
29*) echo 'ext/util/make_ext: WARNING: Please include MAKE=$(MAKE)'
30 echo ' in your call to make_ext. See ext/util/make_ext for details.'
31 exit 1
32 ;;
33esac
34
35
a0d0e21e 36case $CONFIG in
37'')
38 if test -f config.sh; then TOP=.;
39 elif test -f ../config.sh; then TOP=..;
40 elif test -f ../../config.sh; then TOP=../..;
41 elif test -f ../../../config.sh; then TOP=../../..;
42 elif test -f ../../../../config.sh; then TOP=../../../..;
43 else
44 echo "Can't find config.sh generated by Configure"; exit 1
45 fi
46 . $TOP/config.sh
47 ;;
48esac
49
50if test "X$extspec" = X; then
51 echo "make_ext: no extension specified"
52 exit 1;
53fi
54
75f92628 55# The Perl Makefile.SH will expand all extensions to
2698564b 56# lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested)
75f92628 57# A user wishing to run make_ext might use
2698564b 58# X (or X/Y or X::Y if nested)
75f92628 59
60# canonise into X/Y form (pname)
61case "$extspec" in
62lib*) # Remove lib/auto prefix and /*.* suffix
63 pname=`echo "$extspec" | sed -e 's:^lib/auto/::' -e 's:/[^/]*\.[^/]*$::' ` ;;
64*::*) # Convert :: to /
65 pname=`echo "$extspec" | sed -e 's/::/\//g' ` ;;
66*) pname="$extspec" ;;
67esac
68# echo "Converted $extspec to $pname"
a0d0e21e 69
e1666bf5 70mname=`echo "$pname" | sed -e 's!/!::!g'`
a0d0e21e 71depth=`echo "$pname" | sed -e 's![^/][^/]*!..!g'`
75f92628 72makefile=Makefile
42793c05 73makeargs=''
75f92628 74makeopts=''
a0d0e21e 75
76if test ! -d "ext/$pname"; then
42793c05 77 echo " Skipping $extspec (directory does not exist)"
78 exit 0 # not an error ?
a0d0e21e 79fi
80
a0d0e21e 81
42793c05 82echo " Making $mname ($target)"
a0d0e21e 83
84cd ext/$pname
85
42793c05 86# check link type and do any preliminaries
87case "$target" in
75f92628 88 # convert 'static' or 'dynamic' into 'all LINKTYPE=XXX'
89static) makeargs="LINKTYPE=static CCCDLFLAGS="
90 target=all
91 ;;
92dynamic) makeargs="LINKTYPE=dynamic";
93 target=all
94 ;;
95
96*clean) # If Makefile has been moved to Makefile.old by a make clean
97 # then use Makefile.old for realclean rather than rebuild it
98 if test ! -f $makefile -a -f Makefile.old; then
99 makefile=Makefile.old
100 makeopts="-f $makefile"
101 echo "Note: Using Makefile.old"
102 fi
103 ;;
104
42793c05 105*) # for the time being we are strict about what make_ext is used for
75f92628 106 echo "make_ext: unknown make target '$target'"; exit 1
107 ;;
108'') echo "make_ext: no make target specified (eg static or dynamic)"; exit 1
109 ;;
42793c05 110esac
111
75f92628 112if test ! -f $makefile ; then
76c7ba2e 113 test -f Makefile.PL && ../$depth/miniperl -I../$depth/lib Makefile.PL INSTALLDIRS=perl $passthru
a0d0e21e 114fi
75f92628 115if test ! -f $makefile ; then
116 if test -f Makefile.SH; then
117 echo "Warning: Writing $makefile from old-style Makefile.SH!"
118 sh Makefile.SH
119 else
120 echo "Warning: No Makefile!"
121 fi
a0d0e21e 122fi
123
42793c05 124case "$target" in
125clean) ;;
126realclean) ;;
75f92628 127*) # Give makefile an opportunity to rewrite itself.
128 # reassure users that life goes on...
fb73857a 129 $MAKE config $passthru || echo "$MAKE config failed, continuing anyway..."
75f92628 130 ;;
42793c05 131esac
a0d0e21e 132
fb73857a 133$MAKE $makeopts $target $makeargs $passthru || exit
a0d0e21e 134
135exit $?