summaryrefslogtreecommitdiff
path: root/ext/util/extliblist
blob: 2b8938fa4db0e82a32629303e08c7a3aad2ba667 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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."; exit 1
	fi
	. $TOP/config.sh
	;;
esac
: extliblist
:
: Author:  Andy Dougherty    doughera@lafcol.lafayette.edu
:
: This utility takes a list of libraries in the form
: -llib1 -llib2 -llib3
: and prints out lines suitable for inclusion in an extension
: Makefile.  
: Extra library paths may be included with the form -L/another/path
: this will affect the searches for all subsequent libraries.
:
: It is intended to be "dotted" from within an extension Makefile.SH.
: see ext/POSIX/Makefile.SH for an example.
: Prior to calling this, the variable potential_libs should be set 
: to the potential list of libraries
:
: It sets the following
: extralibs = full list of libraries needed for static linking.
:		Only those libraries that actually exist are included.
: dynaloadlibs = full path names of those libraries that are needed 
:		but can be linked in dynamically on this platform.  On 
:		SunOS, for example, this would be .so* libraries, 
:		but not archive libraries.
:		Eventually, this list can be used to write a bootstrap file.
: statloadlibs = list of those libraries which must be statically
:		linked into the shared library.  On SunOS 4.1.3, 
:		for example,  I have only an archive version of
:		-lm, and it must be linked in statically.
:
:  This script uses config.sh variables libs, libpth, and so.  It is mostly
:  taken from the metaconfig libs.U unit.
extralibs=''
dynaloadlibs=''
statloadlibs=''
Llibpth=''
for thislib in `echo "XXX $potential_libs " | $sed 's/ -l/ /g'` ; do
	case "$thislib" in
	XXX)
		: Handle case where potential_libs is empty.
		;;
	-L*)
		: Handle possible linker path arguments.
		newpath=`echo $thislib | $sed 's/^-L//'`
		if $test -d $newpath; then
			Llibpth="$Llibpth $newpath"
			extralibs="$extralibs $thislib"
			statloadlibs="$statloadlibs $thislib"
		fi
		;;
	*)
		: Handle possible library arguments.
		for thispth in $Llibpth $libpth; do
			: Loop over possible wildcards and take the last one.
			for fullname in $thispth/lib$thislib.$so.[0-9]* ; do
				:
			done
			if $test -f $fullname; then
				break
			elif fullname=$thispth/lib$thislib.$so && $test -f $fullname; then
				break
			elif fullname=$thispth/lib${thislib}_s.a && $test -f $fullname; then
				thislib=${thislib}_s
				break
			elif fullname=$thispth/lib${thislib}.a && $test -f $fullname; then
				break
			elif fullname=$thispth/Slib${thislib}.a && $test -f $fullname; then
				break
			else
				fullname=''
			fi
		done
		: Now update library lists
		case "$fullname" in
		'') 
			: Skip nonexistent files
			;;
		*)
			: Do not add it into the extralibs if it is already linked in
			: with the main perl executable.
			case " $libs " in
			*" -l$thislib "*|*" -l${thislib}_s "*) ;;
			*)	extralibs="$extralibs -l$thislib" ;;
			esac
			:
			: For NeXT and DLD, put files into DYNALOADLIBS to be
			: converted into a boostrap file.  For other systems,
			: we will use ld with what I have misnamed STATLOADLIBS
			: to assemble the shared object.
			case "$dlsrc" in
			dl_dld*|dl_next*)
				dynaloadlibs="$dynaloadlibs $fullname"   ;;
			*)
				case "$fullname" in
				*.a)
					statloadlibs="$statloadlibs -l$thislib" 
					;;
				*)   
					: For SunOS4, do not add in this shared library
					: if it is already linked in the main
					: perl executable
					case "$osname" in
					sunos)
						case " $libs " in
						*" -l$thislib "*) ;;
						*)	statloadlibs="$statloadlibs -l$thislib" ;;
						esac
						;;
					*)
						statloadlibs="$statloadlibs -l$thislib" 
						;;
					esac
					;;
				esac
				;;
			esac
			;;
		esac
		;;
	esac
done

case "$dlsrc" in
dl_next*)
	extralibs=`echo " $extralibs "| $sed -e 's/ -lm / /'` ;;
esac

set X $extralibs
shift
extralibs="$*"

set X $dynaloadlibs
shift
dynaloadlibs="$*"

set X $statloadlibs
shift
statloadlibs="$*"