#
# Makefile  -  makefile for miscellaneous programs and files
#
# Copyright (C) 1998-2007 Gero Kuhlmann   <gero@gkminix.han.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; either version 2 of the License, or
#  any later version.
#
#  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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: Makefile,v 1.18 2007/02/01 18:42:10 gkminix Exp $
#


# Directory name of this module
MODNAME = misc


# Include makefile configuration
include ../make.config
include ../make.rules


# Names of configuration files
drivers	= netboot.drivers
db	= netboot.db
difs	= $(wildcard difs/*.dif)


# Names of GCC optimizer rule files - note that order matters!
RULES	= rules.stack rules.gcc rules.post


# Manual page section
MANEXT	= 5


# Specify all subdirectories where we are going to make something
SUBDIRS	= romcheck config



# Generate all target files
all:		makec instdrv gccopt nbmd5 $(nbconfig) netboot.man $(drivers) \
		romcheck-$(GNU16BIT)


# distrib generates all files which are not removed by distclean
# We need makec and gccopt for distrib targets in some other Makefiles,
# so build it here as well.
# Note that gccrules and gccopt need to be linked using libtool
# because they use the nblib library.
distrib:	makec gccopt romcheck-$(GNU16BIT)


romcheck-gnu:
	@echo making all in romcheck ; \
	 (cd romcheck && $(MAKE) all) || exit 1;


romcheck-nognu:


makec:		makec.c
	$(CC) $(CDEFS) $(INCLUDE) -o makec makec.c


gccrules:	$(LIBTOOL) gccrules.o $(LIBNBA)
	@$(LIBTOOL) --mode=link \
	  $(CC) $(CFLAGS) -o gccrules gccrules.o $(LIBS) \
	  -no-install


gccopt.h:	gccrules $(RULES)
	./gccrules -ogccopt.h $(RULES)


gccopt.o:	gccopt.c gccopt.h


gccopt:		$(LIBTOOL) gccopt.o $(LIBNBA)
	@$(LIBTOOL) --mode=link \
	  $(CC) $(CFLAGS) -o gccopt gccopt.o $(LIBS) \
	  -no-install


nbmd5:		$(LIBTOOL) nbmd5.o $(LIBNBA)
	@$(LIBTOOL) --mode=link \
	  $(CC) $(CFLAGS) -o nbmd5 nbmd5.o $(LIBS)


instdrv:	instdrv.in
	sed "s&%PREFIX%&$(prefix)&g;			\
		s&%LIBDIR%&$(nblibdir)&g;		\
		s&%DATADIR%&$(nbdatadir)&g" instdrv.in >instdrv
	@chmod 755 instdrv


$(nbconfig):	netboot.config.in
	sed "s&%PREFIX%&$(prefix)&g;			\
		s&%LIBDIR%&$(nblibdir)&g;		\
		s&%DATADIR%&$(nbdatadir)&g" netboot.config.in >$(nbconfig)


netboot.man:	netboot.man.in
	sed "s&%CONFIG%&$(sysconfdir)/$(nbconfig)&g;	\
		s&%LIBDIR%&$(nblibdir)&g;		\
		s&%DATADIR%&$(nbdatadir)&g" netboot.man.in >netboot.man


$(drivers):	netboot.drivers.in netboot.drivers.end $(difs)
	cat netboot.drivers.in $(difs) netboot.drivers.end >$(drivers)



.PHONY:		install-config install-drivers install-man install-utils \
		install-misc

install:	install-config install-drivers install-man install-utils \
		install-misc install-recursive


install-config:		$(nbconfig)
	$(INSTALL) -d $(DESTDIR)$(sysconfdir)
	$(INSTALL_DATA) $(nbconfig) $(DESTDIR)$(sysconfdir)/$(nbconfig)


install-drivers:	$(drivers)
	$(INSTALL) -d $(DESTDIR)$(nbdatadir)
	$(INSTALL_DATA) $(drivers) $(DESTDIR)$(nbdatadir)/$(drivers)


install-man:		netboot.man $(nbconfig).man $(drivers).man $(db).man
	$(INSTALL) -d $(DESTDIR)$(mandir)/man$(MANEXT)
	$(INSTALL_DATA) netboot.man $(DESTDIR)$(mandir)/man$(MANEXT)/netboot.$(MANEXT)
	$(INSTALL_DATA) $(nbconfig).man $(DESTDIR)$(mandir)/man$(MANEXT)/$(nbconfig).$(MANEXT)
	$(INSTALL_DATA) $(drivers).man $(DESTDIR)$(mandir)/man$(MANEXT)/$(drivers).$(MANEXT)
	$(INSTALL_DATA) $(db).man $(DESTDIR)$(mandir)/man$(MANEXT)/$(db).$(MANEXT)


install-utils:		instdrv nbmd5
	$(INSTALL) -d $(DESTDIR)$(nblibdir)
	$(INSTALL_SCRIPT) instdrv $(DESTDIR)$(nblibdir)/instdrv
	@$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) nbmd5 $(DESTDIR)$(nblibdir)/nbmd5


install-misc:		odbc.sql
	$(INSTALL) -d $(DESTDIR)$(nbmiscdir)
	$(INSTALL_DATA) odbc.sql $(DESTDIR)$(nbmiscdir)/odbc.sql


clean:	clean-general clean-recursive
	rm -f makec gccopt gccrules gccopt.h instdrv nbmd5 \
		$(nbconfig) netboot.man $(drivers)

realclean: 	clean-general realclean-recursive
	rm -f makec gccopt gccrules gccopt.h instdrv nbmd5 \
		$(nbconfig) netboot.man $(drivers)

distclean:	clean-general distclean-recursive
	rm -f makec gccopt gccrules gccopt.h instdrv nbmd5 \
		$(nbconfig) netboot.man $(drivers)


