-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
121 lines (101 loc) · 5.06 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
all: build
###################################################################################################
#Ďóňü ę ęîđíţ
###################################################################################################
ROOT ?= .
####################################################################################################
#Ďđîâĺđęŕ âĺđńčč óňčëčňű make
####################################################################################################
ifneq (3.80,$(MAKE_VERSION))
$(warning This makefile has written for GNU Make 3.80. Your version is $(MAKE_VERSION))
endif
###################################################################################################
#Ďîäęëţ÷ĺíčĺ áŕçîâűő íŕńňđîĺę
###################################################################################################
include $(ROOT)/config/base.mak
###################################################################################################
#Îďđĺäĺëĺíč˙
###################################################################################################
BIN_DIR := $(ROOT)/$(BIN_DIR)
TMP_DIR := $(ROOT)/$(TMP_DIR)
SRC_CORE_DIR := $(ROOT)/$(SRC_CORE_DIR)
SRC_UI_DIR := $(ROOT)/$(SRC_UI_DIR)
INCLUDE_DIR := $(ROOT)/$(INCLUDE_DIR)
EXTERN_DIR := $(ROOT)/$(EXTERN_DIR)
DIRS := $(TMP_DIR) $(BIN_DIR)
DIRS := $(sort $(DIRS))
CONFIG_DIR := $(ROOT)/config
CORE_SOURCES := $(wildcard $(DEFAULT_SOURCES:%=$(SRC_CORE_DIR)/%))
UI_SOURCES := $(wildcard $(DEFAULT_SOURCES:%=$(SRC_UI_DIR)/%))
CORE_OBJS := $(notdir $(basename $(CORE_SOURCES)))
CORE_OBJS := $(CORE_OBJS:%=$(TMP_DIR)/%.obj)
UI_RES_SOURCES := $(wildcard $(DEFAULT_RES_SOURCES:%=$(SRC_UI_DIR)/%))
UI_RESOURCES := $(notdir $(basename $(UI_RES_SOURCES)))
UI_RESOURCES := $(UI_RESOURCES:%=$(TMP_DIR)/%.resources)
UI_OBJS := $(notdir $(basename $(UI_SOURCES)))
UI_OBJS := $(UI_OBJS:%=$(TMP_DIR)/%.obj)
CUSTOM_H_DIRS := $(SRC_CORE_DIR) $(SRC_UI_DIR) $(INCLUDE_DIR) $(foreach i,$(wildcard $(EXTERN_DIR)/*/),$(i)h)
CUSTOM_LIB_DIRS := $(foreach i,$(filter %/,$(wildcard $(EXTERN_DIR)/*/)),$(i)lib)
DLLS := $(wildcard $(CUSTOM_LIB_DIRS:%=%/*.dll))
GOAL := $(BIN_DIR)/$(GOAL).exe
CORE_DLL := $(BIN_DIR)/core.dll
CORE_PCH_NAME := $(wildcard $(SRC_CORE_DIR)/$(PCH_NAME))
UI_PCH_NAME := $(wildcard $(SRC_UI_DIR)/$(PCH_NAME))
CORE_CFLAGS += $(foreach dir,$(CUSTOM_H_DIRS),/I"$(dir)" )
CORE_LINK_FLAGS += $(foreach dir,$(CUSTOM_LIB_DIRS),/LIBPATH:"$(dir)" )
CORE_CFLAGS += /nologo /c $(if $(CORE_PCH_NAME),/Yc$(notdir $(CORE_PCH_NAME)) /Fp"$(TMP_DIR)/core.pch" /FI$(notdir $(CORE_PCH_NAME)))
UI_CFLAGS += $(foreach dir,$(CUSTOM_LIB_DIRS),/AI"$(dir)" ) /AI"$(BIN_DIR)"
UI_CFLAGS += $(foreach dir,$(CUSTOM_H_DIRS),/I"$(dir)" )
UI_CFLAGS += /nologo /c $(if $(UI_PCH_NAME),/Yc$(notdir $(UI_PCH_NAME)) /Fp"$(TMP_DIR)/ui.pch" /FI$(notdir $(UI_PCH_NAME)))
#/SUBSYSTEM:WINDOWS /ENTRY:"main" /MACHINE:X86
UI_LINK_FLAGS += $(foreach dir,$(CUSTOM_LIB_DIRS),/LIBPATH:"$(dir)" ) /LIBPATH:$(TMP_DIR) $(TMP_DIR)/$(notdir $(basename $(CORE_DLL))).lib
###################################################################################################
#Ďđŕâčëŕ ńáîđęč čńőîäíčęîâ
###################################################################################################
#define scan_new_sources
#$(if $(2),for i in $(notdir $(basename $(2))); do \
# if [ $$i.$(1) -nt $(TMP_DIR)/$$i.obj ] || \
# $(if $(PCH_NAME),[ $(PCH_NAME) -nt $(TMP_DIR)/$$i.obj ] ||) \
# ! [ -x $(TMP_DIR)/$$i.$(OBJ_SUFFIX) ]; \
# then echo $(SRC_DIR)/$$i.$(1); fi; done;)
#endef
#NEW_SOURCES := $(shell $(call scan_new_sources,cpp,$(SOURCES)))
#NEW_OBJS := $(basename $(NEW_SOURCES))
#NEW_OBJS := $(NEW_OBJS:$(SRC_DIR)/%=$(TMP_DIR)/%.obj)
#ifdef NEW_OBJS
#$(NEW_OBJS): $(NEW_SOURCES)
# @cl /nologo $(CPPFLAGS) $(CFLAGS) /Fo"$(TMP_DIR)\\" $(NEW_SOURCES)
#
#endif
$(TMP_DIR)/%.obj: $(SRC_CORE_DIR)/%.cpp
@cl $< /c /nologo $(CORE_CFLAGS) $(CORE_CPPFLAGS) /Fo"$@"
$(TMP_DIR)/%.obj: $(SRC_UI_DIR)/%.cpp
@cl $< /clr /c /nologo $(UI_CFLAGS) $(UI_CPPFLAGS) /Fo"$@"
$(TMP_DIR)/%.resources: $(SRC_UI_DIR)/%.resx
@cd $(SRC_UI_DIR) && resgen $(notdir $<) $(notdir $@)
@mv $(SRC_UI_DIR)/$(notdir $@) $@
$(CORE_DLL): $(CORE_OBJS)
@echo Create $@...
@link /nologo /dll /out:"$@" $^ $(CORE_LINK_FLAGS)
@mv -t $(TMP_DIR) $(basename $@).lib $(basename $@).exp
$(GOAL): $(CORE_DLL) $(UI_OBJS) $(UI_RESOURCES)
@echo Linking $@...
@cp -uv $(DLLS) $(BIN_DIR)
@link /nologo /ASSEMBLYRESOURCE:$(UI_RESOURCES) $(UI_LINK_FLAGS) /out:"$@" $(UI_OBJS) $()
###################################################################################################
#Öĺëč ńáîđęč
###################################################################################################
.PHONY: all build rebuild clean mostlyclean prebuild run
build: prebuild $(GOAL)
run: build
# @cd $(ROOT) && cmd /C bin\\$(notdir $(GOAL))
@cd $(ROOT) && bin/$(notdir $(GOAL))
prebuild:
@mkdir -p $(DIRS)
mostlyclean:
@$(RM) $(TMP_DIR)
clean:
@$(RM) -r $(DIRS)
rebuild:
@$(MAKE) -s clean
@$(MAKE) -s build