#------------------------------->  Makefile  <--------------------------------#
#- Copyright (C) 199x by International Computer Science Institute            -#
#- This file is part of the GNU Sather package. It is free software; you may -#
#- redistribute  and/or modify it under the terms of the  GNU General Public -#
#- License (GPL)  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 Doc/GPL for more details.        -#
#- The license text is also available from:  Free Software Foundation, Inc., -#
#- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     -#
#------------->  Please email comments to <bug-sather@gnu.org>  <-------------#

SATHER_HOME=$(shell cd ..;pwd)

include $(SATHER_HOME)/config.default

LIBRARY=../lib
LIBRARY_BOOT=../lib-boot
##########PLIBRARY_BOOT=../lib-boot-psather

default: CONFIG CONFIG-boot

TMPFILE=CONFIG.tmp.c

CONFIG: CONFIG.proto \
	$(LIBRARY)/*.config \
	$(LIBRARY)/Required/*.config \
	$(LIBRARY)/Required/*/config/* \
	$(LIBRARY)/Maths/config/* \
	$(LIBRARY)/External/config/*

CONFIG-boot: CONFIG-boot.proto \
	     $(LIBRARY_BOOT)/*.config \
	     $(LIBRARY_BOOT)/*/*.config
########	     $(PLIBRARY_BOOT)/*/*.config

CONFIG CONFIG-boot: Makefile ../Makefile ../config.platform
	@echo Creating system/$@...
	@echo "-- This file has been created by using cpp on $@.proto" > $(TMPFILE)
	@echo "-- in this directory and by using variables defined " >> $(TMPFILE)
	@echo "-- in the top level Makefile. Please do not edit it" >> $(TMPFILE)
	@echo "#define CONFIG_DEFAULT_PLATFORM \"$(DEFAULT_PLATFORM)\"" >> $(TMPFILE)
	@echo -n "#define CONFIG_PLATFORMS \"" >> $(TMPFILE)
	@echo -n                           $(PLATFORMS) | sed "s/ //g;s/,/\",\"/g" >> $(TMPFILE)
	@echo                                                                    "\"" >> $(TMPFILE)
	@echo "#define CONFIG_VERSION \"$(VERSION)\"" >> $(TMPFILE)
	@echo "#include \"$@.proto\"" >> $(TMPFILE)
	@$(CPP) -P -undef $(TMPFILE) > $@
	@$(RM) $(TMPFILE)

# The following did not work, because of predefined macros. Unfortunately, I could not find a way to
# remove predefined macros while still keep the macros defined at the command line
#	@$(CPP) -Uunix -DCONFIG_DEFAULT_PLATFORM='$(DEFAULT_PLATFORM)' -DCONFIG_PLATFORMS='$(PLATFORMS)' CONFIG.proto >> CONFIG

clean:
	$(RM) CONFIG CONFIG-boot $(TMPFILE)
	$(RM) -r lib include
	$(MAKE) clean -C activethreads
#	$(MAKE) clean -C am
	$(MAKE) clean -C brahma
	$(MAKE) clean -C lwp
	$(MAKE) clean -C psather
	$(MAKE) clean -C siva
