RSP LLE plugin. Compile and run (slowly, eat 50% CPU) on the OpenPandora
[mupen64plus-pandora.git] / source / mupen64plus-rsp-z64 / projects / unix / Makefile
1 #/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 # *   mupen64plus-rsp-z64 - Makefile                                        *
3 # *   http://bitbucket.org/wahrhaft/mupen64plus-rsp-z64/                    *
4 # *   Copyright (C) 2010 Jon Ring                                           *
5 # *   Copyright (C) 2008-2009 Richard Goedeken                              *
6 # *   Copyright (C) 2007-2008 DarkJeztr Tillin9                             *
7 # *                                                                         *
8 # *   This program is free software; you can redistribute it and/or modify  *
9 # *   it under the terms of the GNU General Public License as published by  *
10 # *   the Free Software Foundation; either version 2 of the License, or     *
11 # *   (at your option) any later version.                                   *
12 # *                                                                         *
13 # *   This program is distributed in the hope that it will be useful,       *
14 # *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15 # *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16 # *   GNU General Public License for more details.                          *
17 # *                                                                         *
18 # *   You should have received a copy of the GNU General Public License     *
19 # *   along with this program; if not, write to the                         *
20 # *   Free Software Foundation, Inc.,                                       *
21 # *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
22 # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23 # Makefile for Z64 RSP plugin in Mupen64plus.
24
25 # detect operating system
26 UNAME ?= $(shell uname -s)
27 OS := NONE
28 ifeq ("$(UNAME)","Linux")
29   OS = LINUX
30   SO_EXTENSION = so
31   SHARED = -shared
32 endif
33 ifeq ("$(UNAME)","linux")
34   OS = LINUX
35   SO_EXTENSION = so
36   SHARED = -shared
37 endif
38 ifneq ("$(filter GNU hurd,$(UNAME))","")
39   OS = LINUX
40   SO_EXTENSION = so
41   SHARED = -shared
42 endif
43 ifeq ("$(UNAME)","Darwin")
44   OS = OSX
45   SO_EXTENSION = dylib
46   SHARED = -bundle
47 endif
48 ifeq ("$(UNAME)","FreeBSD")
49   OS = FREEBSD
50   SO_EXTENSION = so
51   SHARED = -shared
52 endif
53 ifeq ("$(UNAME)","OpenBSD")
54   OS = FREEBSD
55   SO_EXTENSION = so
56   SHARED = -shared
57   $(warning OS type "$(UNAME)" not officially supported.')
58 endif
59 ifneq ("$(filter GNU/kFreeBSD kfreebsd,$(UNAME))","")
60   OS = LINUX
61   SO_EXTENSION = so
62   SHARED = -shared
63 endif
64 ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW")
65   OS = MINGW
66   SO_EXTENSION = dll
67   SHARED = -shared
68   PIC = 0
69 endif
70 ifeq ("$(OS)","NONE")
71   $(error OS type "$(UNAME)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
72 endif
73
74 # detect system architecture
75 HOST_CPU ?= $(shell uname -m)
76 NO_ASM ?= 1
77 CPU := NONE
78 ifneq ("$(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
87 endif
88 ifneq ("$(filter pentium i%86,$(HOST_CPU))","")
89   CPU := X86
90   ARCH_DETECTED := 32BITS
91   PIC ?= 0
92 endif
93 ifneq ("$(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.')
99 endif
100 ifneq ("$(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.')
106 endif
107 ifneq ("$(filter arm%,$(HOST_CPU))","")
108   ifeq ("$(filter arm%b,$(HOST_CPU))","")
109     CPU := ARM
110     ARCH_DETECTED := 32BITS
111     PIC ?= 1
112     HLEVIDEO ?= 1
113     CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char
114     $(warning Architecture "$(HOST_CPU)" not officially supported.')
115   endif
116 endif
117 ifeq ("$(CPU)","NONE")
118   $(error CPU type "$(HOST_CPU)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
119 endif
120
121 # base CFLAGS, LDLIBS, and LDFLAGS
122 OPTFLAGS ?= -O3 -flto
123 WARNFLAGS ?= -Wall
124 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src
125 CXXFLAGS += -fvisibility-inlines-hidden
126 LDFLAGS += $(SHARED)
127
128 # Since we are building a shared library, we must compile with -fPIC on some architectures
129 # 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
130 ifeq ($(PIC), 1)
131   CFLAGS += -fPIC
132 else
133   CFLAGS += -fno-PIC
134 endif
135
136 ifeq ($(HLEVIDEO), 1)
137   CFLAGS += -DVIDEO_HLE_ALLOWED
138   POSTFIX = -hlevideo
139 endif
140
141 ifeq ($(BIG_ENDIAN), 1)
142   CFLAGS += -DM64P_BIG_ENDIAN
143 endif
144
145 # tweak flags for 32-bit build on 64-bit system
146 ifeq ($(ARCH_DETECTED), 64BITS_32)
147   ifeq ($(OS), FREEBSD)
148     $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386)
149   endif
150   CFLAGS += -m32
151   LDFLAGS += -Wl,-m,elf_i386
152 endif
153
154 # set special flags per-system
155 ifeq ($(OS), LINUX)
156   # only export api symbols
157   LDFLAGS += -Wl,-version-script,$(SRCDIR)/rsp_api_export.ver
158   LDLIBS += -ldl
159 endif
160 ifeq ($(OS), FREEBSD)
161   LDLIBS += -lc
162 endif
163 ifeq ($(OS), OSX)
164   # Select the proper SDK
165   # Also, SDKs are stored in a different location since XCode 4.3
166   OSX_SDK ?= $(shell sw_vers -productVersion | cut -f1 -f2 -d .)
167   OSX_XCODEMAJ = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f1 -d .)
168   OSX_XCODEMIN = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f2 -d .)
169   OSX_XCODEGE43 = $(shell echo "`expr $(OSX_XCODEMAJ) \>= 4``expr $(OSX_XCODEMIN) \>= 3`")
170   ifeq ($(OSX_XCODEGE43), 11)
171     OSX_SYSROOT := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
172   else
173     OSX_SYSROOT := /Developer/SDKs
174   endif
175
176   ifeq ($(CPU), X86)
177     ifeq ($(ARCH_DETECTED), 64BITS)
178       CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
179       LDLIBS += -ldl
180     else
181       CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
182       LDLIBS += -ldl
183     endif
184   endif
185 endif
186
187 # set mupen64plus core API header path
188 ifneq ("$(APIDIR)","")
189   CFLAGS += "-I$(APIDIR)"
190 else
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
207 endif
208
209 # reduced compile output when running make without V=1
210 ifneq ($(findstring $(MAKEFLAGS),s),s)
211 ifndef V
212         Q_CC  = @echo '    CC  '$@;
213         Q_CXX = @echo '    CXX '$@;
214         Q_LD  = @echo '    LD  '$@;
215 endif
216 endif
217
218 # set base program pointers and flags
219 CC        = $(CROSS_COMPILE)gcc
220 CXX       = $(CROSS_COMPILE)g++
221 RM       ?= rm -f
222 INSTALL  ?= install
223 MKDIR ?= mkdir -p
224 COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
225 COMPILE.cc = $(Q_CXX)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
226 LINK.o = $(Q_LD)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TARGET_ARCH)
227
228 # set special flags for given Makefile parameters
229 ifeq ($(DEBUG),1)
230   CFLAGS += -g
231   INSTALL_STRIP_FLAG ?= 
232 else
233   INSTALL_STRIP_FLAG ?= -s
234 endif
235
236 # set installation options
237 ifeq ($(PREFIX),)
238   PREFIX := /usr/local
239 endif
240 ifeq ($(LIBDIR),)
241   LIBDIR := $(PREFIX)/lib
242 endif
243 ifeq ($(PLUGINDIR),)
244   PLUGINDIR := $(LIBDIR)/mupen64plus
245 endif
246
247 SRCDIR = ../../src
248 OBJDIR = _obj$(POSTFIX)
249
250 # list of source files to compile
251 SOURCE = \
252         $(SRCDIR)/rsp.cpp \
253         $(SRCDIR)/rsp_opinfo.cpp \
254         $(SRCDIR)/rsp_recomp.cpp \
255         $(SRCDIR)/rsp_dasm.cpp \
256         $(SRCDIR)/main_rsp.cpp 
257
258 # generate a list of object files build, make a temporary directory for them
259 OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE)))
260 OBJECTS += $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(filter %.cpp, $(SOURCE)))
261 OBJDIRS = $(dir $(OBJECTS))
262 $(shell $(MKDIR) $(OBJDIRS))
263
264 # build targets
265 TARGET = mupen64plus-rsp-z64$(POSTFIX).$(SO_EXTENSION)
266
267 targets:
268         @echo "Mupen64Plus-rsp-z64 makefile. "
269         @echo "  Targets:"
270         @echo "    all           == Build Mupen64Plus rsp-hle plugin"
271         @echo "    clean         == remove object files"
272         @echo "    rebuild       == clean and re-build all"
273         @echo "    install       == Install Mupen64Plus rsp-hle plugin"
274         @echo "    uninstall     == Uninstall Mupen64Plus rsp-hle plugin"
275         @echo "  Options:"
276         @echo "    BITS=32       == build 32-bit binaries on 64-bit machine"
277         @echo "    APIDIR=path   == path to find Mupen64Plus Core headers"
278         @echo "    OPTFLAGS=flag == compiler optimization (default: -O3 -flto)"
279         @echo "    WARNFLAGS=flag == compiler warning levels (default: -Wall)"
280         @echo "    PIC=(1|0)     == Force enable/disable of position independent code"
281         @echo "    HLEVIDEO=(1|0) == Move task of gfx emulation to a HLE video plugins"
282         @echo "    POSTFIX=name  == String added to the name of the the build (default: '')"
283         @echo "  Install Options:"
284         @echo "    PREFIX=path   == install/uninstall prefix (default: /usr/local)"
285         @echo "    LIBDIR=path   == library prefix (default: PREFIX/lib)"
286         @echo "    PLUGINDIR=path == path to install plugin libraries (default: LIBDIR/mupen64plus)"
287         @echo "    DESTDIR=path  == path to prepend to all installation paths (only for packagers)"
288         @echo "  Debugging Options:"
289         @echo "    DEBUG=1       == add debugging symbols"
290         @echo "    V=1           == show verbose compiler output"
291
292 all: $(TARGET)
293
294 install: $(TARGET)
295         $(INSTALL) -d "$(DESTDIR)$(PLUGINDIR)"
296         $(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(PLUGINDIR)"
297
298 uninstall:
299         $(RM) "$(DESTDIR)$(PLUGINDIR)/$(TARGET)"
300
301 clean:
302         $(RM) -r $(OBJDIR) $(TARGET)
303
304 rebuild: clean all
305
306 # build dependency files
307 CFLAGS += -MD
308 -include $(OBJECTS:.o=.d)
309
310 CXXFLAGS += $(CFLAGS)
311
312 # standard build rules
313 $(OBJDIR)/%.o: $(SRCDIR)/%.c
314         $(COMPILE.c) -o $@ $<
315
316 $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
317         $(COMPILE.cc) -o $@ $<
318
319 $(TARGET): $(OBJECTS)
320         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
321
322 .PHONY: all clean install uninstall targets