-
Notifications
You must be signed in to change notification settings - Fork 79
/
Makefile
76 lines (55 loc) · 1.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Project directory
PWD ?= "`pwd`"
# Executable
BINS = amiitool
STATICLIBS = mbedtls
# Compilation flags
CFLAGS ?= -Wall -pedantic -O2 -fsigned-char
ALL_CFLAGS = -I $(PWD)/include -I $(MBEDTLS_DIR)/include $(CFLAGS)
LDFLAGS = -L $(MBEDTLS_DIR)/library -l mbedcrypto
# Commands
INSTALL = /usr/bin/install -D
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
# Directories
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
# mbed TLS libraries
MBEDTLS_DIR = $(PWD)/mbedtls
MBEDTLS_CONFIG = $(PWD)/configs/mbedtls.h
MBEDTLS_CFLAGS = -DMBEDTLS_CONFIG_FILE='\"$(MBEDTLS_CONFIG)\"' $(CFLAGS)
HEADERS := $(wildcard *.h) gitversion.h
OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c))
LIBSOBJ := $(filter-out $(BINS:%=%.o),$(OBJECTS))
# Disable built-in wildcard rules
.SUFFIXES:
# Keep objects to speed up recompilation
.PRECIOUS: %.o
# Always execute Makefiles for static libraries
.PHONY: $(STATICLIBS)
# Default target: compile all programs
all: $(BINS)
%: %.o $(LIBSOBJ) $(STATICLIBS)
$(CC) $(ALL_CFLAGS) $(LIBSOBJ) $< -o $@ $(LDFLAGS)
%.o: %.c $(HEADERS)
$(CC) $(ALL_CFLAGS) -c $< -o $@
gitversion.h:
echo "#define GIT_COMMIT_ID 0x`git rev-parse HEAD | head -c8`" > $(PWD)/gitversion.h
echo "#define GIT_COMMIT_COUNT `git rev-list --count --all`" >> $(PWD)/gitversion.h
# Static mbed TLS
mbedtls: $(MBEDTLS_CONFIG)
"$(MAKE)" lib -C $(MBEDTLS_DIR) CFLAGS="$(MBEDTLS_CFLAGS)"
# Clean targets
clean: mostlyclean
$(MAKE) -C $(MBEDTLS_DIR) clean
mostlyclean:
$(RM) $(OBJECTS) $(BINS) gitversion.h
# Install
install: $(BINS:%=install_%)
install_%: %
$(INSTALL_PROGRAM) $< $(DESTDIR)$(bindir)/$<
# Uninstall
uninstall: $(BINS:%=uninstall_%)
uninstall_%: %
$(RM) $(DESTDIR)$(bindir)/$<