1#!/usr/bin/make -f 2# Makefile for DPF # 3# ---------------- # 4# Created by falkTX 5# 6 7AR ?= ar 8CC ?= gcc 9CXX ?= g++ 10 11# --------------------------------------------------------------------------------------------------------------------- 12# Protect against multiple inclusion 13 14ifneq ($(DPF_MAKEFILE_BASE_INCLUDED),true) 15 16DPF_MAKEFILE_BASE_INCLUDED = true 17 18# --------------------------------------------------------------------------------------------------------------------- 19# Auto-detect OS if not defined 20 21TARGET_MACHINE := $(shell $(CC) -dumpmachine) 22 23ifneq ($(BSD),true) 24ifneq ($(HAIKU),true) 25ifneq ($(HURD),true) 26ifneq ($(LINUX),true) 27ifneq ($(MACOS),true) 28ifneq ($(WINDOWS),true) 29 30ifneq (,$(findstring bsd,$(TARGET_MACHINE))) 31BSD=true 32endif 33ifneq (,$(findstring haiku,$(TARGET_MACHINE))) 34HAIKU=true 35endif 36ifneq (,$(findstring linux,$(TARGET_MACHINE))) 37LINUX=true 38else ifneq (,$(findstring gnu,$(TARGET_MACHINE))) 39HURD=true 40endif 41ifneq (,$(findstring apple,$(TARGET_MACHINE))) 42MACOS=true 43endif 44ifneq (,$(findstring mingw,$(TARGET_MACHINE))) 45WINDOWS=true 46endif 47ifneq (,$(findstring windows,$(TARGET_MACHINE))) 48WINDOWS=true 49endif 50 51endif 52endif 53endif 54endif 55endif 56endif 57 58# --------------------------------------------------------------------------------------------------------------------- 59# Auto-detect the processor 60 61TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE))) 62 63ifneq (,$(filter i%86,$(TARGET_PROCESSOR))) 64CPU_I386=true 65CPU_I386_OR_X86_64=true 66endif 67ifneq (,$(filter x86_64,$(TARGET_PROCESSOR))) 68CPU_X86_64=true 69CPU_I386_OR_X86_64=true 70endif 71ifneq (,$(filter arm%,$(TARGET_PROCESSOR))) 72CPU_ARM=true 73CPU_ARM_OR_AARCH64=true 74endif 75ifneq (,$(filter arm64%,$(TARGET_PROCESSOR))) 76CPU_ARM64=true 77CPU_ARM_OR_AARCH64=true 78endif 79ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR))) 80CPU_AARCH64=true 81CPU_ARM_OR_AARCH64=true 82endif 83 84# --------------------------------------------------------------------------------------------------------------------- 85# Set PKG_CONFIG (can be overridden by environment variable) 86 87ifeq ($(WINDOWS),true) 88# Build statically on Windows by default 89PKG_CONFIG ?= pkg-config --static 90else 91PKG_CONFIG ?= pkg-config 92endif 93 94# --------------------------------------------------------------------------------------------------------------------- 95# Set LINUX_OR_MACOS 96 97ifeq ($(LINUX),true) 98LINUX_OR_MACOS=true 99endif 100 101ifeq ($(MACOS),true) 102LINUX_OR_MACOS=true 103endif 104 105# --------------------------------------------------------------------------------------------------------------------- 106# Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS 107 108ifeq ($(HAIKU),true) 109HAIKU_OR_MACOS_OR_WINDOWS=true 110endif 111 112ifeq ($(MACOS),true) 113MACOS_OR_WINDOWS=true 114HAIKU_OR_MACOS_OR_WINDOWS=true 115endif 116 117ifeq ($(WINDOWS),true) 118MACOS_OR_WINDOWS=true 119HAIKU_OR_MACOS_OR_WINDOWS=true 120endif 121 122# --------------------------------------------------------------------------------------------------------------------- 123# Set UNIX 124 125ifeq ($(BSD),true) 126UNIX=true 127endif 128 129ifeq ($(HURD),true) 130UNIX=true 131endif 132 133ifeq ($(LINUX),true) 134UNIX=true 135endif 136 137ifeq ($(MACOS),true) 138UNIX=true 139endif 140 141# --------------------------------------------------------------------------------------------------------------------- 142# Set build and link flags 143 144BASE_FLAGS = -Wall -Wextra -pipe -MD -MP 145BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections 146 147ifeq ($(CPU_I386_OR_X86_64),true) 148BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse 149endif 150 151ifeq ($(CPU_ARM),true) 152ifneq ($(CPU_ARM64),true) 153BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard 154endif 155endif 156 157ifeq ($(MACOS),true) 158# MacOS linker flags 159LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs 160ifneq ($(SKIP_STRIPPING),true) 161LINK_OPTS += -Wl,-x 162endif 163else 164# Common linker flags 165LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed 166ifneq ($(SKIP_STRIPPING),true) 167LINK_OPTS += -Wl,--strip-all 168endif 169endif 170 171ifeq ($(NOOPT),true) 172# Non-CPU-specific optimization flags 173BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections 174endif 175 176ifeq ($(WINDOWS),true) 177# Needed for windows, see https://github.com/falkTX/Carla/issues/855 178BASE_OPTS += -mstackrealign 179else 180# Not needed for Windows 181BASE_FLAGS += -fPIC -DPIC 182endif 183 184ifeq ($(DEBUG),true) 185BASE_FLAGS += -DDEBUG -O0 -g 186LINK_OPTS = 187else 188BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden 189CXXFLAGS += -fvisibility-inlines-hidden 190endif 191 192BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS) 193BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++11 $(CXXFLAGS) 194LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS) 195 196ifneq ($(MACOS),true) 197# Not available on MacOS 198LINK_FLAGS += -Wl,--no-undefined 199endif 200 201ifeq ($(MACOS_OLD),true) 202BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0 203endif 204 205ifeq ($(WINDOWS),true) 206# Always build statically on windows 207LINK_FLAGS += -static -static-libgcc -static-libstdc++ 208endif 209 210# --------------------------------------------------------------------------------------------------------------------- 211# Strict test build 212 213ifeq ($(TESTBUILD),true) 214BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings 215BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5 216# BASE_FLAGS += -Wfloat-equal 217ifeq ($(CC),clang) 218BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command 219BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal 220else 221BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations 222endif 223ifneq ($(MACOS),true) 224BASE_FLAGS += -Wmissing-declarations -Wsign-conversion 225ifneq ($(CC),clang) 226BASE_FLAGS += -Wlogical-op 227endif 228endif 229CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes 230CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual 231endif 232 233# --------------------------------------------------------------------------------------------------------------------- 234# Check for required libraries 235 236HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true) 237 238# Vulkan is not supported yet 239# HAVE_VULKAN = $(shell $(PKG_CONFIG) --exists vulkan && echo true) 240 241ifeq ($(MACOS_OR_WINDOWS),true) 242HAVE_OPENGL = true 243else 244HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true) 245ifneq ($(HAIKU),true) 246HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true) 247HAVE_XCURSOR = $(shell $(PKG_CONFIG) --exists xcursor && echo true) 248HAVE_XEXT = $(shell $(PKG_CONFIG) --exists xext && echo true) 249HAVE_XRANDR = $(shell $(PKG_CONFIG) --exists xrandr && echo true) 250endif 251endif 252 253# --------------------------------------------------------------------------------------------------------------------- 254# Check for optional libraries 255 256HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true) 257 258ifeq ($(MACOS),true) 259HAVE_RTAUDIO = true 260else ifeq ($(WINDOWS),true) 261HAVE_RTAUDIO = true 262else ifneq ($(HAIKU),true) 263HAVE_ALSA = $(shell $(PKG_CONFIG) --exists alsa && echo true) 264HAVE_PULSEAUDIO = $(shell $(PKG_CONFIG) --exists libpulse-simple && echo true) 265ifeq ($(HAVE_ALSA),true) 266HAVE_RTAUDIO = true 267else ifeq ($(HAVE_PULSEAUDIO),true) 268HAVE_RTAUDIO = true 269endif 270endif 271 272# backwards compat 273HAVE_JACK = true 274 275# --------------------------------------------------------------------------------------------------------------------- 276# Set Generic DGL stuff 277 278ifeq ($(HAIKU),true) 279DGL_SYSTEM_LIBS += -lbe 280endif 281 282ifeq ($(MACOS),true) 283DGL_SYSTEM_LIBS += -framework Cocoa -framework CoreVideo 284endif 285 286ifeq ($(WINDOWS),true) 287DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32 288endif 289 290ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true) 291ifeq ($(HAVE_X11),true) 292DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11 293DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11) 294ifeq ($(HAVE_XCURSOR),true) 295# TODO -DHAVE_XCURSOR 296DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) 297DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor) 298endif 299ifeq ($(HAVE_XEXT),true) 300DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC 301DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext) 302endif 303ifeq ($(HAVE_XRANDR),true) 304DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR 305DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr) 306endif 307endif 308endif 309 310# --------------------------------------------------------------------------------------------------------------------- 311# Set Cairo specific stuff 312 313ifeq ($(HAVE_CAIRO),true) 314 315DGL_FLAGS += -DHAVE_CAIRO 316 317CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo) 318CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo) 319 320HAVE_CAIRO_OR_OPENGL = true 321 322endif 323 324# --------------------------------------------------------------------------------------------------------------------- 325# Set OpenGL specific stuff 326 327ifeq ($(HAVE_OPENGL),true) 328 329DGL_FLAGS += -DHAVE_OPENGL 330 331ifeq ($(HAIKU),true) 332OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl) 333OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl) 334endif 335 336ifeq ($(MACOS),true) 337OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations 338OPENGL_LIBS = -framework OpenGL 339endif 340 341ifeq ($(WINDOWS),true) 342OPENGL_LIBS = -lopengl32 343endif 344 345ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true) 346OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11) 347OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11) 348endif 349 350HAVE_CAIRO_OR_OPENGL = true 351 352endif 353 354# --------------------------------------------------------------------------------------------------------------------- 355# Set Stub specific stuff 356 357ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true) 358HAVE_STUB = true 359else 360HAVE_STUB = $(HAVE_X11) 361endif 362 363# --------------------------------------------------------------------------------------------------------------------- 364# Set Vulkan specific stuff 365 366ifeq ($(HAVE_VULKAN),true) 367 368DGL_FLAGS += -DHAVE_VULKAN 369 370VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan) 371VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan) 372 373ifneq ($(WINDOWS),true) 374VULKAN_LIBS += -ldl 375endif 376 377endif 378 379# --------------------------------------------------------------------------------------------------------------------- 380# Set optional libraries specific stuff 381 382ifeq ($(HAVE_ALSA),true) 383ALSA_FLAGS = $(shell $(PKG_CONFIG) --cflags alsa) 384ALSA_LIBS = $(shell $(PKG_CONFIG) --libs alsa) 385endif 386 387ifeq ($(HAVE_LIBLO),true) 388LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo) 389LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo) 390endif 391 392ifeq ($(HAVE_PULSEAUDIO),true) 393PULSEAUDIO_FLAGS = $(shell $(PKG_CONFIG) --cflags libpulse-simple) 394PULSEAUDIO_LIBS = $(shell $(PKG_CONFIG) --libs libpulse-simple) 395endif 396 397ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true) 398SHARED_MEMORY_LIBS = -lrt 399endif 400 401# --------------------------------------------------------------------------------------------------------------------- 402# Backwards-compatible HAVE_DGL 403 404ifeq ($(MACOS_OR_WINDOWS),true) 405HAVE_DGL = true 406else ifeq ($(HAVE_OPENGL),true) 407ifeq ($(HAIKU),true) 408HAVE_DGL = true 409else 410HAVE_DGL = $(HAVE_X11) 411endif 412endif 413 414# --------------------------------------------------------------------------------------------------------------------- 415# Set app extension 416 417ifeq ($(WINDOWS),true) 418APP_EXT = .exe 419endif 420 421# --------------------------------------------------------------------------------------------------------------------- 422# Set shared lib extension 423 424LIB_EXT = .so 425 426ifeq ($(MACOS),true) 427LIB_EXT = .dylib 428endif 429 430ifeq ($(WINDOWS),true) 431LIB_EXT = .dll 432endif 433 434# --------------------------------------------------------------------------------------------------------------------- 435# Set shared library CLI arg 436 437ifeq ($(MACOS),true) 438SHARED = -dynamiclib 439else 440SHARED = -shared 441endif 442 443# --------------------------------------------------------------------------------------------------------------------- 444# Handle the verbosity switch 445 446ifeq ($(VERBOSE),true) 447SILENT = 448else 449SILENT = @ 450endif 451 452# --------------------------------------------------------------------------------------------------------------------- 453# all needs to be first 454 455all: 456 457# --------------------------------------------------------------------------------------------------------------------- 458# helper to print what is available/possible to build 459 460print_available = @echo $(1): $(shell echo $($(1)) | grep -q true && echo Yes || echo No) 461 462features: 463 @echo === Detected CPU 464 $(call print_available,CPU_AARCH64) 465 $(call print_available,CPU_ARM) 466 $(call print_available,CPU_ARM64) 467 $(call print_available,CPU_ARM_OR_AARCH64) 468 $(call print_available,CPU_I386) 469 $(call print_available,CPU_I386_OR_X86_64) 470 @echo === Detected OS 471 $(call print_available,BSD) 472 $(call print_available,HAIKU) 473 $(call print_available,HURD) 474 $(call print_available,LINUX) 475 $(call print_available,MACOS) 476 $(call print_available,WINDOWS) 477 $(call print_available,HAIKU_OR_MACOS_OR_WINDOWS) 478 $(call print_available,LINUX_OR_MACOS) 479 $(call print_available,MACOS_OR_WINDOWS) 480 $(call print_available,UNIX) 481 @echo === Detected features 482 $(call print_available,HAVE_ALSA) 483 $(call print_available,HAVE_CAIRO) 484 $(call print_available,HAVE_DGL) 485 $(call print_available,HAVE_LIBLO) 486 $(call print_available,HAVE_OPENGL) 487 $(call print_available,HAVE_PULSEAUDIO) 488 $(call print_available,HAVE_RTAUDIO) 489 $(call print_available,HAVE_STUB) 490 $(call print_available,HAVE_VULKAN) 491 $(call print_available,HAVE_X11) 492 $(call print_available,HAVE_XCURSOR) 493 $(call print_available,HAVE_XEXT) 494 $(call print_available,HAVE_XRANDR) 495 496# --------------------------------------------------------------------------------------------------------------------- 497# Protect against multiple inclusion 498 499endif # DPF_MAKEFILE_BASE_INCLUDED 500 501# --------------------------------------------------------------------------------------------------------------------- 502