#   Makefile - Build the SFB library in host mode
#   Copyright (C) 2008 The Regents of the University of New Mexico.  All rights reserved.

#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Lesser General Public
#   License as published by the Free Software Foundation; either
#   version 2.1 of the License, or (at your option) any later version.

#   This library 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
#   Lesser General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with this library; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
#   USA

BASEDIR:=../../..
include $(BASEDIR)/config/Makevars.mk
include $(BASEDIR)/config/Makecommon.mk

CPPFLAGS+=$(CORE_EXTRA_CPPFLAGS) -I$(INCLUDEDIR) -I$(INCLUDEDIR)/lpc
CFLAGS+=$(CORE_EXTRA_CFLAGS) -I$(INCLUDEDIR) -I$(INCLUDEDIR)/lpc

all:	$(LIBDIR)/libreflex.a

SRCFILES:=$(wildcard *.cpp *.c)

HDRFILES:=$(SRCFILES)
HDRFILES:=$(patsubst %.cpp, $(INCLUDEDIR)/%.h, $(HDRFILES))
HDRFILES:=$(patsubst %.c, $(INCLUDEDIR)/%.h, $(HDRFILES))

OBJFILES:=$(SRCFILES)
OBJFILES:=$(patsubst %.cpp, $(OBJDIR)/%.o, $(OBJFILES))
OBJFILES:=$(patsubst %.c, $(OBJDIR)/%.o, $(OBJFILES))

$(LIBDIR)/libreflex.a:	$(OBJFILES) # $(info SRCFILES='$(SRCFILES) OBJFILES='$(OBJFILES)' OBJDIR='$(OBJDIR)')
	mkdir -p $(LIBDIR)
	ar ruc "$@" $(OBJFILES)

testPacketBuffer:	FORCE
	@rm -f SFBPacketBuffer.o
	DEFINES=-DTEST_PACKET_BUFFER make -k
	$(GCC) -o"$@" SFBPacketBuffer.o SFBUtils.o
	./"$@"

testWeaksum:	FORCE
	@rm -f SFBWeaksum.o
	DEFINES=-DTEST_WEAKSUM make -k
	$(GCC) -o"$@" SFBWeaksum.o
	./"$@"

clean:	FORCE
	@rm -f $(OBJFILES) *~

realclean:	clean 
	@rm -f $(LIBDIR)/libreflex.a
	@rm -f $(OBJDIR)/*.[do]


.PHONY:	FORCE

include $(BASEDIR)/config/Makedeps.mk

