-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
62 lines (46 loc) · 1.53 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
#
# 'make' build executable file 'main'
# 'make clean' removes all .o and executable files
#
# define the Cpp compiler to use
CXX = g++
# define any compile-time flags
CXXFLAGS := -std=c++17 -Wall -Wextra -g
# define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify
# their path using -Lpath, something like:
LFLAGS = -L"C:\SFML\lib" -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lfreetype -lwinmm -lgdi32 -mwindows
INCLUDES := -I"C:\SFML\include" -DSFML_STATIC
EXE := SimpleFractals.exe
BINDIR := bin
OBJDIR := obj
SRCDIR := src
subdirs = $(filter-out $1,$(sort $(dir $(wildcard $1*/))))
rfind = $(wildcard $1$2) $(foreach d,$(call subdirs,$1),$(call rfind,$d,$2))
RM := del /q /f
MD := mkdir
FIXPATH = $(subst /,\,$1)
EXEPATH := $(call FIXPATH,$(BINDIR)/$(EXE))
SOURCES := $(call rfind,$(SRCDIR)/,*.cpp)
OBJECTS := $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES))
all: build
./$(EXEPATH)
@echo Run complete!
build: $(BINDIR) $(OBJDIR) $(EXEPATH)
@echo Build complete!
$(EXEPATH): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(INCLUDES) $(OBJECTS) -o $(EXEPATH) $(LFLAGS)
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
.SECONDEXPANSION:
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | $$(@D)
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
$(BINDIR):
@$(MD) $@
$(OBJDIR):
@$(MD) $(subst /,\,$(patsubst %/, %, $(sort $(dir $(OBJECTS)))))
.PHONY: clean
clean:
$(RM) $(EXEPATH)
$(RM) $(call FIXPATH,$(OBJECTS))
@echo Cleanup complete!