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# Auto-detect OS if not defined 13 14ifneq ($(BSD),true) 15ifneq ($(HAIKU),true) 16ifneq ($(HURD),true) 17ifneq ($(LINUX),true) 18ifneq ($(MACOS),true) 19ifneq ($(WIN32),true) 20 21TARGET_MACHINE := $(shell $(CC) -dumpmachine) 22ifneq (,$(findstring bsd,$(TARGET_MACHINE))) 23BSD=true 24endif 25ifneq (,$(findstring haiku,$(TARGET_MACHINE))) 26HAIKU=true 27endif 28ifneq (,$(findstring gnu,$(TARGET_MACHINE))) 29HURD=true 30endif 31ifneq (,$(findstring linux,$(TARGET_MACHINE))) 32LINUX=true 33endif 34ifneq (,$(findstring apple,$(TARGET_MACHINE))) 35MACOS=true 36endif 37ifneq (,$(findstring mingw,$(TARGET_MACHINE))) 38WIN32=true 39endif 40 41endif 42endif 43endif 44endif 45endif 46endif 47 48# --------------------------------------------------------------------------------------------------------------------- 49# Set LINUX_OR_MACOS 50 51ifeq ($(LINUX),true) 52LINUX_OR_MACOS=true 53endif 54 55ifeq ($(MACOS),true) 56LINUX_OR_MACOS=true 57endif 58 59# --------------------------------------------------------------------------------------------------------------------- 60# Set MACOS_OR_WIN32 61 62ifeq ($(MACOS),true) 63MACOS_OR_WIN32=true 64endif 65 66ifeq ($(WIN32),true) 67MACOS_OR_WIN32=true 68endif 69 70# --------------------------------------------------------------------------------------------------------------------- 71# Set UNIX 72 73ifeq ($(BSD),true) 74UNIX=true 75endif 76 77ifeq ($(HURD),true) 78UNIX=true 79endif 80 81ifeq ($(LINUX),true) 82UNIX=true 83endif 84 85ifeq ($(MACOS),true) 86UNIX=true 87endif 88 89# --------------------------------------------------------------------------------------------------------------------- 90# Set build and link flags 91 92BASE_FLAGS = -Wall -Wextra -pipe -MD -MP 93BASE_OPTS = -O3 -ffast-math -msse -msse2 -fdata-sections -ffunction-sections 94 95ifeq ($(MACOS),true) 96# MacOS linker flags 97LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs 98else 99# Common linker flags 100LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed 101ifneq ($(SKIP_STRIPPING),true) 102LINK_OPTS += -Wl,--strip-all 103endif 104endif 105 106ifeq ($(NOOPT),true) 107# No CPU-specific optimization flags 108BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections 109endif 110 111ifeq ($(WIN32),true) 112# mingw has issues with this specific optimization 113# See https://github.com/falkTX/Carla/issues/696 114BASE_OPTS += -fno-rerun-cse-after-loop 115# See https://github.com/falkTX/Carla/issues/855 116BASE_OPTS += -mstackrealign 117ifeq ($(BUILDING_FOR_WINDOWS),true) 118BASE_FLAGS += -DBUILDING_CARLA_FOR_WINDOWS 119endif 120else 121# Not needed for Windows 122BASE_FLAGS += -fPIC -DPIC 123endif 124 125ifeq ($(DEBUG),true) 126BASE_FLAGS += -DDEBUG -O0 -g 127LINK_OPTS = 128else 129BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden 130CXXFLAGS += -fvisibility-inlines-hidden 131endif 132 133BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS) 134BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS) 135LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS) 136 137ifneq ($(MACOS),true) 138# Not available on MacOS 139LINK_FLAGS += -Wl,--no-undefined 140endif 141 142ifeq ($(MACOS_OLD),true) 143BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0 144endif 145 146ifeq ($(WIN32),true) 147# Always build statically on windows 148LINK_FLAGS += -static 149endif 150 151# --------------------------------------------------------------------------------------------------------------------- 152# Strict test build 153 154ifeq ($(TESTBUILD),true) 155BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings 156BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5 157# BASE_FLAGS += -Wfloat-equal 158ifeq ($(CC),clang) 159BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command 160BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal 161else 162BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations 163endif 164ifneq ($(MACOS),true) 165BASE_FLAGS += -Wmissing-declarations -Wsign-conversion 166ifneq ($(CC),clang) 167BASE_FLAGS += -Wlogical-op 168endif 169endif 170CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes 171CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual 172endif 173 174# --------------------------------------------------------------------------------------------------------------------- 175# Check for optional libs 176 177ifeq ($(MACOS_OR_WIN32),true) 178HAVE_DGL = true 179else 180HAVE_DGL = $(shell pkg-config --exists gl x11 && echo true) 181HAVE_JACK = $(shell pkg-config --exists jack && echo true) 182HAVE_LIBLO = $(shell pkg-config --exists liblo && echo true) 183endif 184 185# --------------------------------------------------------------------------------------------------------------------- 186# Set libs stuff 187 188ifeq ($(HAVE_DGL),true) 189 190ifeq ($(MACOS),true) 191DGL_LIBS = -framework OpenGL -framework Cocoa 192endif 193 194ifeq ($(WIN32),true) 195DGL_LIBS = -lopengl32 -lgdi32 196endif 197 198ifneq ($(MACOS_OR_WIN32),true) 199DGL_FLAGS = $(shell pkg-config --cflags gl x11) 200DGL_LIBS = $(shell pkg-config --libs gl x11) 201endif 202 203endif # HAVE_DGL 204 205# --------------------------------------------------------------------------------------------------------------------- 206# Set app extension 207 208ifeq ($(WIN32),true) 209APP_EXT = .exe 210endif 211 212# --------------------------------------------------------------------------------------------------------------------- 213# Set shared lib extension 214 215LIB_EXT = .so 216 217ifeq ($(MACOS),true) 218LIB_EXT = .dylib 219endif 220 221ifeq ($(WIN32),true) 222LIB_EXT = .dll 223endif 224 225# --------------------------------------------------------------------------------------------------------------------- 226# Set shared library CLI arg 227 228SHARED = -shared 229 230ifeq ($(MACOS),true) 231SHARED = -dynamiclib 232endif 233 234# --------------------------------------------------------------------------------------------------------------------- 235