44# CROSSCOMPILE crosscompiler prefix, if any
55# CFLAGS compiler flags for compiling all C files
66# ERL_CFLAGS additional compiler flags for files using Erlang header files
7- # ERL_EI_LIBDIR path to libei.a
7+ # ERL_EI_INCLUDE_DIR include path to ei.h (Required for crosscompile)
8+ # ERL_EI_LIBDIR path to libei.a (Required for crosscompile)
89# LDFLAGS linker flags for linking all binaries
910# ERL_LDFLAGS additional linker flags for projects referencing Erlang libraries
1011
1112# Check that we're on a supported build platform
1213ifeq ($(CROSSCOMPILE ) ,)
1314 # Not crosscompiling, so check that we're on Linux.
1415 ifneq ($(shell uname -s),Linux)
15- $(error Elixir ALE only works on Linux. Crosscompiling is possible if $$CROSSCOMPILE is set.)
16+ $(warning Elixir ALE only works on Linux, but crosscompilion)
17+ $(warning is supported by defining $$CROSSCOMPILE, $$ERL_EI_INCLUDE_DIR,)
18+ $(warning and $$ERL_EI_LIBDIR. See Makefile for details. If using Nerves,)
19+ $(warning this should be done automatically.)
20+ $(warning .)
21+ $(warning Skipping C compilation unless targets explicitly passed to make.)
22+ DEFAULT_TARGETS = priv
1623 endif
1724endif
25+ DEFAULT_TARGETS ?= priv priv/ale
1826
1927# Look for the EI library and header files
20- ERL_EI_INCLUDE_DIR ?= $(shell find /usr/local/lib/erlang /usr/lib/erlang ~/.asdf/installs/erlang/19.0/lib/erlang/usr/include/ -name ei.h -printf '% h\n' 2> /dev/null | head -1)
21- ERL_EI_LIBDIR ?= $(shell find /usr/local/lib/erlang /usr/lib/erlang ~/.asdf/installs/erlang/19.0/lib/erlang/usr/lib -name libei.a -printf '% h\n' 2> /dev/null | head -1)
22-
28+ # For crosscompiled builds, ERL_EI_INCLUDE_DIR and ERL_EI_LIBDIR must be
29+ # passed into the Makefile.
2330ifeq ($(ERL_EI_INCLUDE_DIR ) ,)
24- $(error Could not find include directory for ei.h. Check that Erlang header files are available)
31+ ERL_ROOT_DIR = $(shell erl -eval "io:format(\"~s~n\", [code:root_dir() ])" -s init stop -noshell)
32+ ifeq ($(ERL_ROOT_DIR ) ,)
33+ $(error Could not find the Erlang installation. Check to see that 'erl' is in your PATH)
2534endif
26- ifeq ( $( ERL_EI_LIBDIR ) ,)
27- $(error Could not find libei.a. Check your Erlang installation)
35+ ERL_EI_INCLUDE_DIR = " $( ERL_ROOT_DIR ) /usr/include"
36+ ERL_EI_LIBDIR = " $( ERL_ROOT_DIR ) /usr/lib"
2837endif
2938
3039# Set Erlang-specific compile and linker flags
@@ -35,15 +44,20 @@ LDFLAGS +=
3544CFLAGS ?= -O2 -Wall -Wextra -Wno-unused-parameter
3645CC ?= $(CROSSCOMPILER ) gcc
3746
47+ SRC =$(wildcard src/* .c)
48+ OBJ=$(SRC:.c =.o)
49+
3850.PHONY : all clean
3951
40- all : priv/ale
52+ all : $( DEFAULT_TARGETS )
4153
4254% .o : % .c
4355 $(CC ) -c $(ERL_CFLAGS ) $(CFLAGS ) -o $@ $<
4456
45- priv/ale : src/ale_main.o src/gpio_port.o src/i2c_port.o src/spi_port.o src/erlcmd.o
46- @mkdir -p priv
57+ priv :
58+ mkdir -p priv
59+
60+ priv/ale : $(OBJ )
4761 $(CC ) $^ $(ERL_LDFLAGS ) $(LDFLAGS ) -o $@
4862
4963clean :
0 commit comments