
#########################################################
#                                                       #
#       FuturaSoft Topfield TAP Library                 #
#       Makefile for TAP user directory                 #
#       Version 1.00                                    #
#                                                       #
#       Copyright (c) 2015 Martin Krämer                #
#                                                       #
#########################################################

#APP_NAMES = MyTap1 MyTap2

# Options
#VERBOSE = 1				# you can see the compile options

# Default settings
CUR_DIR = $(abspath .)
TAP_USER_DIR = $(HOME)/tap

# Auto detect application names and directories
ifeq ($(APP_NAMES),)
APP_NAMES := $(filter-out def%, $(patsubst $(CUR_DIR)/%/Makefile, %, $(wildcard $(CUR_DIR)/*/Makefile)))
endif

ifeq ($(FSTAP_DIR),)
FSTAP_DIR = /opt/fstap
ifneq ($(wildcard $(FSTAP_DIR)/),)
$(info [Auto detect FuturaSoft's tap directory at ... $(FSTAP_DIR)])
else
$(error FuturaSoft's tap directory not found)
endif
endif

# Make options
ifeq ($(VERBOSE),)
Q = @
endif

# Target objects
MY_APPS := $(APP_NAMES)
TOUCH_APPS := $(addprefix _touch, $(APP_NAMES))
ZIP_APPS := $(addprefix _zip, $(APP_NAMES))
CLEAN_APPS := $(addprefix _clean, $(APP_NAMES))

# Commands
MKDIR = mkdir -p
CP = cp -f
TOUCH = touch -c
ZIP = zip

# Targets
.PHONY: all touch zip clean .home FORCE $(MY_APPS) $(TOUCH_APPS) $(ZIP_APPS) $(CLEAN_APPS)
.SUFFIXES:				# Delete the default suffixes

all: $(MY_APPS)
touch: $(TOUCH_APPS)
zip: $(ZIP_APPS)
clean: $(CLEAN_APPS)

$(MY_APPS):
	$(Q)$(MAKE) -C $(addprefix $(CUR_DIR)/, $@)

$(TOUCH_APPS):
	$(Q)$(MAKE) -C $(patsubst _touch%, $(CUR_DIR)/%, $@) touch

$(ZIP_APPS):
	$(Q)$(MAKE) -C $(patsubst _zip%, $(CUR_DIR)/%, $@) zip

$(CLEAN_APPS):
	$(Q)$(MAKE) -C $(patsubst _clean%, $(CUR_DIR)/%, $@) clean

.home:
	$(info [Make TAP user directory ... $(TAP_USER_DIR)])
	$(Q)$(MKDIR) $(TAP_USER_DIR)
	$(Q)$(CP) -irv $(filter-out $(FSTAP_DIR)/user/def%, $(wildcard $(FSTAP_DIR)/user/*)) $(TAP_USER_DIR)/

%.new: FORCE
	$(info [Make TAP directory ... $(basename $@)])
	$(Q)$(MKDIR) $(basename $@)
	$(Q)$(CP) -rv $(FSTAP_DIR)/user/def/* $(basename $@)/

FORCE: ;

