#
# (C) Copyright 2002
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
# See file CREDITS for list of people who contributed to this
# project.
#
# 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 (at your option) 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., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#

LIBDIR=/usr/
TOPDIR=../
#LINUXDIR=/usr/src/linux-headers-2.6.27-17-generic
#LINUXDIR=./kernel/ti/linux-2.6.18/src

include ../Rules.mak

CFLAGS+=-Wall -g -fPIC

CFLAGS+=$(SSP_ALL_CFLAGS) -DUSE_HOSTCC

CFLAGS+=-DLIBNVRAM_ON_FS

#CFLAGS+=-I$(LIBDIR)zlib

#CFLAGS+=-I$(LINUXDIR)/include
#CFLAGS+=-I$(LINUXDIR)/include/linux

LIBNVRAM=lib$(CONFIG_LIB_NVRAM_PREFIX).a
LIBNVRAM_SHARED=lib$(CONFIG_LIB_NVRAM_PREFIX).so
LIBNVRAM_SHARED_FULLNAME=lib$(CONFIG_LIB_NVRAM_PREFIX)-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so

OBJS	:= $(BUILDDIR)/crc32.o $(BUILDDIR)/nvram_env.o $(BUILDDIR)/flash_api.o
HEADERS := nvram_env.h nvram.h flash_api.h

LDFLAGS := -fPIC -shared -Wl,--soname=$(LIBNVRAM_SHARED)

all:	shared

$(OBJS): $(BUILDDIR)/%.o : %.c
	@echo "BUILDDIR: $(BUILDDIR), first:$<,all:$^,*:$*."
	@mkdir -p $(BUILDDIR)
	$(CC) $(CFLAGS) -c $< -o $@
#	$(STRIPTOOL) -x -R .note -R .comment $(BUILDDIR)/$*.o

shared: $(OBJS)
	@echo "BUILDDIR: $(BUILDDIR)."
	@echo 'Building target: $@'
	@echo 'Invoking: GCC C Linker'
	$(CC) -shared -o $(BUILDDIR)/$(LIBNVRAM_SHARED_FULLNAME) $(OBJS)
	@echo 'Finished building target: $@'
	@echo ' '
	$(LN) -sf $(LIBNVRAM_SHARED_FULLNAME) $(BUILDDIR)/$(LIBNVRAM_SHARED)
	$(LN) -sf $(LIBNVRAM_SHARED_FULLNAME) $(BUILDDIR)/$(LIBNVRAM_SHARED).$(MAJOR_VERSION)

$(LIBNVRAM) ar-target: $(OBJS)
	$(AR) $(ARFLAGS) $(LIBNVRAM) $(OBJS)
#	$(INSTALL) -d $(TOPDIR)lib
#	$(RM) $(TOPDIR)lib/$(LIBNVRAM)
#	$(INSTALL) -m 644 $(LIBNVRAM) $(TOPDIR)lib

$(OBJS): $(HEADERS) Makefile

clean:
	( cd $(BUILDDIR); \
	$(RM) *.[oa] $(LIBNVRAM_SHARED)* $(LIBNVRAM_SHARED_FULLNAME)*; )

