-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
132 lines (116 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
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
#######################################################################
#
# Instructions:
#
# make
# Compiles all .c and .cpp files in the src directory to .o
# files in the obj directory, and links them into an
# executable named 'game' or 'game.exe' in the currect directory.
#
# make clean
# Removes all .o files from the obj directory.
#
# make veryclean
# Removes all .o files and the game executable.
#
# Optional parameters:
#
# STATICLINK=1
# Compiles/removes a statically linked version of the game without
# DLL dependencies. The static object files are put in obj/static
# and the executable has '_static' appended to the name.
#
# NAME=game_name
# Sets the name of the game executable. By default the game
# executable is called 'game' or 'game.exe'.
#
# If you use add-on libraries, add them to the lines starting with
# 'LIBS='. Make sure you enter the libraries in both lines, for the
# normal and static version!
#
#######################################################################
ifndef CC
CC = gcc
endif
ifndef CXX
CXX = g++
endif
ifndef LD
LD = g++
endif
CFLAGS = -Iinclude -O3 -s -W -Wall
# Change NAME = to the name of your game
ifndef NAME
NAME = distrain
endif
# Add-on libraries go here
ifdef STATICLINK
LIBS =
else
LIBS =
endif
ifndef WINDOWS
ifdef MINGDIR
WINDOWS = 1
endif
endif
ifdef WINDOWS
ifdef ALLEGRO_INCLUDE
CFLAGS += -I$(ALLEGRO_INCLUDE)
endif
RM = del /q
CFLAGS += -D__GTHREAD_HIDE_WIN32API
LFLAGS = -Wl,--subsystem,windows
ifdef ALLEGRO_LIB
LFLAGS += -L$(ALLEGRO_LIB)
endif
ifdef STATICLINK
CFLAGS += -DALLEGRO_STATICLINK
LFLAGS += -static-libgcc
LIBS += -lallegro-5.0.10-monolith-static-mt -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound -lopengl32 -lpsapi
OBJDIR = obj/static
BIN = $(NAME)_static.exe
else
LIBS += -lallegro-5.0.10-monolith-mt
OBJDIR = obj
BIN = $(NAME).exe
endif
else
RM = rm -f
ifdef STATICLINK
LIBS += `pkg-config --libs --static allegro-5.0 allegro_acodec-5.0 allegro_audio-5.0 allegro_color-5.0 allegro_font-5.0 allegro_image-5.0 allegro_main-5.0 allegro_memfile-5.0 allegro_physfs-5.0 allegro_primitives-5.0 allegro_ttf-5.0`
OBJDIR = obj/static
BIN = $(NAME)_static
else
LIBS += `pkg-config --libs allegro-5.0 allegro_acodec-5.0 allegro_audio-5.0 allegro_color-5.0 allegro_font-5.0 allegro_image-5.0 allegro_main-5.0 allegro_memfile-5.0 allegro_physfs-5.0 allegro_primitives-5.0 allegro_ttf-5.0`
OBJDIR = obj
BIN = $(NAME)
endif
endif
OBJ_CPP := $(addprefix $(OBJDIR)/, $(subst src/,,$(patsubst %.cpp,%.o,$(wildcard src/*.cpp))))
OBJ_C := $(addprefix $(OBJDIR)/, $(subst src/,,$(patsubst %.c,%.o,$(wildcard src/*.c))))
all: game
$(OBJDIR)/%.o: src/%.c
$(CC) $(CFLAGS) -o $@ -c $<
$(OBJDIR)/%.o: src/%.cpp
$(CXX) $(CFLAGS) -o $@ -c $<
game: $(OBJ_C) $(OBJ_CPP)
$(LD) -o $(BIN) $(OBJ_C) $(OBJ_CPP) $(LIBS) $(LFLAGS)
clean:
ifdef WINDOWS
ifneq ($(OBJ_C),)
-$(RM) $(subst /,\,$(OBJ_C))
endif
ifneq ($(OBJ_CPP),)
-$(RM) $(subst /,\,$(OBJ_CPP))
endif
else
ifneq ($(OBJ_C),)
-$(RM) $(OBJ_C)
endif
ifneq ($(OBJ_CPP),)
-$(RM) $(OBJ_CPP)
endif
endif
veryclean: clean
-$(RM) $(BIN)