# This code was developed in the joint research project APPLY funded by
# the German Ministry of Research and Technology under the project code
# ITW9102D5.
# 
# Copyright 1994-2010 Fraunhofer ISST
# 
# Licensed under the EUPL, Version 1.1 or  as soon they will be approved by the European Commission - subsequent 
# versions of the EUPL (the "Licence");
# 
# You may not use this work except in compliance with the Licence.
# You may obtain a copy of the Licence at:
# http://www.osor.eu/eupl/european-union-public-licence-eupl-v.1.1
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 
# See the Licence for the specific language governing permissions and limitations under the Licence.

#
#the default name of basic module 
basic_module = eulisp-level-0
image :sh= echo ${Eu2CIMAGENAME:-eu2c}
basic_image = $(image) 
EulispModules =EulispModules/*.em EulispModules/*.lisp 
ApplyModules = ApplyModules/*.am 
Apply = Apply/*.em Apply/*.bin Apply/*.lisp 
#create the eu2c compiler and a basic system

#.KEEP_STATE:

all: 
	$(MAKE) $(MFLAGS) $(basic_image)
	$(MAKE) $(MFLAGS) libs
	cd $$Eu2CROOT
	$(MAKE) $(MFLAGS) compile_basic_system basic_module=$(basic_module) basic_image=$(basic_image)
	$(MAKE) $(MFLAGS) load_basic_system basic_module=$(basic_module) basic_image=$(basic_image)



#create the eu2c compiler only
$(basic_image):
	$$Eu2CROOT/Apply/boot.eu2c 1
	$$Eu2CROOT/Apply/boot.eu2c 2
	$(MAKE) $(MFLAGS) libs

#compile basic module

./ApplyC/$(basic_module).a: $(basic_image)
	Apply/boot.eu2c 3 $(basic_module)
	@rm -f $$Eu2CROOT/ApplyModules/$(basic_module).c
	@rm -f $$Eu2CROOT/ApplyModules/$(basic_module).inst
	@rm -f $$Eu2CROOT/ApplyModules/$(basic_module).o

load_basic_system: ./ApplyC/$(basic_module).a
	Apply/boot.eu2c 4 $(basic_module)

compile_basic_system: ./ApplyC/$(basic_module).a
	echo "basic module compiled in Library" $$Eu2CROOT/ApplyC/$(basic_module).a
	make ./ApplyC/$(basic_module).a  basic_module=$(basic_module) basic_image=$(basic_image)



#create a basic system only , $(basic_image) must be already built
basic_system: $(basic_image)
	$(MAKE) $(MFLAGS) compile_basic_system basic_module=$(basic_module) basic_image=$(basic_image)
	$(MAKE) $(MFLAGS) load_basic_system basic_module=$(basic_module) basic_image=$(basic_image)

libs:  
	$$Eu2CROOT/ApplyC/create_libs.eu2c



remove_sources:
	$(MAKE) $(MFLAGS) clean_compiler_sources
	$(MAKE) $(MFLAGS) clean_runtime_sources
	$(MAKE) $(MFLAGS) clean_eu2c_image
	$(MAKE) $(MFLAGS) clean_c_sources
	

clean_compiler_sources:
	rm -f $(EulispModules) $(Apply)

clean_runtime_sources:
	rm -f $(ApplyModules)


clean_eu2c_image:
	rm -f $$Eu2CROOT/$(basic_image)

clean_basic_system:
	rm -f $$Eu2CROOT/$(basic_image).$(basic_module)
	rm -f $$Eu2CROOT/ApplyC/$(basic_module).[ah]

clean_libs:
	rm -f $$Eu2CROOT/APPLYC/eu2c*.a

clean_c_sources:
	rm -f $$Eu2CROOT/ApplyC/*.[co]


