aboutsummaryrefslogtreecommitdiff
path: root/contrib/lib9p/GNUmakefile
blob: 79108f2ceb619f0ed2f333979b595d95d93d2e1b (plain) (blame)
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
CC_VERSION := $(shell $(CC) --version | \
    sed -n -e '/clang-/s/.*clang-\([0-9][0-9]*\).*/\1/p')
ifeq ($(CC_VERSION),)
# probably not clang
CC_VERSION := 0
endif

WFLAGS :=

# Warnings are version-dependent, unfortunately,
# so test for version before adding a -W flag.
# Note: gnu make requires $(shell test ...) for "a > b" type tests.
ifeq ($(shell test $(CC_VERSION) -gt 0; echo $$?),0)
WFLAGS += -Weverything
WFLAGS += -Wno-padded
WFLAGS += -Wno-gnu-zero-variadic-macro-arguments
WFLAGS += -Wno-format-nonliteral
WFLAGS += -Wno-unused-macros
WFLAGS += -Wno-disabled-macro-expansion
WFLAGS += -Werror
endif

ifeq ($(shell test $(CC_VERSION) -gt 600; echo $$?),0)
WFLAGS += -Wno-reserved-id-macro
endif

CFLAGS := $(WFLAGS) \
	-g \
	-O0 \
	-DL9P_DEBUG=L9P_DEBUG
# Note: to turn on debug, use -DL9P_DEBUG=L9P_DEBUG,
# and set env variable LIB9P_LOGGING to stderr or to
# the (preferably full path name of) the debug log file.

LIB_SRCS := \
	pack.c \
	connection.c \
	request.c \
	genacl.c \
	log.c \
	hashtable.c \
	utils.c \
	rfuncs.c \
	threadpool.c \
	sbuf/sbuf.c \
	transport/socket.c \
	backend/fs.c

SERVER_SRCS := \
	example/server.c

BUILD_DIR := build
LIB_OBJS := $(addprefix build/,$(LIB_SRCS:.c=.o))
SERVER_OBJS := $(SERVER_SRCS:.c=.o)
LIB := lib9p.dylib
SERVER := server

all: build $(LIB) $(SERVER)

$(LIB): $(LIB_OBJS)
	cc -dynamiclib $^ -o build/$@

$(SERVER): $(SERVER_OBJS) $(LIB)
	cc $< -o build/$(SERVER) -Lbuild/ -l9p

clean:
	rm -rf build
	rm -f $(SERVER_OBJS)
build:
	mkdir build
	mkdir build/sbuf
	mkdir build/transport
	mkdir build/backend

build/%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@