ALL: Huge upstream synch + PerRom DelaySI & CountPerOp parameters
[mupen64plus-pandora.git] / source / gles2rice / projects / unix / Makefile
1 #/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 # *   Mupen64plus-video-rice - Makefile                                     *
3 # *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4 # *   Copyright (C) 2007-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 RiceVideo plugin in Mupen64Plus
23
24 # detect operating system
25 UNAME ?= $(shell uname -s)
26 OS := NONE
27 ifeq ("$(UNAME)","Linux")
28   OS = LINUX
29   SO_EXTENSION = so
30   SHARED = -shared
31 endif
32 ifeq ("$(UNAME)","linux")
33   OS = LINUX
34   SO_EXTENSION = so
35   SHARED = -shared
36 endif
37 ifneq ("$(filter GNU hurd,$(UNAME))","")
38   OS = LINUX
39   SO_EXTENSION = so
40   SHARED = -shared
41 endif
42 ifeq ("$(UNAME)","Darwin")
43   OS = OSX
44   SO_EXTENSION = dylib
45   SHARED = -bundle
46   PIC = 1  # force PIC under OSX
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 CPU := NONE
77 ifneq ("$(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
86 endif
87 ifneq ("$(filter pentium i%86,$(HOST_CPU))","")
88   CPU := X86
89   ARCH_DETECTED := 32BITS
90   PIC ?= 0
91 endif
92 ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","")
93   CPU := PPC
94   ARCH_DETECTED := 32BITS
95   BIG_ENDIAN := 1
96   PIC ?= 1
97   NO_ASM := 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   NO_ASM := 1
106   $(warning Architecture "$(HOST_CPU)" not officially supported.')
107 endif
108 ifneq ("$(filter arm%,$(HOST_CPU))","")
109   ifeq ("$(filter arm%b,$(HOST_CPU))","")
110     CPU := ARM
111     ARCH_DETECTED := 32BITS
112     PIC ?= 1
113     NO_ASM := 1
114     CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char -ffast-math
115     CFLAGS += -DANDROID
116     CFLAGS += -DPAULSCODE 
117     $(warning Architecture "$(HOST_CPU)" not officially supported.')
118   endif
119 endif
120 ifeq ("$(CPU)","NONE")
121   $(error CPU type "$(HOST_CPU)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
122 endif
123
124 # base CFLAGS, LDLIBS, and LDFLAGS
125 OPTFLAGS ?= -O4 -ffast-math 
126 #-flto -fuse-linker-plugin
127 WARNFLAGS ?= -Wall
128 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src
129 CXXFLAGS += -fvisibility-inlines-hidden
130 LDFLAGS += $(SHARED)
131
132 ifeq ($(CPU), X86)
133   CFLAGS += -msse
134 endif
135
136 # Since we are building a shared library, we must compile with -fPIC on some architectures
137 # 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
138 ifeq ($(PIC), 1)
139   CFLAGS += -fPIC
140 else
141   CFLAGS += -fno-PIC
142 endif
143
144 ifeq ($(BIG_ENDIAN), 1)
145   CFLAGS += -DM64P_BIG_ENDIAN
146 endif
147
148 # tweak flags for 32-bit build on 64-bit system
149 ifeq ($(ARCH_DETECTED), 64BITS_32)
150   ifeq ($(OS), FREEBSD)
151     $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386)
152   endif
153   CFLAGS += -m32
154   LDFLAGS += -Wl,-m,elf_i386
155 endif
156
157 # set special flags per-system
158 ifeq ($(OS), LINUX)
159   LDLIBS += -ldl
160   # only export api symbols
161   LDFLAGS += -Wl,-version-script,$(SRCDIR)/video_api_export.ver
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       LDFLAGS += -bundle
180       LDLIBS += -ldl
181     else
182       CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
183       LDFLAGS += -bundle
184       LDLIBS += -ldl
185     endif
186   endif
187 endif
188
189 # test for essential build dependencies
190 ifeq ($(origin PKG_CONFIG), undefined)
191   PKG_CONFIG = $(CROSS_COMPILE)pkg-config
192   ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
193     $(error $(PKG_CONFIG) not found)
194   endif
195 endif
196
197 ifeq ($(origin LIBPNG_CFLAGS) $(origin LIBPNG_LDLIBS), undefined undefined)
198   ifeq ($(shell $(PKG_CONFIG) --modversion libpng 2>/dev/null),)
199     $(error No libpng development libraries found!)
200   endif
201   LIBPNG_CFLAGS += $(shell $(PKG_CONFIG) --cflags libpng)
202   LIBPNG_LDLIBS +=  $(shell $(PKG_CONFIG) --libs libpng)
203 endif
204 CFLAGS += $(LIBPNG_CFLAGS)
205 LDLIBS += $(LIBPNG_LDLIBS)
206
207 # search for OpenGL libraries
208 ifeq ($(OS), OSX)
209   GL_LDLIBS = -framework OpenGL
210 endif
211 ifeq ($(OS), MINGW)
212   GL_LDLIBS = -lopengl32
213 endif
214 ifeq ($(origin GL_CFLAGS) $(origin GL_LDLIBS), undefined undefined)
215   ifeq ($(shell $(PKG_CONFIG) --modversion gl 2>/dev/null),)
216     $(error No OpenGL development libraries found!)
217   endif
218 #  GL_CFLAGS += $(shell $(PKG_CONFIG) --cflags gl)
219 #  GL_LDLIBS +=  $(shell $(PKG_CONFIG) --libs gl)
220   GL_CFLAGS += -I/mnt/utmp/codeblocks/usr/include/GLES2
221   GL_LDLIBS += -lGLESv2 -lrt
222 endif
223 CFLAGS += $(GL_CFLAGS)
224 LDLIBS += $(GL_LDLIBS)
225
226 # test for presence of SDL
227 ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined)
228   SDL_CONFIG = $(CROSS_COMPILE)sdl-config
229   ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),)
230     $(error No SDL development libraries found!)
231   endif
232   SDL_CFLAGS  += $(shell $(SDL_CONFIG) --cflags)
233   SDL_LDLIBS += $(shell $(SDL_CONFIG) --libs)
234 endif
235 CFLAGS += $(SDL_CFLAGS)
236 LDLIBS += $(SDL_LDLIBS)
237
238 # set mupen64plus core API header path
239 ifneq ("$(APIDIR)","")
240   CFLAGS += "-I$(APIDIR)"
241 else
242   TRYDIR = ../../../mupen64plus-core/src/api
243   ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
244     CFLAGS += -I$(TRYDIR)
245   else
246     TRYDIR = /usr/local/include/mupen64plus
247     ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
248       CFLAGS += -I$(TRYDIR)
249     else
250       TRYDIR = /usr/include/mupen64plus
251       ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
252         CFLAGS += -I$(TRYDIR)
253       else
254         $(error Mupen64Plus API header files not found! Use makefile parameter APIDIR to force a location.)
255       endif
256     endif
257   endif
258 endif
259
260 # reduced compile output when running make without V=1
261 ifneq ($(findstring $(MAKEFLAGS),s),s)
262 ifndef V
263         Q_CC  = @echo '    CC  '$@;
264         Q_CXX = @echo '    CXX '$@;
265         Q_LD  = @echo '    LD  '$@;
266 endif
267 endif
268
269 # set base program pointers and flags
270 CC        = $(CROSS_COMPILE)gcc
271 CXX       = $(CROSS_COMPILE)g++
272 RM       ?= rm -f
273 INSTALL  ?= install
274 MKDIR ?= mkdir -p
275 COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
276 COMPILE.cc = $(Q_CXX)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
277 LINK.o = $(Q_LD)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TARGET_ARCH)
278
279 # set special flags for given Makefile parameters
280 ifeq ($(DEBUG),1)
281   CFLAGS += -g
282   INSTALL_STRIP_FLAG ?= 
283 else
284   ifneq ($(OS),OSX)
285     INSTALL_STRIP_FLAG ?= -s
286   endif
287 endif
288 ifeq ($(NO_ASM), 1)
289   CFLAGS += -DNO_ASM
290 endif
291
292 # set installation options
293 ifeq ($(PREFIX),)
294   PREFIX := /usr/local
295 endif
296 ifeq ($(SHAREDIR),)
297   SHAREDIR := $(PREFIX)/share/mupen64plus
298 endif
299 ifeq ($(LIBDIR),)
300   LIBDIR := $(PREFIX)/lib
301 endif
302 ifeq ($(PLUGINDIR),)
303   PLUGINDIR := $(LIBDIR)/mupen64plus
304 endif
305
306 SRCDIR = ../../src
307 OBJDIR = _obj$(POSTFIX)
308
309 # list of source files to compile
310 SOURCE = \
311     $(SRCDIR)/Blender.cpp               \
312     $(SRCDIR)/Combiner.cpp              \
313     $(SRCDIR)/CombinerTable.cpp         \
314     $(SRCDIR)/Config.cpp                \
315     $(SRCDIR)/ConvertImage.cpp          \
316     $(SRCDIR)/ConvertImage16.cpp        \
317     $(SRCDIR)/Debugger.cpp              \
318     $(SRCDIR)/DecodedMux.cpp            \
319     $(SRCDIR)/DeviceBuilder.cpp         \
320     $(SRCDIR)/DirectXDecodedMux.cpp     \
321     $(SRCDIR)/FrameBuffer.cpp           \
322     $(SRCDIR)/GeneralCombiner.cpp       \
323     $(SRCDIR)/GraphicsContext.cpp       \
324     $(SRCDIR)/OGLCombiner.cpp           \
325     $(SRCDIR)/OGLDecodedMux.cpp         \
326     $(SRCDIR)/OGLExtCombiner.cpp        \
327     $(SRCDIR)/OGLExtRender.cpp          \
328     $(SRCDIR)/OGLES2FragmentShaders.cpp \
329     $(SRCDIR)/OGLGraphicsContext.cpp    \
330     $(SRCDIR)/OGLRender.cpp             \
331     $(SRCDIR)/OGLRenderExt.cpp          \
332     $(SRCDIR)/OGLTexture.cpp            \
333     $(SRCDIR)/Render.cpp                \
334     $(SRCDIR)/RenderBase.cpp            \
335     $(SRCDIR)/RenderExt.cpp             \
336     $(SRCDIR)/RenderTexture.cpp         \
337     $(SRCDIR)/RSP_Parser.cpp            \
338     $(SRCDIR)/RSP_S2DEX.cpp             \
339     $(SRCDIR)/Texture.cpp               \
340     $(SRCDIR)/TextureFilters.cpp        \
341     $(SRCDIR)/TextureFilters_2xsai.cpp  \
342     $(SRCDIR)/TextureFilters_hq2x.cpp   \
343     $(SRCDIR)/TextureFilters_hq4x.cpp   \
344     $(SRCDIR)/TextureManager.cpp        \
345     $(SRCDIR)/VectorMath.cpp            \
346     $(SRCDIR)/Video.cpp                 \
347     $(SRCDIR)/liblinux/BMGImage.c       \
348     $(SRCDIR)/liblinux/BMGUtils.c       \
349     $(SRCDIR)/liblinux/bmp.c            \
350     $(SRCDIR)/liblinux/pngrw.c          \
351
352 ifeq ($(OS),MINGW)
353 SOURCE += \
354         $(SRCDIR)/osal_dynamiclib_win32.c \
355         $(SRCDIR)/osal_files_win32.c
356 else
357 SOURCE += \
358         $(SRCDIR)/osal_dynamiclib_unix.c \
359         $(SRCDIR)/osal_files_unix.c
360 endif
361
362 # generate a list of object files build, make a temporary directory for them
363 OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE)))
364 OBJECTS += $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(filter %.cpp, $(SOURCE)))
365 OBJDIRS = $(dir $(OBJECTS))
366 $(shell $(MKDIR) $(OBJDIRS))
367
368 # build targets
369 TARGET = mupen64plus-video-rice$(POSTFIX).$(SO_EXTENSION)
370
371 targets:
372         @echo "Mupen64plus-video-rice N64 Graphics plugin makefile. "
373         @echo "  Targets:"
374         @echo "    all           == Build Mupen64plus-video-rice plugin"
375         @echo "    clean         == remove object files"
376         @echo "    rebuild       == clean and re-build all"
377         @echo "    install       == Install Mupen64Plus-video-rice plugin"
378         @echo "    uninstall     == Uninstall Mupen64Plus-video-rice plugin"
379         @echo "  Options:"
380         @echo "    BITS=32       == build 32-bit binaries on 64-bit machine"
381         @echo "    NO_ASM=1      == build without inline assembly code (x86 MMX/SSE)"
382         @echo "    APIDIR=path   == path to find Mupen64Plus Core headers"
383         @echo "    OPTFLAGS=flag == compiler optimization (default: -O3 -flto)"
384         @echo "    WARNFLAGS=flag == compiler warning levels (default: -Wall)"
385         @echo "    PIC=(1|0)     == Force enable/disable of position independent code"
386         @echo "    POSTFIX=name  == String added to the name of the the build (default: '')"
387         @echo "  Install Options:"
388         @echo "    PREFIX=path   == install/uninstall prefix (default: /usr/local)"
389         @echo "    SHAREDIR=path == path to install shared data files (default: PREFIX/share/mupen64plus)"
390         @echo "    LIBDIR=path   == library prefix (default: PREFIX/lib)"
391         @echo "    PLUGINDIR=path == path to install plugin libraries (default: LIBDIR/mupen64plus)"
392         @echo "    DESTDIR=path  == path to prepend to all installation paths (only for packagers)"
393         @echo "  Debugging Options:"
394         @echo "    DEBUG=1       == add debugging symbols"
395         @echo "    V=1           == show verbose compiler output"
396
397 all: $(TARGET)
398
399 install: $(TARGET)
400         $(INSTALL) -d "$(DESTDIR)$(PLUGINDIR)"
401         $(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(PLUGINDIR)"
402         $(INSTALL) -d "$(DESTDIR)$(SHAREDIR)"
403         $(INSTALL) -m 0644 "../../data/RiceVideoLinux.ini" "$(DESTDIR)$(SHAREDIR)"
404
405 uninstall:
406         $(RM) "$(DESTDIR)$(PLUGINDIR)/$(TARGET)"
407         $(RM) "$(DESTDIR)$(SHAREDIR)/RiceVideoLinux.ini"
408
409 clean:
410         $(RM) -r $(OBJDIR) $(TARGET)
411
412 rebuild: clean all
413
414 # build dependency files
415 CFLAGS += -MD
416 -include $(OBJECTS:.o=.d)
417
418 CXXFLAGS += $(CFLAGS)
419
420 # standard build rules
421 $(OBJDIR)/%.o: $(SRCDIR)/%.c
422         $(COMPILE.c) -o $@ $<
423
424 $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
425         $(COMPILE.cc) -o $@ $<
426
427 $(TARGET): $(OBJECTS)
428         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
429
430 .PHONY: all clean install uninstall targets