acinclude/pkg.m4
author Sam Lantinga <slouken@libsdl.org>
Tue, 21 May 2013 21:09:26 -0700
changeset 616 7ead8213dfb0
parent 425 d39ef8d550b6
permissions -rw-r--r--
Fixed bug 1833 - Memory leak issue in SDL_mixer-1.2.12/music.c file

Nitz

In this code 'music' is dynamically allocated. But memory get leaked at return MUS_NONE.
slouken@425
     1
# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
slouken@425
     2
# 
slouken@425
     3
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
slouken@425
     4
#
slouken@425
     5
# This program is free software; you can redistribute it and/or modify
slouken@425
     6
# it under the terms of the GNU General Public License as published by
slouken@425
     7
# the Free Software Foundation; either version 2 of the License, or
slouken@425
     8
# (at your option) any later version.
slouken@425
     9
#
slouken@425
    10
# This program is distributed in the hope that it will be useful, but
slouken@425
    11
# WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@425
    12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@425
    13
# General Public License for more details.
slouken@425
    14
#
slouken@425
    15
# You should have received a copy of the GNU General Public License
slouken@425
    16
# along with this program; if not, write to the Free Software
slouken@425
    17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
slouken@425
    18
#
slouken@425
    19
# As a special exception to the GNU General Public License, if you
slouken@425
    20
# distribute this file as part of a program that contains a
slouken@425
    21
# configuration script generated by Autoconf, you may include it under
slouken@425
    22
# the same distribution terms that you use for the rest of that program.
slouken@425
    23
slouken@425
    24
# PKG_PROG_PKG_CONFIG([MIN-VERSION])
slouken@425
    25
# ----------------------------------
slouken@425
    26
AC_DEFUN([PKG_PROG_PKG_CONFIG],
slouken@425
    27
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
slouken@425
    28
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
slouken@425
    29
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
slouken@425
    30
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
slouken@425
    31
	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
slouken@425
    32
fi
slouken@425
    33
if test -n "$PKG_CONFIG"; then
slouken@425
    34
	_pkg_min_version=m4_default([$1], [0.9.0])
slouken@425
    35
	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
slouken@425
    36
	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
slouken@425
    37
		AC_MSG_RESULT([yes])
slouken@425
    38
	else
slouken@425
    39
		AC_MSG_RESULT([no])
slouken@425
    40
		PKG_CONFIG=""
slouken@425
    41
	fi
slouken@425
    42
		
slouken@425
    43
fi[]dnl
slouken@425
    44
])# PKG_PROG_PKG_CONFIG
slouken@425
    45
slouken@425
    46
# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
slouken@425
    47
#
slouken@425
    48
# Check to see whether a particular set of modules exists.  Similar
slouken@425
    49
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
slouken@425
    50
#
slouken@425
    51
#
slouken@425
    52
# Similar to PKG_CHECK_MODULES, make sure that the first instance of
slouken@425
    53
# this or PKG_CHECK_MODULES is called, or make sure to call
slouken@425
    54
# PKG_CHECK_EXISTS manually
slouken@425
    55
# --------------------------------------------------------------
slouken@425
    56
AC_DEFUN([PKG_CHECK_EXISTS],
slouken@425
    57
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
slouken@425
    58
if test -n "$PKG_CONFIG" && \
slouken@425
    59
    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
slouken@425
    60
  m4_ifval([$2], [$2], [:])
slouken@425
    61
m4_ifvaln([$3], [else
slouken@425
    62
  $3])dnl
slouken@425
    63
fi])
slouken@425
    64
slouken@425
    65
slouken@425
    66
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
slouken@425
    67
# ---------------------------------------------
slouken@425
    68
