# -- JavaScript Make File
# Prepares JavaScript files for distribution with optional compression (minification)
# Created by Travis Hensgen (Traversal) - http://traversal.com.au

# --- Command Line Switches --- #
# build <fast|final> 	The build type: fast = concatentation with no compression (for quick debugging), final = concatentation and compression
# os <unix|win>			The platform os: unix = Unix based OSes: Unix, Linux, Mac OS X, Solaris. win = Windows

os = unix

# Directory Separator setup - DON'T MODIFY THIS
ifeq ($(os), unix)
DS = /
else
DS=\\
endif

# --- Compress Commands Paths --- #
# Set these to the command required to run the compressor of your choice for your platform
CMD_COMPRESS_UNIX = java -jar /Library/WebServer/yuicompressor-2.4.6.jar
CMD_COMPRESS_WIN =  java -jar C:\\Inetpub\\AdminScripts\\yuicompressor.jar

# -- Compress command line options (both platforms)
CMD_COMPRESS_OPTIONS = --type=css


# ------------------------------------------------------------------------------------------------------------------------------
# INPUT & OUTPUT FILES 
# ------------------------------------------------------------------------------------------------------------------------------

# Note - $(DS) is a variable symbol for the Directory Separator
# To maintain portability between Unix and Windows
# ALWAYS USE $(DS) instead of / (unix), \\ (windows, escaped)


# ------------------------------------------------------------------------------------------------------------------------------
#  OUTPUT FILES, PREFIXES, SUFFIXES
# ------------------------------------------------------------------------------------------------------------------------------

# General Output Directory where scripts can be installed (relative to this makefile)
# You don't have to use this, but it is useful for the common case when you want minified files in one directory 
DIR_OUT = .$(DS)

# Output file for COMBINED site-specific scripts
SITE_OUT = 

# Output file for COMBINED library scripts
THEME_OUT = $(DIR_OUT)codemirror.themes.css

# Output dir, prefix, suffix for SEPARATE Site-specific scripts
# Set SITE_SEP_OUT_SUFFIX to something other than .js to replace the extension of each output file (example .min.js)

SITE_SEP_DIR_OUT = $(DIR_OUT)
SITE_SEP_OUT_PREFIX = 
SITE_SEP_OUT_SUFFIX = .min.js

# Output dir, prefix, suffix for SEPARATE Library scripts
# Set THEME_SEP_OUT_SUFFIX to something other than .js to replace the extension of each output file (example .min.js)

THEME_SEP_DIR_OUT = $(DIR_OUT)
THEME_SEP_OUT_PREFIX = 
THEME_SEP_OUT_SUFFIX = .min.js


# ------------------------------------------------------------------------------------------------------------------------------
#  INPUT FILES 
# ------------------------------------------------------------------------------------------------------------------------------

THEME_FILES = $(wildcard theme/*.css)

# -----------
# MAKE RULES

all: make_theme complete

# -----------------
# OS PLATFORM SETUP


ifeq ($(os), unix)

# --- Unix Setup --- #

SHELL=/bin/bash
# OS commands
CMD_CAT = cat
CMD_CP = cp

# The compressor command to run
CMD_COMPRESS = $(CMD_COMPRESS_UNIX)
CMD_COMPLETE = echo "Completed: $$(date)"

else
 
# --- Windows Setup --- #

SHELL=cmd.exe
# OS commands
CMD_CAT = type
CMD_CP = copy
# The compress (minification) command to run
CMD_COMPRESS = $(CMD_COMPRESS_WIN)
CMD_COMPLETE = echo Completed: %DATE% - %TIME%
# special options to keep the Windows command shell QUIET!
CMD_STDERR_SUPPRESS = 2>nul
CMD_STDOUT_SUPPRESS = >nul

endif

THEME_DEP = $(THEME_FILES)

# --- Library Build --- #

make_theme: $(THEME_DEP)

ifneq ($(strip $(THEME_FILES)),)
		@echo Building: Combined Theme Files...
		@$(CMD_CAT) $(addprefix $(THEME_DIR), $(THEME_FILES)) $(CMD_STDERR_SUPPRESS) | $(CMD_COMPRESS) $(CMD_COMPRESS_OPTIONS) > $(THEME_OUT)
endif
	
complete:
	@$(CMD_COMPLETE)