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