-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
43 lines (36 loc) · 1.53 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
mkfile_path := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
SOCKT_BUILD_ROOT := $(shell cd $(shell dirname $(mkfile_path)); pwd)
rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
CC ?= clang
CXX ?= c++
SOCKT_BUILD_PRODUCT := socket_t_test
SOCKT_BUILD_CFLAGS := -fPIC -g3
SOCKT_BUILD_CPPFLAGS := -std=c++1z -fexceptions -frtti -Wall -Wextra -pedantic -Werror -Werror=old-style-cast
SOCKT_BUILD_LDFLAGS := -pthread
SOCKT_BUILD_OUTDIR := out
SOCKT_BUILD_HEADERS := $(call rwildcard,,*.h)
SOCKT_BUILD_CSOURCES := $(call rwildcard,,*.c)
SOCKT_BUILD_CPPSOURCES := $(call rwildcard,,*.cpp)
SOCKT_BUILD_OBJECTS := $(patsubst %.c,%.o,$(patsubst %,$(SOCKT_BUILD_OUTDIR)/%,$(SOCKT_BUILD_CSOURCES))) \
$(patsubst %.cpp,%.o,$(patsubst %,$(SOCKT_BUILD_OUTDIR)/%,$(SOCKT_BUILD_CPPSOURCES)))
SOCKT_BUILD_CFLAGS += -I$(SOCKT_BUILD_ROOT)/include \
-I$(SOCKT_BUILD_ROOT)/test/include
SOCKT_BUILD_CFLAGS += $(CFLAGS)
SOCKT_BUILD_CPPFLAGS += $(CPPFLAGS)
SOCKT_BUILD_LDFLAGS += $(LDFLAGS)
all: $(SOCKT_BUILD_OUTDIR)/$(SOCKT_BUILD_PRODUCT)
$(SOCKT_BUILD_OUTDIR)/%.o: %.c $(SOCKT_BUILD_HEADERS)
@mkdir -p $(dir $@)
@echo Compiling C $<
$(CC) -c -o $@ $< $(SOCKT_BUILD_CFLAGS)
$(SOCKT_BUILD_OUTDIR)/%.o: %.cpp $(SOCKT_BUILD_HEADERS)
@mkdir -p $(dir $@)
@echo Compiling C++ $<
$(CXX) -c -o $@ $< $(SOCKT_BUILD_CFLAGS) $(SOCKT_BUILD_CPPFLAGS)
$(SOCKT_BUILD_OUTDIR)/$(SOCKT_BUILD_PRODUCT): $(SOCKT_BUILD_OBJECTS)
@echo Linking $@
$(CXX) -o $@ $^ $(SOCKT_BUILD_LDFLAGS)
@echo Success
.PHONY: clean run
clean:
@rm -rf $(SOCKT_BUILD_OUTDIR)