5288f542 |
1 | #/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | # * Mupen64plus - Makefile * |
3 | # * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ * |
4 | # * Copyright (C) 2009 Richard42 * |
5 | # * * |
6 | # * This program is free software; you can redistribute it and/or modify * |
7 | # * it under the terms of the GNU General Public License as published by * |
8 | # * the Free Software Foundation; either version 2 of the License, or * |
9 | # * (at your option) any later version. * |
10 | # * * |
11 | # * This program is distributed in the hope that it will be useful, * |
12 | # * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | # * GNU General Public License for more details. * |
15 | # * * |
16 | # * You should have received a copy of the GNU General Public License * |
17 | # * along with this program; if not, write to the * |
18 | # * Free Software Foundation, Inc., * |
19 | # * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
20 | # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
21 | # Makefile for Mupen64plus-ui-console |
22 | |
23 | # detect operation system |
24 | UNAME ?= $(shell uname -s) |
25 | OS := NONE |
26 | ifeq ("$(UNAME)","Linux") |
27 | OS = LINUX |
28 | endif |
29 | ifeq ("$(UNAME)","linux") |
30 | OS = LINUX |
31 | endif |
32 | ifneq ("$(filter GNU hurd,$(UNAME))","") |
33 | OS = LINUX |
34 | endif |
35 | ifeq ("$(UNAME)","Darwin") |
36 | OS = OSX |
37 | endif |
38 | ifeq ("$(UNAME)","FreeBSD") |
39 | OS = FREEBSD |
40 | endif |
41 | ifeq ("$(UNAME)","OpenBSD") |
42 | OS = FREEBSD |
43 | $(warning OS type "$(UNAME)" not officially supported.') |
44 | endif |
45 | ifneq ("$(filter GNU/kFreeBSD kfreebsd,$(UNAME))","") |
46 | OS = LINUX |
47 | endif |
48 | ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW") |
49 | OS = MINGW |
50 | endif |
51 | ifeq ("$(OS)","NONE") |
52 | $(error OS type "$(UNAME)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues') |
53 | endif |
54 | |
55 | # detect system architecture |
56 | HOST_CPU ?= $(shell uname -m) |
57 | NO_ASM ?= 1 |
58 | CPU := NONE |
59 | ifneq ("$(filter x86_64 amd64,$(HOST_CPU))","") |
60 | CPU := X86 |
61 | ifeq ("$(BITS)", "32") |
62 | ARCH_DETECTED := 64BITS_32 |
63 | else |
64 | ARCH_DETECTED := 64BITS |
65 | endif |
66 | endif |
67 | ifneq ("$(filter pentium i%86,$(HOST_CPU))","") |
68 | CPU := X86 |
69 | ARCH_DETECTED := 32BITS |
70 | endif |
71 | ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","") |
72 | CPU := PPC |
73 | ARCH_DETECTED := 32BITS |
74 | BIG_ENDIAN := 1 |
75 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
76 | endif |
77 | ifneq ("$(filter ppc64 powerpc64,$(HOST_CPU))","") |
78 | CPU := PPC |
79 | ARCH_DETECTED := 64BITS |
80 | BIG_ENDIAN := 1 |
81 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
82 | endif |
83 | ifneq ("$(filter arm%,$(HOST_CPU))","") |
84 | ifeq ("$(filter arm%b,$(HOST_CPU))","") |
85 | CPU := ARM |
86 | ARCH_DETECTED := 32BITS |
87 | CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char -ffast-math |
88 | # CFLAGS += -DANDROID |
89 | # CFLAGS += -DPAULSCODE |
90 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
91 | endif |
92 | endif |
93 | ifeq ("$(CPU)","NONE") |
94 | $(error CPU type "$(HOST_CPU)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues') |
95 | endif |
96 | |
97 | # base CFLAGS, LDLIBS, and LDFLAGS |
98 | OPTFLAGS ?= -O3 |
99 | WARNFLAGS ?= -Wall |
100 | |
101 | CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -I../../src |
102 | ifeq ($(OS), MINGW) |
103 | CFLAGS += -lpthread |
104 | LDLIBS += -lpthread |
105 | else |
106 | CFLAGS += -pthread |
107 | LDLIBS += -pthread |
108 | endif |
109 | |
110 | ifeq ($(PIE), 1) |
111 | CFLAGS += -fPIE |
112 | LDFLAGS += -pie |
113 | else |
114 | CFLAGS += -fno-PIE |
115 | endif |
116 | |
117 | # set special flags per-system |
118 | ifeq ($(OS), LINUX) |
119 | LDLIBS += -ldl |
120 | endif |
121 | ifeq ($(OS), OSX) |
122 | # Select the proper SDK |
123 | # Also, SDKs are stored in a different location since XCode 4.3 |
124 | OSX_SDK ?= $(shell sw_vers -productVersion | cut -f1 -f2 -d .) |
125 | OSX_XCODEMAJ = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f1 -d .) |
126 | OSX_XCODEMIN = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f2 -d .) |
127 | OSX_XCODEGE43 = $(shell echo "`expr $(OSX_XCODEMAJ) \>= 4``expr $(OSX_XCODEMIN) \>= 3`") |
128 | ifeq ($(OSX_XCODEGE43), 11) |
129 | OSX_SYSROOT := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs |
130 | else |
131 | OSX_SYSROOT := /Developer/SDKs |
132 | endif |
133 | |
134 | ifeq ($(CPU), X86) |
135 | ifeq ($(ARCH_DETECTED), 64BITS) |
136 | CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk |
137 | else |
138 | CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk |
139 | endif |
140 | endif |
141 | endif |
142 | |
143 | # test for presence of SDL |
144 | ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined) |
145 | SDL_CONFIG = $(CROSS_COMPILE)sdl-config |
146 | ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),) |
147 | $(error No SDL development libraries found!) |
148 | endif |
149 | SDL_CFLAGS += $(shell $(SDL_CONFIG) --cflags) |
150 | SDL_LDLIBS += $(shell $(SDL_CONFIG) --libs) |
151 | endif |
152 | CFLAGS += $(SDL_CFLAGS) |
153 | LDLIBS += $(SDL_LDLIBS) |
154 | |
155 | ifeq ($(OS), MINGW) |
156 | LDLIBS += -mconsole |
157 | endif |
158 | |
159 | ifeq ($(BIG_ENDIAN), 1) |
160 | CFLAGS += -DM64P_BIG_ENDIAN |
161 | endif |
162 | |
163 | # tweak flags for 32-bit build on 64-bit system |
164 | ifeq ($(ARCH_DETECTED), 64BITS_32) |
165 | ifeq ($(OS), FREEBSD) |
166 | $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386) |
167 | endif |
168 | CFLAGS += -m32 |
169 | LDFLAGS += -Wl,-m,elf_i386 |
170 | endif |
171 | |
172 | # set mupen64plus core API header path |
173 | ifneq ("$(APIDIR)","") |
174 | CFLAGS += "-I$(APIDIR)" |
175 | else |
176 | TRYDIR = ../../../mupen64plus-core/src/api |
177 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
178 | CFLAGS += -I$(TRYDIR) |
179 | else |
180 | TRYDIR = /usr/local/include/mupen64plus |
181 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
182 | CFLAGS += -I$(TRYDIR) |
183 | else |
184 | TRYDIR = /usr/include/mupen64plus |
185 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
186 | CFLAGS += -I$(TRYDIR) |
187 | else |
188 | $(error Mupen64Plus API header files not found! Use makefile parameter APIDIR to force a location.) |
189 | endif |
190 | endif |
191 | endif |
192 | endif |
193 | |
194 | # reduced compile output when running make without V=1 |
195 | ifneq ($(findstring $(MAKEFLAGS),s),s) |
196 | ifndef V |
197 | Q_CC = @echo ' CC '$@; |
198 | Q_LD = @echo ' LD '$@; |
199 | endif |
200 | endif |
201 | |
202 | # set base program pointers and flags |
203 | CC = $(CROSS_COMPILE)gcc |
204 | CXX = $(CROSS_COMPILE)g++ |
205 | RM ?= rm -f |
206 | INSTALL ?= install |
207 | MKDIR ?= mkdir -p |
208 | COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c |
209 | LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) |
210 | |
211 | # set special flags for given Makefile parameters |
212 | # note: COREDIR _must_ end in a slash if you want it to work; not necessary for the others |
213 | ifneq ($(PLUGINDIR),) |
214 | CFLAGS += '-DPLUGINDIR="$(PLUGINDIR)"' |
215 | endif |
216 | ifneq ($(COREDIR),) |
217 | CFLAGS += '-DCOREDIR="$(COREDIR)"' |
218 | endif |
219 | ifneq ($(SHAREDIR),) |
220 | CFLAGS += '-DSHAREDIR="$(SHAREDIR)"' |
221 | endif |
222 | ifeq ($(DEBUG),1) |
223 | CFLAGS += -g -gdwarf-2 |
224 | INSTALL_STRIP_FLAG ?= |
225 | else |
226 | INSTALL_STRIP_FLAG ?= -s |
227 | endif |
228 | |
229 | # set installation options |
230 | ifeq ($(PREFIX),) |
231 | PREFIX := /usr/local |
232 | endif |
233 | ifeq ($(BINDIR),) |
234 | BINDIR := $(PREFIX)/bin |
235 | endif |
236 | ifeq ($(MANDIR),) |
237 | MANDIR := $(PREFIX)/share/man |
238 | endif |
239 | |
240 | SRCDIR = ../../src |
241 | OBJDIR = _obj$(POSTFIX) |
242 | |
243 | ifeq ("$(OS)","MINGW") |
244 | EXEEXT = .exe |
245 | else |
246 | EXEEXT = |
247 | endif |
248 | |
249 | # list of source files to compile |
250 | SOURCE = \ |
251 | $(SRCDIR)/cheat.c \ |
252 | $(SRCDIR)/compare_core.c \ |
253 | $(SRCDIR)/core_interface.c \ |
254 | $(SRCDIR)/main.c \ |
255 | $(SRCDIR)/plugin.c |
256 | |
257 | ifeq ($(OS), MINGW) |
258 | SOURCE += \ |
259 | $(SRCDIR)/osal_dynamiclib_win32.c \ |
260 | $(SRCDIR)/osal_files_win32.c |
261 | else |
262 | SOURCE += \ |
263 | $(SRCDIR)/osal_dynamiclib_unix.c \ |
264 | $(SRCDIR)/osal_files_unix.c |
265 | endif |
266 | |
267 | # generate a list of object files build, make a temporary directory for them |
268 | OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE))) |
269 | OBJDIRS = $(dir $(OBJECTS)) |
270 | $(shell $(MKDIR) $(OBJDIRS)) |
271 | |
272 | # build targets |
273 | TARGET = mupen64plus$(POSTFIX)$(EXEEXT) |
274 | |
275 | targets: |
276 | @echo "Mupen64Plus-ui-console makefile." |
277 | @echo " Targets:" |
278 | @echo " all == Build Mupen64Plus console front-end application" |
279 | @echo " clean == remove object files and build products" |
280 | @echo " rebuild == clean and re-build all" |
281 | @echo " install == Install Mupen64Plus console front-end application" |
282 | @echo " uninstall == Uninstall Mupen64Plus console front-end application" |
283 | @echo " Options:" |
284 | @echo " COREDIR=path == default path to search for Mupen64Plus Core (must end with slash)" |
285 | @echo " PLUGINDIR=path == default path to search for plugins" |
286 | @echo " SHAREDIR=path == default path to search for shared data files" |
287 | @echo " APIDIR=path == path to find Mupen64Plus Core headers" |
288 | @echo " OPTFLAGS=flags == compiler optimization (default: -O3 -flto)" |
289 | @echo " WARNFLAGS=flag == compiler warning levels (default: -Wall)" |
290 | @echo " PIE=(1|0) == Force enable/disable of position independent executables" |
291 | @echo " POSTFIX=name == String added to the name of the the build (default: '')" |
292 | @echo " Install Options:" |
293 | @echo " PREFIX=path == install/uninstall prefix (default: /usr/local/)" |
294 | @echo " BINDIR=path == path to install mupen64plus binary (default: PREFIX/bin/)" |
295 | @echo " MANDIR=path == path to install mupen64plus manual page (default: PREFIX/share/man)" |
296 | @echo " DESTDIR=path == path to prepend to all installation paths (only for packagers)" |
297 | @echo " Debugging Options:" |
298 | @echo " DEBUG=1 == add debugging symbols to application binary" |
299 | @echo " V=1 == show verbose compiler output" |
300 | |
301 | all: $(TARGET) |
302 | |
303 | clean: |
304 | $(RM) -r $(OBJDIR) $(TARGET) |
305 | |
306 | rebuild: clean all |
307 | |
308 | install: $(TARGET) |
309 | $(INSTALL) -d "$(DESTDIR)$(BINDIR)" |
310 | $(INSTALL) -m 0755 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(BINDIR)" |
311 | $(INSTALL) -d "$(DESTDIR)$(MANDIR)/man6" |
312 | $(INSTALL) -m 0644 ../../doc/mupen64plus.6 "$(DESTDIR)$(MANDIR)/man6" |
313 | |
314 | uninstall: |
315 | $(RM) "$(DESTDIR)$(BINDIR)/$(TARGET)" "$(DESTDIR)$(MANDIR)/man6/mupen64plus.6" |
316 | |
317 | # build dependency files |
318 | CFLAGS += -MD |
319 | -include $(OBJECTS:.o=.d) |
320 | |
321 | # standard build rules |
322 | $(OBJDIR)/%.o: $(SRCDIR)/%.c |
323 | $(COMPILE.c) -o $@ $< |
324 | |
325 | $(TARGET): $(OBJECTS) |
326 | $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ |
327 | |
328 | .PHONY: all clean install uninstall targets |