This repository has been archived by the owner on Sep 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
153 lines (123 loc) · 4.04 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# **************************************************************************** #
# #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: pholster <[email protected]> +#+ #
# +#+ #
# Created: 2019/01/07 20:00:45 by pholster #+# #+# #
# Updated: 2020/03/06 17:50:43 by jvisser ######## odam.nl #
# #
# **************************************************************************** #
# Sublib folder names
SUBLIBS = main color sdl_extra tga_reader gui game gui_config sdl_thread \
audio keymap serializer eventstate map_parse table renderer init \
cmath loop textures \
player \
enemy \
map_editor \
# Executable name
NAME = doom-nukem
PARENTNAME = $(NAME)
# Compile settings
CCSILENT = FALSE
CCSTRICT = -Wall -Werror -Wextra
CCOPTIMISE = -O3
# Gcov settings
GCOV = FALSE
GCOVSILENT = TRUE
GCOVFLAGS = -f -b -c
LIBFT_DISABLE_GCOV = TRUE
# Mafile includes
MAKEINCLUDES = includes/libft
include $(MAKEINCLUDES)/Makefile.color
# Libft info
LIBPATH = libft
LIB = $(LIBPATH)/libft.a
# FrameWorkPaths
ifeq ($(shell uname -s), Linux)
FRAMEWORKPATH := /usr
else
FRAMEWORKPATH := $(shell brew --cellar)/..
endif
# Path to framework includes folder
FRAMEWORKINCLUDES = $(FRAMEWORKPATH)/include
# SDL2 dependency
SDL2LIB = -L$(FRAMEWORKPATH)/lib -lSDL2
# SDL2_TTF dependency
SDL2TTF = -L$(FRAMEWORKPATH)/lib -lSDL2_ttf
# SDL2_Mix dependency
SDL2MIX = -L$(FRAMEWORKPATH)/lib -lSDL2_mixer
# All libs for compilation
LIBS = $(LIB) $(SDL2LIB) $(SDL2TTF) $(SDL2MIX)
ifeq ($(shell uname -s), Linux)
LIBS += -lm
endif
# Sublib info
SUBLIBSPATH = .sublibs
SUBLIBS := $(sort $(SUBLIBS))
SUBLIBS := $(SUBLIBS:%=src/$(SUBLIBSPATH)/%.content)
SUBLIBMAKE = $(MAKE) -s -e -C src FOLDER=$(SUBLIBSPATH)
# Fclean target files
FCLEAN := $(wildcard $(NAME) $(SUBLIBS))
# Function - Get all objects of sublibs
GETOBJS = $(shell cat $(1) | grep '\.o' | sed 's/^/src\//g')
OBJS = $(foreach DIR,$(SUBLIBS),$(call GETOBJS,$(DIR)))
# Function - Clean all sublib .content
CLEANSUBLIB = $(SUBLIBMAKE) SUBLIB=$(1:src/$(SUBLIBSPATH)/%=%) clean &&
SUBLIBS_CLEAN := $(foreach DIR,$(SUBLIBS),$(call CLEANSUBLIB,$(DIR))) :
# Function - Clean all sublib .content
GCOVSUBLIB = $(SUBLIBMAKE) SUBLIB=$(1:src/$(SUBLIBSPATH)/%=%) gcovreport &&
SUBLIBS_GCOV := $(foreach DIR,$(SUBLIBS),$(call GCOVSUBLIB,$(DIR))) :
# Export vars to sublib makefile
export GCOV
export GCOVSILENT
export GCOVFLAGS
export CCSILENT
export CCSTRICT
export CCOPTIMISE
export PARENTNAME
export FRAMEWORKPATH
export FRAMEWORKINCLUDES
export SDL2LIB
export SDL2TTF
export SDL2MIX
export LIBFT_DISABLE_GCOV
all: $(NAME)
# Create $(NAME)
$(NAME): $(LIB) $(SUBLIBS)
@$(call FNC_PRINT_EQUAL,$(NAME),$(NAME))
@rm -f $(NAME)
@gcc -g -coverage $(CCOPTIMISE) -o $(NAME) $(OBJS) $(LIBS)
@bash pack_textures.bash
# Compile $(LIB)
$(LIB): FORCE
@$(MAKE) -s -e -C $(LIBPATH)
# Compile $(SUBLIBS)
src/$(SUBLIBSPATH)/%.content: src/$(SUBLIBSPATH) FORCE
@$(SUBLIBMAKE) SUBLIB=$(@:src/$(SUBLIBSPATH)/%=%)
# Create $(SUBLIBSPATH) if it doesnt exsist
src/$(SUBLIBSPATH):
@mkdir src/$(SUBLIBSPATH)
# Clean all non .content files
clean:
ifneq ($(wildcard $(TESTPATH)),)
@$(MAKE) -s -e -C $(TESTPATH) NAME=$(TESTNAME) clean
endif
@$(SUBLIBS_CLEAN)
@$(MAKE) -s -e -C $(LIBPATH) clean
# Clean all .content files
fclean: clean
ifneq ($(wildcard $(TESTPATH)),)
@$(MAKE) -s -e -C $(TESTPATH) NAME=$(TESTNAME) fclean
endif
ifneq ($(FCLEAN),)
@$(call FNC_PRINT_DEL,$(NAME),fclean $(FCLEAN:src/$(SUBLIBSPATH)/%=%))
@rm -f $(NAME) $(SUBLIBS)
endif
@$(MAKE) -s -e -C $(LIBPATH) fclean
# Recompile only the project
re: fclean
@$(MAKE)
FORCE: ;
.PHONY: all clean fclean re FORCE