#
# Makefile  -  makefile for netboot library
#
# 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.27 2007/02/01 12:09:24 gkminix Exp $
#


# Directory name of this module
MODNAME   = nblib


# Library version information
LIBCURRENT	= 1
LIBREVISION	= 5
LIBAGE		= 1
LIBVERSION	= $(LIBCURRENT):$(LIBREVISION):$(LIBAGE)


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


# Additional compiler flags for Berkeley DB module
dbbdb_FLAGS = $(BDB_FLAGS)


# Additional compiler flags for ODBC module
dbodbc_FLAGS = $(ODBC_FLAGS)


# Additional compiler flags for setup module
setup_FLAGS = -DDEFAULT_DIR=\"$(nblibdir)\" \
			-DDEFAULT_CONFIG=\"$(sysconfdir)/$(nbconfig)\" \
			-DDEFAULT_DATABASE=\"$(nbdatabase)\"



# Source and object files. Note that NBLIBOBJS gets defined by configure,
# and it contains all the objects which have to get compiled to replace
# missing or defective C library routines. However, SRCS still has to
# contain all sources in this directory in order to be able to generate
# a dependency file.
REQSRCS = parseopt.c parsefile.c parsesect.c config.c setup.c sysdb.c \
		dbsetup.c db.c dbmatch.c dbtext.c \
		charset.c memory.c signal.c \
		nbmalloc.c nblog.c nbexit.c nbexec.c \
		access.c fileio.c filesize.c filetime.c lockfile.c \
		tempfile.c md5.c readelf.c help.c list.c
OPTSRCS = getopt.c getopt1.c strstr.c strspn.c strcspn.c strchr.c \
		strrchr.c strncmp.c strtol.c \
		vfprintf.c vsprintf.c vasprintf.c \
		memset.c memcpy.c memcmp.c memmove.c \
		dbbdb.c dbodbc.c
SRCS	= $(REQSRCS) $(OPTSRCS)
OBJS	= $(REQSRCS:.c=.o) $(NBLIBOBJS)
TARGET	= libnb.la


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

libnb.a:	libnb.a($(OBJS))
		$(RANLIB) libnb.a


libnb.la:	$(LIBTOOL) $(OBJS:.o=.lo)
	@$(LIBTOOL) --mode=link \
	  $(CC) $(LDFLAGS) -o $@ $(OBJS:.o=.lo) \
	  $(BDBLIB) $(ODBCLIB) $(SYSLIBS) \
	  -version-info $(LIBVERSION) -rpath $(libdir) -no-undefined


# Make ELF reading test program
readelf-test:	readelf.c libnb.a
	$(CC)	-g -DTEST -DHAVE_CONFIG_H -DNETBOOT $(INCLUDE) \
			-o readelf-test readelf.c -L. -lnb


# Install library
install:	$(LIBTOOL) $(TARGET)
	$(INSTALL) -d $(DESTDIR)$(libdir)
	@$(LIBTOOL) --mode=install \
	  $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(libdir)/$(TARGET)


# Cleanup
clean:		clean-general
		rm -f libnb.a readelf-test

distclean:	clean

realclean:	distclean


