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