f4a1b8884e00bfcb6ec753facee533a0149e2794
[p5sagit/p5-mst-13.2.git] / ext / util / make_ext
1 # This script acts as a simple interface for building extensions.
2 # It primarily used by the perl Makefile:
3 #
4 # d_dummy $(dynamic_ext): miniperl preplibrary FORCE
5 #        ext/util/make_ext dynamic $@
6 #
7 # It may be deleted in a later release of perl so try to
8 # avoid using it for other purposes.
9
10 target=$1;  shift
11 extspec=$1; shift
12 passthru="$*" # allow extra macro=value to be passed through
13 echo ""
14
15 case $CONFIG in
16 '')
17     if test -f config.sh; then TOP=.;
18     elif test -f ../config.sh; then TOP=..;
19     elif test -f ../../config.sh; then TOP=../..;
20     elif test -f ../../../config.sh; then TOP=../../..;
21     elif test -f ../../../../config.sh; then TOP=../../../..;
22     else
23         echo "Can't find config.sh generated by Configure"; exit 1
24     fi
25     . $TOP/config.sh
26     ;;
27 esac
28
29 if test "X$extspec" = X; then
30         echo "make_ext: no extension specified"
31         exit 1;
32 fi
33
34 # canonise
35 extspec=`echo "$extspec" | sed -e 's:^ext/::' -e 's:\.[^\.]*$::'`
36 extspec="ext/$extspec"
37 tailext=`echo "$extspec" | sed -e 's:.*/\([^/]*\)$:\1:'"`
38 headext=`echo "$extspec" | sed -e 's:/[^/]*$::'"`
39 if test -d "$headext/$tailext"; then
40     extspec="$headext/$tailext"
41 fi
42 if test -f "$extspec/$tailext.xs"; then
43     extspec="$extspec/$tailext"
44 fi
45
46 # get extension directory path, module name and depth
47 pname=`echo "$extspec" | sed -e 's:^ext/::' -e 's:/[^/]*$::'`
48 mname=`echo "$pname"   | sed -e 's!/!::!g'`
49 depth=`echo "$pname"   | sed -e 's![^/][^/]*!..!g'`
50 make=${altmake-make}
51 makeargs=''
52
53 if test ! -d "ext/$pname"; then
54     echo "      Skipping $extspec (directory does not exist)"
55     exit 0 # not an error ?
56 fi
57
58
59 echo "  Making $mname ($target)"
60
61 cd ext/$pname
62
63 # check link type and do any preliminaries
64 case "$target" in
65         # convert 'static' or 'dynamic' into 'all LINKTYPE=XXX'
66 static)  makeargs="LINKTYPE=static CCCDLFLAGS="; target=all ;;
67 dynamic) makeargs="LINKTYPE=dynamic";            target=all ;;
68 *clean) ;;
69 *)      # for the time being we are strict about what make_ext is used for
70         echo "make_ext: unknown make target '$target'"; exit 1;;
71 '')     echo "make_ext: no make target specified (eg static or dynamic)"; exit 1;;
72 esac
73
74 if test ! -f Makefile ; then
75         test -f Makefile.PL && ../$depth/miniperl -I../$depth/lib Makefile.PL
76 fi
77 if test ! -f Makefile ; then
78         test -f Makefile.SH && sh Makefile.SH
79 fi
80
81 case "$target" in
82 clean)          ;;
83 realclean)      ;;
84 *)              $make config $passthru;;
85 esac
86
87 $make $target $makeargs $passthru || exit
88
89 exit $?