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