ALL: Huge upstream synch + PerRom DelaySI & CountPerOp parameters
[mupen64plus-pandora.git] / source / mupen64plus-rsp-hle / projects / unix / Makefile
CommitLineData
d9e74a6f 1#/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2# * mupen64plus-rsp-hle - Makefile *
3# * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4# * Copyright (C) 2008-2009 Richard Goedeken *
5# * Copyright (C) 2007-2008 DarkJeztr 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 Mupen64 HLE RSP plugin in Mupen64plus.
23
24# detect operating system
25UNAME ?= $(shell uname -s)
26OS := NONE
27ifeq ("$(UNAME)","Linux")
28 OS = LINUX
29 SO_EXTENSION = so
30 SHARED = -shared
31endif
32ifeq ("$(UNAME)","linux")
33 OS = LINUX
34 SO_EXTENSION = so
35 SHARED = -shared
36endif
37ifneq ("$(filter GNU hurd,$(UNAME))","")
38 OS = LINUX
39 SO_EXTENSION = so
40 SHARED = -shared
41endif
42ifeq ("$(UNAME)","Darwin")
43 OS = OSX
44 SO_EXTENSION = dylib
45 SHARED = -bundle
46endif
47ifeq ("$(UNAME)","FreeBSD")
48 OS = FREEBSD
49 SO_EXTENSION = so
50 SHARED = -shared
51endif
52ifeq ("$(UNAME)","OpenBSD")
53 OS = FREEBSD
54 SO_EXTENSION = so
55 SHARED = -shared
56 $(warning OS type "$(UNAME)" not officially supported.')
57endif
58ifneq ("$(filter GNU/kFreeBSD kfreebsd,$(UNAME))","")
59 OS = LINUX
60 SO_EXTENSION = so
61 SHARED = -shared
62endif
63ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW")
64 OS = MINGW
65 SO_EXTENSION = dll
66 SHARED = -shared
67 PIC = 0
68endif
69ifeq ("$(OS)","NONE")
70 $(error OS type "$(UNAME)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
71endif
72
73# detect system architecture
74HOST_CPU ?= $(shell uname -m)
75NO_ASM ?= 1
76CPU := NONE
77ifneq ("$(filter x86_64 amd64,$(HOST_CPU))","")
78 CPU := X86
79 ifeq ("$(BITS)", "32")
80 ARCH_DETECTED := 64BITS_32
81 PIC ?= 0
82 else
83 ARCH_DETECTED := 64BITS
84 PIC ?= 1
85 endif
86endif
87ifneq ("$(filter pentium i%86,$(HOST_CPU))","")
88 CPU := X86
89 ARCH_DETECTED := 32BITS
90 PIC ?= 0
91endif
92ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","")
93 CPU := PPC
94 ARCH_DETECTED := 32BITS
95 BIG_ENDIAN := 1
96 PIC ?= 1
97 $(warning Architecture "$(HOST_CPU)" not officially supported.')
98endif
99ifneq ("$(filter ppc64 powerpc64,$(HOST_CPU))","")
100 CPU := PPC
101 ARCH_DETECTED := 64BITS
102 BIG_ENDIAN := 1
103 PIC ?= 1
104 $(warning Architecture "$(HOST_CPU)" not officially supported.')
105endif
106ifneq ("$(filter arm%,$(HOST_CPU))","")
107 ifeq ("$(filter arm%b,$(HOST_CPU))","")
108 CPU := ARM
109 ARCH_DETECTED := 32BITS
110 PIC ?= 1
111 CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char
112 $(warning Architecture "$(HOST_CPU)" not officially supported.')
113 endif
114endif
115ifeq ("$(CPU)","NONE")
116 $(error CPU type "$(HOST_CPU)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
117endif
118
119# base CFLAGS, LDLIBS, and LDFLAGS
120OPTFLAGS ?= -O3
121WARNFLAGS ?= -Wall
122CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src
123CXXFLAGS += -fvisibility-inlines-hidden
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 # only export api symbols
150 LDFLAGS += -Wl,-version-script,$(SRCDIR)/rsp_api_export.ver
151endif
152ifeq ($(OS), OSX)
2d262872 153 #xcode-select has been around since XCode 3.0, i.e. OS X 10.5
154 OSX_SDK_ROOT = $(shell xcode-select -print-path)/Platforms/MacOSX.platform/Developer/SDKs
155 OSX_SDK_PATH = $(OSX_SDK_ROOT)/$(shell ls $(OSX_SDK_ROOT) | tail -1)
d9e74a6f 156
157 ifeq ($(CPU), X86)
158 ifeq ($(ARCH_DETECTED), 64BITS)
2d262872 159 CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=10.5 -isysroot $(OSX_SDK_PATH)
d9e74a6f 160 else
2d262872 161 CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=10.5 -isysroot $(OSX_SDK_PATH)
d9e74a6f 162 LDFLAGS += -read_only_relocs suppress
163 endif
164 endif
165endif
166
167# set mupen64plus core API header path
168ifneq ("$(APIDIR)","")
169 CFLAGS += "-I$(APIDIR)"
170else
171 TRYDIR = ../../../mupen64plus-core/src/api
172 ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
173 CFLAGS += -I$(TRYDIR)
174 else
175 TRYDIR = /usr/local/include/mupen64plus
176 ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
177 CFLAGS += -I$(TRYDIR)
178 else
179 TRYDIR = /usr/include/mupen64plus
180 ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
181 CFLAGS += -I$(TRYDIR)
182 else
183 $(error Mupen64Plus API header files not found! Use makefile parameter APIDIR to force a location.)
184 endif
185 endif
186 endif
187endif
188
189# reduced compile output when running make without V=1
190ifneq ($(findstring $(MAKEFLAGS),s),s)
191ifndef V
192 Q_CC = @echo ' CC '$@;
193 Q_CXX = @echo ' CXX '$@;
194 Q_LD = @echo ' LD '$@;
195endif
196endif
197
198# set base program pointers and flags
199CC = $(CROSS_COMPILE)gcc
200CXX = $(CROSS_COMPILE)g++
201RM ?= rm -f
202INSTALL ?= install
203MKDIR ?= mkdir -p
204COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
205COMPILE.cc = $(Q_CXX)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
206LINK.o = $(Q_LD)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TARGET_ARCH)
207
208# set special flags for given Makefile parameters
209ifeq ($(DEBUG),1)
210 CFLAGS += -g
211 INSTALL_STRIP_FLAG ?=
212else
213 ifneq ($(OS),OSX)
214 INSTALL_STRIP_FLAG ?= -s
215 endif
216endif
217
218# set installation options
219ifeq ($(PREFIX),)
220 PREFIX := /usr/local
221endif
222ifeq ($(LIBDIR),)
223 LIBDIR := $(PREFIX)/lib
224endif
225ifeq ($(PLUGINDIR),)
226 PLUGINDIR := $(LIBDIR)/mupen64plus
227endif
228
229SRCDIR = ../../src
230OBJDIR = _obj$(POSTFIX)
231
232# list of source files to compile
233SOURCE = \
234 $(SRCDIR)/main.c \
235 $(SRCDIR)/alist.c \
236 $(SRCDIR)/cicx105.c \
237 $(SRCDIR)/jpeg.c \
238 $(SRCDIR)/ucode3.cpp \
239 $(SRCDIR)/ucode2.cpp \
240 $(SRCDIR)/ucode1.cpp \
241 $(SRCDIR)/ucode3mp3.cpp
242
243# generate a list of object files build, make a temporary directory for them
244OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE)))
245OBJECTS += $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(filter %.cpp, $(SOURCE)))
246OBJDIRS = $(dir $(OBJECTS))
247$(shell $(MKDIR) $(OBJDIRS))
248
249# build targets
250TARGET = mupen64plus-rsp-hle$(POSTFIX).$(SO_EXTENSION)
251
252targets:
253 @echo "Mupen64Plus-rsp-hle makefile. "
254 @echo " Targets:"
255 @echo " all == Build Mupen64Plus rsp-hle plugin"
256 @echo " clean == remove object files"
257 @echo " rebuild == clean and re-build all"
258 @echo " install == Install Mupen64Plus rsp-hle plugin"
259 @echo " uninstall == Uninstall Mupen64Plus rsp-hle plugin"
260 @echo " Options:"
261 @echo " BITS=32 == build 32-bit binaries on 64-bit machine"
262 @echo " APIDIR=path == path to find Mupen64Plus Core headers"
263 @echo " OPTFLAGS=flag == compiler optimization (default: -O3 -flto)"
264 @echo " WARNFLAGS=flag == compiler warning levels (default: -Wall)"
265 @echo " PIC=(1|0) == Force enable/disable of position independent code"
266 @echo " POSTFIX=name == String added to the name of the the build (default: '')"
267 @echo " Install Options:"
268 @echo " PREFIX=path == install/uninstall prefix (default: /usr/local)"
269 @echo " LIBDIR=path == library prefix (default: PREFIX/lib)"
270 @echo " PLUGINDIR=path == path to install plugin libraries (default: LIBDIR/mupen64plus)"
271 @echo " DESTDIR=path == path to prepend to all installation paths (only for packagers)"
272 @echo " Debugging Options:"
273 @echo " DEBUG=1 == add debugging symbols"
274 @echo " V=1 == show verbose compiler output"
275
276all: $(TARGET)
277
278install: $(TARGET)
279 $(INSTALL) -d "$(DESTDIR)$(PLUGINDIR)"
280 $(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(PLUGINDIR)"
281
282uninstall:
283 $(RM) "$(DESTDIR)$(PLUGINDIR)/$(TARGET)"
284
285clean:
286 $(RM) -r $(OBJDIR) $(TARGET)
287
288rebuild: clean all
289
290# build dependency files
2d262872 291CFLAGS += -MD -MP
d9e74a6f 292-include $(OBJECTS:.o=.d)
293
294CXXFLAGS += $(CFLAGS)
295
296# standard build rules
297$(OBJDIR)/%.o: $(SRCDIR)/%.c
298 $(COMPILE.c) -o $@ $<
299
300$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
301 $(COMPILE.cc) -o $@ $<
302
303$(TARGET): $(OBJECTS)
304 $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
305
306.PHONY: all clean install uninstall targets