-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
191 lines (157 loc) · 4.27 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
190
191
# -*- Makefile -*- for sdl2
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
QUIET_CC = @echo ' ' CC $@;
QUIET_AR = @echo ' ' AR $@;
QUIET_RANLIB = @echo ' ' RANLIB $@;
QUIET_INSTALL = @echo ' ' INSTALL $<;
export V
endif
endif
uname_S ?= $(shell uname -s)
# Since Windows builds could be done with MinGW or Cygwin,
# set a TARGET_OS_WINDOWS flag when either shows up.
ifneq (,$(findstring MINGW,$(uname_S)))
TARGET_OS_WINDOWS := YesPlease
endif
ifneq (,$(findstring MSYS,$(uname_S)))
TARGET_OS_WINDOWS := YesPlease
endif
ifneq (,$(findstring CYGWIN,$(uname_S)))
TARGET_OS_WINDOWS := YesPlease
endif
SDL2_LIB = libSDL2.a
SDL2MAIN_LIB = libSDL2main.a
AR ?= ar
CC ?= gcc
RANLIB?= ranlib
RM ?= rm -f
CFLAGS ?= -O2
prefix ?= /usr/local
libdir := $(prefix)/lib
includedir := $(prefix)/include/SDL2
HEADERS = include/*.h
SDL2_SOURCES = \
src/*.c \
src/audio/*.c \
src/atomic/*.c \
src/cpuinfo/*.c \
src/events/*.c \
src/file/*.c \
src/haptic/*.c \
src/joystick/*.c \
src/power/*.c \
src/render/*.c \
src/stdlib/*.c \
src/thread/*.c \
src/timer/*.c \
src/video/*.c \
src/audio/disk/*.c \
src/audio/dummy/*.c \
src/filesystem/dummy/*.c \
src/haptic/dummy/*.c \
src/joystick/dummy/*.c \
src/render/software/*.c \
src/render/opengl/*.c \
src/timer/dummy/*.c \
src/video/dummy/*.c \
src/loadso/dummy/*.c
SDL2MAIN_SOURCES = \
src/main/dummy/*.c
ifeq ($(uname_S),Linux)
SDL2_SOURCES += \
src/audio/alsa/*.c \
src/audio/dsp/*.c \
src/core/linux/*.c \
src/core/unix/*.c \
src/haptic/linux/*.c \
src/joystick/linux/*.c \
src/joystick/steam/*.c \
src/loadso/dlopen/*.c \
src/power/linux/*.c \
src/thread/pthread/*.c \
src/timer/unix/*.c \
src/video/directfb/*.c \
src/video/x11/*.c
CFLAGS += -D_GNU_SOURCE -D_REENTRANT
endif
ifeq ($(uname_S),Darwin)
SDL2_SOURCES += \
src/audio/coreaudio/*.m \
src/file/cocoa/*.m \
src/filesystem/cocoa/*.m \
src/haptic/darwin/*.c \
src/joystick/darwin/*.c \
src/loadso/dlopen/*.c \
src/power/macosx/*.c \
src/thread/pthread/*.c \
src/timer/unix/*.c \
src/video/cocoa/*.m
endif
ifdef TARGET_OS_WINDOWS
SDL2_SOURCES += \
src/audio/directsound/*.c \
src/audio/winmm/*.c \
src/core/windows/*.c \
src/filesystem/windows/*.c \
src/haptic/windows/*.c \
src/joystick/windows/*.c \
src/libm/*.c \
src/loadso/windows/*.c \
src/power/windows/*.c \
src/render/direct3d/*.c \
src/thread/windows/*.c \
src/thread/generic/*.c \
src/timer/windows/*.c \
src/video/windows/*.c \
SDL2MAIN_SOURCES += \
src/main/windows/*.c
endif
SDL2_SOURCES := $(shell echo $(SDL2_SOURCES))
SDL2MAIN_SOURCES := $(shell echo $(SDL2MAIN_SOURCES))
HEADERS := $(shell echo $(HEADERS))
HEADERS_INST := $(patsubst include/%,$(includedir)/%,$(HEADERS))
# First handle .c files
SDL2_OBJECTS := $(patsubst %.c,%.o,$(SDL2_SOURCES))
SDL2MAIN_OBJECTS := $(patsubst %.c,%.o,$(SDL2MAIN_SOURCES))
# Now .m files
SDL2_OBJECTS := $(patsubst %.m,%.o,$(SDL2_OBJECTS))
SDL2MAIN_OBJECTS := $(patsubst %.m,%.o,$(SDL2MAIN_OBJECTS))
CFLAGS += -I. -Iinclude -DNO_STDIO_REDIRECT
ifeq (,$(shell ./test_xinput.sh))
CFLAGS += -DHAVE_XINPUT_GAMEPAD_EX -DHAVE_XINPUT_STATE_EX
endif
.PHONY: install
all: $(SDL2_LIB) $(SDL2MAIN_LIB)
$(includedir)/%.h: include/%.h
-@if [ ! -d $(includedir) ]; then mkdir -p $(includedir); fi
$(QUIET_INSTALL)cp $< $@
@chmod 0644 $@
$(libdir)/%.a: %.a
-@if [ ! -d $(libdir) ]; then mkdir -p $(libdir); fi
$(QUIET_INSTALL)cp $< $@
@chmod 0644 $@
install: $(HEADERS_INST) $(libdir)/$(SDL2_LIB) $(libdir)/$(SDL2MAIN_LIB)
clean:
$(RM) $(SDL2_OBJECTS) $(SDL2MAIN_OBJECTS) *.a .cflags
distclean: clean
$(SDL2_LIB): $(SDL2_OBJECTS)
@$(RM) $@
$(QUIET_AR)$(AR) rcu $@ $^
$(QUIET_RANLIB)$(RANLIB) $@
$(SDL2MAIN_LIB): $(SDL2MAIN_OBJECTS)
@$(RM) $@
$(QUIET_AR)$(AR) rcu $@ $^
$(QUIET_RANLIB)$(RANLIB) $@
%.o: %.c .cflags
$(QUIET_CC)$(CC) $(CFLAGS) -o $@ -c $<
%.o: %.m .cflags
$(QUIET_CC)$(CC) $(CFLAGS) -o $@ -c $<
TRACK_CFLAGS = $(subst ','\'',$(CC) $(CFLAGS))
.cflags: .force-cflags
@FLAGS='$(TRACK_CFLAGS)'; \
if test x"$$FLAGS" != x"`cat .cflags 2>/dev/null`" ; then \
echo " * rebuilding sdl2: new build flags or prefix"; \
echo "$$FLAGS" > .cflags; \
fi
.PHONY: .force-cflags