summaryrefslogtreecommitdiff
path: root/ext/util/make_ext
blob: dca9a8d8e9bd4480d084a549d11f74d3cbd026c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This script acts as a simple interface for building extensions.
# It primarily used by the perl Makefile:
#
# d_dummy $(dynamic_ext): miniperl preplibrary FORCE
#        ext/util/make_ext dynamic $@
#
# It may be deleted in a later release of perl so try to
# avoid using it for other purposes.

target=$1;  shift
extspec=$1; shift
passthru="$*" # allow extra macro=value to be passed through
echo ""

case $CONFIG in
'')
    if test -f config.sh; then TOP=.;
    elif test -f ../config.sh; then TOP=..;
    elif test -f ../../config.sh; then TOP=../..;
    elif test -f ../../../config.sh; then TOP=../../..;
    elif test -f ../../../../config.sh; then TOP=../../../..;
    else
        echo "Can't find config.sh generated by Configure"; exit 1
    fi
    . $TOP/config.sh
    ;;
esac

if test "X$extspec" = X; then
	echo "make_ext: no extension specified"
	exit 1;
fi

# convert old style Name.a into ext/Name/Name.a format
case "$extspec" in
ext/*)	;;
*::*)	extspec=`echo "$extspec" | sed -e 's!\(.*\)::\(.*\)!ext/\1/\2/\2.a!'` ;;
*)	extspec=`echo "$extspec" | sed -e 's:\(.*\)\.\(.*\):ext/\1/\1.\2:'` ;;
esac

# get extension directory path, module name and depth
pname=`echo "$extspec" | sed -e 's:^ext/::' -e 's:/[^/]*$::'`
mname=`echo "$pname"   | sed -e 's!/!::!g'`
depth=`echo "$pname"   | sed -e 's![^/][^/]*!..!g'`
make=${altmake-make}
makeargs=''

if test ! -d "ext/$pname"; then
    echo "	Skipping $extspec (directory does not exist)"
    exit 0 # not an error ?
fi


echo "	Making $mname ($target)"

cd ext/$pname

# check link type and do any preliminaries
case "$target" in
	# convert 'static' or 'dynamic' into 'all LINKTYPE=XXX'
static)  makeargs="LINKTYPE=static CCCDLFLAGS="; target=all ;;
dynamic) makeargs="LINKTYPE=dynamic";            target=all ;;
*clean)	;;
*)	# for the time being we are strict about what make_ext is used for
	echo "make_ext: unknown make target '$target'"; exit 1;;
'')	echo "make_ext: no make target specified (eg static or dynamic)"; exit 1;;
esac

if test ! -f Makefile ; then
	test -f Makefile.PL && ../$depth/miniperl -I../$depth/lib Makefile.PL
fi
if test ! -f Makefile ; then
	test -f Makefile.SH && sh Makefile.SH
fi

case "$target" in
clean)		;;
realclean)	;;
*)		$make config $passthru;;
esac

$make $target $makeargs $passthru || exit

exit $?