Skip to content

Commit

Permalink
Changed from rebar to erlang.mk
Browse files Browse the repository at this point in the history
Fixed a couple of Erlang compile warnings in the process.

Note: the build on Mac using cross compilation does not work right now.
  • Loading branch information
lehoff committed Jul 2, 2013
1 parent 024bd7e commit 6548ec6
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 56 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ ebin/*
variables-*
*/temp/*

dump_excludes
dump_to_pi
sync_excludes
sync_to_pi
54 changes: 29 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
PROJECT=erlang_ale

#DEPS = edown gen_leader gproc meck pihwm erlang_portutil
DEPS = gproc meck pihwm erlang_portutil

#dep_edown = https://github.com/esl/edown.git master
#dep_gen_leader = https://github.com/abecciu/gen_leader_revival.git master
dep_gproc = https://github.com/lehoff/gproc.git master
#0.2.13.3
dep_meck = https://github.com/eproxus/meck.git 0.7.2
dep_pihwm = https://github.com/omerk/pihwm.git master "./configure"
dep_erlang_portutil = https://github.com/omerk/erlang_portutil master

include erlang.mk

REBAR_DEPS_DIR=${DEPS_DIR}

ERL_LIBS:=./deps:${ERL_LIBS}


UNAME := $(shell uname)

ifeq ($(UNAME), Darwin)
XC_DIR=/usr/local/gcc-4.8.0-for-linux32
ERL_LIB=/usr/local/lib/erlang/lib/erl_interface-3.7.11
CFLAGS=-Wall -I/usr/local/include -I$(ERL_LIB)/include -I$(XC_DIR)/include -Ideps/erlang-portutil -Ideps/pihwm/lib
CFLAGS=-Wall -I/usr/local/include -I$(ERL_LIB)/include -I$(XC_DIR)/include -Ideps/erlang_portutil -Ideps/pihwm/lib
CC=$(XC_DIR)/bin/i586-pc-linux-gcc
endif

ifeq ($(UNAME), Linux)
ERL_LIB=/usr/lib/erlang/lib/erl_interface-3.7.9
CFLAGS=-Wall -I/usr/local/include -I$(ERL_LIB)/include -Ideps/erlang-portutil -Ideps/pihwm/lib
CFLAGS=-Wall -I/usr/local/include -I$(ERL_LIB)/include -Ideps/erlang_portutil -Ideps/pihwm/lib
CC=gcc
endif

LDFLAGS=-L. -L$(ERL_LIB)/lib -Ldeps/pihwm/lib -Lpriv

PIHWMLIB = pihwm pi_gpio
# PIHWMLIB = pihwm pi_gpio

all: library gpio_port build
# all: library gpio_port build

init:
mkdir -p priv
./rebar get-deps

library: $(PIHWMLIB)

$(PIHWMLIB):
@echo Building library: $@...
$(CC) $(CFLAGS) -o priv/$@.o -c -lpthread deps/pihwm/lib/$@.c


#build: rebar_plugin
build:
./rebar compile

#rebar_plugin: plugins/compile-deps/src/rebar_compiledeps_plugin.beam
# library: $(PIHWMLIB)

#plugins/compile-deps/src/%.beam: plugins/compile-deps/src/%.erl
# erlc -o plugins/compile-deps/src $<
# $(PIHWMLIB):
# @echo Building library: $@...
# $(CC) $(CFLAGS) -o priv/$@.o -c -lpthread deps/pihwm/lib/$@.c


build_sim:
./rebar -D simulation_mode compile

build_examples:
erlc -o examples examples/*.erl
Expand All @@ -57,14 +63,12 @@ run_test:
ct_run -noshell -pa deps/*/ebin -pa ebin -sname ct -env TEST_DIR test -dir test


gpio_port: priv/gpio_port.o priv/port_comms.o library
$(CC) ${LDFLAGS} priv/port_comms.o priv/pihwm.o priv/pi_gpio.o priv/gpio_port.o -lerl_interface -lei -lpthread -o priv/gpio_port
gpio_port: priv/gpio_port.o deps/erlang_portutil/port_comms.o
$(CC) ${LDFLAGS} deps/erlang_portutil/port_comms.o deps/pihwm/lib/pihwm.o deps/pihwm/lib/pi_gpio.o priv/gpio_port.o -lerl_interface -lei -lpthread -o priv/gpio_port

