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