-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
52 lines (42 loc) · 1.45 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
CC = g++
CPPFLAGS= -std=c++17 -s -Os -flto=auto -fno-ident -fno-ident -fno-asynchronous-unwind-tables -fvisibility=hidden -fmerge-all-constants -fno-exceptions -Iinclude -I./yyjson/src
SFLAGS= -static-libgcc -static-libstdc++ -static
LDFLAGS += -Lyyjson
OBJECTS := build/minipost.o build/terminal.o build/completion.o build/sjson.o build/utils.o build/logging.o build/chat.o build/yyjson.o
COPY_FILES = $(if $(filter Windows_NT, $(OS)), \
copy $(subst /,\,$(1)) $(subst /,\,$(2)), \
cp $(1) $(2))
RM_FILES = $(if $(filter Windows_NT, $(OS)), \
del $(subst /,\,$(1)), \
rm $(1) || true)
# copy function for windows and linux
ifeq ($(OS),Windows_NT)
LDFLAGS += -lws2_32
CLEAN_COMMAND := del /F /Q
MKDIR = if not exist $(subst /,\\,$1) mkdir $(subst /,\\,$1)
else
CLEAN_COMMAND := rm -f
MKDIR = mkdir -p $1
endif
copy_config:
$(call COPY_FILES, config/*.*, dist/)
build/%.o: src/%.cpp
$(call MKDIR,build)
$(CC) -c $< -o $@ $(CPPFLAGS)
build/yyjson.o: yyjson/src/yyjson.c
$(call MKDIR,build)
$(CC) -c $< -o $@ $(CPPFLAGS)
chat: $(OBJECTS)
$(call MKDIR,dist)
$(CC) src/main.cpp $(OBJECTS) -o dist/chat $(CPPFLAGS) $(LDFLAGS)
$(MAKE) copy_config
static: $(OBJECTS)
$(call MKDIR,dist)
$(CC) src/main.cpp $(OBJECTS) -o dist/chat $(CPPFLAGS) $(SFLAGS) $(LDFLAGS)
$(MAKE) copy_config
clean:
$(call RM_FILES, build/*.o)
$(call RM_FILES, dist/chat*)
$(call RM_FILES, dist/*.json)
$(call RM_FILES, dist/*.sh)
$(call RM_FILES, dist/*.bat)