| 1 | #/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2 | # * Mupen64plus-input-sdl - Makefile * |
| 3 | # * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ * |
| 4 | # * Copyright (C) 2007-2009 Richard Goedeken * |
| 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 SDL Input plugin in Mupen64plus |
| 22 | |
| 23 | # detect operating system |
| 24 | UNAME ?= $(shell uname -s) |
| 25 | OS := NONE |
| 26 | ifeq ("$(UNAME)","Linux") |
| 27 | OS = LINUX |
| 28 | SO_EXTENSION = so |
| 29 | SHARED = -shared |
| 30 | endif |
| 31 | ifeq ("$(UNAME)","linux") |
| 32 | OS = LINUX |
| 33 | SO_EXTENSION = so |
| 34 | SHARED = -shared |
| 35 | endif |
| 36 | ifneq ("$(filter GNU hurd,$(UNAME))","") |
| 37 | OS = LINUX |
| 38 | SO_EXTENSION = so |
| 39 | SHARED = -shared |
| 40 | endif |
| 41 | ifeq ("$(UNAME)","Darwin") |
| 42 | OS = OSX |
| 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 | CPU := NONE |
| 76 | ifneq ("$(filter x86_64 amd64,$(HOST_CPU))","") |
| 77 | CPU := X86 |
| 78 | ifeq ("$(BITS)", "32") |
| 79 | ARCH_DETECTED := 64BITS_32 |
| 80 | PIC ?= 0 |
| 81 | else |
| 82 | ARCH_DETECTED := 64BITS |
| 83 | PIC ?= 1 |
| 84 | endif |
| 85 | endif |
| 86 | ifneq ("$(filter pentium i%86,$(HOST_CPU))","") |
| 87 | CPU := X86 |
| 88 | ARCH_DETECTED := 32BITS |
| 89 | PIC ?= 0 |
| 90 | endif |
| 91 | ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","") |
| 92 | CPU := PPC |
| 93 | ARCH_DETECTED := 32BITS |
| 94 | BIG_ENDIAN := 1 |
| 95 | PIC ?= 1 |
| 96 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
| 97 | endif |
| 98 | ifneq ("$(filter ppc64 powerpc64,$(HOST_CPU))","") |
| 99 | CPU := PPC |
| 100 | ARCH_DETECTED := 64BITS |
| 101 | BIG_ENDIAN := 1 |
| 102 | PIC ?= 1 |
| 103 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
| 104 | endif |
| 105 | ifneq ("$(filter arm%,$(HOST_CPU))","") |
| 106 | ifeq ("$(filter arm%b,$(HOST_CPU))","") |
| 107 | CPU := ARM |
| 108 | ARCH_DETECTED := 32BITS |
| 109 | PIC ?= 1 |
| 110 | CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char |
| 111 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
| 112 | endif |
| 113 | endif |
| 114 | ifeq ("$(CPU)","NONE") |
| 115 | $(error CPU type "$(HOST_CPU)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues') |
| 116 | endif |
| 117 | |
| 118 | # base CFLAGS, LDLIBS, and LDFLAGS |
| 119 | OPTFLAGS ?= -O3 |
| 120 | WARNFLAGS ?= -Wall |
| 121 | CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src -D_GNU_SOURCE=1 |
| 122 | LDFLAGS += $(SHARED) |
| 123 | |
| 124 | # Since we are building a shared library, we must compile with -fPIC on some architectures |
| 125 | # 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 |
| 126 | ifeq ($(PIC), 1) |
| 127 | CFLAGS += -fPIC |
| 128 | else |
| 129 | CFLAGS += -fno-PIC |
| 130 | endif |
| 131 | |
| 132 | ifeq ($(BIG_ENDIAN), 1) |
| 133 | CFLAGS += -DM64P_BIG_ENDIAN |
| 134 | endif |
| 135 | |
| 136 | # tweak flags for 32-bit build on 64-bit system |
| 137 | ifeq ($(ARCH_DETECTED), 64BITS_32) |
| 138 | CFLAGS += -m32 |
| 139 | LDFLAGS += -Wl,-m,elf_i386 |
| 140 | endif |
| 141 | |
| 142 | # set special flags per-system |
| 143 | ifeq ($(OS), FREEBSD) |
| 144 | ifeq ($(ARCH_DETECTED), 64BITS_32) |
| 145 | $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386) |
| 146 | endif |
| 147 | endif |
| 148 | ifeq ($(OS), LINUX) |
| 149 | LDLIBS += -ldl |
| 150 | endif |
| 151 | ifeq ($(OS), OSX) |
| 152 | # Select the proper SDK |
| 153 | # Also, SDKs are stored in a different location since XCode 4.3 |
| 154 | OSX_SDK ?= $(shell sw_vers -productVersion | cut -f1 -f2 -d .) |
| 155 | OSX_XCODEMAJ = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f1 -d .) |
| 156 | OSX_XCODEMIN = $(shell xcodebuild -version | grep '[0-9]*\.[0-9]*' | cut -f2 -d ' ' | cut -f2 -d .) |
| 157 | OSX_XCODEGE43 = $(shell echo "`expr $(OSX_XCODEMAJ) \>= 4``expr $(OSX_XCODEMIN) \>= 3`") |
| 158 | ifeq ($(OSX_XCODEGE43), 11) |
| 159 | OSX_SYSROOT := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs |
| 160 | else |
| 161 | OSX_SYSROOT := /Developer/SDKs |
| 162 | endif |
| 163 | |
| 164 | ifeq ($(CPU), X86) |
| 165 | ifeq ($(ARCH_DETECTED), 64BITS) |
| 166 | CFLAGS += -arch x86_64 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk |
| 167 | LDLIBS += -ldl |
| 168 | else |
| 169 | CFLAGS += -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk |
| 170 | LDLIBS += -ldl -read_only_relocs suppress |
| 171 | endif |
| 172 | endif |
| 173 | endif |
| 174 | |
| 175 | # test for presence of SDL |
| 176 | ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined) |
| 177 | SDL_CONFIG = $(CROSS_COMPILE)sdl-config |
| 178 | ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),) |
| 179 | $(error No SDL development libraries found!) |
| 180 | endif |
| 181 | SDL_CFLAGS += $(shell $(SDL_CONFIG) --cflags) |
| 182 | SDL_LDLIBS += $(shell $(SDL_CONFIG) --libs) |
| 183 | endif |
| 184 | CFLAGS += $(SDL_CFLAGS) |
| 185 | LDLIBS += $(SDL_LDLIBS) |
| 186 | |
| 187 | # set mupen64plus core API header path |
| 188 | ifneq ("$(APIDIR)","") |
| 189 | CFLAGS += "-I$(APIDIR)" |
| 190 | else |
| 191 | TRYDIR = ../../../mupen64plus-core/src/api |
| 192 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
| 193 | CFLAGS += -I$(TRYDIR) |
| 194 | else |
| 195 | TRYDIR = /usr/local/include/mupen64plus |
| 196 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
| 197 | CFLAGS += -I$(TRYDIR) |
| 198 | else |
| 199 | TRYDIR = /usr/include/mupen64plus |
| 200 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
| 201 | CFLAGS += -I$(TRYDIR) |
| 202 | else |
| 203 | $(error Mupen64Plus API header files not found! Use makefile parameter APIDIR to force a location.) |
| 204 | endif |
| 205 | endif |
| 206 | endif |
| 207 | endif |
| 208 | |
| 209 | # reduced compile output when running make without V=1 |
| 210 | ifneq ($(findstring $(MAKEFLAGS),s),s) |
| 211 | ifndef V |
| 212 | Q_CC = @echo ' CC '$@; |
| 213 | Q_LD = @echo ' LD '$@; |
| 214 | endif |
| 215 | endif |
| 216 | |
| 217 | # set base program pointers and flags |
| 218 | CC = $(CROSS_COMPILE)gcc |
| 219 | CXX = $(CROSS_COMPILE)g++ |
| 220 | RM ?= rm -f |
| 221 | INSTALL ?= install |
| 222 | MKDIR ?= mkdir -p |
| 223 | COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c |
| 224 | LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) |
| 225 | |
| 226 | # set special flags for given Makefile parameters |
| 227 | ifeq ($(DEBUG),1) |
| 228 | CFLAGS += -g |
| 229 | INSTALL_STRIP_FLAG ?= |
| 230 | else |
| 231 | ifneq ($(OS),OSX) |
| 232 | INSTALL_STRIP_FLAG ?= -s |
| 233 | endif |
| 234 | endif |
| 235 | ifeq ($(PLUGINDBG), 1) |
| 236 | CFLAGS += -D_DEBUG |
| 237 | endif |
| 238 | |
| 239 | # set installation options |
| 240 | ifeq ($(PREFIX),) |
| 241 | PREFIX := /usr/local |
| 242 | endif |
| 243 | ifeq ($(SHAREDIR),) |
| 244 | SHAREDIR := $(PREFIX)/share/mupen64plus |
| 245 | endif |
| 246 | ifeq ($(LIBDIR),) |
| 247 | LIBDIR := $(PREFIX)/lib |
| 248 | endif |
| 249 | ifeq ($(PLUGINDIR),) |
| 250 | PLUGINDIR := $(LIBDIR)/mupen64plus |
| 251 | endif |
| 252 | |
| 253 | SRCDIR = ../../src |
| 254 | OBJDIR = _obj$(POSTFIX) |
| 255 | |
| 256 | # list of source files to compile |
| 257 | SOURCE = \ |
| 258 | $(SRCDIR)/plugin.c \ |
| 259 | $(SRCDIR)/autoconfig.c \ |
| 260 | $(SRCDIR)/config.c |
| 261 | |
| 262 | ifeq ($(OS),MINGW) |
| 263 | SOURCE += $(SRCDIR)/osal_dynamiclib_win32.c |
| 264 | else |
| 265 | SOURCE += $(SRCDIR)/osal_dynamiclib_unix.c |
| 266 | endif |
| 267 | |
| 268 | # generate a list of object files build, make a temporary directory for them |
| 269 | OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE))) |
| 270 | OBJDIRS = $(dir $(OBJECTS)) |
| 271 | $(shell $(MKDIR) $(OBJDIRS)) |
| 272 | |
| 273 | # build targets |
| 274 | TARGET = mupen64plus-input-sdl$(POSTFIX).$(SO_EXTENSION) |
| 275 | |
| 276 | targets: |
| 277 | @echo "Mupen64Plus-input-sdl makefile. " |
| 278 | @echo " Targets:" |
| 279 | @echo " all == Build Mupen64Plus SDL input plugin" |
| 280 | @echo " clean == remove object files" |
| 281 | @echo " rebuild == clean and re-build all" |
| 282 | @echo " install == Install Mupen64Plus SDL input plugin" |
| 283 | @echo " uninstall == Uninstall Mupen64Plus SDL input plugin" |
| 284 | @echo " Options:" |
| 285 | @echo " BITS=32 == build 32-bit binaries on 64-bit machine" |
| 286 | @echo " APIDIR=path == path to find Mupen64Plus Core headers" |
| 287 | @echo " OPTFLAGS=flag == compiler optimization (default: -O3 -flto)" |
| 288 | @echo " WARNFLAGS=flag == compiler warning levels (default: -Wall)" |
| 289 | @echo " PIC=(1|0) == Force enable/disable of position independent code" |
| 290 | @echo " POSTFIX=name == String added to the name of the the build (default: '')" |
| 291 | @echo " Install Options:" |
| 292 | @echo " PREFIX=path == install/uninstall prefix (default: /usr/local)" |
| 293 | @echo " SHAREDIR=path == path to install shared data files (default: PREFIX/share/mupen64plus)" |
| 294 | @echo " LIBDIR=path == library prefix (default: PREFIX/lib)" |
| 295 | @echo " PLUGINDIR=path == path to install plugin libraries (default: LIBDIR/mupen64plus)" |
| 296 | @echo " DESTDIR=path == path to prepend to all installation paths (only for packagers)" |
| 297 | @echo " Debugging Options:" |
| 298 | @echo " DEBUG=1 == add debugging symbols" |
| 299 | @echo " PLUGINDBG=1 == print extra debugging information while running" |
| 300 | @echo " V=1 == show verbose compiler output" |
| 301 | |
| 302 | all: $(TARGET) |
| 303 | |
| 304 | install: $(TARGET) |
| 305 | $(INSTALL) -d "$(DESTDIR)$(PLUGINDIR)" |
| 306 | $(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(PLUGINDIR)" |
| 307 | $(INSTALL) -d "$(DESTDIR)$(SHAREDIR)" |
| 308 | $(INSTALL) -m 0644 "../../data/InputAutoCfg.ini" "$(DESTDIR)$(SHAREDIR)" |
| 309 | |
| 310 | uninstall: |
| 311 | $(RM) "$(DESTDIR)$(PLUGINDIR)/$(TARGET)" |
| 312 | $(RM) "$(DESTDIR)$(SHAREDIR)/InputAutoCfg.ini" |
| 313 | |
| 314 | clean: |
| 315 | $(RM) -r $(OBJDIR) $(TARGET) |
| 316 | |
| 317 | rebuild: clean all |
| 318 | |
| 319 | # build dependency files |
| 320 | CFLAGS += -MD |
| 321 | -include $(OBJECTS:.o=.d) |
| 322 | |
| 323 | # standard build rules |
| 324 | $(OBJDIR)/%.o: $(SRCDIR)/%.c |
| 325 | $(COMPILE.c) -o $@ $< |
| 326 | |
| 327 | $(TARGET): $(OBJECTS) |
| 328 | $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ |
| 329 | |
| 330 | .PHONY: all clean install uninstall targets |