gpio_test: priv/gpio_test.o
$(CC) $(LDFLAGS) $< pihwm.o pi_gpio.o -lpthread -o $@

priv/port_comms.o: deps/erlang-portutil/port_comms.c
$(CC) -g $(CFLAGS) -c -o $@ $<

priv/%.o: c_src/%.c
$(CC) -g $(CFLAGS) -c -o $@ $<
Expand Down
160 changes: 160 additions & 0 deletions erlang.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Copyright (c) 2013, Loïc Hoguin <essen@ninenines.eu>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# Verbosity and tweaks.

V ?= 0

appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
appsrc_verbose = $(appsrc_verbose_$(V))

erlc_verbose_0 = @echo " ERLC " $(filter-out %.dtl,$(?F));
erlc_verbose = $(erlc_verbose_$(V))

dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
dtl_verbose = $(dtl_verbose_$(V))

gen_verbose_0 = @echo " GEN " $@;
gen_verbose = $(gen_verbose_$(V))

.PHONY: all clean-all app clean deps clean-deps docs clean-docs \
build-tests tests build-plt dialyze

# Deps directory.

DEPS_DIR ?= $(CURDIR)/deps
export DEPS_DIR

REBAR_DEPS_DIR = $(DEPS_DIR)
export REBAR_DEPS_DIR

ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(DEPS))
ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))

# Application.

ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
+warn_shadow_vars +warn_obsolete_guard # +bin_opt_info +warn_missing_spec
COMPILE_FIRST ?=
COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))

all: deps app

clean-all: clean clean-deps clean-docs
$(gen_verbose) rm -rf .$(PROJECT).plt $(DEPS_DIR) logs

app: ebin/$(PROJECT).app
$(eval MODULES := $(shell find ebin -name \*.beam \
| sed 's/ebin\///;s/\.beam/,/' | sed '$$s/.$$//'))
$(appsrc_verbose) cat src/$(PROJECT).app.src \
| sed 's/{modules, \[\]}/{modules, \[$(MODULES)\]}/' \
> ebin/$(PROJECT).app

define compile_erl
$(erlc_verbose) ERL_LIBS=deps erlc -v $(ERLC_OPTS) -o ebin/ -pa ebin/ \
-I include/ $(COMPILE_FIRST_PATHS) $(1)
endef

define compile_dtl
$(dtl_verbose) erl -noshell -pa ebin/ deps/erlydtl/ebin/ -eval ' \
Compile = fun(F) -> \
Module = list_to_atom( \
string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \
erlydtl_compiler:compile(F, Module, [{out_dir, "ebin/"}]) \
end, \
_ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
init:stop()'
endef

ebin/$(PROJECT).app: src/*.erl $(wildcard src/*.core) $(wildcard templates/*.dtl)
@mkdir -p ebin/
$(if $(strip $(filter-out %.dtl,$?)), \
$(call compile_erl,$(filter-out %.dtl,$?)))
$(if $(strip $(filter %.dtl,$?)), \
$(call compile_dtl,$(filter %.dtl,$?)))

clean:
$(gen_verbose) rm -rf ebin/ test/*.beam erl_crash.dump

# Dependencies.

define get_dep
@mkdir -p $(DEPS_DIR)
git clone -n -- $(word 1,$(dep_$(1))) $(DEPS_DIR)/$(1)
cd $(DEPS_DIR)/$(1) ; git checkout -q $(word 2,$(dep_$(1)))
cd $(DEPS_DIR)/$(1) ; if [ -n $(word 3,$(dep_$(1))) ]; then eval $(word 3,$(dep_$(1))); fi
endef

define dep_target
$(DEPS_DIR)/$(1):
$(call get_dep,$(1))
endef

$(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))

deps: $(ALL_DEPS_DIRS)
@for dep in $(ALL_DEPS_DIRS) ; do $(MAKE) -C $$dep; done

clean-deps:
@for dep in $(ALL_DEPS_DIRS) ; do $(MAKE) -C $$dep clean; done

# Documentation.

docs: clean-docs
$(gen_verbose) erl -noshell \
-eval 'edoc:application($(PROJECT), ".", []), init:stop().'

clean-docs:
$(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info

# Tests.

$(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))

build-test-deps: $(ALL_TEST_DEPS_DIRS)
@for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done

build-tests: build-test-deps
$(gen_verbose) ERL_LIBS=deps erlc -v $(ERLC_OPTS) -o test/ \
$(wildcard test/*.erl test/*/*.erl) -pa ebin/

