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