## $Id: pkgconfig.am,v 1.2 2005/10/28 16:03:28 ensc Exp $	---*- makefile -*---

## Copyright (C) 2002 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
##  
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; version 2 of the License.
##  
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##  
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##  

BAD_INC_PATHS		=  /usr/include|/usr/local/include
BAD_LIB_PATHS		=  /usr/lib

pkgconfdir              =  $(libdir)/pkgconfig
pkgconf_DATA            =  $(addsuffix .pc, $(PKGCONFIG_FILES))

CLEANFILES		+= $(addsuffix .pc,       $(PKGCONFIG_FILES))
EXTRA_DIST		+= $(addsuffix .pc.subst, $(PKGCONFIG_FILES))

pkgconf_SUBST =		s!@'PACKAGE'@!$(PACKAGE)!g;					\
			s!@'VERSION'@!$(VERSION)!g;					\
			s!@'prefix'@!$(prefix)!g;					\
			s!@'exec_prefix'@!$(exec_prefix)!g;				\
			s!@'libdir'@!$(libdir)!g;					\
			s!@'includedir'@!$(includedir)!g;				\
			s!@'libflags"@!$${libflags}$(pkgconf_LIBFLAGS)!g;"'		\
			s!@'incflags"@!$${incflags}$(pkgconf_INCFLAGS)!g;"'		\
			s!@'pkgincflags"@!$${pkgincflags}$(pkgconf_PKGINCFLAGS)!g;"'	\
			s!@'pkgincludedir'@!$(pkgincludedir)!g


%.pc:			%.pc.subst Makefile
			rm -f $@
			@case '$(libdir)' in							\
				$(BAD_LIB_PATHS))	libflags=;;				\
				*)			libflags='-L$${libdir} ';;		\
			esac;									\
			case '$(pkgincludedir)' in						\
				$(BAD_INC_PATHS))	pkgincflags=;;				\
				*)			pkgincflags='-I$${pkgincludedir} ';;	\
			esac;									\
			case '$(includedir)' in							\
				$(BAD_INC_PATHS))	incflags=;;				\
				*)			incflags='-I$${includedir} ';;		\
			esac;									\
			sed -e '$(pkgconf_SUBST)' $< >$@
			test -z "$(CHMOD_REFERENCE)" || $(CHMOD_REFERENCE) '$<' '$@'
			chmod a-w $@
