-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (65 loc) · 2.1 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
#-------------------------------------------------------------------------------
# Estrutura do projeto
# sdl2mf/
#├── bin/
#│ └── sdl2mf*
#├── doc/
#├── inc/
#│ └── game.h
#├── obj/
#│ ├── game.o
#│ └── main.o
#├── src/
#│ ├── game.cpp
#│ └── main.cpp
#├── LICENSE
#├── Makefile
#└── README.md
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Nome do projeto
# https://stackoverflow.com/questions/18136918/how-to-get-current-relative-directory-of-your-makefile
#-------------------------------------------------------------------------------
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
NAME := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
#-------------------------------------------------------------------------------
# Diretórios
#-------------------------------------------------------------------------------
BIN_DIR=./bin
INC_DIR=./inc
OBJ_DIR=./obj
SRC_DIR=./src
#-------------------------------------------------------------------------------
# Source, Header, and Object
#-------------------------------------------------------------------------------
SRC = ${wildcard $(SRC_DIR)/*.cpp}
OBJ = ${addprefix $(OBJ_DIR)/, ${notdir ${SRC:.cpp=.o}}}
INC = -I${INC_DIR}
#-------------------------------------------------------------------------------
# Compilador, flags e bibliotecas
#-------------------------------------------------------------------------------
CC=g++
CFLAGS= -Wall -Wextra -pedantic -ansi -std=c++17
LFLAGS= -lSDL2
TARGET=$(BIN_DIR)/$(NAME)
.PHONY: clean all dirs run
all:
@echo
@echo Compiling
$(MAKE) $(TARGET)
dirs:
@mkdir -vp $(BIN_DIR) $(OBJ_DIR)
$(TARGET): dirs $(OBJ)
@echo
@echo Linking $@
$(CC) -o $@ $(OBJ) $(LIB) $(LFLAGS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
@echo
@echo Building $@
$(CC) -c $^ -o $@ $(CFLAGS) $(INC)
run: $(TARGET)
$(TARGET) 2>&1 | tee log.err
clean:
@echo Cleaning...
@rm -rvf *~ $(OBJ_DIR) $(BIN_DIR)
.PRECIOUS: %.o