-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
189 lines (151 loc) · 4.69 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# CG Madness - a Marble Madness clone
# Copyright (C) 2007 Sven Reinck <sreinck@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
CPREFIX :=
CC := $(CPREFIX)gcc
CFLAGS := -Wall
CXX := $(CPREFIX)g++
CXXFLAGS = $(CFLAGS) -pedantic -include cstdlib -include Prefix.pch -I.
LD := $(CPREFIX)g++
LDFLAGS :=
LIBS_OPENGL :=
PERL := perl
MACHINE := $(shell $(CC) -dumpmachine)
BUILD := build/$(MACHINE)
DEPS := .deps
PWD := $(notdir $(shell pwd))
PROJECT := cgmadness
NAME := CG Madness
SHADER := golfball ballshadow
GL_H := <GL/glew.h>
GLU_H := <GL/glew.h>
GLUT_H := <GL/freeglut.h>
# Check if compiling with Linux or Cygwin/MinGW
ifneq ($(findstring mingw32,$(MACHINE))$(findstring cygwin,$(MACHINE)),)
CFLAGS += -mno-cygwin
CFLAGS += -DWIN32
CXXFLAGS += -DGLUT_DISABLE_ATEXIT_HACK
LDFLAGS += -mno-cygwin
LIBS_OPENGL += -lglut32 -lglu32 -lopengl32 -lglew32
EXECSUFFIX := .exe
endif
ifneq ($(findstring linux-gnu,$(MACHINE)),)
CXXFLAGS += -ansi
LIBS_OPENGL += -lglut -lGLU -lGL -lGLEW
EXECSUFFIX :=
endif
ifneq ($(findstring apple-darwin,$(MACHINE)),)
CFLAGS += -DDARWIN
CXXFLAGS += -I/opt/local/include
LIBS_OPENGL += -framework OpenGL -framework GLUT -lGLEW
EXECSUFFIX :=
GL_H := <GL/glew.h>
GLU_H := <GL/glew.h>
GLUT_H := <GLUT/glut.h>
endif
CXXFLAGS += -DGL_H="$(GL_H)" -DGLU_H="$(GLU_H)" -DGLUT_H="$(GLUT_H)"
findOpenGL = $(if $(findstring /callback.o,$(1)),$(LIBS_OPENGL))
FIND_LIBS := findOpenGL
MAINS := $(shell $(PERL) mains.pl)
CODE := $(subst ./,,$(shell find . -name '*.c' -or -name '*.cpp'))
INCLUDE := $(subst ./,,$(shell find . -name '*.h' -or -name '*.hpp' -or -name '*.inc'))
SRC := $(CODE) $(INCLUDE)
DATA := $(wildcard data/*.tga levels/*.cgm) $(SHADER:%=%.vert) $(SHADER:%=%.frag)
DLL := glut32.dll glew32.dll
DEV := $(wildcard *.pl)
DOC := license.txt credits.txt
DOC_DEV := $(DOC) compile.txt
EXEC := $(MAINS:%=%$(EXECSUFFIX))
DEP := $(CODE:%=$(DEPS)/%.d) $(MAINS:%=$(DEPS)/%.o.d)
CLEAN := $(BUILD) $(EXEC)
# main part
.PHONY: all
all: $(EXEC)
.PHONY: release
release: src tar mingw-zip
.PHONY: mingw-%
mingw-%:
@$(MAKE) $* COMSPEC=1 CPREFIX="i586-mingw32msvc-"
.PHONY: profile
profile:
@$(MAKE) BUILD=profile/$(MACHINE) EXECSUFFIX=".profile$(EXECSUFFIX)" CFLAGS="-pg $(CFLAGS) -O0" LDFLAGS="-pg $(filter-out -s,$(LDFLAGS))"
.PHONY: debug
debug:
@$(MAKE) BUILD=debug/$(MACHINE) EXECSUFFIX=".debug$(EXECSUFFIX)" CFLAGS="-g $(CFLAGS) -O0" LDFLAGS="-g $(filter-out -s,$(LDFLAGS))"
.SECONDEXPANSION:
%$(EXECSUFFIX): $(BUILD)/%.o
@echo " LINK $@"
@$(LD) $(LDFLAGS) $^ $(foreach find, $(FIND_LIBS), $(call $(find),$^)) -o $@
$(BUILD)/%.o: %.c | $$(@D)/.
@echo " CC $@"
@$(CC) -c $(CFLAGS) $< -o $@
$(BUILD)/%.o: %.cpp Prefix.pch | $$(@D)/.
@echo " CXX $@"
@$(CXX) -c $(CXXFLAGS) $< -o $@
# building archives
BASENAME := $(PROJECT)
SRC_TAR := $(BASENAME)-src.tar.bz2
TAR := $(BASENAME).tar.bz2
ZIP := $(BASENAME).zip
APP := $(NAME).app
CMD := $(wildcard *.cmd)
CLEAN += $(TAR) $(SRC_TAR) $(ZIP)
.PHONY: src
src: $(SRC_TAR)
$(SRC_TAR): Makefile $(SRC) $(DATA) $(DEV) $(DOC_DEV)
@echo " TAR $@"
@tar -C .. -cjf $@ $(^:%=$(PWD)/%)
.PHONY: tar
tar: $(TAR)
$(TAR): $(EXEC) $(DATA) $(DOC)
@echo " TAR $@"
@tar -C .. -cjf $@ $(^:%=$(PWD)/%)
.PHONY: zip
zip: $(ZIP)
ifneq ($(findstring apple-darwin,$(MACHINE)),)
$(ZIP): $(EXEC) $(DATA) $(DOC)
@echo " APP $@"
@ant -Dzip="$(ZIP)" -Dapp="$(APP)" -Dexec="$(word 1,$(EXEC))" -Dres="$(DATA) $(DOC)" > /dev/null
else
$(ZIP): $(EXEC) $(CMD) $(DATA) $(DLL) $(DOC)
@echo " ZIP $@"
@zip "$@" $^ > /dev/null 2>&1
endif
# clean up
.PHONY: clean
clean:
@echo " CLEAN"
@rm -rf $(CLEAN)
# dependancies
include $(DEP)
.DELETE_ON_ERROR:
$(DEPS)/%.o.d: %.c modules.pl | $$(@D)/.
@echo " MODULES $@"
@$(PERL) modules.pl $< > $@
$(DEPS)/%.o.d: %.cpp modules.pl | $$(@D)/.
@echo " MODULES $@"
@$(PERL) modules.pl $< > $@
$(DEPS)/%.c.d: %.c dep.pl | $$(@D)/.
@echo " DEP $@"
@$(PERL) dep.pl $< > $@
$(DEPS)/%.cpp.d: %.cpp dep.pl | $$(@D)/.
@echo " DEP $@"
@$(PERL) dep.pl $< > $@
# create necessary directories
.PRECIOUS: %/.
%/.:
@echo " MKDIR $*"
@mkdir -p $*