#
# Makefile  -  makefile for utility program to generate bootrom
#
# Copyright (C) 1997-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.19 2007/02/01 12:09:21 gkminix Exp $
#


# Directory name of this module
MODNAME   = makerom


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


# MANEXT is the manual section number
MANEXT    = 8



# Subdirectories
SUBDIRS   = flash


# Module-specific compiler flags
CMODFLAGS =


# Source and object files for the host system
SRCS      = main.c doconfig.c drvdb.c getdb.c user.c passes.c netdrv.c \
		freeze.c protini.c makeflash.c makehex.c console.c \
		md5.c install.c
BINSRCS   = flash_c.c
OBJS      = $(SRCS:.c=.o) $(BINSRCS:.c=.o)
TARGET    = makerom



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

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



# Rules to generate a new bootrom
.PHONY:	bootrom

$(MISCDIR)/netboot.config $(MISCDIR)/netboot.drivers:
		(cd $(MISCDIR) && $(MAKE) netboot.config) || exit 1
		(cd $(MISCDIR) && $(MAKE) netboot.drivers) || exit 1


bootrom:	$(LIBTOOL) makerom $(MISCDIR)/netboot.config $(MISCDIR)/netboot.drivers
		@$(LIBTOOL) --mode=execute \
		  ./makerom -C $(MISCDIR)/netboot.config \
				-N $(TOPDIR)/makerom \
				-L $(ROMDIR) \
				-d $(MISCDIR)/netboot.drivers \
				-m none



# Generate C source file from FlashCard loader binary source
flash_c.c:	stamp-flash-$(GNU16BIT)
		@touch $@

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

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

stamp-flash-nognu:
		@touch stamp-flash-nognu
		cp flash_c.c-default flash_c.c


# distrib generates all files which will not be removed by distclean
distrib:	stamp-flash-gnu

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


clean:		clean-local clean-recursive

clean-local:	clean-general
		rm -f image.rom image.flo image.flash image.bin image.hex image.bios
		rm -f flash_c.c


distclean:	distclean-local distclean-recursive

distclean-local:	clean-local


realclean:	realclean-local realclean-recursive

realclean-local:	distclean-local
		rm -f flash_c.c-default


