1CC_VERSION := $(shell $(CC) --version | \ 2 sed -n -e '/clang-/s/.*clang-\([0-9][0-9]*\).*/\1/p') 3ifeq ($(CC_VERSION),) 4# probably not clang 5CC_VERSION := 0 6endif 7 8WFLAGS := 9 10# Warnings are version-dependent, unfortunately, 11# so test for version before adding a -W flag. 12# Note: gnu make requires $(shell test ...) for "a > b" type tests. 13ifeq ($(shell test $(CC_VERSION) -gt 0; echo $$?),0) 14WFLAGS += -Weverything 15WFLAGS += -Wno-padded 16WFLAGS += -Wno-gnu-zero-variadic-macro-arguments 17WFLAGS += -Wno-format-nonliteral 18WFLAGS += -Wno-unused-macros 19WFLAGS += -Wno-disabled-macro-expansion 20WFLAGS += -Werror 21endif 22 23ifeq ($(shell test $(CC_VERSION) -gt 600; echo $$?),0) 24WFLAGS += -Wno-reserved-id-macro 25endif 26 27CFLAGS := $(WFLAGS) \ 28 -g \ 29 -O0 \ 30 -DL9P_DEBUG=L9P_DEBUG 31# Note: to turn on debug, use -DL9P_DEBUG=L9P_DEBUG, 32# and set env variable LIB9P_LOGGING to stderr or to 33# the (preferably full path name of) the debug log file. 34 35LIB_SRCS := \ 36 pack.c \ 37 connection.c \ 38 request.c \ 39 genacl.c \ 40 log.c \ 41 hashtable.c \ 42 utils.c \ 43 rfuncs.c \ 44 threadpool.c \ 45 sbuf/sbuf.c \ 46 transport/socket.c \ 47 backend/fs.c 48 49SERVER_SRCS := \ 50 example/server.c 51 52BUILD_DIR := build 53LIB_OBJS := $(addprefix build/,$(LIB_SRCS:.c=.o)) 54SERVER_OBJS := $(SERVER_SRCS:.c=.o) 55LIB := lib9p.dylib 56SERVER := server 57 58all: build $(LIB) $(SERVER) 59 60$(LIB): $(LIB_OBJS) 61 cc -dynamiclib $^ -o build/$@ 62 63$(SERVER): $(SERVER_OBJS) $(LIB) 64 cc $< -o build/$(SERVER) -Lbuild/ -l9p 65 66clean: 67 rm -rf build 68 rm -f $(SERVER_OBJS) 69build: 70 mkdir build 71 mkdir build/sbuf 72 mkdir build/transport 73 mkdir build/backend 74 75build/%.o: %.c 76 $(CC) $(CFLAGS) -c $< -o $@ 77