xref: /freebsd/contrib/libpcap/pcap-config.in (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1#! /bin/sh
2
3#
4# Script to give the appropriate compiler flags and linker flags
5# to use when building code that uses libpcap.
6#
7# These variables come from the configure script, so includedir and
8# libdir may be defined in terms of prefix and exec_prefix, so the
9# latter must be defined as well.
10#
11prefix="@prefix@"
12exec_prefix="@exec_prefix@"
13includedir="@includedir@"
14libdir="@libdir@"
15LIBS="@LIBS@"
16LIBS_STATIC="@LIBS_STATIC@"
17VERSION="@PACKAGE_VERSION@"
18
19static=0
20static_pcap_only=0
21show_cflags=0
22show_libs=0
23show_additional_libs=0
24while [ "$#" != 0 ]
25do
26	case "$1" in
27
28	--static)
29		static=1
30		;;
31
32	--static-pcap-only)
33		static_pcap_only=1
34		;;
35
36	--cflags)
37		show_cflags=1
38		;;
39
40	--libs)
41		show_libs=1
42		;;
43
44	--additional-libs)
45		show_additional_libs=1
46		;;
47
48	-h|--help)
49		echo "Usage: pcap-config [ --help ] [--version] [ --static | --static-pcap-only ] [ --libs | --additional-libs ]"
50		exit 0
51		;;
52
53	--version)
54		echo "$VERSION"
55		exit 0
56		;;
57
58	*)
59		echo "pcap-config: Invalid command-line option $1 specified" 1>&2
60		echo "Usage: pcap-config [ --help ] [ --static | --static-pcap-only ] [ --libs | --additional-libs ]" 1>&2
61		exit 1
62		;;
63	esac
64	shift
65done
66
67#
68# If we aren't installing in /usr, then provide a -L flag to let build
69# processes find our library.
70#
71# (We must check $prefix, as $libdir isn't necessarily /usr/lib in this
72# case - for example, Linux distributions for 64-bit platforms that
73# also provide support for binaries for a 32-bit version of the
74# platform may put the 64-bit libraries, the 32-bit libraries, or both
75# in directories other than /usr/lib.)
76#
77if [ "$prefix" != "/usr" ]
78then
79	LPATH=-L$libdir
80fi
81if [ "$static" = 1 ]
82then
83	#
84	# Include LIBS_STATIC so that the flags include libraries
85	# containing routines that libpcap uses, and libraries
86	# containing routines those libraries use, etc., so that a
87	# completely statically linked program - i.e., linked only with
88	# static libraries - will be linked with all necessary
89	# libraries.
90	#
91	if [ "$show_cflags" = 1 -a "$show_libs" = 1 ]
92	then
93		echo "-I$includedir $LPATH -l@PACKAGE_NAME@ $LIBS_STATIC"
94	elif [ "$show_cflags" = 1 -a "$show_additional_libs" = 1 ]
95	then
96		echo "-I$includedir $LPATH $LIBS_STATIC"
97	elif [ "$show_cflags" = 1 ]
98	then
99		echo "-I$includedir"
100	elif [ "$show_libs" = 1 ]
101	then
102		echo "$LPATH -l@PACKAGE_NAME@ $LIBS_STATIC"
103	elif [ "$show_additional_libs" = 1 ]
104	then
105		echo "$LIBS_STATIC"
106	fi
107elif [ "$static_pcap_only" = 1 ]
108then
109	#
110	# Include LIBS so that the flags include libraries
111	# containing routines that libpcap uses, but not the libraries
112	# on which libpcap depends, so that an otherwise
113	# dynamically-linked program, linked statically only with
114	# libpcap - i.e., linked with a static libpcap and dynamic
115	# versions of other libraries - will be linked with all
116	# necessary libraries.
117	#
118	if [ "$show_cflags" = 1 -a "$show_libs" = 1 ]
119	then
120		echo "-I$includedir $LPATH -l@PACKAGE_NAME@ $LIBS"
121	elif [ "$show_cflags" = 1 -a "$show_additional_libs" = 1 ]
122	then
123		echo "-I$includedir $LPATH $LIBS"
124	elif [ "$show_cflags" = 1 ]
125	then
126		echo "-I$includedir"
127	elif [ "$show_libs" = 1 ]
128	then
129		echo "$LPATH -l@PACKAGE_NAME@ $LIBS"
130	elif [ "$show_additional_libs" = 1 ]
131	then
132		echo "$LIBS"
133	fi
134else
135	#
136	# Don't included LIBS or LIBS_STATIC, for building a program
137	# with a dynamic libpcap; libpcap, being a dynamic library, will
138	# cause all of its dynamic-library dependencies to be pulled in
139	# at run time.
140	#
141	# Do, however, include RPATH, to make sure that, on platforms
142	# that require this, programs built with this version of
143	# libpcap can find it at run time.
144	#
145	if [ "$show_cflags" = 1 -a "$show_libs" = 1 ]
146	then
147		echo "-I$includedir $LPATH @RPATH@ -l@PACKAGE_NAME@"
148	elif [ "$show_cflags" = 1 -a "$show_additional_libs" = 1 ]
149	then
150		echo "-I$includedir"
151	elif [ "$show_cflags" = 1 ]
152	then
153		echo "-I$includedir"
154	elif [ "$show_libs" = 1 ]
155	then
156		echo "$LPATH @RPATH@ -l@PACKAGE_NAME@"
157	fi
158fi
159