| | 1 | #/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| | 2 | # * Mupen64plus-audio-sdl - Makefile * |
| | 3 | # * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ * |
| | 4 | # * Copyright (C) 2007-2009 Richard Goedeken * |
| | 5 | # * Copyright (C) 2007-2008 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 SDL Audio plugin in Mupen64plus |
| | 23 | |
| | 24 | # detect operation system |
| | 25 | UNAME ?= $(shell uname -s) |
| | 26 | OS := NONE |
| | 27 | ifeq ("$(UNAME)","Linux") |
| | 28 | OS = LINUX |
| | 29 | SHARED = -shared |
| | 30 | SO_EXTENSION = so |
| | 31 | endif |
| | 32 | ifeq ("$(UNAME)","linux") |
| | 33 | OS = LINUX |
| | 34 | SHARED = -shared |
| | 35 | SO_EXTENSION = so |
| | 36 | endif |
| | 37 | ifneq ("$(filter GNU hurd,$(UNAME))","") |
| | 38 | OS = LINUX |
| | 39 | SHARED = -shared |
| | 40 | SO_EXTENSION = so |
| | 41 | endif |
| | 42 | ifeq ("$(UNAME)","Darwin") |
| | 43 | OS = OSX |
| | 44 | SHARED = -bundle |
| | 45 | SO_EXTENSION = dylib |
| | 46 | endif |
| | 47 | ifeq ("$(UNAME)","FreeBSD") |
| | 48 | OS = FREEBSD |
| | 49 | SHARED = -shared |
| | 50 | SO_EXTENSION = so |
| | 51 | endif |
| | 52 | ifeq ("$(UNAME)","OpenBSD") |
| | 53 | OS = FREEBSD |
| | 54 | SHARED = -shared |
| | 55 | SO_EXTENSION = so |
| | 56 | $(warning OS type "$(UNAME)" not officially supported.') |
| | 57 | endif |
| | 58 | ifneq ("$(filter GNU/kFreeBSD kfreebsd,$(UNAME))","") |
| | 59 | OS = LINUX |
| | 60 | SHARED = -shared |
| | 61 | SO_EXTENSION = so |
| | 62 | endif |
| | 63 | ifeq ("$(patsubst MINGW%,MINGW,$(UNAME))","MINGW") |
| | 64 | OS = MINGW |
| | 65 | SHARED = -shared |
| | 66 | SO_EXTENSION = dll |
| | 67 | PIC = 0 |
| | 68 | NO_OSS = 1 |
| | 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 | NO_ASM ?= 1 |
| | 77 | CPU := NONE |
| | 78 | ifneq ("$(filter x86_64 amd64,$(HOST_CPU))","") |
| | 79 | CPU := X86 |
| | 80 | ifeq ("$(BITS)", "32") |
| | 81 | ARCH_DETECTED := 64BITS_32 |
| | 82 | PIC ?= 0 |
| | 83 | else |
| | 84 | ARCH_DETECTED := 64BITS |
| | 85 | PIC ?= 1 |
| | 86 | endif |
| | 87 | endif |
| | 88 | ifneq ("$(filter pentium i%86,$(HOST_CPU))","") |
| | 89 | CPU := X86 |
| | 90 | ARCH_DETECTED := 32BITS |
| | 91 | PIC ?= 0 |
| | 92 | endif |
| | 93 | ifneq ("$(filter ppc macppc socppc powerpc,$(HOST_CPU))","") |
| | 94 | CPU := PPC |
| | 95 | ARCH_DETECTED := 32BITS |
| | 96 | BIG_ENDIAN := 1 |
| | 97 | PIC ?= 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 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
| | 106 | endif |
| | 107 | ifneq ("$(filter arm%,$(HOST_CPU))","") |
| | 108 | ifeq ("$(filter arm%b,$(HOST_CPU))","") |
| | 109 | CPU := ARM |
| | 110 | ARCH_DETECTED := 32BITS |
| | 111 | CFLAGS += -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mtune=cortex-a8 -fsigned-char |
| | 112 | PIC ?= 1 |
| | 113 | $(warning Architecture "$(HOST_CPU)" not officially supported.') |
| | 114 | endif |
| | 115 | endif |
| | 116 | ifeq ("$(CPU)","NONE") |
| | 117 | $(error CPU type "$(HOST_CPU)" not supported. Please file bug report at 'http://code.google.com/p/mupen64plus/issues') |
| | 118 | endif |
| | 119 | |
| | 120 | # base CFLAGS, LDLIBS, and LDFLAGS |
| | 121 | OPTFLAGS ?= -O3 |
| | 122 | WARNFLAGS ?= -Wall |
| | 123 | CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src |
| | 124 | LDFLAGS += $(SHARED) |
| | 125 | |
| | 126 | # Since we are building a shared library, we must compile with -fPIC on some architectures |
| | 127 | # 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 |
| | 128 | ifeq ($(PIC), 1) |
| | 129 | CFLAGS += -fPIC |
| | 130 | else |
| | 131 | CFLAGS += -fno-PIC |
| | 132 | endif |
| | 133 | |
| | 134 | ifeq ($(BIG_ENDIAN), 1) |
| | 135 | CFLAGS += -DM64P_BIG_ENDIAN |
| | 136 | endif |
| | 137 | |
| | 138 | # tweak flags for 32-bit build on 64-bit system |
| | 139 | ifeq ($(ARCH_DETECTED), 64BITS_32) |
| | 140 | ifeq ($(OS), FREEBSD) |
| | 141 | $(error Do not use the BITS=32 option with FreeBSD, use -m32 and -m elf_i386) |
| | 142 | endif |
| | 143 | CFLAGS += -m32 |
| | 144 | LDFLAGS += -Wl,-m,elf_i386 |
| | 145 | endif |
| | 146 | |
| | 147 | # set special flags per-system |
| | 148 | ifeq ($(OS), LINUX) |
| | 149 | LDLIBS += -ldl |
| | 150 | endif |
| | 151 | ifeq ($(OS), OSX) |
| | 152 | #xcode-select has been around since XCode 3.0, i.e. OS X 10.5 |
| | 153 | OSX_SDK_ROOT = $(shell xcode-select -print-path)/Platforms/MacOSX.platform/Developer/SDKs |
| | 154 | OSX_SDK_PATH = $(OSX_SDK_ROOT)/$(shell ls $(OSX_SDK_ROOT) | tail -1) |
| | 155 | |
| | 156 | ifeq ($(CPU), X86) |
| | 157 | ifeq ($(ARCH_DETECTED), 64BITS) |
| | 158 | CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=10.5 -isysroot $(OSX_SDK_PATH) |
| | 159 | LDLIBS += -ldl |
| | 160 | else |
| | 161 | CFLAGS += -pipe -mmmx -msse -fomit-frame-pointer -arch i686 -mmacosx-version-min=10.5 -isysroot $(OSX_SDK_PATH) |
| | 162 | LDLIBS += -ldl -read_only_relocs suppress |
| | 163 | endif |
| | 164 | endif |
| | 165 | endif |
| | 166 | |
| | 167 | # test for presence of SDL |
| | 168 | ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined) |
| | 169 | SDL_CONFIG = $(CROSS_COMPILE)sdl-config |
| | 170 | ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),) |
| | 171 | $(error No SDL development libraries found!) |
| | 172 | endif |
| | 173 | SDL_CFLAGS += $(shell $(SDL_CONFIG) --cflags) |
| | 174 | SDL_LDLIBS += $(shell $(SDL_CONFIG) --libs) |
| | 175 | endif |
| | 176 | CFLAGS += $(SDL_CFLAGS) |
| | 177 | LDLIBS += $(SDL_LDLIBS) |
| | 178 | |
| | 179 | # test for essential build dependencies |
| | 180 | ifeq ($(origin PKG_CONFIG), undefined) |
| | 181 | PKG_CONFIG = $(CROSS_COMPILE)pkg-config |
| | 182 | ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),) |
| | 183 | $(error $(PKG_CONFIG) not found) |
| | 184 | endif |
| | 185 | endif |
| | 186 | |
| | 187 | # test for presence of speexdsp |
| | 188 | ifneq ($(NO_SPEEX), 1) |
| | 189 | ifeq ($(origin SPEEX_CFLAGS) $(origin SPEEX_LDLIBS), undefined undefined) |
| | 190 | ifneq ($(strip $(shell $(PKG_CONFIG) speexdsp --modversion 2> /dev/null)),) |
| | 191 | # set speexdsp flags and libraries |
| | 192 | SPEEX_CFLAGS += $(shell $(PKG_CONFIG) speexdsp --cflags) -DUSE_SPEEX |
| | 193 | SPEEX_LDLIBS += $(shell $(PKG_CONFIG) speexdsp --libs) |
| | 194 | else |
| | 195 | # warn user |
| | 196 | $(warning No libspeexdsp development libraries found. Mupen64plus-sdl-audio will be built without speex-* resampler.) |
| | 197 | endif |
| | 198 | else |
| | 199 | SPEEX_CFLAGS += -DUSE_SPEEX |
| | 200 | endif |
| | 201 | CFLAGS += $(SPEEX_CFLAGS) |
| | 202 | LDLIBS += $(SPEEX_LDLIBS) |
| | 203 | endif |
| | 204 | |
| | 205 | # test for presence of libsamplerate |
| | 206 | ifneq ($(NO_SRC), 1) |
| | 207 | ifeq ($(origin SRC_CFLAGS) $(origin SRC_LDLIBS), undefined undefined) |
| | 208 | ifneq ($(strip $(shell $(PKG_CONFIG) samplerate --modversion 2> /dev/null)),) |
| | 209 | # set libsamplerate flags and libraries |
| | 210 | SRC_CFLAGS += $(shell $(PKG_CONFIG) samplerate --cflags) -DUSE_SRC |
| | 211 | SRC_LDLIBS += $(shell $(PKG_CONFIG) samplerate --libs) |
| | 212 | else |
| | 213 | $(warning No libsamplerate development libraries found. Mupen64plus-sdl-audio will be built without src-* resampler.) |
| | 214 | endif |
| | 215 | else |
| | 216 | SRC_CFLAGS += -DUSE_SRC |
| | 217 | endif |
| | 218 | CFLAGS += $(SRC_CFLAGS) |
| | 219 | LDLIBS += $(SRC_LDLIBS) |
| | 220 | endif |
| | 221 | |
| | 222 | # test for the presence of OSS |
| | 223 | ifneq ($(wildcard /dev/mixer),) |
| | 224 | ifneq ($(NO_OSS), 1) |
| | 225 | CFLAGS += -DHAS_OSS_SUPPORT |
| | 226 | endif |
| | 227 | endif |
| | 228 | |
| | 229 | # set mupen64plus core API header path |
| | 230 | ifneq ("$(APIDIR)","") |
| | 231 | CFLAGS += "-I$(APIDIR)" |
| | 232 | else |
| | 233 | TRYDIR = ../../../mupen64plus-core/src/api |
| | 234 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
| | 235 | CFLAGS += -I$(TRYDIR) |
| | 236 | else |
| | 237 | TRYDIR = /usr/local/include/mupen64plus |
| | 238 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
| | 239 | CFLAGS += -I$(TRYDIR) |
| | 240 | else |
| | 241 | TRYDIR = /usr/include/mupen64plus |
| | 242 | ifneq ("$(wildcard $(TRYDIR)/m64p_types.h)","") |
| | 243 | CFLAGS += -I$(TRYDIR) |
| | 244 | else |
| | 245 | $(error Mupen64Plus API header files not found! Use makefile parameter APIDIR to force a location.) |
| | 246 | endif |
| | 247 | endif |
| | 248 | endif |
| | 249 | endif |
| | 250 | |
| | 251 | # reduced compile output when running make without V=1 |
| | 252 | ifneq ($(findstring $(MAKEFLAGS),s),s) |
| | 253 | ifndef V |
| | 254 | Q_CC = @echo ' CC '$@; |
| | 255 | Q_LD = @echo ' LD '$@; |
| | 256 | endif |
| | 257 | endif |
| | 258 | |
| | 259 | # set base program pointers and flags |
| | 260 | CC = $(CROSS_COMPILE)gcc |
| | 261 | RM ?= rm -f |
| | 262 | INSTALL ?= install |
| | 263 | MKDIR ?= mkdir -p |
| | 264 | COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c |
| | 265 | LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) |
| | 266 | |
| | 267 | # set special flags for given Makefile parameters |
| | 268 | ifeq ($(DEBUG),1) |
| | 269 | CFLAGS += -g |
| | 270 | INSTALL_STRIP_FLAG ?= |
| | 271 | else |
| | 272 | ifneq ($(OS),OSX) |
| | 273 | INSTALL_STRIP_FLAG ?= -s |
| | 274 | endif |
| | 275 | endif |
| | 276 | |
| | 277 | # set installation options |
| | 278 | ifeq ($(PREFIX),) |
| | 279 | PREFIX := /usr/local |
| | 280 | endif |
| | 281 | ifeq ($(LIBDIR),) |
| | 282 | LIBDIR := $(PREFIX)/lib |
| | 283 | endif |
| | 284 | ifeq ($(PLUGINDIR),) |
| | 285 | PLUGINDIR := $(LIBDIR)/mupen64plus |
| | 286 | endif |
| | 287 | |
| | 288 | SRCDIR = ../../src |
| | 289 | OBJDIR = _obj$(POSTFIX) |
| | 290 | |
| | 291 | # list of source files to compile |
| | 292 | SOURCE = \ |
| | 293 | $(SRCDIR)/main.c \ |
| | 294 | $(SRCDIR)/volume.c |
| | 295 | |
| | 296 | ifeq ($(OS),MINGW) |
| | 297 | SOURCE += $(SRCDIR)/osal_dynamiclib_win32.c |
| | 298 | else |
| | 299 | SOURCE += $(SRCDIR)/osal_dynamiclib_unix.c |
| | 300 | endif |
| | 301 | |
| | 302 | # generate a list of object files build, make a temporary directory for them |
| | 303 | OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE))) |
| | 304 | OBJDIRS = $(dir $(OBJECTS)) |
| | 305 | $(shell $(MKDIR) $(OBJDIRS)) |
| | 306 | |
| | 307 | # build targets |
| | 308 | TARGET = mupen64plus-audio-sdl$(POSTFIX).$(SO_EXTENSION) |
| | 309 | |
| | 310 | targets: |
| | 311 | @echo "Mupen64Plus-audio-sdl makefile. " |
| | 312 | @echo " Targets:" |
| | 313 | @echo " all == Build Mupen64Plus SDL audio plugin" |
| | 314 | @echo " clean == remove object files" |
| | 315 | @echo " rebuild == clean and re-build all" |
| | 316 | @echo " install == Install Mupen64Plus SDL audio plugin" |
| | 317 | @echo " uninstall == Uninstall Mupen64Plus SDL audio plugin" |
| | 318 | @echo " Options:" |
| | 319 | @echo " BITS=32 == build 32-bit binaries on 64-bit machine" |
| | 320 | @echo " APIDIR=path == path to find Mupen64Plus Core headers" |
| | 321 | @echo " OPTFLAGS=flag == compiler optimization (default: -O3 -flto)" |
| | 322 | @echo " WARNFLAGS=flag == compiler warning levels (default: -Wall)" |
| | 323 | @echo " PIC=(1|0) == Force enable/disable of position independent code" |
| | 324 | @echo " NO_SRC=1 == build without libsamplerate; disables src-* high-quality audio resampling" |
| | 325 | @echo " NO_SPEEX=1 == build without libspeexdsp; disables speex-* high-quality audio resampling" |
| | 326 | @echo " NO_OSS=1 == build without OSS; disables Open Sound System support" |
| | 327 | @echo " POSTFIX=name == String added to the name of the the build (default: '')" |
| | 328 | @echo " Install Options:" |
| | 329 | @echo " PREFIX=path == install/uninstall prefix (default: /usr/local)" |
| | 330 | @echo " LIBDIR=path == library prefix (default: PREFIX/lib)" |
| | 331 | @echo " PLUGINDIR=path == path to install plugin libraries (default: LIBDIR/mupen64plus)" |
| | 332 | @echo " DESTDIR=path == path to prepend to all installation paths (only for packagers)" |
| | 333 | @echo " Debugging Options:" |
| | 334 | @echo " DEBUG=1 == add debugging symbols" |
| | 335 | @echo " V=1 == show verbose compiler output" |
| | 336 | |
| | 337 | |
| | 338 | all: $(TARGET) |
| | 339 | |
| | 340 | install: $(TARGET) |
| | 341 | $(INSTALL) -d "$(DESTDIR)$(PLUGINDIR)" |
| | 342 | $(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(PLUGINDIR)" |
| | 343 | |
| | 344 | uninstall: |
| | 345 | $(RM) "$(DESTDIR)$(PLUGINDIR)/$(TARGET)" |
| | 346 | |
| | 347 | clean: |
| | 348 | $(RM) -r $(OBJDIR) $(TARGET) |
| | 349 | |
| | 350 | rebuild: clean all |
| | 351 | |
| | 352 | # build dependency files |
| | 353 | CFLAGS += -MD -MP |
| | 354 | -include $(OBJECTS:.o=.d) |
| | 355 | |
| | 356 | # standard build rules |
| | 357 | $(OBJDIR)/%.o: $(SRCDIR)/%.c |
| | 358 | $(COMPILE.c) -o $@ $< |
| | 359 | |
| | 360 | $(TARGET): $(OBJECTS) |
| | 361 | $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ |
| | 362 | |
| | 363 | .PHONY: all clean install uninstall targets |