mirror of
https://gitlab.freedesktop.org/pkg-config/pkg-config.git
synced 2025-12-27 10:10:04 +01:00
306 lines
7.5 KiB
Bash
306 lines
7.5 KiB
Bash
#!/bin/sh
|
|
|
|
# All variables are prefixed with pc_ so that there is low likelyhood of
|
|
# conflicts with the .pc files.
|
|
|
|
IFS=":$IFS"
|
|
|
|
prefix=@prefix@
|
|
exec_prefix=@exec_prefix@
|
|
pc_default_path=@libexecdir@/pkgconfig
|
|
|
|
if [ ! -d ${pc_default_path} ]; then
|
|
echo "${pc_default_path} doesn't exist. Make sure you've installed pkgconfig correctly."
|
|
exit 1;
|
|
fi
|
|
if [ ! -f "${pc_default_path}/gnomeconfig.pce" ]; then
|
|
echo "Can't find gnomeconfig.pce. Make sure you've installed pkgconfig correctly."
|
|
exit 1;
|
|
fi
|
|
|
|
cleanup() {
|
|
pc_prepend=$1
|
|
shift
|
|
pc_keep=$1
|
|
shift
|
|
pc_cleanup_var=$1
|
|
shift
|
|
pc_temp=""
|
|
while [ $# -ne 0 ]; do
|
|
pc_var=$1 # iterate over $1 ...
|
|
shift
|
|
if test "x$pc_keep" = "xkeepfirst"; then
|
|
case " $pc_temp " in
|
|
*\ $pc_var\ *) ;;
|
|
*) if test "x$pc_prepend" = "xprepend"; then
|
|
pc_temp="$pc_var $pc_temp"
|
|
else
|
|
pc_temp="$pc_temp $pc_var"
|
|
fi
|
|
;;
|
|
esac
|
|
else
|
|
# use : as seperator because that's what we prepended to IFS
|
|
case ":$*:" in
|
|
*\:$pc_var\:*) ;;
|
|
*) if test "x$pc_prepend" = "xprepend"; then
|
|
pc_temp="$pc_var $pc_temp"
|
|
else
|
|
pc_temp="$pc_temp $pc_var"
|
|
fi
|
|
;;
|
|
esac
|
|
fi
|
|
done
|
|
eval $pc_cleanup_var='$pc_temp'
|
|
}
|
|
|
|
find_configfile() {
|
|
for pc_dir in $pc_path XXX; do
|
|
if [ -f "${pc_dir}/${pc_pkg}.pc" ]; then
|
|
. ${pc_dir}/${pc_pkg}.pc
|
|
break
|
|
fi
|
|
done
|
|
if [ "$pc_dir" = XXX ]; then
|
|
pc_extns=`ls ${pc_default_path}/*.pce`
|
|
for pc_ext in $pc_extns XXX; do
|
|
if [ -f "${pc_ext}" ]; then
|
|
. ${pc_ext} $pc_pkg
|
|
# sh on Tru64 (OSF1??) doesn't like return in sourced
|
|
# files, so we set $result
|
|
if [ "$result" = "0" ]; then
|
|
break;
|
|
fi
|
|
fi
|
|
done
|
|
if [ "$pc_ext" = XXX ]; then
|
|
echo "couldn't find information for package $pc_pkg." 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
fi
|
|
}
|
|
|
|
# make sure we give a non-zero return value if we get interrupted
|
|
# signals HUP, INT and TERM
|
|
trap 'echo; echo "Interrupted."; exit 1' 1 2 15
|
|
|
|
pc_help_msg="Usage: $0 [-I DIR] [GENERIC_OPTION | FLAGSOPTION...] [LIBRARY...]
|
|
|
|
-I DIR Add a directory to the .pc file search path
|
|
|
|
Generic options:
|
|
--version Output the pkg-config version and exit
|
|
--modversion Output the version of the first library and exit
|
|
--help Show this help and exit
|
|
--expand Show expanded list of packages to link with
|
|
--print-pc-dir Print the default .pc search dir and exit
|
|
--extra-flags Print the extra flags the selected modules support
|
|
--get-flag FLAGNAME Print the content of the extra flag specified
|
|
|
|
Output link information for a combination of libraries
|
|
Options to control which compile/link flags to output
|
|
|
|
--cflags Show cflags to compile with
|
|
--libs-only-L Output only -L/-R flags needed for the libraries listed
|
|
--libs-onlu-l-self Output the -l flags for the libraries listed
|
|
--libs-only-l-system Output the -l flags for system libraries the
|
|
listed libraries depend on.
|
|
--libs Output a combination of all the --libs-only-* flags above
|
|
LIBRARIES Packages that your program needs to compile
|
|
|
|
"
|
|
|
|
pc_want_ldflags=no
|
|
pc_want_libs_self=no
|
|
pc_want_libs_system=no
|
|
pc_want_cflags=no
|
|
pc_want_libs=no
|
|
pc_want_expand=no
|
|
pc_want_dir=no
|
|
pc_want_varlist=no
|
|
pc_want_extra_var=no
|
|
pc_prev=
|
|
pc_extra_var=
|
|
|
|
# show help and exit with an errorstatus when no arguments
|
|
if test $# -eq 0; then
|
|
echo "$pc_help_msg"
|
|
exit 1
|
|
fi
|
|
|
|
# add extra path to searched dirs
|
|
pc_path=
|
|
if [ -n "$PC_INCLUDEPATH" ]; then
|
|
pc_path="${PC_INCLUDEPATH}:${pc_path}"
|
|
fi
|
|
for pc_extra in `echo $GNOME_PATH | sed 's/:/ /g'`; do
|
|
pc_path="${extra}/libexec/pkgconfig:${pc_path}"
|
|
done
|
|
# only use default path if no other paths are given, to
|
|
# avoid ACLOCAL_CONFIG type problems
|
|
if [ -z "${GNOME_PATH}${PC_INCLUDEPATH}" ]; then
|
|
pc_path="${pc_default_path}"
|
|
fi
|
|
|
|
|
|
while [ $# -ne 0 ]; do
|
|
pc_arg="$1"
|
|
shift
|
|
case "$pc_arg" in
|
|
-*=*) pc_optarg=`echo $pc_arg | sed 's/[-_a-zA-Z0-9]*=//'` ;;
|
|
*) pc_optarg= ;;
|
|
esac
|
|
if [ -n "$pc_prev" ]; then
|
|
if [ "$pc_prev" = pcpath ]; then
|
|
pc_path="$pc_arg:$pc_path"
|
|
elif [ "$pc_prev" = "extravar" ]; then
|
|
pc_extra_var="$pc_arg"
|
|
else
|
|
eval "$pc_prev=\$pc_arg"
|
|
fi
|
|
pc_prev=
|
|
continue
|
|
fi
|
|
case "$pc_arg" in
|
|
--help)
|
|
echo "$pc_help_msg"
|
|
exit 0 ;;
|
|
--version)
|
|
echo "pkgconfig @VERSION@"
|
|
exit 0 ;;
|
|
-I*) pc_path="`echo $pc_arg | sed 's/^-I//'`:$pc_path" ;;
|
|
-I) pc_prev=pcpath ;;
|
|
--cflags) pc_want_cflags=yes ;;
|
|
--libs-only-L) pc_want_ldflags=yes ;;
|
|
--libs-only-l-self) pc_want_libs_self=yes ;;
|
|
--libs-only-l-system) pc_want_libs_system=yes ;;
|
|
--libs)
|
|
pc_want_ldflags=yes
|
|
pc_want_libs_self=yes
|
|
pc_want_libs_system=yes ;;
|
|
--expand) pc_want_expand=yes ;;
|
|
--modversion) pc_want_modversion=yes ;;
|
|
--print-pc-dir) pc_want_dir=yes ;;
|
|
--extra-flags) pc_want_varlist=yes ;;
|
|
--get-flag) pc_prev="extravar" pc_want_var=yes ;;
|
|
-*)
|
|
echo "Unknown option: $pc_arg"
|
|
echo "$pc_help_msg"
|
|
exit 1 ;;
|
|
*) pc_caps="$pc_caps $pc_arg" ;;
|
|
esac
|
|
done
|
|
|
|
# print the default pc_path only
|
|
if [ "$pc_want_dir" = yes ]; then
|
|
echo $pc_default_path
|
|
exit 0
|
|
fi
|
|
|
|
# expand the packages list, so to satisfy dependencies ...
|
|
set - $pc_caps
|
|
pc_pkgs=""
|
|
while [ $# -ne 0 ]; do
|
|
pc_pkg="$1"
|
|
shift
|
|
|
|
if [ -z "$pc_pkg" ]; then
|
|
# ash seems to count the space at the start of pc_caps as an extra
|
|
# argument. This catches that case.
|
|
continue
|
|
fi
|
|
pc_pkgs="$pc_pkgs $pc_pkg"
|
|
REQUIRES=""
|
|
|
|
find_configfile $pc_pkg
|
|
|
|
if [ "x$REQUIRES" != x ]; then
|
|
for pc_dep in $REQUIRES; do
|
|
case ":$*:" in
|
|
*\:$pc_dep\:*) ;;
|
|
*) set - $* $pc_dep;;
|
|
esac
|
|
done
|
|
fi
|
|
done
|
|
|
|
# now remove duplicate packages from the list (all but last duplicate) ...
|
|
cleanup prepend keepfirst pc_pkgs $pc_pkgs
|
|
|
|
|
|
#
|
|
# from this point on, the list of packages should all exist, and be ordered
|
|
#
|
|
|
|
# give the module version
|
|
if [ "$pc_want_modversion" = yes ]; then
|
|
echo $VERSION
|
|
exit 0
|
|
fi
|
|
|
|
# list the expanded list of packages if asked for ...
|
|
if [ "$pc_want_expand" = yes ]; then
|
|
echo $pc_pkgs
|
|
exit 0;
|
|
fi
|
|
|
|
# list the list of extra vars
|
|
if [ "$pc_want_varlist" = yes ]; then
|
|
cleanup prepend keepfirst pc_varlist $EXTRA_VARS
|
|
echo $pc_varlist
|
|
exit 0;
|
|
fi
|
|
|
|
if [ "$pc_want_var" = yes ]; then
|
|
eval echo \$`eval echo $pc_extra_var`
|
|
exit 0;
|
|
fi
|
|
|
|
#ignore what the previous runs of the scripts have set
|
|
CFLAGS=
|
|
LIBS_PATH=
|
|
LIBS_LINK_SELF=
|
|
LIBS_LINK_SYSTEM=
|
|
|
|
for pc_pkg in $pc_pkgs; do
|
|
find_configfile $pc_pkg
|
|
done
|
|
|
|
# clean up duplicate flags. Discard all but last occurence of -l* flags,
|
|
# and all but first occurence of other flags
|
|
if [ "$pc_want_cflags" = "yes" ]; then
|
|
pc_includepath=
|
|
for pc_flag in $CFLAGS; do
|
|
if [ "$pc_flag" != "-I/usr/include" ]; then
|
|
pc_includepath="$pc_includepath $pc_flag"
|
|
fi
|
|
done
|
|
cleanup append keepfirst CFLAGS $pc_includepath
|
|
echo -n $CFLAGS
|
|
fi
|
|
if [ "$pc_want_ldflags" = "yes" ]; then
|
|
pc_libpath=
|
|
for pc_flag in $LIBS_PATH; do
|
|
if [ "$pc_flag" != "-L/usr/lib" ]; then
|
|
pc_libpath="$pc_libpath $pc_flag"
|
|
fi
|
|
done
|
|
cleanup append keepfirst LIBS_PATH $pc_libpath
|
|
echo -n "$LIBS_PATH"
|
|
fi
|
|
if [ "$pc_want_libs_self" = "yes" ]; then
|
|
cleanup append keeplast LIBS_LINK_SELF $LIBS_LINK_SELF
|
|
echo -n "$LIBS_LINK_SELF"
|
|
fi
|
|
if [ "$pc_want_libs_system" = "yes" ];then
|
|
cleanup append keeplast LIBS_LINK_SYSTEM $LIBS_LINK_SYSTEM
|
|
echo -n "$LIBS_LINK_SYSTEM"
|
|
fi
|
|
|
|
#end the line
|
|
echo
|
|
#everything seems to have gone well
|
|
exit 0
|
|
|