Newer
Older
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
TYPE=exec# shared, static or exec
BUILD=debug# debug or release
EXEC=main
CXXFLAGS=-Wall -std=c++11 -DLINUX -DSSLSOCKET
CXXFLAGS_debug=-g
CXXFLAGS_release=-s -O2
LDFLAGS=-ldl -lpthread -L./mbedtls-2.2.1/library -lmbedtls -lmbedx509 -lmbedcrypto
LDFLAGS_debug=
LDFLAGS_release=
INCLUDES=-I./mbedtls-2.2.1/include
srcdir=.
hdir=.
objdir=.
bindir=.
CXX=g++
AR=ar
CXXFLAGS+= $(CXXFLAGS_$(BUILD)) -I$(hdir) $(INCLUDES)
ifeq ($(TYPE),shared)
CXXFLAGS+= -fPIC
endif
LDFLAGS+= $(LDFLAGS_$(BUILD))
SRC=$(wildcard $(srcdir)/*.cpp)
OBJ=$(addprefix $(objdir)/,$(notdir $(SRC:.cpp=.o)))
all: $(EXEC)
@echo "$(EXEC) built ($(TYPE) $(BUILD))"
$(EXEC): $(OBJ)
ifeq ($(TYPE),static)
@$(AR) -q $(bindir)/lib$@.a $^
endif
ifeq ($(TYPE),exec)
@$(CXX) -o $(bindir)/$@ $^ $(LDFLAGS)
endif
ifeq ($(TYPE),shared)
@$(CXX) -shared -fPIC -o $(bindir)/lib$@.so $^ $(LDFLAGS)
endif
#----DEPENDENCES----
#ex: main.o: hello.h
$(objdir)/%.o: $(srcdir)/%.cpp
@$(CXX) -c $(CXXFLAGS) -o $@ $<
.PHONY: clean mrproper
clean:
@rm -rf $(objdir)/*.o
mrproper: clean
@rm -rf $(bindir)/$(EXEC)