# -- 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=js


# ------------------------------------------------------------------------------------------------------------------------------
# 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
LIB_OUT = $(DIR_OUT)mp.all.min.js


# 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 LIB_SEP_OUT_SUFFIX to something other than .js to replace the extension of each output file (example .min.js)

LIB_SEP_DIR_OUT = $(DIR_OUT)
LIB_SEP_OUT_PREFIX = 
LIB_SEP_OUT_SUFFIX = .min.js


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

# Library Scripts COMBINED then compressed into LIB_OUT. 
LIB_FILES = \
  src/jquery.scroll-to.js \
  src/jquery.metadata.js \
  src/inflection.js \
  src/iris.js \
  src/jquery.affix.js \
  src/jquery.reveal.js \
  src/jquery.inputmask.js \
  src/sprintf.js \
  src/jquery.mp-tabs.js \
  src/jquery.auto-grow-input.js \
  src/jquery.linkify.js \
  src/jquery.client.js \
  src/jquery.limit-maxlength.js \
  src/jquery.inputspinner.js \
  src/fileuploader.js \
  src/jquery.mp-select2.js \
	src/jquery-ui-timepicker-addon.js \
	src/jquery.autoresize.min.js \
	src/mp.js \
  src/mpv.js \
  src/mp-file-uploader.js \
  src/mpft.js \
	src/mpv-meta.js



# Separate Library Scripts compressed as separate files into the directory LIB_SEP_DIR_OUT
LIB_SEP_FILES = \
  src/matchmedia.js \
  src/picturefill.js \
  src/jquery.imageload.js \
  src/jquery.picturefill.js \
  src/handlebars.js \
  src/jquery.scroll-to.js \
  src/jquery.lazyload.js \
  src/jquery.metadata.js \
  src/inflection.js \



# ------------------------------------------------------------------------------------------------------------------------------
# NO NEED TO MODIFY ANYTHING BELOW THIS LINE
# ------------------------------------------------------------------------------------------------------------------------------


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

all: make_lib 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

LIB_DEP = $(LIB_FILES) $(LIB_SEP_FILES)

# --- Library Build --- #

make_lib: $(LIB_DEP)

ifneq ($(strip $(LIB_FILES)),)
		@echo Building: Combined Library Files...
		@$(CMD_CAT) $(addprefix $(LIB_DIR), $(LIB_FILES)) $(CMD_STDERR_SUPPRESS) | $(CMD_COMPRESS) $(CMD_COMPRESS_OPTIONS) > $(LIB_OUT)
endif

ifneq ($(strip $(LIB_SEP_FILES)),)
		@echo Building: Separate Library Files...
    $(foreach f, $(LIB_SEP_FILES), $(shell $(CMD_COMPRESS) $(CMD_COMPRESS_OPTIONS) $(f) > $(LIB_SEP_DIR_OUT)$(LIB_SEP_OUT_PREFIX)$(notdir $(basename $(f)))$(LIB_SEP_OUT_SUFFIX))) 
endif
	
complete:
	@$(CMD_COMPLETE)