-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
42 lines (36 loc) · 1.41 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
#-----------------------------------------#
# COMPILER OPTIONS
#-----------------------------------------#
CX = g++
CXFLAGS = -std=c++14 -Wall
EXT = cpp
LIBS = -lsfml-graphics -lsfml-system -lsfml-window -lm
DIR_OBJS = ./bin
EXEC = $(DIR_OBJS)/monopoly
#-----------------------------------------#
# FILES
#-----------------------------------------#
SRC := $(shell echo src/*.$(EXT))
#notdir : returns the file only without its folder (src/main.c -> main.c)
#basename : returns the file withtout its suffix (main.c -> main)
#addprefix : returns the file with its new prefix (main -> DIR_OBJS/main)
#addsuffix : returns the file with its new suffix (DIR_OBJS/main -> DIR_OBJS/main.o)
OBJS = $(addsuffix .o, $(addprefix $(DIR_OBJS)/, $(basename $(notdir $(SRC)))))
#-----------------------------------------#
# COMPILING RULES
#-----------------------------------------#
all: build $(OBJS)
$(CX) $(CXFLAGS) $(OBJS) -o $(EXEC) $(LIBS)
@echo Project compiled !
# Builds .o's from .cpp's using automatic variables
# $<: the name of the prerequisite of the rule -> .cpp file
# $@: the name of the target of the rule -> .o file
$(DIR_OBJS)/%.o : ./src/%.$(EXT)
$(CX) $(CXFLAGS) -c $< -o $@
.PHONY: build # To avoid errors when building
build:
mkdir -p $(DIR_OBJS)
.PHONY: clean # To avoid errors when cleaning
clean:
rm -rf $(DIR_OBJS)
@echo Files deleted, project clean.