#
# Makefile  -  makefile for mknbi program for Linux
#
# Copyright (C) 1995-2007 Gero Kuhlmann   <gero@gkminix.han.de>
# Copyright (C) 1996,1997 Gero Kuhlmann   <gero@gkminix.han.de>
#		 and Markus Gutschke <gutschk@math.uni-muenster.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.16 2007/02/01 12:09:24 gkminix Exp $
#


# Directory name of this module
MODNAME   = mknbi-linux


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


# MANEXT is the manual section number
MANEXT    = 8


# Subdirectories
SUBDIRS   = first


# Module-specific compiler flags
CMODFLAGS =


# Source and object files for the host system
SRCS      = mknbi.c sysdb.c
BINSRCS   = first_c.c firstd_c.c
OBJS      = $(SRCS:.c=.o) $(BINSRCS:.c=.o)
TARGET    = mknbi-linux


# Rules to make the target
all:		$(TARGET)

$(TARGET):	mknbi

mknbi:		$(LIBTOOL) $(OBJS) $(LIBNBA)
		@$(LIBTOOL) --mode=link \
		  $(CC) -o mknbi $(LDFLAGS) $(OBJS) $(LIBS)


# Generate C source file from boot image loader binary source
first_c.c:	stamp-first-$(GNU16BIT)
		@touch $@

first/first.b86::
		@if !(cd first && $(MAKE) -q first.b86); then		\
		   echo making first.b86 in first;			\
		   (cd first && $(MAKE) first.b86) || exit 1;		\
		 fi

stamp-first-gnu:	first/first.b86 | $(MAKEC)
		@touch stamp-first-gnu
		$(MAKEC) first <first/first.b86 >first_c.c
		@$(CPATTR) first_c.c first_c.c-default

stamp-first-nognu:
		@touch stamp-first-nognu
		cp first_c.c-default first_c.c


firstd_c.c:	stamp-firstd-$(GNU16BIT)
		@touch $@

first/first-debug.b86::
		@if !(cd first && $(MAKE) -q first-debug.b86); then	\
		   echo making first-debug.b86 in first;		\
		   (cd first && $(MAKE) first-debug.b86) || exit 1;	\
		 fi

stamp-firstd-gnu:	first/first-debug.b86 | $(MAKEC)
		@touch stamp-firstd-gnu
		$(MAKEC) firstd <first/first-debug.b86 >firstd_c.c
		@$(CPATTR) firstd_c.c firstd_c.c-default

stamp-firstd-nognu:
		@touch stamp-firstd-nognu
		cp firstd_c.c-default firstd_c.c


# distrib generates all files which are not removed by distclean
distrib:	stamp-first-gnu stamp-firstd-gnu

install:	$(LIBTOOL) all
		$(INSTALL) -d $(DESTDIR)$(bindir)
		$(INSTALL) -d $(DESTDIR)$(mandir)/man$(MANEXT)
		@$(LIBTOOL) --mode=install \
		  $(INSTALL_PROGRAM) mknbi $(DESTDIR)$(bindir)/$(TARGET)
		$(INSTALL_DATA) mknbi.man $(DESTDIR)$(mandir)/man$(MANEXT)/$(TARGET).$(MANEXT)


clean:			clean-local clean-recursive

clean-local:		clean-general
			rm -f mknbi first_c.c firstd_c.c


distclean:		distclean-local distclean-recursive

distclean-local:	clean-local


realclean:		realclean-local realclean-recursive

realclean-local:	distclean-local
			rm -f first_c.c-default firstd_c.c-default


