-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
121 lines (89 loc) · 2.56 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Makefile :)
OS_UNAME = $(shell uname -s)
ifeq ($(OS_UNAME), Linux)
OS=linux
PROGRAMEXT=
else
OS=windows
PROGRAMEXT=.exe
endif
ifeq ($(OS_UNAME), FreeBSD)
OS=freebsd
PROGRAMEXT=
endif
SRCDIR=src
NAME=vkbot
CC?=gcc
CXX?=g++
ifeq ($(CLANG), 1)
CC=clang
CXX=clang++
endif
ifeq ($(TCC), 1)
CC=tcc
endif
OPT_CFLAGS = -O2 -funroll-loops -fno-omit-frame-pointer
BASE_CFLAGS = -std=gnu11 -DVERSION=\"$(VERSION)\" -DARCH=\"$(ARCH)\" -Wall -Wextra -Wlogical-op -Wduplicated-cond -Wshift-overflow=2 -fcommon -fPIC -fstack-protector-all
ARCH=$(shell uname -m)
COMMIT := $(firstword $(shell git rev-parse --short=6 HEAD) unknown)
ifeq ($(ARCH), i686)
ARCH_CFLAGS +=-msse3 -march=i686 -mtune=generic
else ifeq ($(ARCH), x86_64)
ARCH_CFLAGS +=-msse3 -mtune=generic
ifeq ($(TARGET_ARCH), i686)
ARCH = i686
ARCH_CFLAGS +=-m32 -msse3 -march=i686 -mtune=generic
endif
else ifeq ($(ARCH), aarch64)
ARCH_CFLAGS +=
else ifeq (, $(findstring arm,$(ARCH_UNAME)))
ARCH_CFLAGS +=
endif
ifeq ($(DEBUG),1)
BUILD_TYPE = debug
BUILD_TYPE_CFLAGS = -g -DDEBUG
#-fsanitize=undefined -fsanitize=address -fsanitize=thread
ifeq ($(FIND_LEAK),1)
BUILD_TYPE_CFLAGS += -DVKBOT_FIND_LEAK
LDFLAGS += -lgc
endif
else
BUILD_TYPE = release
BUILD_TYPE_CFLAGS = -DNDEBUG
DEBUG=0
endif
VERSION := $(COMMIT)-$(BUILD_TYPE)
OBJDIR=$(BUILD_TYPE).$(OS).$(ARCH)
CFLAGS = $(BUILD_TYPE_CFLAGS) $(BASE_CFLAGS) $(OPT_CFLAGS) $(ARCH_CFLAGS)
INCLUDE=-I. -I$(SRCDIR) -Icjson
LDFLAGS += -lpthread -lcurl -lcjson -ldl -flto -Lcjson/
DO_CC=$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
DO_CXX=$(CXX) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(DO_CC)
SRC = $(wildcard src/*.c)
OBJ := $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
$(NAME)_$(ARCH)$(PROGRAMEXT): thirdparty modules_build neat depend $(OBJ)
$(CC) $(CFLAGS) $(OBJ) $(LDFLAGS) -o $(OBJDIR)/$@
# TODO:rework
modules_build:
cd modules/core && $(MAKE) DEBUG=$(DEBUG) CC=$(CC)
mv modules/core/$(OBJDIR)/core_$(ARCH).so $(OBJDIR)
cd modules/openssl && $(MAKE) DEBUG=$(DEBUG) CC=$(CC)
mv modules/openssl/$(OBJDIR)/openssl_$(ARCH).so $(OBJDIR)
thirdparty:
cd cjson && $(MAKE) CFLAGS=-O2 static
neat:
@mkdir -p $(OBJDIR)
$(OBJDIR): neat
clean: depend
cd modules/core && $(MAKE) DEBUG=$(DEBUG) CC=$(CC) clean
cd modules/openssl && $(MAKE) DEBUG=$(DEBUG) CC=$(CC) clean
-rm -f $(OBJDIR)/*.so
-rm -f $(OBJ)
-rm -f $(OBJDIR)/$(NAME)_$(ARCH)$(PROGRAMEXT)
-rm -f $(OBJDIR)/Rules.depend
depend: $(OBJDIR)/Rules.depend
$(OBJDIR)/Rules.depend: $(SRCFILES) $(OBJDIR)
$(CC) -MM $(INCLUDE) $(SRC) $(CFLAGS) | sed "s;\(^[^ ]*\):\(.*\);$(OBJDIR)/\1:\2;" > $@
include $(OBJDIR)/Rules.depend