Arachnoid GLESv1.1 plugin. Compile and run (a bit glitchy and no frameskip) on the...
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / projects / unix / Makefile
1 #/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 # *   Arachnoid - Makefile                                                  *
3 # *   http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/            *
4 # *   Copyright (C) 2009 Richard42, Jon Ring                                *
5 # *                                                                         *
6 # *   This program is free software; you can redistribute it and/or modify  *
7 # *   it under the terms of the GNU General Public License as published by  *
8 # *   the Free Software Foundation; either version 2 of the License, or     *
9 # *   (at your option) any later version.                                   *
10 # *                                                                         *
11 # *   This program is distributed in the hope that it will be useful,       *
12 # *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13 # *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14 # *   GNU General Public License for more details.                          *
15 # *                                                                         *
16 # *   You should have received a copy of the GNU General Public License     *
17 # *   along with this program; if not, write to the                         *
18 # *   Free Software Foundation, Inc.,                                       *
19 # *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
20 # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21 # Makefile for mupen64plus-video-arachnoid
22
23 # detect operation system
24 UNAME ?= $(shell uname -s)
25 ifeq ("$(UNAME)","Linux")
26   OS = LINUX
27   SO_EXTENSION = so
28   SHARED = -shared
29 endif
30 ifeq ("$(UNAME)","linux")
31   OS = LINUX
32   SO_EXTENSION = so
33   SHARED = -shared
34 endif
35 ifneq ("$(filter GNU hurd,$(UNAME))","")
36   OS = LINUX
37   SO_EXTENSION = so
38   SHARED = -shared
39 endif
40 ifeq ("$(UNAME)","Darwin")
41   OS = OSX
42   LDLIBS += -liconv -lpng
43   SO_EXTENSION = dylib
44   SHARED = -bundle
45 endif
46 ifeq ("$(UNAME)","FreeBSD")
47   OS = FREEBSD
48   SO_EXTENSION = so
49   SHARED = -shared
50 endif
51 ifeq ("$(UNAME)","OpenBSD")
52   OS = FREEBSD
53   SO_EXTENSION = so
54   SHARED = -shared
55   $(warning OS type "$(UNAME)" not officially supported.')
56 endif
57 ifneq ("$(filter GNU/kFreeBSD kfreebsd,$(UNAME))","")
58   OS = LINUX
59   SO_EXTENSION = so
60   SHARED = -shared
61 endif
62 ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW")
63   OS = MINGW
64   SO_EXTENSION = dll
65   SHARED = -shared
66   PIC = 0
67 endif
68 ifeq ("$(OS)","NONE")
69   $(error OS type "$(UNAME)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
70 endif
71
72 # detect system architecture
73 HOST_CPU ?= $(shell uname -m)
74 NO_ASM ?= 1
75 ifneq ("$(filter x86_64 amd64,$(HOST_CPU))","")
76   CPU := X86
77   ifeq ("$(BITS)", "32")
78     ARCH_DETECTED := 64BITS_32
79   else
80     ARCH_DETECTED := 64BITS
81     PIC ?= 1
82   endif
83 endif
84 ifneq ("$(filter pentium i%86,$(HOST_CPU))","")
85   CPU := X86
86   ARCH_DETECTED := 32BITS
87 endif
88 ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","")
89   CPU := PPC
90   ARCH_DETECTED := 32BITS
91   BIG_ENDIAN := 1
92   PIC ?= 1
93   $(warning Architecture "$(HOST_CPU)" not officially supported.')
94 endif
95 ifneq ("$(filter ppc64 powerpc64,$(HOST_CPU))","")
96   CPU := PPC
97   ARCH_DETECTED := 64BITS
98   BIG_ENDIAN := 1
99   PIC ?= 1
100   $(warning Architecture "$(HOST_CPU)" not officially supported.')
101 endif
102 ifneq ("$(filter arm%,$(HOST_CPU))","")
103   ifeq ("$(filter arm%b,$(HOST_CPU))","")
104     CPU := ARM
105     ARCH_DETECTED := 32BITS
106     PIC ?= 1
107     CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char -ffast-math -fpermissive
108     CFLAGS += -DHAVE_GLES
109     $(warning Architecture "$(HOST_CPU)" not officially supported.')
110   endif
111 endif
112
113 # base CFLAGS, LDLIBS, and LDFLAGS
114 OPTFLAGS ?= -O3
115 WARNFLAGS ?= -Wall
116 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src \
117                  -I../../src/hash -I../../src/ucodes -I../../src/GBI -I../../src/RDP -I../../src/utils \
118                  -I../../src/log -I../../src/RSP -I../../src/framebuffer -I../../src/math -I../../src/renderer \
119                  -I../../src/Assembler -I../../src/texture -I../../src/config -I../../src/Combiner 
120 CXXFLAGS += -fvisibility-inlines-hidden
121 LDFLAGS += $(SHARED)
122
123 # On OS X, add a few extra flags to elegantly support cross-compilation and backward
124 # compatibility (and also the flags to link against OpenGL)
125 ifeq ($(OS), OSX)
126   # Select the proper SDK
127   # Also, SDKs are stored in a different location since XCode 4.3
128   OSX_SDK ?= $(shell sw_vers -productVersion | cut -f1 -f2 -d .)
129   OSX_XCODEMAJ = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f1 -d .)
130   OSX_XCODEMIN = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f2 -d .)
131   OSX_XCODEGE43 = $(shell echo "`expr $(OSX_XCODEMAJ) \>= 4``expr $(OSX_XCODEMIN) \>= 3`")
132   ifeq ($(OSX_XCODEGE43), 11)
133     OSX_SYSROOT := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
134   else
135     OSX_SYSROOT := /Developer/SDKs
136   endif
137
138   ifeq ($(CPU), X86)
139     ifeq ($(ARCH_DETECTED), 64BITS)
140       CFLAGS += -arch x86_64 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
141       LDFLAGS += -bundle
142     else
143       CFLAGS += -arch i686 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
144       LDFLAGS += -bundle
145     endif
146   endif
147 else
148   # search for OpenGL libraries
149   ifeq ($(OS), OSX)
150     GL_LDLIBS = -framework OpenGL
151   endif
152   ifeq ($(OS), MINGW)
153     GL_LDLIBS = -lopengl32
154   endif
155
156   ifeq ($(origin GL_CFLAGS) $(origin GL_LDLIBS), undefined undefined)
157     ifeq ($(origin PKG_CONFIG), undefined)
158       PKG_CONFIG = $(CROSS_COMPILE)pkg-config
159       ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
160         $(error $(PKG_CONFIG) not found)
161       endif
162     endif
163
164     ifeq ($(shell $(PKG_CONFIG) --modversion gl 2>/dev/null),)
165       $(error No OpenGL development libraries found!)
166     endif
167     #GL_CFLAGS += $(shell $(PKG_CONFIG) --cflags gl)
168     #GL_LDLIBS +=  $(shell $(PKG_CONFIG) --libs gl)
169     GL_CFLAGS += $(shell sdl-config --cflags)
170     GL_LDLIBS += $(shell sdl-config --libs)
171     GL_CFLAGS += -I/mnt/utmp/codeblocks/usr/include/GLES
172         GL_LDLIBS += -lGLES_CM -lEGL -lrt
173   endif
174   CFLAGS += $(GL_CFLAGS)
175   LDLIBS += $(GL_LDLIBS)
176
177   CFLAGS += -pthread
178 endif
179 ifeq ($(OS), LINUX)
180   LDLIBS += -ldl 
181 endif
182 ifeq ($(OS), FREEBSD)
183   LDLIBS += -lc
184 endif
185
186
187 # Since we are building a shared library, we must compile with -fPIC on some architectures
188 # 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
189 ifeq ($(PIC), 1)
190   CFLAGS += -fPIC
191 else
192   CFLAGS += -fno-PIC
193 endif
194
195 ifeq ($(BIG_ENDIAN), 1)
196   CFLAGS += -DM64P_BIG_ENDIAN
197 endif
198
199 # set mupen64plus core API header path
200 ifneq ("$(APIDIR)","")
201   CFLAGS += "-I$(APIDIR)"
202 else
203   TRYDIR = ../../../mupen64plus-core/src/api
204   ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
205     CFLAGS += -I$(TRYDIR)
206   else
207     TRYDIR = /usr/local/include/mupen64plus
208     ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
209       CFLAGS += -I$(TRYDIR)
210     else
211       TRYDIR = /usr/include/mupen64plus
212       ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
213         CFLAGS += -I$(TRYDIR)
214       endif
215     endif
216   endif
217 endif
218
219 # set special flags per-system
220 ifeq ($(OS), LINUX)
221   # only export api symbols
222   LDFLAGS += -Wl,-version-script,$(SRCDIR)/video_api_export.ver
223 endif
224 ifneq ($(OS), FREEBSD)
225   ifeq ($(CPU), X86)
226     # tweak flags for 32-bit build on 64-bit system
227     ifeq ($(ARCH_DETECTED), 64BITS_32)
228       CFLAGS += -m32
229       LDFLAGS += -Wl,-m,elf_i386
230     endif
231   endif
232 else
233   ifeq ($(ARCH_DETECTED), 64BITS_32)
234     $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386)
235   endif
236 endif
237
238 # reduced compile output when running make without V=1
239 ifneq ($(findstring $(MAKEFLAGS),s),s)
240 ifndef V
241         Q_CC  = @echo '    CC  '$@;
242         Q_CXX = @echo '    CXX '$@;
243         Q_LD  = @echo '    LD  '$@;
244 endif
245 endif
246
247 # set base program pointers and flags
248 CC        = $(CROSS_COMPILE)gcc
249 CXX       = $(CROSS_COMPILE)g++
250 RM       ?= rm -f
251 INSTALL  ?= install
252 MKDIR ?= mkdir -p
253 COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
254 COMPILE.cc = $(Q_CXX)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
255 LINK.o = $(Q_LD)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TARGET_ARCH)
256
257 # set special flags for given Makefile parameters
258 ifeq ($(DEBUG),1)
259   CFLAGS += -g
260   INSTALL_STRIP_FLAG ?= 
261 else
262   INSTALL_STRIP_FLAG ?= -s
263 endif
264
265 # set installation options
266 ifeq ($(PREFIX),)
267   PREFIX := /usr/local
268 endif
269 ifeq ($(SHAREDIR),)
270   SHAREDIR := $(PREFIX)/share/mupen64plus
271 endif
272 ifeq ($(LIBDIR),)
273   LIBDIR := $(PREFIX)/lib
274 endif
275 ifeq ($(PLUGINDIR),)
276   PLUGINDIR := $(LIBDIR)/mupen64plus
277 endif
278
279
280 SRCDIR = ../../src
281 OBJDIR = _obj$(POSTFIX)
282
283 # list of source files to compile
284 SOURCE = \
285         $(SRCDIR)/main.cpp \
286         $(SRCDIR)/log/Logger.cpp \
287         $(SRCDIR)/config/Config.cpp \
288         $(SRCDIR)/config/StringFunctions.cpp \
289         $(SRCDIR)/GraphicsPlugin.cpp \
290         $(SRCDIR)/OpenGLManager.cpp \
291         $(SRCDIR)/renderer/OpenGLRenderer.cpp \
292         $(SRCDIR)/framebuffer/FrameBuffer.cpp \
293         $(SRCDIR)/FogManager.cpp \
294         $(SRCDIR)/MultiTexturingExt.cpp \
295         $(SRCDIR)/ExtensionChecker.cpp \
296         $(SRCDIR)/SecondaryColorExt.cpp \
297         $(SRCDIR)/Memory.cpp \
298         $(SRCDIR)/math/Matrix4.cpp \
299         $(SRCDIR)/texture/CachedTexture.cpp \
300         $(SRCDIR)/texture/TextureCache.cpp \
301         $(SRCDIR)/texture/ImageFormatSelector.cpp \
302         $(SRCDIR)/hash/CRCCalculator.cpp \
303         $(SRCDIR)/hash/CRCCalculator2.cpp \
304         $(SRCDIR)/texture/TextureLoader.cpp \
305         $(SRCDIR)/DisplayListParser.cpp \
306         $(SRCDIR)/VI.cpp \
307         $(SRCDIR)/ucodes/UCodeSelector.cpp \
308         $(SRCDIR)/ucodes/UCode0.cpp \
309         $(SRCDIR)/ucodes/UCode1.cpp \
310         $(SRCDIR)/ucodes/UCode2.cpp \
311         $(SRCDIR)/ucodes/UCode3.cpp \
312         $(SRCDIR)/ucodes/UCode4.cpp \
313         $(SRCDIR)/ucodes/UCode5.cpp \
314         $(SRCDIR)/ucodes/UCode6.cpp \
315         $(SRCDIR)/ucodes/UCode7.cpp \
316         $(SRCDIR)/ucodes/UCode8.cpp \
317         $(SRCDIR)/ucodes/UCode9.cpp \
318         $(SRCDIR)/ucodes/UCode10.cpp \
319         $(SRCDIR)/GBI/GBI.cpp \
320         $(SRCDIR)/RSP/RSP.cpp \
321         $(SRCDIR)/RSP/RSPMatrixManager.cpp \
322         $(SRCDIR)/RSP/RSPVertexManager.cpp \
323         $(SRCDIR)/RSP/RSPLightManager.cpp \
324         $(SRCDIR)/Combiner/AdvancedCombinerManager.cpp \
325         $(SRCDIR)/Combiner/CombinerBase.cpp \
326         $(SRCDIR)/Combiner/AdvancedTexEnvCombiner.cpp \
327         $(SRCDIR)/Combiner/SimpleTexEnvCombiner.cpp \
328         $(SRCDIR)/Combiner/DummyCombiner.cpp \
329         $(SRCDIR)/Combiner/CombinerStageMerger.cpp \
330         $(SRCDIR)/Combiner/CombinerStageCreator.cpp \
331         $(SRCDIR)/Combiner/CombinerCache.cpp \
332         $(SRCDIR)/RomDetector.cpp \
333         $(SRCDIR)/RDP/RDP.cpp \
334         $(SRCDIR)/RDP/RDPInstructions.cpp               \
335     $(SRCDIR)/renderer/eglport.cpp          \
336         $(SRCDIR)/renderer/OpenGL2DRenderer.cpp \
337
338 ifeq ($(OS),MINGW)
339 SOURCE += $(SRCDIR)/osal_dynamiclib_win32.cpp
340 else
341 SOURCE += $(SRCDIR)/osal_dynamiclib_unix.cpp
342 endif
343
344
345 # generate a list of object files build, make a temporary directory for them
346 OBJECTS := $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(filter %.cpp, $(SOURCE)))
347 OBJDIRS = $(dir $(OBJECTS))
348 $(shell $(MKDIR) $(OBJDIRS))
349
350 # build targets
351
352 TARGET = mupen64plus-video-arachnoid$(POSTFIX).$(SO_EXTENSION)
353 targets:
354         @echo "Mupen64plus-video-arachnoid N64 Graphics plugin makefile. "
355         @echo "  Targets:"
356         @echo "    all           == Build Mupen64plus-video-arachnoid plugin"
357         @echo "    clean         == remove object files"
358         @echo "    rebuild       == clean and re-build all"
359         @echo "    install       == Install Mupen64Plus-video-arachnoid plugin"
360         @echo "    uninstall     == Uninstall Mupen64Plus-video-arachnoid plugin"
361         @echo "  Options:"
362         @echo "    BITS=32       == build 32-bit binaries on 64-bit machine"
363         @echo "    APIDIR=path   == path to find Mupen64Plus Core headers"
364         @echo "    OPTFLAGS=flag == compiler optimization (default: -O3 -flto)"
365         @echo "    WARNFLAGS=flag == compiler warning levels (default: -Wall)"
366         @echo "    PIC=(1|0)     == Force enable/disable of position independent code"
367         @echo "    POSTFIX=name  == String added to the name of the the build (default: '')"
368         @echo "  Install Options:"
369         @echo "    PREFIX=path   == install/uninstall prefix (default: /usr/local)"
370         @echo "    LIBDIR=path   == library prefix (default: PREFIX/lib)"
371         @echo "    PLUGINDIR=path == path to install plugin libraries (default: LIBDIR/mupen64plus)"
372         @echo "    DESTDIR=path  == path to prepend to all installation paths (only for packagers)"
373         @echo "  Debugging Options:"
374         @echo "    DEBUG=1       == add debugging symbols"
375         @echo "    V=1           == show verbose compiler output"
376
377 all: $(TARGET)
378
379 install: $(TARGET)
380         $(INSTALL) -d "$(DESTDIR)$(PLUGINDIR)"
381         $(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(PLUGINDIR)"
382
383 uninstall:
384         $(RM) "$(DESTDIR)$(PLUGINDIR)/$(TARGET)"
385
386
387 clean:
388         $(RM) -r $(OBJDIR) $(TARGET)
389
390 # build dependency files
391 CFLAGS += -MD
392 -include $(OBJECTS:.o=.d)
393
394 CXXFLAGS += $(CFLAGS)
395
396 # standard build rules
397 $(OBJDIR)/%.o: $(SRCDIR)/%.c
398         $(COMPILE.c) -o $@ $<
399
400 $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
401         $(COMPILE.cc) -o $@ $<
402
403 $(TARGET): $(OBJECTS)
404         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
405
406 .PHONY: all clean install uninstall targets