CT_RUN = ct_run \
-no_auto_compile \
-noshell \
-pa ebin $(DEPS_DIR)/*/ebin \
-dir test \
-logdir logs
# -cover test/cover.spec

CT_SUITES ?=
CT_SUITES_FULL = $(addsuffix _SUITE,$(CT_SUITES))

tests: ERLC_OPTS += -DTEST=1 +'{parse_transform, eunit_autoexport}'
tests: clean deps app build-tests
@mkdir -p logs/
@$(CT_RUN) -suite $(CT_SUITES_FULL)
$(gen_verbose) rm -f test/*.beam

# Dialyzer.

PLT_APPS ?=
DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
-Wunmatched_returns # -Wunderspecs

build-plt: deps app
@dialyzer --build_plt --output_plt .$(PROJECT).plt \
--apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIRS)

dialyze:
@dialyzer --src src --plt .$(PROJECT).plt --no_native $(DIALYZER_OPTS)
File renamed without changes.
38 changes: 8 additions & 30 deletions src/gpio.erl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ handle_call({write, _Value}, _From, #state{direction=input}=State) ->
Reply = {error, writing_to_input_pin},
{reply, Reply, State};
handle_call(read, From, #state{direction=input,
pin=Pin,
pending=Pending,
port=Port}=State) ->
port_lib:call_to_port(Port, From, {read}),
Expand All @@ -183,7 +182,7 @@ handle_call({set_int, Condition, Requestor},
Reply = ok,
Interrupt = {Condition, [Requestor|Pids]},
{reply, Reply, State#state{interrupt=Interrupt}};
handle_call({set_int, Condition, Requestor},
handle_call({set_int, _Condition, _Requestor},
_From,
#state{direction=input,
interrupt={_,_}}=State) ->
Expand Down Expand Up @@ -220,7 +219,7 @@ handle_cast(_Msg, State) ->
%% the from_port/2 function for all messages from the port.
handle_info({Port, {data, Msg}},
#state{port=Port, pin=Pin}=State) ->
apply_after(0, ?MODULE, from_port, [Pin, binary_to_term(Msg)]),
timer:apply_after(0, ?MODULE, from_port, [Pin, binary_to_term(Msg)]),
{noreply, State}.

terminate(_Reason, #state{port=Port}=_State) ->
Expand All @@ -242,34 +241,13 @@ pname(Pin) ->


%% @doc value_change(Old, New)
value_change(0, 1) ->
raising;
value_change(1, 0) ->
falling;
value_change(_, _) ->
no_change.










%% value_change(0, 1) ->
%% raising;
%% value_change(1, 0) ->
%% falling;
%% value_change(_, _) ->
%% no_change.

apply_after(Time, M, F, Args) ->
Ref = make_ref(),
Self = self(),
Pid = spawn( fun() ->
receive
Ref ->
apply(M, F, Args)
end
end ),
erlang:send_after(Time, Pid, Ref),
ok.

%%% Local Variables:
%%% erlang-indent-level: 2
Expand Down
6 changes: 5 additions & 1 deletion src/pubsub.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
-module(pubsub).

-compile(export_all).
%% todo: must export sensible set the day we need these functions.
-export([set_interrupt/2,
simulate_interrupt/2,
pin_interrupts/1]).


%% @doc set_interrupt will create an interrupt for pin N on the
%% condition C.
Expand Down

0 comments on commit 6548ec6

Please sign in to comment.