forked from EGBAEMU/EGBAEMU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
69 lines (55 loc) · 1.87 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
SRC := src
OUT := bin
BUILDDIR := build
MSC_BUILDDIR := msc_build
CC := g++
CCFLAGS := -std=c++17 -ffast-math -Wall -I$(SRC)
ifeq ($(OS),Windows_NT)
LDFLAGS := -lmingw32 -lSDL2main -lSDL2 -pthread
else
LDFLAGS := -lSDL2 -pthread
endif
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
#srcs := $(wildcard $(SRC)/*.cpp)
srcs := $(call rwildcard,$(SRC),*.cpp)
objs = $(patsubst %, $(BUILDDIR)/%,$(srcs:.cpp=.o))
deps = $(patsubst %, $(BUILDDIR)/%,$(srcs:.cpp=.d))
.PHONY: all clean gbaemu windows CMakeLists.txt release debug
all: release
debug: CCFLAGS += -g
debug: gbaemu
release: CCFLAGS += -Ofast
release: gbaemu
profiling: CCFLAGS += -Ofast -g -pg
profiling: LDFLAGS += -Ofast -pg --no-pie
profiling: release
gbaemu: $(objs)
@mkdir -p $(OUT)
$(CC) $^ -o $(OUT)/$@ $(LDFLAGS)
#%.o: %.cpp
$(objs): $(BUILDDIR)/%.o : %.cpp
@mkdir -p $(@D)
$(CC) $(CCFLAGS) -MMD -MP -c $< -o $@
CMakeLists.txt:
echo "cmake_minimum_required(VERSION 3.7)" > CMakeLists.txt
echo "project(gbaemu)" >> CMakeLists.txt
echo "set (CMAKE_CXX_STANDARD 17)" >> CMakeLists.txt
echo "find_package(SDL2 REQUIRED)" >> CMakeLists.txt
echo -n "include_directories($$" >> CMakeLists.txt
echo "{SDL2_INCLUDE_DIRS} $(SRC))" >> CMakeLists.txt
echo "add_executable(gbaemu $(srcs))" >> CMakeLists.txt
echo -n "target_link_libraries(gbaemu " >> CMakeLists.txt
echo "SDL2main SDL2)" >> CMakeLists.txt
# echo -n "target_link_libraries(gbaemu $$" >> CMakeLists.txt
# echo "{SDL2_LIBRARIES})" >> CMakeLists.txt
windows: CMakeLists.txt
rm -rf $(MSC_BUILDDIR) && \
mkdir -p $(MSC_BUILDDIR) && \
cd $(MSC_BUILDDIR) && \
cmake .. && \
cmake --build . --config Release --target ALL_BUILD
windows_: $(MSC_BUILDDIR)
cd $(MSC_BUILDDIR) && cmake --build . --config Release --target ALL_BUILD
clean:
rm -rf $(objs) $(deps) $(OUT) $(BUILDDIR) CMakeLists.txt $(MSC_BUILDDIR)
-include $(deps)