#############################################################################
#	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		#
#	This software is released under the GNU General Public License, version	#
#	3, with the exemptions that 1) the header files installed by this 	 	#
#	package can be included in closed-source code and 2) the libraries		#
#	built by this package can be statically linked into a closed-source 	#
#	binary. See the file LICENSE for the details.							#
#	This software is provided "AS IS", without any warranty or guarantee.	#
#	By using this software you acknowledge that neither Bendor Research nor	#
#	any of its personnel or affiliates can be held liable for any damages,	#
#	including, but not limited to, loss of business, loss of money, loss of #
#	life, loss of reputation, arising out of this software being faulty or	#
#	not performing as advertised, even if Bendor Research was aware of such	#
#	faults in the software. You use this software at your own risk, any and #
#	all liabilities that arise out of your using this software are strictly	#
#	yours.																	#
#############################################################################

FILES	= lpclib_open.c lpclib_serial.c lpclib_error.c lpclib_target.c	\
		  lpclib_chips.c lpclib_uu.c lpclib_fileio.c lpclib_srec.c \
		  lpclib_ihex.c

INCNAME	= lpclib.h

CFLAGS	= -g -O2 -std=gnu99 -pipe -MMD -idirafter $(PWD)/include \
		  -W -Werror -Wall -Wundef -Wshadow -Wmissing-declarations \
		  -Wpointer-arith -Wwrite-strings -Wmissing-field-initializers \
		  -DLPC_HEADER='"$(PWD)/include/tools/$(INCNAME)"' -fpic

OBJECTS	= $(patsubst %.c,$(BINDIR)/%.o,$(FILES))
DEPENDS	= $(patsubst %.c,$(BINDIR)/%.d,$(FILES))
HERE	= $(patsubst $(PWD)/%,%,$(shell pwd))

build_libs:	$(PWD)/include/tools/$(INCNAME) $(RESDIR)/$(SONAME)
	@true

.PHONY:	build_libs

$(RESDIR)/$(SONAME): $(OBJECTS) Makefile
	@echo "Linking     " $(patsubst $(RESDIR)/%,%,$@)
	@cc -shared -Wl,-soname,$(SONAME),-export-dynamic \
	-o $(RESDIR)/$(SONAME) $(OBJECTS) -lc -lm 2> $*.err
	@rm $*.err

$(BINDIR)/%.o:	%.c
	@echo "Compiling   " $(HERE)/$<
	@cc $(CFLAGS) -c -MF $(patsubst %.o,%.d,$@) -o $@ $< 2> $(PWD)/$*.err
	@rm $(PWD)/$*.err

-include $(DEPENDS)

