Last active
April 1, 2019 08:22
-
-
Save haxiomic/0d316a34b6ee7adc5f27d4aaeb1ae692 to your computer and use it in GitHub Desktop.
Haxe makefile with file watching. Requires fswatch (`brew install fswatch`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HXML ?= $(shell find . -name "*.hxml" -print -quit) | |
SOURCES ?= $(shell find . -name "*.hx") | |
# Determine output file or directory from target arguments in HXML | |
OUTPUT ?= $(shell echo ' \ | |
class M { static function main() { \ | |
var r = ~/^\s*-?-(js|lua|swf|as3|neko|php|cpp|cppia|cs|java|python|hl)\s+([^\\n]+)/im; \ | |
if (r.match(sys.io.File.getContent(Sys.args()[0]))) \ | |
Sys.print(r.matched(2)); \ | |
} } \ | |
' > /tmp/M.hx && haxe -p /tmp/ --run M $(HXML); rm /tmp/M.hx ) | |
HAXE_FLAGS ?= | |
SERVER_FLAG = | |
ifdef SERVER | |
SERVER_FLAG = --connect $(SERVER) | |
endif | |
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) | |
.PHONY: all | |
all: $(OUTPUT) | |
$(OUTPUT): $(SOURCES) $(HXML) | |
@printf "$(CARET) Compiling ${BOLD}$(HXML)$(RESET)\t" | |
@# set output color to red to color errors | |
@printf "$(RED)" | |
@haxe $(SERVER_FLAG) $(HAXE_FLAGS) $(HXML) && \ | |
printf "$(RESET)" && \ | |
printf "$(BOLD)$(GREEN)OK\n" || \ | |
printf "$(RESET)" | |
@printf "$(RESET)" | |
@printf "\n" | |
.PHONY: libs | |
libs: | |
haxelib install $(HXML) --always | |
.PHONY: clean | |
clean: | |
@printf "$(CARET) $(BOLD)Are you sure you want to delete $(OUTPUT)?$(RESET)\n[y/N] " && read ans && [ $${ans:-N} == y ] | |
rm -rf $(OUTPUT) | |
PORT ?= 6009 | |
.PHONY: watch | |
watch: | |
@printf "$(BOLD)Starting compilation server on port $(PORT)$(RESET)\n" | |
@haxe --wait $(PORT) & | |
@make --file=$(mkfile_path) all SERVER=$(PORT) HAXE_FLAGS="$(HAXE_FLAGS)" || true | |
@while true; do \ | |
alias shell=""; \ | |
fswatch $(value SOURCES) $(value HXML) --one-event | xargs -n1 -I% make --file=$(mkfile_path) all SERVER=$(PORT) HAXE_FLAGS="$(HAXE_FLAGS)"; \ | |
test $$? -gt 128 && break; \ | |
done | |
# Pretty-logging variables | |
ifdef NO_COLOR | |
BOLD:= | |
GREEN:= | |
RED:= | |
GRAY:= | |
RESET:= | |
else | |
BOLD:=\x1B[1m | |
GREEN:=\x1B[38;5;10m | |
RED:=\x1B[38;5;1m | |
GRAY:=\x1B[38;5;8m | |
RESET:=\x1B[m | |
endif | |
CARET:=${BOLD}${GRAY}>${RESET} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment