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