Skip to content

Instantly share code, notes, and snippets.

@DurandA
Created March 13, 2018 09:54
Show Gist options
  • Save DurandA/431f68ea3b10672938742fda133f0432 to your computer and use it in GitHub Desktop.
Save DurandA/431f68ea3b10672938742fda133f0432 to your computer and use it in GitHub Desktop.
CryptoAuthLib makefile for Linux I2C userspace
.PHONY: all libcryptoauth libateccssl libpkcs11 dist install clean
OPTIONS := ATCAPRINTF ATCA_HAL_I2C ENGINE_DYNAMIC_SUPPORT USE_ECCX08 ECC_DEBUG
SYSTEM_INCLUDES := /usr/include
# Define helpful macros for interacting with the specific environment
BACK2SLASH = $(subst \,/,$(1))
SLASH2BACK = $(subst /,\,$(1))
FIND = $(shell find $(abspath $(1)) -name $(2))
MKDIR = $(shell mkdir -p $(1) 2>/dev/null)
CFLAGS += -g -O1 -m64 -Wall -fPIC $(addprefix -D,$(OPTIONS))
TARGET_ARCH := Linux
OUTDIR := $(abspath .build)
DEPFLAGS = -MT $@ -MMD -MP -MF $(OUTDIR)/$*.d
ARFLAGS = rcs
# Wildcard all the sources and headers
SOURCES := $(call FIND,lib,*.c)
INCLUDE := $(sort $(dir $(call FIND, lib, *.h)))
# Gather libcryptoauth objects
LIBCRYPTOAUTH_OBJECTS := $(filter-out $(abspath lib/hal)/%, $(SOURCES))
LIBCRYPTOAUTH_OBJECTS += atca_hal.c
# General Linux Support
LIBCRYPTOAUTH_OBJECTS += hal_linux_timer.c
# Native I2C hardware/driver
LIBCRYPTOAUTH_OBJECTS += hal_linux_i2c_userspace.c
LIBCRYPTOAUTH_OBJECTS := $(addprefix $(OUTDIR)/,$(notdir $(LIBCRYPTOAUTH_OBJECTS:.c=.o)))
CFLAGS += $(addprefix -I, $(INCLUDE) $(TEST_INCLUDE) $(SYSTEM_INCLUDES))
# Regardless of platform set the vpath correctly
vpath %.c $(call BACK2SLASH,$(sort $(dir $(SOURCES) $(TEST_SOURCES))))
$(OUTDIR):
$(call MKDIR, $(OUTDIR))
$(OUTDIR)/%.o : %.c $(OUTDIR)/%.d | $(OUTDIR)
$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
$(OUTDIR)/%.d: ;
.PRECIOUS: $(OUTDIR)/%.d
$(OUTDIR)/libcryptoauth.a: $(LIBCRYPTOAUTH_OBJECTS) | $(OUTDIR)
$(AR) $(ARFLAGS) $@ $(LIBCRYPTOAUTH_OBJECTS)
include $(wildcard $(patsubst %,$(OUTDIR)/%.d,$(basename $(SOURCES))))
libcryptoauth: $(OUTDIR)/libcryptoauth.a | $(OUTDIR)
all: $(LIBCRYPTOAUTH_OBJECTS) | $(OUTDIR)
clean:
rm -r $(OUTDIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment