1#!/usr/bin/make -f
2# Makefile for 2FS #
3# ---------------- #
4# Created by falkTX
5#
6
7# ---------------------------------------------------------------------------------------------------------------------
8# Check for fluidsynth
9
10HAVE_FLUIDSYNTH = $(shell pkg-config --exists fluidsynth && echo true)
11
12ifneq ($(HAVE_FLUIDSYNTH),true)
13$(error fluidsynth missing, cannot continue)
14endif
15
16# ---------------------------------------------------------------------------------------------------------------------
17# Fallback to Linux if no other OS defined
18
19ifneq ($(HAIKU),true)
20ifneq ($(MACOS),true)
21ifneq ($(WIN32),true)
22LINUX=true
23endif
24endif
25endif
26
27# ---------------------------------------------------------------------------------------------------------------------
28# Set compiler
29
30CC  ?= gcc
31CXX ?= g++
32
33# ---------------------------------------------------------------------------------------------------------------------
34# Set build and link flags
35
36BASE_FLAGS = -Wall -Wextra -Wshadow -pipe
37BASE_OPTS  = -O2 -ffast-math $(PORT_SIMD_FLAGS) -fdata-sections -ffunction-sections
38
39ifeq ($(MACOS),true)
40# MacOS linker flags
41LINK_OPTS  = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
42else
43# Common linker flags
44LINK_OPTS  = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed -Wl,--strip-all
45endif
46
47ifeq ($(NOOPT),true)
48# No optimization flags
49BASE_OPTS  = -O2 -ffast-math -fdata-sections -ffunction-sections
50endif
51
52ifneq ($(WIN32),true)
53# Not needed for Windows
54BASE_FLAGS += -fPIC -DPIC
55endif
56
57ifeq ($(DEBUG),true)
58BASE_FLAGS += -DDEBUG -O0 -g
59ifeq ($(WIN32),true)
60BASE_FLAGS += -msse -msse2
61endif
62LINK_OPTS   =
63else
64BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
65CXXFLAGS   += -fvisibility-inlines-hidden
66endif
67
68BUILD_C_FLAGS   = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
69BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
70LINK_FLAGS      = $(LINK_OPTS) $(LDFLAGS)
71
72ifneq ($(MACOS),true)
73# Not available on MacOS
74LINK_FLAGS     += -Wl,--no-undefined
75endif
76
77# ---------------------------------------------------------------------------------------------------------------------
78# Set fluidsynth flags
79
80FLUIDSYNTH_FLAGS = $(shell pkg-config --cflags fluidsynth)
81FLUIDSYNTH_LIBS  = $(shell pkg-config --libs fluidsynth)
82
83# ---------------------------------------------------------------------------------------------------------------------
84# Set app extension
85
86ifeq ($(WIN32),true)
87APP_EXT = .exe
88endif
89
90# ---------------------------------------------------------------------------------------------------------------------
91# Set shared lib extension
92
93LIB_EXT = .so
94
95ifeq ($(MACOS),true)
96LIB_EXT = .dylib
97endif
98
99ifeq ($(WIN32),true)
100LIB_EXT = .dll
101endif
102
103# ---------------------------------------------------------------------------------------------------------------------
104# Set shared library CLI arg
105
106ifeq ($(MACOS),true)
107SHARED = -dynamiclib
108else
109SHARED = -shared
110endif
111
112# ---------------------------------------------------------------------------------------------------------------------
113