-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
73 lines (55 loc) · 3.15 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
#If you are using SDL2
SDL_COMP_FLAGS=-IC:/MinGW/include/SDL2 # -I[full path to SDL2 include folder]. Default: -IC:/MinGW/include/SDL2
SDL_LINK_FLAGS=-lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
################################
#executable name (without extension)
FILE=prog
#main file name (where the main function is)
MAINFILE=main
#source files extension (.c, .cpp)
SOURCE_EXT=.cpp
#header files extension (.h, .hpp)
HEADER_EXT=.hpp
#folder that contains the source files (.c, .cpp)
SRCFOLDER=src
#folder that contains the header files (.h, .hpp)
INCFOLDER=include
#folder where the binary files (.o) will be compiled
OBJFOLDER=objects
#compiler that will be used to build binaries and link the executable (gcc, g++, c++...)
COMPILER=g++
#flags that will be used when compiling binaries
COMPILATION_FLAGS=-O3 -Wall -Wextra -pedantic -std=c++11
#flags that will be used when linking the executable
LINKER_FLAGS=
#environment defines (to use with #ifdef for example)
DEFINES=DEBUG
################################
PERCENT=0
FILE-SOURCE=$(wildcard ./$(SRCFOLDER)/*$(SOURCE_EXT))
HEADERS=$(wildcard ./$(INCFOLDER)/*$(HEADER_EXT))
OBJECTS=$(subst $(SOURCE_EXT),.o,$(subst ./$(SRCFOLDER)/,./$(OBJFOLDER)/,$(FILE-SOURCE)))
OBJCOUNT=$(shell echo|set /a $(words $(OBJECTS))+1)
CURCOUNT=0
#DEVELOPEMENT
all: objdir $(FILE)
@ echo [100%%] Built target $(FILE)
$(FILE): $(OBJECTS)
@ $(eval PERCENT=$(shell echo|set /a $(CURCOUNT)*100/$(OBJCOUNT)))
@ if $(PERCENT) LSS 10 (echo [ $(PERCENT)%%] [92mLinking executable $(FILE)[0m) else (if $(PERCENT) GEQ 10 (echo [ $(PERCENT)%%] [92mLinking executable $(FILE)[0m) else (if $(PERCENT) EQU 100 (echo [100%%] [92mLinking executable $(FILE)[0m)))
@ $(COMPILER) $^ $(COMPILATION_FLAGS) $(LINKER_FLAGS) -o $(FILE) $(foreach I,./$(INCFOLDER)/,$(shell echo -I$(I)))
./$(OBJFOLDER)/%.o: ./$(SRCFOLDER)/%$(SOURCE_EXT) ./$(INCFOLDER)/%$(HEADER_EXT)
@ $(eval PERCENT=$(shell echo|set /a $(CURCOUNT)*100/$(OBJCOUNT)))
@ if $(PERCENT) LSS 10 (echo [ $(PERCENT)%%] [32mBuilding $(COMPILER) object $@[0m) else (if $(PERCENT) GEQ 10 (echo [ $(PERCENT)%%] [32mBuilding $(COMPILER) object $@[0m) else (if $(PERCENT) EQU 100 (echo [100%%] [32mBuilding $(COMPILER) object $@[0m)))
@ $(COMPILER) $< -c $(COMPILATION_FLAGS) -o $@ $(foreach I,./$(INCFOLDER)/,$(shell echo -I$(I))) $(foreach d,$(DEFINES),$(shell echo -D$(d)))
@ $(eval CURCOUNT=$(shell echo|set /a $(CURCOUNT)+1))
./$(OBJFOLDER)/$(MAINFILE).o: ./$(SRCFOLDER)/$(MAINFILE)$(SOURCE_EXT) $(HEADERS)
@ $(eval PERCENT=$(shell echo|set /a $(CURCOUNT)*100/$(OBJCOUNT)))
@ if $(PERCENT) LSS 10 (echo [ $(PERCENT)%%] [32mBuilding $(COMPILER) object $@[0m) else (if $(PERCENT) GEQ 10 (echo [ $(PERCENT)%%] [32mBuilding $(COMPILER) object $@[0m) else (if $(PERCENT) EQU 100 (echo [100%%] [32mBuilding $(COMPILER) object $@[0m)))
@ $(COMPILER) $< -c $(COMPILATION_FLAGS) -o $@ $(foreach I,./$(INCFOLDER)/,$(shell echo -I$(I))) $(foreach d,$(DEFINES),$(shell echo -D$(d)))
@ $(eval CURCOUNT=$(shell echo|set /a $(CURCOUNT)+1))
objdir:
-@ if NOT EXIST "$(OBJFOLDER)" (mkdir "$(OBJFOLDER)" >nul)
clean:
-@ del /f /s /q "$(OBJFOLDER)\*.o" "$(FILE).exe" *~ >nul 2>nul
.PHONY: all clean