Skip to content

Commit

Permalink
Warn if not compiling for Linux
Browse files Browse the repository at this point in the history
This makes it possible to compile Elixir ALE on OSX and other platforms.
The idea is that you're not really using it, but removing elixir_ale from
your deps programmatically is annoying.

This also includes some Makefile cleanup based on nerves_uart.
  • Loading branch information
fhunleth committed Apr 3, 2017
1 parent 5e63767 commit fc6ae91
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@
# CROSSCOMPILE crosscompiler prefix, if any
# CFLAGS compiler flags for compiling all C files
# ERL_CFLAGS additional compiler flags for files using Erlang header files
# ERL_EI_LIBDIR path to libei.a
# ERL_EI_INCLUDE_DIR include path to ei.h (Required for crosscompile)
# ERL_EI_LIBDIR path to libei.a (Required for crosscompile)
# LDFLAGS linker flags for linking all binaries
# ERL_LDFLAGS additional linker flags for projects referencing Erlang libraries

# Check that we're on a supported build platform
ifeq ($(CROSSCOMPILE),)
# Not crosscompiling, so check that we're on Linux.
ifneq ($(shell uname -s),Linux)
$(error Elixir ALE only works on Linux. Crosscompiling is possible if $$CROSSCOMPILE is set.)
$(warning Elixir ALE only works on Linux, but crosscompilion)
$(warning is supported by defining $$CROSSCOMPILE, $$ERL_EI_INCLUDE_DIR,)
$(warning and $$ERL_EI_LIBDIR. See Makefile for details. If using Nerves,)
$(warning this should be done automatically.)
$(warning .)
$(warning Skipping C compilation unless targets explicitly passed to make.)
DEFAULT_TARGETS = priv
endif
endif
DEFAULT_TARGETS ?= priv priv/ale

# Look for the EI library and header files
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)
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)

# For crosscompiled builds, ERL_EI_INCLUDE_DIR and ERL_EI_LIBDIR must be
# passed into the Makefile.
ifeq ($(ERL_EI_INCLUDE_DIR),)
$(error Could not find include directory for ei.h. Check that Erlang header files are available)
ERL_ROOT_DIR = $(shell erl -eval "io:format(\"~s~n\", [code:root_dir()])" -s init stop -noshell)
ifeq ($(ERL_ROOT_DIR),)
$(error Could not find the Erlang installation. Check to see that 'erl' is in your PATH)
endif
ifeq ($(ERL_EI_LIBDIR),)
$(error Could not find libei.a. Check your Erlang installation)
ERL_EI_INCLUDE_DIR = "$(ERL_ROOT_DIR)/usr/include"
ERL_EI_LIBDIR = "$(ERL_ROOT_DIR)/usr/lib"
endif

# Set Erlang-specific compile and linker flags
Expand All @@ -35,15 +44,20 @@ LDFLAGS +=
CFLAGS ?= -O2 -Wall -Wextra -Wno-unused-parameter
CC ?= $(CROSSCOMPILER)gcc

SRC=$(wildcard src/*.c)
OBJ=$(SRC:.c=.o)

.PHONY: all clean

all: priv/ale
all: $(DEFAULT_TARGETS)

%.o: %.c
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) -o $@ $<

priv/ale: src/ale_main.o src/gpio_port.o src/i2c_port.o src/spi_port.o src/erlcmd.o
@mkdir -p priv
priv:
mkdir -p priv

priv/ale: $(OBJ)
$(CC) $^ $(ERL_LDFLAGS) $(LDFLAGS) -o $@

clean:
Expand Down

0 comments on commit fc6ae91

Please sign in to comment.