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