# Expected Environent:
#
# CIAOBASE:    directory with the CiAO os source (i.e., the trunk/os subdirectory)

CIAOVARIANT := $(CIAOBASE)/kconf/config

ifeq ($(CIAOBASE),)
  CIAOBASE := $(error Environment variable CIAOBASE is not set)
endif

$(if $(wildcard copter),,$(error You need to create a subdirectory or symlink "copter" to the copter source code))

# default target 
default : all

APP     := $(shell basename $(PWD))

KCONF_ROOT := $(CIAOBASE)/kconf
CONFIGDIR=$(KCONF_ROOT)/config

QCONF=$(KCONF_ROOT)/ciao-kconfig/scripts/kconfig/qconf
CAM=$(KCONF_ROOT)/common/scripts/app_create_model.pl
TRANSFORM=$(KCONF_ROOT)/common/scripts/transform.pl

.PHONY: all clean distclean xconfig transform
all:

xconfig: SystemObjects.fm $(APP).fm
	$(QCONF) $(APP).fm $(APP).config

transform:
	$(TRANSFORM) -f $(APP).config -s $(APP).configspace.pl -i $(CIAOBASE)/os -o $(CONFIGDIR) -l
	@if test -d files; then cp -v files/* $(CONFIGDIR)/test/ciao/os/krn/$(APP)/; fi

clean:
	rm -rf $(CONFIGDIR)

SystemObjects.fm: $(APP).profile.pl $(KCONF_ROOT)/common/ciaoApp.scheme.pl $(CAM)
	$(CAM) $(APP).profile.pl $(KCONF_ROOT)/common/ciaoApp.scheme.pl SystemObjects.fm

$(APP).config: $(APP).fm SystemObjects.fm
	$(QCONF) $(APP).fm $(APP).config

