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