This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[fix crash in regexec.c]
[perl5.git] / ext / util / make_ext
CommitLineData
a0d0e21e
LW
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
42793c05
TB
10target=$1; shift
11extspec=$1; shift
12passthru="$*" # allow extra macro=value to be passed through
13echo ""
a0d0e21e
LW
14
15case $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 ;;
27esac
28
29if test "X$extspec" = X; then
30 echo "make_ext: no extension specified"
31 exit 1;
32fi
33
ecfc5424
AD
34# canonise
35extspec=`echo "$extspec" | sed -e 's:^ext/::' -e 's:\.[^\.]*$::'`
36extspec="ext/$extspec"
37tailext=`echo "$extspec" | sed -e 's:.*/\([^/]*\)$:\1:'"`
38headext=`echo "$extspec" | sed -e 's:/[^/]*$::'"`
39if test -d "$headext/$tailext"; then
40 extspec="$headext/$tailext"
41fi
42if test -f "$extspec/$tailext.xs"; then
43 extspec="$extspec/$tailext"
44fi
a0d0e21e
LW
45
46# get extension directory path, module name and depth
47pname=`echo "$extspec" | sed -e 's:^ext/::' -e 's:/[^/]*$::'`
e1666bf5 48mname=`echo "$pname" | sed -e 's!/!::!g'`
a0d0e21e 49depth=`echo "$pname" | sed -e 's![^/][^/]*!..!g'`
42793c05
TB
50make=${altmake-make}
51makeargs=''
a0d0e21e
LW
52
53if test ! -d "ext/$pname"; then
42793c05
TB
54 echo " Skipping $extspec (directory does not exist)"
55 exit 0 # not an error ?
a0d0e21e
LW
56fi
57
a0d0e21e 58
42793c05 59echo " Making $mname ($target)"
a0d0e21e
LW
60
61cd ext/$pname
62
42793c05
TB
63# check link type and do any preliminaries
64case "$target" in
65 # convert 'static' or 'dynamic' into 'all LINKTYPE=XXX'
66static) makeargs="LINKTYPE=static CCCDLFLAGS="; target=all ;;
67dynamic) 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;;
72esac
73
a0d0e21e
LW
74if test ! -f Makefile ; then
75 test -f Makefile.PL && ../$depth/miniperl -I../$depth/lib Makefile.PL
76fi
77if test ! -f Makefile ; then
78 test -f Makefile.SH && sh Makefile.SH
79fi
80
42793c05
TB
81case "$target" in
82clean) ;;
83realclean) ;;
84*) $make config $passthru;;
85esac
a0d0e21e 86
42793c05 87$make $target $makeargs $passthru || exit
a0d0e21e
LW
88
89exit $?