Skip to content

Instantly share code, notes, and snippets.

@oscherler
Last active April 7, 2017 18:55
Show Gist options
  • Save oscherler/22c7a2ee91b066d2e09890c13125fe33 to your computer and use it in GitHub Desktop.
Save oscherler/22c7a2ee91b066d2e09890c13125fe33 to your computer and use it in GitHub Desktop.
# http://www.erlang-factory.com/upload/presentations/33/EUnitinPractice.pdf
ERLC_FLAGS=
# finds all the files in the current directory that end in .erl
# and set variable SOURCES to the list
SOURCES=$(wildcard *.erl)
# same for .hrl files in variable HEADERS
HEADERS=$(wildcard *.hrl)
# take every file in .erl in variable SOURCES, transform them to a .beam file in folder ebin
# and set variable OBJECTS to that new list
OBJECTS=$(SOURCES:%.erl=ebin/%.beam)
# so assuming you have program.erl, util.erl and global.hrl in the root folder, you will have:
# SOURCES=program.erl util.erl
# HEADERS=global.hrl
# OBJECTS=ebin/program.beam ebin/util.beam
# the first target is the default one
# it requires target compile and test to be made
all: compile test
# compile requires all the OBJECTS files to be made
# in our example, it means the ebin/%.beam target will be made for ebin/program.beam and ebin/util.beam
compile: $(OBJECTS)
# when a .beam file in ebin needs to be made:
# - make sure the target directory (ebin) exists
# - compile the input file (in .erl), put the result .beam into ebin
# the .beam file needs to be remade if the .erl file or any file in HEADERS or the Makefile changes
ebin/%.beam: %.erl $(HEADERS) Makefile
@mkdir -p $(@D)
erlc $(ERLC_FLAGS) -o ebin/ $<
# delete all the object files
# the minus means don’t report errors
clean:
-rm $(OBJECTS)
test:
@erl -noshell -pa ebin \
-eval 'eunit:test( "ebin", [ verbose ] )' \
-s init stop
gettysburg: text=gettysburg-address.txt
gettysburg: print
dickens: text=dickens-christmas.txt
dickens: print
print: compile
@erl -noshell -pa ebin \
-eval 'indexer:print_file_index("text/'$(text)'")' \
-s init stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment