9bff5b3131a4c05425a62193ad815939c5a5b5b8
[mupen64plus-pandora.git] / source / front-end / projects / unix / Makefile
1 #/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 # *   Mupen64plus - Makefile                                                *
3 # *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4 # *   Copyright (C) 2009 Richard42                                          *
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-ui-console
22
23 # detect operation system
24 UNAME ?= $(shell uname -s)
25 OS := NONE
26 ifeq ("$(UNAME)","Linux")
27   OS = LINUX
28 endif
29 ifeq ("$(UNAME)","linux")
30   OS = LINUX
31 endif
32 ifneq ("$(filter GNU hurd,$(UNAME))","")
33   OS = LINUX
34 endif
35 ifeq ("$(UNAME)","Darwin")
36   OS = OSX
37 endif
38 ifeq ("$(UNAME)","FreeBSD")
39   OS = FREEBSD
40 endif
41 ifeq ("$(UNAME)","OpenBSD")
42   OS = FREEBSD
43   $(warning OS type "$(UNAME)" not officially supported.')
44 endif
45 ifneq ("$(filter GNU/kFreeBSD kfreebsd,$(UNAME))","")
46   OS = LINUX
47 endif
48 ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW")
49   OS = MINGW
50 endif
51 ifeq ("$(OS)","NONE")
52   $(error OS type "$(UNAME)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
53 endif
54
55 # detect system architecture
56 HOST_CPU ?= $(shell uname -m)
57 NO_ASM ?= 1
58 CPU := NONE
59 ifneq ("$(filter x86_64 amd64,$(HOST_CPU))","")
60   CPU := X86
61   ifeq ("$(BITS)", "32")
62     ARCH_DETECTED := 64BITS_32
63   else
64     ARCH_DETECTED := 64BITS
65   endif
66 endif
67 ifneq ("$(filter pentium i%86,$(HOST_CPU))","")
68   CPU := X86
69   ARCH_DETECTED := 32BITS
70 endif
71 ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","")
72   CPU := PPC
73   ARCH_DETECTED := 32BITS
74   BIG_ENDIAN := 1
75   $(warning Architecture "$(HOST_CPU)" not officially supported.')
76 endif
77 ifneq ("$(filter ppc64 powerpc64,$(HOST_CPU))","")
78   CPU := PPC
79   ARCH_DETECTED := 64BITS
80   BIG_ENDIAN := 1
81   $(warning Architecture "$(HOST_CPU)" not officially supported.')
82 endif
83 ifneq ("$(filter arm%,$(HOST_CPU))","")
84   ifeq ("$(filter arm%b,$(HOST_CPU))","")
85     CPU := ARM
86     ARCH_DETECTED := 32BITS
87     #CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8
88     CFLAGS += -mcpu=native -mtune=native -marm -mfpu=neon
89     CFLAGS += -fsigned-char -ffast-math
90 #    CFLAGS += -DANDROID
91 #    CFLAGS += -DPAULSCODE 
92     $(warning Architecture "$(HOST_CPU)" not officially supported.')
93   endif
94 endif
95 ifeq ("$(CPU)","NONE")
96   $(error CPU type "$(HOST_CPU)" not supported.  Please file bug report at 'http://code.google.com/p/mupen64plus/issues')
97 endif
98
99 # base CFLAGS, LDLIBS, and LDFLAGS
100 OPTFLAGS ?= -O3
101 WARNFLAGS ?= -Wall
102
103 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -I../../src
104 ifeq ($(OS), MINGW)
105   CFLAGS += -lpthread
106   LDLIBS += -lpthread
107 else
108   CFLAGS += -pthread
109   LDLIBS += -pthread
110 endif
111
112 ifeq ($(PIE), 1)
113   CFLAGS += -fPIE
114   LDFLAGS += -pie
115 else
116   CFLAGS += -fno-PIE
117 endif
118
119 # set special flags per-system
120 ifeq ($(OS), LINUX)
121   LDLIBS += -ldl
122 endif
123 ifeq ($(OS), OSX)
124   #xcode-select has been around since XCode 3.0, i.e. OS X 10.5
125   OSX_SDK_ROOT = $(shell xcode-select -print-path)/Platforms/MacOSX.platform/Developer/SDKs
126   OSX_SDK_PATH = $(OSX_SDK_ROOT)/$(shell ls $(OSX_SDK_ROOT) | tail -1)
127
128   ifeq ($(CPU), X86)
129     ifeq ($(ARCH_DETECTED), 64BITS)
130       CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=10.5 -isysroot $(OSX_SDK_PATH)
131     else
132       CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=10.5 -isysroot $(OSX_SDK_PATH)
133     endif
134   endif
135 endif
136
137 # test for presence of SDL
138 ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined)
139   SDL_CONFIG = $(CROSS_COMPILE)sdl-config
140   ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),)
141     $(error No SDL development libraries found!)
142   endif
143   SDL_CFLAGS  += $(shell $(SDL_CONFIG) --cflags)
144   SDL_LDLIBS += $(shell $(SDL_CONFIG) --libs)
145 endif
146 CFLAGS += $(SDL_CFLAGS)
147 LDLIBS += $(SDL_LDLIBS)
148
149 ifeq ($(OS), MINGW)
150   LDLIBS += -mconsole
151 endif
152
153 ifeq ($(BIG_ENDIAN), 1)
154   CFLAGS += -DM64P_BIG_ENDIAN
155 endif
156
157 # tweak flags for 32-bit build on 64-bit system
158 ifeq ($(ARCH_DETECTED), 64BITS_32)
159   ifeq ($(OS), FREEBSD)
160     $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386)
161   endif
162   CFLAGS += -m32
163   LDFLAGS += -Wl,-m,elf_i386
164 endif
165
166 # set mupen64plus core API header path
167 ifneq ("$(APIDIR)","")
168   CFLAGS += "-I$(APIDIR)"
169 else
170   TRYDIR = ../../../mupen64plus-core/src/api
171   ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
172     CFLAGS += -I$(TRYDIR)
173   else
174     TRYDIR = /usr/local/include/mupen64plus
175     ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
176       CFLAGS += -I$(TRYDIR)
177     else
178       TRYDIR = /usr/include/mupen64plus
179       ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","")
180         CFLAGS += -I$(TRYDIR)
181       else
182         $(error Mupen64Plus API header files not found! Use makefile parameter APIDIR to force a location.)
183       endif
184     endif
185   endif
186 endif
187
188 # reduced compile output when running make without V=1
189 ifneq ($(findstring $(MAKEFLAGS),s),s)
190 ifndef V
191         Q_CC  = @echo '    CC  '$@;
192         Q_LD  = @echo '    LD  '$@;
193 endif
194 endif
195
196 # set base program pointers and flags
197 CC        = $(CROSS_COMPILE)gcc
198 CXX       = $(CROSS_COMPILE)g++
199 RM       ?= rm -f
200 INSTALL  ?= install
201 MKDIR ?= mkdir -p
202 COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
203 LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH)
204
205 # set special flags for given Makefile parameters
206 # note: COREDIR _must_ end in a slash if you want it to work; not necessary for the others
207 ifneq ($(PLUGINDIR),)
208   CFLAGS += '-DPLUGINDIR="$(PLUGINDIR)"'
209 endif
210 ifneq ($(COREDIR),)
211   CFLAGS += '-DCOREDIR="$(COREDIR)"'
212 endif
213 ifneq ($(SHAREDIR),)
214   CFLAGS += '-DSHAREDIR="$(SHAREDIR)"'
215 endif
216 ifeq ($(DEBUG),1)
217   CFLAGS += -g -gdwarf-2
218   INSTALL_STRIP_FLAG ?= 
219 else
220   INSTALL_STRIP_FLAG ?= -s
221 endif
222
223 # set installation options
224 ifeq ($(PREFIX),)
225   PREFIX := /usr/local
226 endif
227 ifeq ($(BINDIR),)
228   BINDIR := $(PREFIX)/bin
229 endif
230 ifeq ($(MANDIR),)
231   MANDIR := $(PREFIX)/share/man
232 endif
233
234 SRCDIR = ../../src
235 OBJDIR = _obj$(POSTFIX)
236
237 ifeq ("$(OS)","MINGW")
238   EXEEXT = .exe
239 else
240   EXEEXT =
241 endif
242
243 # list of source files to compile
244 SOURCE = \
245         $(SRCDIR)/cheat.c \
246         $(SRCDIR)/compare_core.c \
247         $(SRCDIR)/core_interface.c \
248         $(SRCDIR)/main.c \
249         $(SRCDIR)/plugin.c
250
251 ifeq ($(OS), MINGW)
252 SOURCE += \
253         $(SRCDIR)/osal_dynamiclib_win32.c \
254         $(SRCDIR)/osal_files_win32.c
255 else
256 SOURCE += \
257         $(SRCDIR)/osal_dynamiclib_unix.c \
258         $(SRCDIR)/osal_files_unix.c
259 endif
260
261 # generate a list of object files build, make a temporary directory for them
262 OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE)))
263 OBJDIRS = $(dir $(OBJECTS))
264 $(shell $(MKDIR) $(OBJDIRS))
265
266 # build targets
267 TARGET = mupen64plus$(POSTFIX)$(EXEEXT)
268
269 targets:
270         @echo "Mupen64Plus-ui-console makefile."
271         @echo "  Targets:"
272         @echo "    all            == Build Mupen64Plus console front-end application"
273         @echo "    clean          == remove object files and build products"
274         @echo "    rebuild        == clean and re-build all"
275         @echo "    install        == Install Mupen64Plus console front-end application"
276         @echo "    uninstall      == Uninstall Mupen64Plus console front-end application"
277         @echo "  Options:"
278         @echo "    COREDIR=path   == default path to search for Mupen64Plus Core (must end with slash)"
279         @echo "    PLUGINDIR=path == default path to search for plugins"
280         @echo "    SHAREDIR=path  == default path to search for shared data files"
281         @echo "    APIDIR=path    == path to find Mupen64Plus Core headers"
282         @echo "    OPTFLAGS=flags == compiler optimization (default: -O3 -flto)"
283         @echo "    WARNFLAGS=flag == compiler warning levels (default: -Wall)"
284         @echo "    PIE=(1|0)      == Force enable/disable of position independent executables"
285         @echo "    POSTFIX=name  == String added to the name of the the build (default: '')"
286         @echo "  Install Options:"
287         @echo "    PREFIX=path    == install/uninstall prefix (default: /usr/local/)"
288         @echo "    BINDIR=path    == path to install mupen64plus binary (default: PREFIX/bin/)"
289         @echo "    MANDIR=path    == path to install mupen64plus manual page (default: PREFIX/share/man)"
290         @echo "    DESTDIR=path   == path to prepend to all installation paths (only for packagers)"
291         @echo "  Debugging Options:"
292         @echo "    DEBUG=1        == add debugging symbols to application binary"
293         @echo "    V=1            == show verbose compiler output"
294
295 all: $(TARGET)
296
297 clean:
298         $(RM) -r $(OBJDIR) $(TARGET)
299
300 rebuild: clean all
301
302 install: $(TARGET)
303         $(INSTALL) -d "$(DESTDIR)$(BINDIR)"
304         $(INSTALL) -m 0755 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(BINDIR)"
305         $(INSTALL) -d "$(DESTDIR)$(MANDIR)/man6"
306         $(INSTALL) -m 0644 ../../doc/mupen64plus.6 "$(DESTDIR)$(MANDIR)/man6"
307
308 uninstall:
309         $(RM) "$(DESTDIR)$(BINDIR)/$(TARGET)" "$(DESTDIR)$(MANDIR)/man6/mupen64plus.6"
310
311 # build dependency files
312 CFLAGS += -MD -MP
313 -include $(OBJECTS:.o=.d)
314
315 # standard build rules
316 $(OBJDIR)/%.o: $(SRCDIR)/%.c
317         $(COMPILE.c) -o $@ $<
318
319 $(TARGET): $(OBJECTS)
320         $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
321
322 .PHONY: all clean install uninstall targets