
# This file 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; either version 2, or (at your option)
# any later version.

# This file 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 GNU Emacs; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

# Copyright (C) 2004 California Digital Corporation

# $Id: Makefile,v 1.32 2004/10/25 17:29:54 itz Exp $

SHELL := /bin/sh

include Makefile.config

man8dir := $(mandir)/man8
pkgconfdir := $(sysconfdir)/biosconfig

# force use of bison and flex, since we use flex specific features
BISON := bison
FLEX := flex
MAKEINFO := makeinfo

modules := biosconfig.o regexp.o valuefile.o cmosop.o cmoslow.o layoutlex.o \
	layoutgrm.o object.o smbios.o md5.o escape.o options.o $(LIBOBJS)

all : biosconfig biosconfig.8 biosconfig.info

biosconfig : $(modules)
	$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@

$(modules) : %.o : %.c Makefile.config
	@echo $(CC) -c $(DEBUG) $< -o $@
	@$(CC) -c $(CFLAGS) $(CPPFLAGS) -D_GNU_SOURCE -DPKGCONFDIR=\"${pkgconfdir}\" $(DEBUG) $< -o $@

biosconfig.8 : biosconfig.pod configure
	pod2man --section=8 --name=BIOSCONFIG --center='System Administration' \
	 --release=`./configure --version | head -1 | cut -d' ' -f3`  $< > $@

options.c biosconfig.pod options.texi : options.stamp
	touch $@

options.stamp : options.pl
	echo > $@
	perl $<

version.texi : configure
	echo "@set VERSION `./configure --version | head -1 | cut -d' ' -f3`" > $@

biosconfig.info : biosconfig.texi version.texi options.texi
	$(MAKEINFO) --no-split $<

# this cancels the incovenient old yacc implicit rule
%.c : %.y

layoutgrm.h layoutgrm.c : layoutgrm.stamp

layoutgrm.stamp : layoutgrm.y
	echo > $@
	$(BISON) $(BISONFLAGS) -d -o $(<:%.y=%.c) $<

layoutlex.c : layoutlex.l
	$(FLEX) $(FLFLAGS) -o $@ $<

install : all
	$(INSTALL) -d $(DESTDIR)$(sbindir) $(DESTDIR)$(man8dir) $(DESTDIR)$(pkgconfdir) $(DESTDIR)$(infodir)
	$(INSTALL_DATA) biosconfig.8 $(DESTDIR)$(man8dir)/biosconfig.8
	$(INSTALL_DATA) biosconfig.info $(DESTDIR)$(infodir)/biosconfig.info
	$(INSTALL_PROGRAM) biosconfig $(DESTDIR)$(sbindir)/biosconfig
	$(INSTALL_PROGRAM) biosconfig-rehash $(DESTDIR)$(sbindir)/biosconfig-rehash

clean :
	rm -f biosconfig $(modules)

maintainer_clean := layoutgrm.c layoutgrm.h layoutgrm.stamp options.stamp layoutlex.c \
 options.c biosconfig.8 biosconfig.pod configure version.texi options.texi biosconfig.info \
 Makefile.config config.log 

distclean : 
	rm -f biosconfig $(modules) Makefile.config config.log config.status

maintainer-clean :
	rm -f biosconfig $(modules) $(maintainer_clean)

Makefile.config : Makefile.config.in config.status
	./config.status Makefile.config

config.status: configure
	./config.status --recheck

configure : configure.ac
	autoconf

dist : $(maintainer_clean)
	mkdir biosconfig-$(PACKAGE_VERSION)
	tar cf - -h `sed -e '/^[ 	]*#/d' MANIFEST` | tar xf - -C biosconfig-$(PACKAGE_VERSION)
	tar cf ../biosconfig-$(PACKAGE_VERSION).tar biosconfig-$(PACKAGE_VERSION)
	gzip -9 ../biosconfig-$(PACKAGE_VERSION).tar
	rm -rf biosconfig-$(PACKAGE_VERSION)


# courtesy of gcc -MM
biosconfig.o: biosconfig.c regexp.h valuefile.h cmosop.h object.h \
  layoutlex.h md5.h escape.h options.h
options.o : options.h
cmoslow.o: cmoslow.c cmoslow.h 
cmosop.o: cmosop.c cmosop.h valuefile.h object.h cmoslow.h 
layoutgrm.o: layoutgrm.c layoutlex.h object.h 
layoutlex.o: layoutlex.c object.h layoutgrm.h layoutlex.h escape.h 
object.o: object.c object.h 
regexp.o: regexp.c regexp.h 
valuefile.o: valuefile.c valuefile.h regexp.h 
smbios.o: smbios.c smbios.h 
md5.o: md5.c md5.h 
escape.o: escape.c escape.h 
