Anthony F. Molinaro | ef16420 | 2010-09-07 03:35:30 +0000 | [diff] [blame] | 1 | # ---------------------------------------------------- |
| 2 | # Application version |
| 3 | # ---------------------------------------------------- |
| 4 | |
| 5 | APP_NAME=$(PACKAGE_NAME) |
| 6 | VSN=$(PACKAGE_VERSION) |
| 7 | |
| 8 | # ---------------------------------------------------- |
| 9 | # FLAGS |
| 10 | # ---------------------------------------------------- |
| 11 | |
| 12 | ERL_FLAGS = |
| 13 | ERL_INCLUDE = -I../include |
| 14 | ERL_BEHAV_PATH = -pz ../ebin |
| 15 | ERL_COMPILE_FLAGS = $(ERL_INCLUDE) $(ERL_BEHAV_PATH) |
| 16 | |
| 17 | EBIN ?= ../ebin |
| 18 | ESRC ?= . |
| 19 | EMULATOR = beam |
| 20 | |
| 21 | ERLC_WFLAGS = -W |
| 22 | ERLC = erlc $(ERLC_WFLAGS) $(ERLC_FLAGS) |
| 23 | ERL = erl -boot start_clean |
| 24 | |
| 25 | $(EBIN)/%.beam: $(ESRC)/%.erl |
| 26 | @echo " ERLC $<" |
| 27 | @$(ERLC) $(ERL_FLAGS) $(ERL_COMPILE_FLAGS) -o$(EBIN) $< |
| 28 | |
| 29 | .erl.beam: |
| 30 | $(ERLC) $(ERL_FLAGS) $(ERL_COMPILE_FLAGS) -o$(dir $@) $< |
| 31 | |
| 32 | # ---------------------------------------------------- |
| 33 | # Target Specs |
| 34 | # ---------------------------------------------------- |
| 35 | |
| 36 | MODULES = $(shell find . -name \*.erl | sed 's:^\./::' | sed 's/\.erl//') |
| 37 | MODULES_STRING_LIST = $(shell find . -name \*.erl | sed 's:^\./::' | sed 's/\.erl/,/') |
| 38 | BEHAV_MODULES = $(shell find . -name \*.erl | xargs grep -l behaviour_info | sed 's:^\./::' | sed 's/\.erl//') |
| 39 | |
| 40 | ERL_FILES= $(MODULES:%=%.erl) |
| 41 | DOC_FILES=$(ERL_FILES) |
| 42 | |
| 43 | APP_FILE= $(APP_NAME).app |
| 44 | APP_SRC= $(APP_FILE).src |
| 45 | APP_TARGET= $(EBIN)/$(APP_FILE) |
| 46 | |
| 47 | BEAMS= $(MODULES:%=$(EBIN)/%.$(EMULATOR)) |
| 48 | BEHAV_BEAMS= $(BEHAV_MODULES:%=$(EBIN)/%.$(EMULATOR)) |
| 49 | TARGET_FILES= $(BEHAV_BEAMS) $(BEAMS) $(APP_TARGET) $(APPUP_TARGET) |
| 50 | |
| 51 | # ---------------------------------------------------- |
| 52 | # Targets |
| 53 | # ---------------------------------------------------- |
| 54 | |
| 55 | all debug opt: $(EBIN) $(TARGET_FILES) |
| 56 | |
| 57 | # Note: In the open-source build clean must not destroy the preloaded |
| 58 | # beam files. |
| 59 | clean: |
| 60 | rm -f $(TARGET_FILES) |
| 61 | rm -f *~ |
| 62 | rm -f core |
| 63 | rm -rf $(EBIN) |
| 64 | rm -rf *html |
| 65 | |
| 66 | $(EBIN): |
| 67 | mkdir $(EBIN) |
| 68 | |
| 69 | dialyzer: $(TARGET_FILES) |
| 70 | dialyzer --src -r . $(ERL_INCLUDE) |
| 71 | |
| 72 | # ---------------------------------------------------- |
| 73 | # Special Build Targets |
| 74 | # ---------------------------------------------------- |
| 75 | |
| 76 | $(APP_TARGET): $(APP_SRC) $(BEAMS) |
| 77 | sed -e 's;%VSN%;$(VSN);' \ |
| 78 | -e 's;%APP_NAME%;$(APP_NAME);' \ |
| 79 | -e 's;%MODULES%;%MODULES%$(MODULES_STRING_LIST);' \ |
| 80 | $< > $<".tmp" |
| 81 | sed -e 's/%MODULES%\(.*\),/\1/' \ |
| 82 | $<".tmp" > $@ |
| 83 | rm $<".tmp" |