# GEL Top Makefile
#   Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
#   Written by Stephane Carrez (stcarrez@nerim.fr)	
#
# This file is part of GEL.
#
# GEL 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, or (at your option)
# any later version.
#
# GEL 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 GEL; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.  */
# 
SRCDIR=.

GEL_BASEDIR=.

NAME=gel-hc1x

include $(GEL_BASEDIR)/config/make.defs

SUBDIRS=config include lib src examples tests testsuite doc hello

ADASUBDIRS=ainclude ada

FILES=Makefile COPYING COPYING.LIB README ChangeLog \
      AUTHORS NEWS ANNOUNCE README.PORT

all clean dist-clean install::
	test -d bin || mkdir bin
	test -d lib || mkdir lib
	echo "Configured for $(TARGET_BOARD)"
	for i in $(SUBDIRS); do \
	    if test -f $$i/Makefile; then \
	       cd $$i; $(MAKE) $@ ; \
	       cd .. ; \
	    fi ; \
	done
	# Build Ada examples only if the compiler is configured for it
	if ($(CC) -v 2>&1 | grep -i "enable-languages=.*ada"); then \
	   for i in $(ADASUBDIRS); do \
	      if test -f $$i/Makefile; then \
	        $(MAKE) -C $$i $@;\
	      fi \
	   done \
	fi

tar:	dist-clean
	mkdir $(NAME)-$(GEL_VERSION)
	tar --exclude="*~" --exclude="*.[oab]" --exclude="*.elf" \
	    --exclude="*.s19" --exclude="*.bak" --exclude="*.ram" \
	    --exclude="*.log" --exclude="*.ali" \
	    --exclude=latex --exclude=rtf \
	    --exclude=CVS --exclude=.cvsignore --exclude="#*" \
	    -cf - $(FILES) $(SUBDIRS) $(ADASUBDIRS) | \
	(cd $(NAME)-$(GEL_VERSION); tar xf -)
	tar cvzf $(NAME)-$(GEL_VERSION).tar.gz $(NAME)-$(GEL_VERSION)
	rm -rf $(NAME)-$(GEL_VERSION)

clean::
	rm -f lib/*.a
	rm -f bin/*.elf

# Run the DejaGNU testsuite
check:
	test -f bin/event-test.elf || $(MAKE) install
	$(MAKE) -C testsuite $@

BOARDS=bootstrap eeprom-512 m68hc11-32k m68hc11-6270
BOARDS+=m68hc11-cme11  m68hc12-axcmd12

build-all-for-test:
	for i in $(BOARDS); do \
	    echo "Building for $$i"; \
	    $(MAKE) TARGET_BOARD=$$i; \
	    echo "Clleanup for $$i"; \
	    $(MAKE) TARGET_BOARD=$$i clean; \
	done
