-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathMakefile
More file actions
97 lines (81 loc) · 3.49 KB
/
Copy pathMakefile
File metadata and controls
97 lines (81 loc) · 3.49 KB
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
###############################################################################
#
# CoffeeCatch — tiny native POSIX signal catcher
#
###############################################################################
# --- Toolchain (overridable) -------------------------------------------------
# cc/c++/ar are the POSIX defaults; CI overrides CC/CXX with a matching pair
# (gcc/g++ or clang/clang++). The C suite must stay on CC so clang coverage is
# not silently swapped for the default g++.
CC ?= cc
CXX ?= c++
AR ?= ar
RM ?= rm -f
# --- Flags -------------------------------------------------------------------
# CFLAGS/CXXFLAGS hold the user-overridable optimization/debug flags. Everything
# mandatory (PIC, reentrancy, strict warnings) is appended with `override` so it
# survives a command-line CFLAGS=... — e.g. CI injecting sanitizer flags. The
# two are kept apart so `make CFLAGS=-std=gnu99` does not reach the C++ compiler.
CFLAGS ?= -O3 -g
CXXFLAGS ?= -O3 -g
override CPPFLAGS += -D_REENTRANT -D_GNU_SOURCE
override CFLAGS += -fPIC -pthread \
-W -Wall -Wextra -Werror -Wno-unused-function
override CXXFLAGS += -fPIC -pthread \
-W -Wall -Wextra -Werror -Wno-unused-function
# --- Platform shared-library wiring ------------------------------------------
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SHLIB := libcoffeecatch.dylib
SOFLAGS := -dynamiclib -install_name @rpath/$(SHLIB)
SOLIBS :=
LDLIBS :=
else
SHLIB := libcoffeecatch.so
SOFLAGS := -shared -Wl,-soname=$(SHLIB) -Wl,--no-undefined -rdynamic
SOLIBS := -ldl
LDLIBS := -ldl
endif
STATICLIB := libcoffeecatch.a
# --- Sources -----------------------------------------------------------------
# coffeejni.c is intentionally excluded: it needs <jni.h> (an NDK/JDK header)
# and is meant to be compiled into the embedder, not this standalone build.
LIBSRC := coffeecatch.c
LIBOBJ := $(LIBSRC:.c=.o)
BINS := tests tests_cxx sample
# --- Targets -----------------------------------------------------------------
.PHONY: all check test clean dist
.DEFAULT_GOAL := all
all: $(STATICLIB) $(SHLIB) $(BINS)
%.o: %.c coffeecatch.h
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
%.o: %.cpp coffeecatch.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(STATICLIB): $(LIBOBJ)
$(AR) rcs $@ $^
$(SHLIB): $(LIBOBJ)
$(CC) $(CFLAGS) $(SOFLAGS) $(LIBOBJ) -o $@ $(LDFLAGS) $(SOLIBS) $(LDLIBS)
# tests/sample link the static archive: no LD_LIBRARY_PATH, identical run on
# Linux and macOS. The C suite links with $(CC), the C++ suite with $(CXX).
# The C suite links an instrumented coffeecatch instead of the archive:
# -DCOFFEE_TESTING adds a failure-injection seam for the setup-failure test and
# stays out of the shipped $(STATICLIB)/$(SHLIB).
tests.o: tests.c coffeecatch.h
$(CC) $(CPPFLAGS) -DCOFFEE_TESTING $(CFLAGS) -c $< -o $@
coffeecatch-testing.o: coffeecatch.c coffeecatch.h
$(CC) $(CPPFLAGS) -DCOFFEE_TESTING $(CFLAGS) -c $< -o $@
tests: tests.o coffeecatch-testing.o
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS)
tests_cxx: tests_cxx.o $(STATICLIB)
$(CXX) $(CXXFLAGS) $< $(STATICLIB) -o $@ $(LDFLAGS) $(LDLIBS)
sample: sample.o $(STATICLIB)
$(CC) $(CFLAGS) $< $(STATICLIB) -o $@ $(LDFLAGS) $(LDLIBS)
check test: tests tests_cxx
./tests
./tests_cxx
dist:
$(RM) coffeecatch.tgz
tar cvfz coffeecatch.tgz $(LIBSRC) coffeecatch.h coffeejni.c coffeejni.h \
sample.c tests.c tests_cxx.cpp Makefile LICENSE README.md
clean:
$(RM) *.o $(STATICLIB) $(SHLIB) libcoffeecatch.so.* $(BINS) coffeecatch.tgz