Last active
December 21, 2015 11:59
-
-
Save stwind/6303096 to your computer and use it in GitHub Desktop.
Common Erlang Makefile tasks
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
all: app | |
app: $(REBAR) deps | |
@$(REBAR) compile | |
deps: $(REBAR) | |
@$(REBAR) get-deps | |
clean: $(REBAR) | |
@$(REBAR) clean | |
test: $(REBAR) app | |
@$(REBAR) eunit skip_deps=true $(if $(SUITES),suites=$(SUITES),) | |
ct: $(REBAR) app | |
@$(REBAR) ct skip_deps=true | |
BASIC_PLT := basic.plt | |
DIALYZER := dialyzer | |
DIALYZER_APPS := kernel stdlib sasl inets crypto public_key ssl | |
$(BASIC_PLT): build-plt | |
build-plt: | |
@$(DIALYZER) --build_plt --output_plt $(BASIC_PLT) --apps $(DIALYZER_APPS) | |
dialyze: $(BASIC_PLT) | |
@$(DIALYZER) -r src $(DEPS)/*/src --no_native --src --plt $(BASIC_PLT) -Werror_handling \ | |
-Wrace_conditions -Wunmatched_returns # -Wunderspecs | |
xref: $(REBAR) app | |
@$(REBAR) xref skip_deps=true | |
doc: $(REBAR) app | |
@$(REBAR) doc skip_deps=true | |
lock-deps: $(REBAR) deps | |
@$(REBAR) lock-deps skip_deps=true ignore=meck,moka,proper,rebar skip_dirs=rel | |
.PHONY: app doc deps clean test ct xref lock-deps build-plt |
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
APP := erlang_awesome | |
include common.mk | |
include rebar.mk | |
include release.mk | |
include pkg.mk |
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
REPO_TAG := $(shell git describe --tags --always) | |
MAJOR_VERSION ?= $(shell echo $(REPO_TAG) | sed -e 's/\(.*\)-[^-]*-[^-]*/\1/') | |
PKG_BUILD = 1 | |
ERLANG_BIN = $(shell dirname $(shell which erl)) | |
archive_git = git archive --format=tar --prefix=$(1)/ HEAD | (cd $(2) && tar xf -) | |
CLONEDIR ?= $(APP)-clone | |
MANIFEST_FILE ?= dependency_manifest.git | |
get_dist_deps = mkdir distdir && \ | |
git clone . distdir/$(CLONEDIR) && \ | |
cd distdir/$(CLONEDIR) && \ | |
git checkout $(REPO_TAG) && \ | |
$(1) get-deps && \ | |
echo "- Dependencies and their tags at build time of $(REPO) at $(REPO_TAG)" > $(MANIFEST_FILE) && \ | |
for dep in deps/*; do \ | |
cd $${dep} && \ | |
printf "$${dep} version `git describe --always --long --tags 2>/dev/null || git rev-parse HEAD`\n" >> ../../$(MANIFEST_FILE) && \ | |
cd ../..; done && \ | |
LC_ALL=POSIX && export LC_ALL && sort $(MANIFEST_FILE) > $(MANIFEST_FILE).tmp && mv $(MANIFEST_FILE).tmp $(MANIFEST_FILE); | |
NAME_HASH = $(shell git hash-object distdir/$(CLONEDIR)/$(MANIFEST_FILE) 2>/dev/null | cut -c 1-8) | |
CURRENT_BRANCH := $(shell git branch --no-color 2> /dev/null | grep \* | cut -d " " -f 2) | |
ifeq (master, $(CURRENT_BRANCH)) | |
PKG_VERSION = $(MAJOR_VERSION) | |
PKG_ID = $(APP)-$(MAJOR_VERSION) | |
else | |
ifeq ($(REPO_TAG), $(MAJOR_VERSION)) | |
PKG_VERSION = $(REPO_TAG) | |
PKG_ID = $(APP)-$(REPO_TAG) | |
else | |
META = $(subst -,.,$(shell echo $(REPO_TAG) | awk 'BEGIN{FS="-"}{print $$(NF-1)}')) | |
PKG_VERSION = $(MAJOR_VERSION)+build.$(META).$(NAME_HASH) | |
PKG_ID = $(APP)-$(PKG_VERSION) | |
DEV=true | |
endif | |
endif | |
build_clean_dir = cd distdir/$(CLONEDIR) && \ | |
$(call archive_git,$(PKG_ID),..) && \ | |
cp $(MANIFEST_FILE) $(REBAR) ../$(PKG_ID)/ && \ | |
for dep in deps/*; do \ | |
cd $${dep} && \ | |
$(call archive_git,$${dep},../../../$(PKG_ID)) && \ | |
mkdir -p ../../../$(PKG_ID)/$${dep}/priv && \ | |
printf "`git describe --always --long --tags 2>/dev/null || git rev-parse HEAD`" > ../../../$(PKG_ID)/$${dep}/priv/vsn.git && \ | |
cd ../..; done | |
distdir/$(CLONEDIR)/$(MANIFEST_FILE): $(REBAR) | |
$(call get_dist_deps,$(if $(DEV),$(REBAR),$(REBAR) -C rebar.config.lock)) | |
distdir/$(PKG_ID): distdir/$(CLONEDIR)/$(MANIFEST_FILE) | |
$(call build_clean_dir) | |
distdir/$(PKG_ID).tar.gz: distdir/$(PKG_ID) | |
tar -C distdir -czf distdir/$(PKG_ID).tar.gz $(PKG_ID) | |
dist: distdir/$(PKG_ID).tar.gz | |
cp distdir/$(PKG_ID).tar.gz . | |
ballclean: | |
rm -rf $(PKG_ID).tar.gz distdir | |
pkgclean: ballclean | |
rm -rf package | |
package: distdir/$(PKG_ID).tar.gz | |
ln -sf distdir package | |
$(MAKE) -C package -f $(PKG_ID)/deps/node_package/Makefile | |
.PHONY: package | |
export PKG_VERSION PKG_ID PKG_BUILD BASE_DIR ERLANG_BIN REBAR RELEASE |
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
BASE_DIR := $(shell pwd) | |
REBAR_REPO := https://github.com/rebar/rebar.git | |
REBAR ?= $(BASE_DIR)/rebar | |
DEPS ?= deps | |
$(REBAR): | |
@mkdir -p $(DEPS) | |
@[ ! -d $(DEPS)/rebar ] && git clone $(REBAR_REPO) $(DEPS)/rebar; $(MAKE) -C $(DEPS)/rebar | |
@cp $(DEPS)/rebar/rebar . | |
rebar: $(REBAR) |
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
APP ?= demo_app | |
rel: app rel/$(APP) | |
rel/$(APP): | |
@$(REBAR) generate $(OVERLAY_VARS) | |
relclean: | |
@rm -rf rel/$(APP) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment