-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
214 lines (167 loc) · 6.89 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# (c) Samm see License in LICENSE.txt FILE
CC := gcc
CXX := g++
ifeq ($(OS),Windows_NT)
ROOT := $(shell cd)
else
ROOT := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
endif
PROJECT ?=float_compress
# WIN, LINUX, MACOS, UNIX, NONE
OSS ?=WIN
# RELEASE, DEBUG
STATE ?=RELEASE
# x86, x64, ARM, ARM64
ARCH ?=x64
# SOFTWARE, OS
TYPE ?=SOFTWARE
# TRUE, FALSE
TEST ?=FALSE
#define PKG_CONFIG
#export
PKG_CONFIG_PATH := "$(ROOT)shared/lib/$(ARCH)/pkgconfig"
export PKG_CONFIG_PATH
SRC := ./projects/$(PROJECT)/
BUILD := ./build/$(PROJECT)/$(ARCH)_$(STATE)/
INCS := -I"$(ROOT)shared/inc/"
LIBS := -lmingw32 -L"$(ROOT)shared/lib/$(ARCH)" -lSDL2 -lSDL2main -limgui.dll -mwindows -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid
ifeq ($(STATE),DEBUG)
LIBS := -lmingw32 -L"$(ROOT)shared/lib/$(ARCH)" -lSDL2 -lSDL2main -limgui.dll -mconsole -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid
endif
#`pkg-config --static --libs sdl2`
#LIBS := -Wl,--start-group -L./shared/lib/$(ARCH)/ -lSDL2main -lSDL2 -Wl,--end-group
# -L$(ROOT)shared/lib/$(ARCH)/ -limgui
#BLIBS := -limgui
# $(shell pkg-config --cflags --libs sdl2)
#ifeq ($(OS),WIN)
# LIBS += -lversion -lgdi32 -limm32
#endif
ifeq ($(ARCH),x86)
CFLAGS := -m32 $(INCS) -Wall
CXXFLAGS := -m32 -std=c++20 -MMD -MP -pthread $(INCS) -Wall
ASFLAGS := -m32 -f elf
LDFLAGS := -m32
else ifeq ($(ARCH),x64)
CFLAGS := -m64 $(INCS) -Wall
CXXFLAGS := -m64 -std=c++20 -MMD -MP -pthread $(INCS) -Wall
ASFLAGS := -m64 -f elf64
LDFLAGS := -m64
endif
#`pkg-config --cflags sdl2`
# LDFLAGS += -m elf_i386 -T linker.ld
# LDFLAGS += -m elf_x86_64 -T linker.ld
#ifeq ($(TEST),TRUE)
# C_FLAGS += -DTESTING
# CXX_FLAGS += -DTESTING
# AS_FLAGS += -DTESTING
# LDFLAGS += -DTESTING
#endif
OUT := $(BUILD)$(PROJECT).exe
ifeq ($(OSS),WIN)
OUT := $(BUILD)$(PROJECT).exe
else ifeq ($(OSS),LINUX)
OUT := $(BUILD)$(PROJECT).out
else ifeq ($(OSS),MACOS)
OUT := $(BUILD)$(PROJECT).app
else
OUT := $(BUILD)$(PROJECT).bin
endif
#ASM_SOURCES := $(wildcard $(ROOT)shared/inc/*.asm) $(wildcard $(SRC)*.asm)
#C_SOURCES := $(wildcard $(ROOT)shared/inc/*.c) $(wildcard $(SRC)*.c)
#CXX_SOURCES := $(wildcard $(ROOT)shared/inc/*.cpp) $(wildcard $(SRC)*.cpp)
#ASM_SOURCES := $(wildcard $(shell find "$(SRC)" -name '*.asm'))
#ASM_SOURCES += $(wildcard $(shell find "$(ROOT)shared/inc/" -name '*.asm'))
ASM_SOURCES := $(wildcard $(ROOT)shared/inc/**/*.asm) $(wildcard $(ROOT)shared/inc/**/*.S) $(wildcard $(SRC)**/*.asm) $(wildcard $(SRC)**/*.S)
#ASM_SOURCES += $(wildcard $(shell find $(ROOT)shared/inc/* -name '*.asm'))
#ASM_SOURCES += $(wildcard $(shell find $(ROOT)shared/inc/* -name '*.S'))
#C_SOURCES := $(wildcard $(shell find "$(SRC)" -name '*.c'))
#C_SOURCES += $(wildcard $(shell find "$(ROOT)shared/inc/" -name '*.c'))
C_SOURCES := \
$(wildcard $(ROOT)shared/inc/**/*.c) \
$(wildcard $(SRC)**/*.c)
#C_SOURCES += $(wildcard $(shell find $(ROOT)shared/inc/ -name '*.c'))
IMGUISRC := $(wildcard $(shell find "$(ROOT)shared/inc/imgui/" -name '*.cpp'))
#IMGUISRC := $(filter-out $(ROOT)shared/inc/imgui/added_by_samm.cpp, $(wildcard $(ROOT)shared/inc/imgui/*.cpp))
#IMGUISRC += $(ROOT)shared/inc/imgui/added_by_samm.cpp
#CXX_SOURCES := $(wildcard $(shell find "$(ROOT)shared/inc/" -name '*.cpp'))
#CXX_SOURCES += $(wildcard $(shell find "$(SRC)" -name '*.cpp'))
CXX_SOURCES := \
$(wildcard $(ROOT)shared/inc/**/*.cpp) \
$(wildcard $(SRC)*.cpp) \
$(wildcard $(SRC)**/*.cpp)
# $(wildcard $(ROOT)shared/inc/**/*.cpp)
#CXI_SOURCES := $(wildcard $(shell find "$(ROOT)shared/inc/" -name '*.cpp'))
# Change to INC_SOURCES:
CXX_SOURCES := $(filter-out $(wildcard $(ROOT)shared/inc/imgui/**.cpp), $(CXX_SOURCES)) #$(filter-out $(IMGUISRC), $(CXX_SOURCES))
C_ALL_SRC := $(C_SOURCES)
CPP_ALL_SRC := $(CXX_SOURCES) $(IMGUISRC)
#CPPNEW_ALL_SRC := $(patsubst %.cpp,%.new.cpp,$(CPP_ALL_SRC))
#CNEW_ALL_SRC := $(patsubst %.c,%.new.c,$(C_ALL_SRC))
#$(CNEW_ALL_SRC): $(C_ALL_SRC)
# $(CXX) $(CFLAGS) -E -DSDL_MAIN_HANDLED $< -o $@
#
#$(CPPNEW_ALL_SRC): $(CPP_ALL_SRC)
# $(CXX) $(CXXFLAGS) -E -DSDL_MAIN_HANDLED -E -Dmain=SDL_main $< -o $@
#preprocess: $(CNEW_ALL_SRC) $(CPPNEW_ALL_SRC)
ASM_OBJS := $(patsubst %.asm,$(BUILD)objects/%.asm.o,$(notdir $(ASM_SOURCES)))
C_OBJS := $(patsubst %.c,$(BUILD)objects/%.c.o,$(notdir $(C_SOURCES)))
CXX_OBJS := $(patsubst %.cpp,$(BUILD)objects/%.cpp.o,$(notdir $(CXX_SOURCES)))
#CXI_OBJS := $(patsubst %.cpp,%.cpp.o,$(CXI_SOURCES))
#C_OBJS := $(patsubst %.c,%.c.o,$(CNEW_ALL_SRC))
#CXX_OBJS := $(patsubst %.cpp,%.cpp.o,$(CNEW_ALL_SRC))
IMGUIOBJS := $(patsubst %.cpp,$(BUILD)objects/%.imgui.o,$(IMGUISRC))
#IMGUIOBJ := "$(ROOT)shared/inc/imgui/dear.imgui.o"
IMGUI_DLL := "$(ROOT)shared/lib/$(ARCH)/imgui.dll"
IMGUI_DLL_A := "$(ROOT)shared/lib/$(ARCH)/libimgui.dll.a"
$(ASM_OBJS): $(ASM_SOURCES)
$(CC) $(ASFLAGS) -c $< -o $@
$(C_OBJS): $(C_SOURCES)
$(CC) $(CFLAGS) -c $< -o $@
#$(CXI_OBJS): $(CXI_SOURCES)
# $(CXX) $(CXXFLAGS) -c $< -o $@
$(IMGUIOBJS): $(IMGUISRC)
$(CXX) $(CXXFLAGS) -c $< -o $@
#-lSDL2main -lSDL2
#$(IMGUIOBJ): $(IMGUIOBJS)
# ar rcs $@ $^
# $(CXX) $(LDFLAGS) $(INCS) $^ -o $@ $(LIBS)
#-include $(C_OBJS:.o=.d)
#-include $(CXX_OBJS:.o=.d)
#-include $(ASM_OBJS:.o=.d)
$(CXX_OBJS): $(CXX_SOURCES)
$(CXX) $(CXXFLAGS) -c $< -o $@
create_directories:
mkdir -p $(BUILD) $(dir $(OUT)) $(foreach file,$(IMGUIOBJS),$(shell dirname $(file))) $(foreach file,$(ASM_OBJS),$(shell dirname $(file))) $(foreach file,$(C_OBJS),$(shell dirname $(file))) $(foreach file,$(CXX_OBJS),$(shell dirname $(file)))
#"$(ROOT)shared/lib/$(ARCH)/libimgui.a": $(IMGUIOBJS)
# $(CXX) $(LDFLAGS) -shared -o $@ $^
# ar rcs $@ $^
$(IMGUI_DLL): $(IMGUISRC)
$(CXX) $(LDFLAGS) -mwindows $(INCS) -shared -o $@ $^ -L"$(ROOT)shared/lib/$(ARCH)" -lSDL2 -lSDL2main
$(IMGUI_DLL_A): $(IMGUI_DLL)
$(CC) -shared -Wl,--out-implib,$(IMGUI_DLL_A) $<
build_libs: create_directories $(IMGUI_DLL_A) #"$(ROOT)shared/lib/$(ARCH)/libimgui.a"
$(OUT): $(ASM_OBJS) $(C_OBJS) $(CXX_OBJS) $(IMGUI_DLL) # $(IMGUIOBJS)
$(CXX) $(LDFLAGS) $(INCS) $^ -o $@ $(LIBS)
cp $(IMGUI_DLL) $(dir $(OUT))
#$(ASM_OBJS) $(CNEW_ALL_SRC) $(CPPNEW_ALL_SRC)
#.PHONY:
test:
@echo $(CXX_SOURCES)
@echo $(PKG_CONFIG_PATH)
pkg-config --libs sdl2
one: create_directories $(OUT)
#one_all: build_libs one
rebuild: clean one
clean_objs:
rm -rf $(ASM_OBJS) $(C_OBJS) $(CXX_OBJS) $(CPPNEW_ALL_SRC) $(CNEW_ALL_SRC) $(wildcard $(IMGUIOBJS)) $(IMGUIOBJ)
# $(C_OBJS:.o=.d) $(CXX_OBJS:.o=.d) $(ASM_OBJS:.o=.d)
clean-objs: clean_objs
clean:
rm -rf $(ASM_OBJS) $(C_OBJS) $(CXX_OBJS) $(CPPNEW_ALL_SRC) $(CNEW_ALL_SRC) $(wildcard $(IMGUIOBJS)) $(IMGUIOBJ) $(BUILD)
# $(C_OBJS:.o=.d) $(CXX_OBJS:.o=.d) $(ASM_OBJS:.o=.d)
clean_libs:
rm -rf $(IMGUI_DLL) $(IMGUI_DLL_A)
clean_with_libs:
clean
clean_libs
#EOF