-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
143 lines (108 loc) · 3.55 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#
# Makefile
#
# Copyright (C) 2017-2023, Tozny.
# All Rights Reserved.
#
VERSION := 0.0.1
PUBLIC_HEADERS := lib/e3db_core.h
BUILD_DIR := build
SOURCES := $(wildcard lib/*.c)
OBJECTS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(SOURCES))
HEADERS := $(wildcard lib/*.h)
LIB := $(BUILD_DIR)/libe3db.a
CFLAGS := -Wall -g
LDFLAGS :=
# CFLAGS and LDFLAGS for below to debug memory access issues
ifdef DEBUG
CFLAGS := -Wall -g -O1 -fsanitize=address
LDFLAGS := -fsanitize=address
endif
CMD_SOURCES := $(wildcard cmd/*.c)
CMD_OBJECTS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(CMD_SOURCES))
CMD_HEADERS := $(wildcard cmd/*.h)
CMD := $(BUILD_DIR)/e3db
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
DIST_NAME := e3db-core-macosx-$(VERSION)
CFLAGS += -I/usr/local/opt/mbedtls/include
LDFLAGS += -L/usr/local/opt/mbedtls/lib
else
ifeq ($(UNAME),Linux)
DIST_NAME := e3db-core-linux-$(VERSION)
else
$(error "Unknown operating system.")
endif
endif
DIST_DIR := $(BUILD_DIR)/dist
DIST_PRE := ../..
DIST_ZIP := $(DIST_NAME).zip
DIST_BASE := $(DIST_DIR)/$(DIST_NAME)
all: $(LIB) $(CMD)
dist: $(DIST_ZIP)
debug:
@$(MAKE) DEBUG=1 all
SIMPLE_BUILD_DIR := simple
SIMPLE_SOURCES := $(wildcard lib/*.c)
SIMPLE_OBJECTS := $(patsubst %.c,$(SIMPLE_BUILD_DIR)/%.o,$(SIMPLE_SOURCES))
SIMPLE_HEADERS := $(wildcard lib/*.h)
SIMPLE_LIB := $(SIMPLE_BUILD_DIR)/lib_simple.a
EXAMPLES_SOURCES := $(wildcard examples/*.c)
EXAMPLES_OBJECTS := $(patsubst %.c,$(SIMPLE_BUILD_DIR)/%.o,$(EXAMPLES_SOURCES))
EXAMPLES_HEADERS := $(wildcard examples/*.h)
EXAMPLES := $(SIMPLE_BUILD_DIR)/simple
simple: $(SIMPLE_LIB) $(EXAMPLES)
$(SIMPLE_LIB): $(SIMPLE_OBJECTS)
@printf "%-10s %s\n" "AR" "$@"
@ar cru $(SIMPLE_LIB) $(SIMPLE_OBJECTS)
$(EXAMPLES): $(EXAMPLES_OBJECTS) $(EXAMPLES_HEADERS) $(SIMPLE_LIB) $(SIMPLE_HEADERS)
@printf "%-10s %s\n" "LINK" "$@"
@-mkdir -p $(dir $@)
@gcc $(CFLAGS) $(LDFLAGS) -o $@ -Ilib $< $(SIMPLE_LIB) -lm -lsodium -lmbedcrypto
$(SIMPLE_BUILD_DIR)/%.o: %.c $(SIMPLE_HEADERS)
@printf "%-10s %s\n" "CC" "$@"
@-mkdir -p $(dir $@)
@gcc $(CFLAGS) -Ilib -c -o $@ $<
clean-simple:
rm -rf $(SIMPLE_BUILD_DIR)
debug-simple:
@$(MAKE) DEBUG=1 simple
# Stop GNU Make from removing object files resulting from chains
# of implicit rules.
.SECONDARY: $(SIMPLE_OBJECTS) $(CMD_OBJECTS)
$(DIST_ZIP): $(LIB) $(CMD) $(PUBLIC_HEADERS)
@printf "%-10s %s\n" "ZIP" "$@"
@rm -rf $(DIST_ZIP) $(DIST_BASE)
@mkdir -p $(DIST_BASE)/include $(DIST_BASE)/lib $(DIST_BASE)/bin
@cp $(PUBLIC_HEADERS) $(DIST_BASE)/include
@cp $(LIB) $(DIST_BASE)/lib
@cp $(CMD) $(DIST_BASE)/bin
@cd $(DIST_DIR) && zip -qr $(DIST_PRE)/$(DIST_ZIP) $(DIST_NAME)
$(LIB): $(OBJECTS)
@printf "%-10s %s\n" "AR" "$@"
@ar cru $(LIB) $(OBJECTS)
$(CMD): $(CMD_OBJECTS) $(CMD_HEADERS) $(LIB) $(HEADERS)
@printf "%-10s %s\n" "LINK" "$@"
@-mkdir -p $(dir $@)
@gcc $(CFLAGS) $(LDFLAGS) -o $@ -Ilib $< $(LIB) -lm -lsodium -lmbedcrypto
$(BUILD_DIR)/%.o: %.c $(HEADERS)
@printf "%-10s %s\n" "CC" "$@"
@-mkdir -p $(dir $@)
@gcc $(CFLAGS) -Ilib -c -o $@ $<
clean:
rm -rf $(BUILD_DIR) $(DIST_ZIP) $(SIMPLE_BUILD_DIR)
# Stop GNU Make from removing object files resulting from chains
# of implicit rules.
.SECONDARY: $(OBJECTS) $(CMD_OBJECTS)
# vim: set noet ts=2:
# for debug: change below cmake .. to cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake-build: clean
mkdir build && \
cd build && \
cmake .. && \
make
cmake-build-config-file: clean
mkdir build && \
cd build && \
cmake -DUSE_HARDCODED_CONFIG_JSON=true .. && \
make