###########################################################
### Makefile.rules for the GNU PIC Library
###
### Copyright (C) 2005 by Raphael Neider <rneider AT web.de>
###
### The GNU PIC Library was originally designed and
### implemented by
###	Vangelis Rokas <vrokas@otenet.gr>
###
### It is currently maintained by
###	Raphael Neider <rneider AT web.de>
###
### This file may be distributed under the terms of the the
### GNU General Public License (GPL). See COPYING for details.
###
### $Id: Makefile.rules 4791 2007-05-06 20:08:22Z tecodev $
###

# update dependencies
$(top_builddir)/$(builddir)/%.d : %.c
ifndef SILENT
	@echo "[  CPP  ] ==> $(patsubst $(top_builddir)/%,%,$@)"
endif
	$(Q)$(CPP) $(CPPFLAGS) -o "$@" "$<"

# assemble
$(top_builddir)/$(builddir)/%.o : %.S
ifndef SILENT
	@echo "[  AS   ] ==> $(patsubst $(top_builddir)/%,%,$@)"
endif
	$(Q)$(AS) $(ASFLAGS) -o "$@" -c "$<"

# compile
$(top_builddir)/$(builddir)/%.o : %.c
ifndef SILENT
	@echo "[  CC   ] ==> $(patsubst $(top_builddir)/%,%,$@)"
endif
	$(Q)$(CC) $(CFLAGS) -o "$@" -c "$<"

# create library
ifneq (,$(strip $(LIB_O)))
%.lib : $(LIB_O)
ifndef SILENT
	@echo "[  LIB  ] $(patsubst $(top_builddir)/%,%,$@) <== $(patsubst $(top_builddir)/$(builddir)/%,%,$^)"
endif
	$(Q)$(RM) "$@"; $(LIB) $(LIBFLAGS) "$@" $^
else
%.lib : recurse
ifndef SILENT
	@echo "[  LIB  ] $(patsubst $(top_builddir)/%,%,$@) <== **/*.o"
	$(Q)$(RM) "$@"; LIB_O=`find "$(top_builddir)/$(builddir)" -name "*.o"`; echo $${LIB_O}; [ "x$${LIB_O}" = "x" ] || $(LIB) $(LIBFLAGS) "$@" $${LIB_O}
else
	$(Q)$(RM) "$@"; LIB_O=`find "$(top_builddir)/$(builddir)" -name "*.o"`;                 [ "x$${LIB_O}" = "x" ] || $(LIB) $(LIBFLAGS) "$@" $${LIB_O}
endif
endif

.PHONY : recurse force

# build sub-directories
ifneq (,$(strip $(SUBDIRS)))
recurse : force
	$(Q)+for DIR in $(SUBDIRS) ; do \
		[ -f "$(srcdir)/$${DIR}.ignore" ] && $(GREP) "^$${ARCH}$$" "$(srcdir)/$${DIR}.ignore" > /dev/null 2>&1 || ( \
			$(MKDIR) "$(top_builddir)/$(builddir)/$${DIR}"; \
			$(MAKE) -C "$${DIR}" builddir="$(builddir)/$${DIR}" $(MAKECMDGOALS); \
		) || exit 1; \
	done
else
recurse :
	@# nothing to do
endif

# target to force remaking of (seemingly) independent targets
force :
