Current section
Files
Jump to
Current section
Files
src/Makefile
# Variables to override
#
# CC C compiler
# CROSSCOMPILE crosscompiler prefix, if any
# CFLAGS compiler flags for compiling all C files
# LDFLAGS linker flags for linking all binaries
# ERL_CFLAGS additional compiler flags for files using Erlang header files
# ERL_LDFLAGS additional linker flags for projects referencing Erlang libraries
# ERL_EI_INCLUDE_DIR path to Erlang interface header files
# ERL_EI_LIBDIR path to libei.a
LDFLAGS +=
CFLAGS ?= -O2 -Wall -Wextra -Wno-unused-parameter
CFLAGS += -std=c99 -D_GNU_SOURCE
###################
# If you're having trouble with the serial port, commenting in the following line
# may give some more hints. By default, log messages are appended to circuits_uart.log.
# See src/circuits_uart.c to change this. Be sure to rebuild everything by invoking
# "mix clean" and then "mix compile", so that the flag takes effect.
#CFLAGS += -DDEBUG
SRC=$(wildcard src/*.c)
# Windows-specific updates
ifeq ($(OS),Windows_NT)
# Libraries needed to enumerate serial ports
LDFLAGS += -lSetupapi -lCfgmgr32
# On Windows, make defaults CC=cc and
# cc doesn't exist with mingw
ifeq ($(CC),cc)
CC = gcc
endif
# Statically link on Windows to simplify distribution of pre-built version
LDFLAGS += -static
# To avoid linking issues, use copy/pasted version of ei.
# YES, this is unfortunate, but it was easier than
# battling mingw/visual c++ differences.
ERL_CFLAGS = -I"$(CURDIR)/src/ei_copy"
SRC += $(wildcard src/ei_copy/*.c)
CFLAGS += -DUNICODE
EXEEXT=.exe
else
# Non-Windows
# -lrt is needed for clock_gettime() on linux with glibc before version 2.17
# (for example raspbian wheezy)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDFLAGS += -lrt
endif
# The paths to the EI library and header files are either passed in when
# compiled by Nerves (crosscompiled builds) or determined by mix.exs for
# host builds.
ifeq ($(ERL_EI_INCLUDE_DIR),)
$(error ERL_EI_INCLUDE_DIR not set. Invoke via mix)
endif
ifeq ($(ERL_EI_LIBDIR),)
$(error ERL_EI_LIBDIR not set. Invoke via mix)
endif
# Set Erlang-specific compile and linker flags
ERL_CFLAGS ?= -I$(ERL_EI_INCLUDE_DIR)
ERL_LDFLAGS ?= -L$(ERL_EI_LIBDIR) -lei
# If compiling on OSX and not crosscompiling, include CoreFoundation and IOKit
ifeq ($(CROSSCOMPILE),)
ifeq ($(shell uname),Darwin)
LDFLAGS += -framework CoreFoundation -framework IOKit
endif
endif
endif
OBJ=$(SRC:.c=.o)
.PHONY: all clean
all: priv priv/circuits_uart$(EXEEXT)
%.o: %.c
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) -o $@ $<
priv:
mkdir priv
priv/circuits_uart$(EXEEXT): $(OBJ)
$(CC) $^ $(ERL_LDFLAGS) $(LDFLAGS) -o $@
clean:
rm -f priv/circuits_uart$(EXEEXT) src/*.o src/ei_copy/*.o