Input SDL plugin. Compile and run on the OpenPandora. Include config for Pandora...
[mupen64plus-pandora.git] / source / mupen64plus-input-sdl / projects / unix / Makefile
CommitLineData
48d52ab5 1#/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2# * Mupen64plus-input-sdl - Makefile *
3# * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4# * Copyright (C) 2007-2009 Richard Goedeken *
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 SDL Input plugin in Mupen64plus
22
23# detect operating system
24UNAME ?= $(shell uname -s)
25OS := NONE
26ifeq ("$(UNAME)","Linux")
27 OS = LINUX
28 SO_EXTENSION = so
29 SHARED = -shared
30endif
31ifeq ("$(UNAME)","linux")
32 OS = LINUX
33 SO_EXTENSION = so
34 SHARED = -shared
35endif
36ifneq ("$(filter GNU hurd,$(UNAME))","")
37 OS = LINUX
38 SO_EXTENSION = so
39 SHARED = -shared
40endif
41ifeq ("$(UNAME)","Darwin")
42 OS = OSX
43 SO_EXTENSION = dylib
44 SHARED = -bundle
45endif
46ifeq ("$(UNAME)","FreeBSD")
47 OS = FREEBSD
48 SO_EXTENSION = so
49 SHARED = -shared
50endif
51ifeq ("$(UNAME)","OpenBSD")
52 OS = FREEBSD
53 SO_EXTENSION = so
54 SHARED = -shared
55 $(warning OS type "$(UNAME)" not officially supported.')
56endif
57ifneq ("$(filter GNU/kFreeBSD kfreebsd,$(UNAME))","")
58 OS = LINUX
59 SO_EXTENSION = so
60 SHARED = -shared
61endif
62ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW")
63 OS = MINGW
64 SO_EXTENSION = dll
65 SHARED = -shared
66 PIC = 0
67endif
68ifeq ("$(OS)","NONE")
69 $(error OS type "$(UNAME)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
70endif
71
72# detect system architecture
73HOST_CPU ?= $(shell uname -m)
74NO_ASM ?= 1
75CPU := NONE
76ifneq ("$(filter x86_64 amd64,$(HOST_CPU))","")
77 CPU := X86
78 ifeq ("$(BITS)", "32")
79 ARCH_DETECTED := 64BITS_32
80 PIC ?= 0
81 else
82 ARCH_DETECTED := 64BITS
83 PIC ?= 1
84 endif
85endif
86ifneq ("$(filter pentium i%86,$(HOST_CPU))","")
87 CPU := X86
88 ARCH_DETECTED := 32BITS
89 PIC ?= 0
90endif
91ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","")
92 CPU := PPC
93 ARCH_DETECTED := 32BITS
94 BIG_ENDIAN := 1
95 PIC ?= 1
96 $(warning Architecture "$(HOST_CPU)" not officially supported.')
97endif
98ifneq ("$(filter ppc64 powerpc64,$(HOST_CPU))","")
99 CPU := PPC
100 ARCH_DETECTED := 64BITS
101 BIG_ENDIAN := 1
102 PIC ?= 1
103 $(warning Architecture "$(HOST_CPU)" not officially supported.')
104endif
105ifneq ("$(filter arm%,$(HOST_CPU))","")
106 ifeq ("$(filter arm%b,$(HOST_CPU))","")
107 CPU := ARM
108 ARCH_DETECTED := 32BITS
109 PIC ?= 1
110 CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char
111 $(warning Architecture "$(HOST_CPU)" not officially supported.')
112 endif
113endif
114ifeq ("$(CPU)","NONE")
115 $(error CPU type "$(HOST_CPU)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
116endif
117
118# base CFLAGS, LDLIBS, and LDFLAGS
119OPTFLAGS ?= -O3
120WARNFLAGS ?= -Wall
121CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src -D_GNU_SOURCE=1
122LDFLAGS += $(SHARED)
123
124# Since we are building a shared library, we must compile with -fPIC on some architectures
125# 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
126ifeq ($(PIC), 1)
127 CFLAGS += -fPIC
128else
129 CFLAGS += -fno-PIC
130endif
131
132ifeq ($(BIG_ENDIAN), 1)
133 CFLAGS += -DM64P_BIG_ENDIAN
134endif
135
136# tweak flags for 32-bit build on 64-bit system
137ifeq ($(ARCH_DETECTED), 64BITS_32)
138 CFLAGS += -m32
139 LDFLAGS += -Wl,-m,elf_i386
140endif
141
142# set special flags per-system
143ifeq ($(OS), FREEBSD)
144 ifeq ($(ARCH_DETECTED), 64BITS_32)
145 $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386)
146 endif
147endif
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 += -arch x86_64 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
167 LDLIBS += -ldl
168 else
169 CFLAGS += -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# set mupen64plus core API header path
188ifneq ("$(APIDIR)","")
189 CFLAGS += "-I$(APIDIR)"
190else
191 TRYDIR = ../../../mupen64plus-core/src/api
192 ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
193 CFLAGS += -I$(TRYDIR)
194 else
195 TRYDIR = /usr/local/include/mupen64plus
196 ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
197 CFLAGS += -I$(TRYDIR)
198 else
199 TRYDIR = /usr/include/mupen64plus
200 ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
201 CFLAGS += -I$(TRYDIR)
202 else
203 $(error Mupen64Plus API header files not found! Use makefile parameter APIDIR to force a location.)
204 endif
205 endif
206 endif
207endif
208
209# reduced compile output when running make without V=1
210ifneq ($(findstring $(MAKEFLAGS),s),s)
211ifndef V
212 Q_CC = @echo ' CC '$@;
213 Q_LD = @echo ' LD '$@;
214endif
215endif
216
217# set base program pointers and flags
218CC = $(CROSS_COMPILE)gcc
219CXX = $(CROSS_COMPILE)g++
220RM ?= rm -f
221INSTALL ?= install
222MKDIR ?= mkdir -p
223COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
224LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH)
225
226# set special flags for given Makefile parameters
227ifeq ($(DEBUG),1)
228 CFLAGS += -g
229 INSTALL_STRIP_FLAG ?=
230else
231 ifneq ($(OS),OSX)
232 INSTALL_STRIP_FLAG ?= -s
233 endif
234endif
235ifeq ($(PLUGINDBG), 1)
236 CFLAGS += -D_DEBUG
237endif
238
239# set installation options
240ifeq ($(PREFIX),)
241 PREFIX := /usr/local
242endif
243ifeq ($(SHAREDIR),)
244 SHAREDIR := $(PREFIX)/share/mupen64plus
245endif
246ifeq ($(LIBDIR),)
247 LIBDIR := $(PREFIX)/lib
248endif
249ifeq ($(PLUGINDIR),)
250 PLUGINDIR := $(LIBDIR)/mupen64plus
251endif
252
253SRCDIR = ../../src
254OBJDIR = _obj$(POSTFIX)
255
256# list of source files to compile
257SOURCE = \
258 $(SRCDIR)/plugin.c \
259 $(SRCDIR)/autoconfig.c \
260 $(SRCDIR)/config.c
261
262ifeq ($(OS),MINGW)
263SOURCE += $(SRCDIR)/osal_dynamiclib_win32.c
264else
265SOURCE += $(SRCDIR)/osal_dynamiclib_unix.c
266endif
267
268# generate a list of object files build, make a temporary directory for them
269OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE)))
270OBJDIRS = $(dir $(OBJECTS))
271$(shell $(MKDIR) $(OBJDIRS))
272
273# build targets
274TARGET = mupen64plus-input-sdl$(POSTFIX).$(SO_EXTENSION)
275
276targets:
277 @echo "Mupen64Plus-input-sdl makefile. "
278 @echo " Targets:"
279 @echo " all == Build Mupen64Plus SDL input plugin"
280 @echo " clean == remove object files"
281 @echo " rebuild == clean and re-build all"
282 @echo " install == Install Mupen64Plus SDL input plugin"
283 @echo " uninstall == Uninstall Mupen64Plus SDL input plugin"
284 @echo " Options:"
285 @echo " BITS=32 == build 32-bit binaries on 64-bit machine"
286 @echo " APIDIR=path == path to find Mupen64Plus Core headers"
287 @echo " OPTFLAGS=flag == compiler optimization (default: -O3 -flto)"
288 @echo " WARNFLAGS=flag == compiler warning levels (default: -Wall)"
289 @echo " PIC=(1|0) == Force enable/disable of position independent code"
290 @echo " POSTFIX=name == String added to the name of the the build (default: '')"
291 @echo " Install Options:"
292 @echo " PREFIX=path == install/uninstall prefix (default: /usr/local)"
293 @echo " SHAREDIR=path == path to install shared data files (default: PREFIX/share/mupen64plus)"
294 @echo " LIBDIR=path == library prefix (default: PREFIX/lib)"
295 @echo " PLUGINDIR=path == path to install plugin libraries (default: LIBDIR/mupen64plus)"
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"
299 @echo " PLUGINDBG=1 == print extra debugging information while running"
300 @echo " V=1 == show verbose compiler output"
301
302all: $(TARGET)
303
304install: $(TARGET)
305 $(INSTALL) -d "$(DESTDIR)$(PLUGINDIR)"
306 $(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(PLUGINDIR)"
307 $(INSTALL) -d "$(DESTDIR)$(SHAREDIR)"
308 $(INSTALL) -m 0644 "../../data/InputAutoCfg.ini" "$(DESTDIR)$(SHAREDIR)"
309
310uninstall:
311 $(RM) "$(DESTDIR)$(PLUGINDIR)/$(TARGET)"
312 $(RM) "$(DESTDIR)$(SHAREDIR)/InputAutoCfg.ini"
313
314clean:
315 $(RM) -r $(OBJDIR) $(TARGET)
316
317rebuild: clean all
318
319# build dependency files
320CFLAGS += -MD
321-include $(OBJECTS:.o=.d)
322
323# standard build rules
324$(OBJDIR)/%.o: $(SRCDIR)/%.c
325 $(COMPILE.c) -o $@ $<
326
327$(TARGET): $(OBJECTS)
328 $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
329
330.PHONY: all clean install uninstall targets