m4_define([_PKG_CONFIG],
slouken@425
    69
[if test -n "$PKG_CONFIG"; then
slouken@425
    70
    if test -n "$$1"; then
slouken@425
    71
        pkg_cv_[]$1="$$1"
slouken@425
    72
    else
slouken@425
    73
        PKG_CHECK_EXISTS([$3],
slouken@425
    74
                         [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
slouken@425
    75
			 [pkg_failed=yes])
slouken@425
    76
    fi
slouken@425
    77
else
slouken@425
    78
	pkg_failed=untried
slouken@425
    79
fi[]dnl
slouken@425
    80
])# _PKG_CONFIG
slouken@425
    81
slouken@425
    82
# _PKG_SHORT_ERRORS_SUPPORTED
slouken@425
    83
# -----------------------------
slouken@425
    84
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
slouken@425
    85
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
slouken@425
    86
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
slouken@425
    87
        _pkg_short_errors_supported=yes
slouken@425
    88
else
slouken@425
    89
        _pkg_short_errors_supported=no
slouken@425
    90
fi[]dnl
slouken@425
    91
])# _PKG_SHORT_ERRORS_SUPPORTED
slouken@425
    92
slouken@425
    93
slouken@425
    94
# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
slouken@425
    95
# [ACTION-IF-NOT-FOUND])
slouken@425
    96
#
slouken@425
    97
#
slouken@425
    98
# Note that if there is a possibility the first call to
slouken@425
    99
# PKG_CHECK_MODULES might not happen, you should be sure to include an
slouken@425
   100
# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
slouken@425
   101
#
slouken@425
   102
#
slouken@425
   103
# --------------------------------------------------------------
slouken@425
   104
AC_DEFUN([PKG_CHECK_MODULES],
slouken@425
   105
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
slouken@425
   106
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
slouken@425
   107
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
slouken@425
   108
slouken@425
   109
pkg_failed=no
slouken@425
   110
AC_MSG_CHECKING([for $1])
slouken@425
   111
slouken@425
   112
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
slouken@425
   113
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
slouken@425
   114
slouken@425
   115
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
slouken@425
   116
and $1[]_LIBS to avoid the need to call pkg-config.
slouken@425
   117
See the pkg-config man page for more details.])
slouken@425
   118
slouken@425
   119
if test $pkg_failed = yes; then
slouken@425
   120
        _PKG_SHORT_ERRORS_SUPPORTED
slouken@425
   121
        if test $_pkg_short_errors_supported = yes; then
slouken@425
   122
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
slouken@425
   123
        else 
slouken@425
   124
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
slouken@425
   125
        fi
slouken@425
   126
	# Put the nasty error message in config.log where it belongs
slouken@425
   127
	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
slouken@425
   128
slouken@425
   129
	ifelse([$4], , [AC_MSG_ERROR(dnl
slouken@425
   130
[Package requirements ($2) were not met:
slouken@425
   131
slouken@425
   132
$$1_PKG_ERRORS
slouken@425
   133
slouken@425
   134
Consider adjusting the PKG_CONFIG_PATH environment variable if you
slouken@425
   135
installed software in a non-standard prefix.
slouken@425
   136
slouken@425
   137
_PKG_TEXT
slouken@425
   138
])],
slouken@425
   139
		[AC_MSG_RESULT([no])
slouken@425
   140
                $4])
slouken@425
   141
elif test $pkg_failed = untried; then
slouken@425
   142
	ifelse([$4], , [AC_MSG_FAILURE(dnl
slouken@425
   143
[The pkg-config script could not be found or is too old.  Make sure it
slouken@425
   144
is in your PATH or set the PKG_CONFIG environment variable to the full
slouken@425
   145
path to pkg-config.
slouken@425
   146
slouken@425
   147
_PKG_TEXT
slouken@425
   148
slouken@425
   149
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])],
slouken@425
   150
		[$4])
slouken@425
   151
else
slouken@425
   152
	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
slouken@425
   153
	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
slouken@425
   154
        AC_MSG_RESULT([yes])
slouken@425
   155
	ifelse([$3], , :, [$3])
slouken@425
   156
fi[]dnl
slouken@425
   157
])# PKG_CHECK_MODULES