# 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

# 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: xconfig transform

# invokes a GUI frontend to kconf to configure the OS and application
xconfig: SystemObjects.fm $(APP).fm
	$(QCONF) $(APP).fm $(APP).config

# Creates the variant
transform: $(APP).config
	$(TRANSFORM) -f $(APP).config -s $(APP).configspace.pl -i $(CIAOBASE)/os -o $(CONFIGDIR)

# Creates the feature model for configuring the OS object instances defined
# by the application in the $(APP).profile.pl file
SystemObjects.fm: $(APP).profile.pl $(KCONF_ROOT)/common/ciaoApp.scheme.pl $(CAM)
	$(CAM) $(APP).profile.pl $(KCONF_ROOT)/common/ciaoApp.scheme.pl SystemObjects.fm

# invokes a GUI frontend to kconf to configure the OS and application
$(APP).config: SystemObjects.fm $(APP).fm
	$(QCONF) $(APP).fm $(APP).config

