|
0 |
# Makefile.pdlibbuilder dated 2018-03-15
|
|
1 |
version = 0.5.1
|
|
2 |
|
|
3 |
# Helper makefile for Pure Data external libraries.
|
|
4 |
# Written by Katja Vetter March-June 2015 for the public domain. No warranties.
|
|
5 |
# Inspired by Hans Christoph Steiner's Makefile Template and Stephan Beal's
|
|
6 |
# ShakeNMake.
|
|
7 |
#
|
|
8 |
# Grab the newest version of Makefile.pdlibbuilder from
|
|
9 |
# https://github.com/pure-data/pd-lib-builder/
|
|
10 |
#
|
|
11 |
# GNU make version >= 3.81 required.
|
|
12 |
#
|
|
13 |
#
|
|
14 |
#=== characteristics ===========================================================
|
|
15 |
#
|
|
16 |
#
|
|
17 |
# - defines build settings based on autodetected OS and architecture
|
|
18 |
# - defines rules to build Pd class- or lib executables from C or C++ sources
|
|
19 |
# - defines rules for libdir installation
|
|
20 |
# - defines convenience targets for developer and user
|
|
21 |
# - evaluates implicit dependencies for non-clean builds
|
|
22 |
#
|
|
23 |
#
|
|
24 |
#=== basic usage ===============================================================
|
|
25 |
#
|
|
26 |
#
|
|
27 |
# In your Makefile, define your Pd lib name and class files, and include
|
|
28 |
# Makefile.pdlibbuilder at the end of the Makefile. Like so:
|
|
29 |
#
|
|
30 |
# ________________________________________________________________________
|
|
31 |
#
|
|
32 |
# # Makefile for mylib
|
|
33 |
#
|
|
34 |
# lib.name = mylib
|
|
35 |
#
|
|
36 |
# class.sources = myclass1.c myclass2.c
|
|
37 |
#
|
|
38 |
# datafiles = myclass1-help.pd myclass2-help.pd README.txt LICENSE.txt
|
|
39 |
#
|
|
40 |
# include Makefile.pdlibbuilder
|
|
41 |
# ________________________________________________________________________
|
|
42 |
#
|
|
43 |
#
|
|
44 |
# For files in class.sources it is assumed that class basename == source file
|
|
45 |
# basename. The default target builds all classes as individual executables
|
|
46 |
# with Pd's default extension for the platform. For anything more than the
|
|
47 |
# most basic usage, continue reading.
|
|
48 |
#
|
|
49 |
#
|
|
50 |
#=== list of Makefile.pdlibbuilder API variables ===============================
|
|
51 |
#
|
|
52 |
#
|
|
53 |
# Variables available for definition in your library Makefile:
|
|
54 |
#
|
|
55 |
# - lib.name
|
|
56 |
# - lib.setup.sources
|
|
57 |
# - class.sources
|
|
58 |
# - common.sources
|
|
59 |
# - shared.sources
|
|
60 |
# - <classname>.class.sources
|
|
61 |
# - <classname>.class.ldflags
|
|
62 |
# - <classname>.class.ldlibs
|
|
63 |
# - cflags
|
|
64 |
# - ldflags
|
|
65 |
# - ldlibs
|
|
66 |
# - datafiles
|
|
67 |
# - datadirs
|
|
68 |
# - makefiles
|
|
69 |
# - makefiledirs
|
|
70 |
# - externalsdir
|
|
71 |
#
|
|
72 |
# Optional multiline defines evaluated per operating system:
|
|
73 |
#
|
|
74 |
# - forLinux
|
|
75 |
# - forDarwin
|
|
76 |
# - forWindows
|
|
77 |
#
|
|
78 |
# Variables available for your makefile or make command line:
|
|
79 |
#
|
|
80 |
# - make-lib-executable
|
|
81 |
# - suppress-wunused
|
|
82 |
#
|
|
83 |
# Path variables for make command line or environment:
|
|
84 |
#
|
|
85 |
# - PDDIR
|
|
86 |
# - PDINCLUDEDIR
|
|
87 |
# - PDBINDIR
|
|
88 |
# - PDLIBDIR
|
|
89 |
#
|
|
90 |
# Standard make variables for make command line or environment:
|
|
91 |
#
|
|
92 |
# - CPPFLAGS
|
|
93 |
# - CFLAGS
|
|
94 |
# - LDFLAGS
|
|
95 |
# - CC
|
|
96 |
# - CXX
|
|
97 |
# - INSTALL
|
|
98 |
# - STRIP
|
|
99 |
# - DESTDIR
|
|
100 |
#
|
|
101 |
# Deprecated path variables:
|
|
102 |
#
|
|
103 |
# - pdincludepath
|
|
104 |
# - pdbinpath
|
|
105 |
# - objectsdir
|
|
106 |
#
|
|
107 |
#
|
|
108 |
#=== descriptions of Makefile.pdlibbuilder API variables =======================
|
|
109 |
#
|
|
110 |
#
|
|
111 |
# lib.name:
|
|
112 |
# Name of the library directory as it will be installed / distributed. Also the
|
|
113 |
# name of the lib executable in the case where all classes are linked into
|
|
114 |
# a single binary.
|
|
115 |
#
|
|
116 |
# lib.setup.sources:
|
|
117 |
# Source file(s) (C or C++) which must be compiled only when linking all classes
|
|
118 |
# into a single lib binary.
|
|
119 |
#
|
|
120 |
# class.sources:
|
|
121 |
# All sources files (C or C++) for which the condition holds that
|
|
122 |
# class name == source file basename.
|
|
123 |
#
|
|
124 |
# <classname>.class.sources:
|
|
125 |
# Source file(s) (C or C++) specific to class <classname>. Use this for
|
|
126 |
# multiple-source classes or when class name != source file basename.
|
|
127 |
#
|
|
128 |
# common.sources:
|
|
129 |
# Source file(s) which must be statically linked to each class in the library.
|
|
130 |
#
|
|
131 |
# shared.sources:
|
|
132 |
# Source file(s) (C or C++) to build a shared dynamic link lib, to be linked
|
|
133 |
# with all class executables.
|
|
134 |
#
|
|
135 |
# cflags, ldflags, ldlibs:
|
|
136 |
# Define cflags (preprocessor&compiler), ldflags (linker) and ldlibs (dynamic
|
|
137 |
# link libs) for the whole library. These flags are added to platform-specific
|
|
138 |
# flags defined by Makefile.pdlibbuilder.
|
|
139 |
#
|
|
140 |
# <classname>.class.ldflags and <classname>.class.ldlibs:
|
|
141 |
# Define ldflags resp. ldlibs specific to class <classname>. These flags are
|
|
142 |
# added to platform-specific flags defined by Makefile.pdlibbuilder, and flags
|
|
143 |
# defined in your Makefile for the whole library. Note: cflags can not be
|
|
144 |
# defined per class in the current implementation.
|
|
145 |
#
|
|
146 |
# datafiles and datadirs:
|
|
147 |
# All extra files you want to include in binary distributions of the
|
|
148 |
# library: abstractions and help patches, example patches, meta patch, readme
|
|
149 |
# and license texts, manuals, sound files, etcetera. Use 'datafiles' for all
|
|
150 |
# files that should go into your lib rootdir and 'datadirs' for complete
|
|
151 |
# directories you want to copy from source to distribution.
|
|
152 |
#
|
|
153 |
# forLinux, forDarwin, forWindows:
|
|
154 |
# Shorthand for 'variable definitions for Linux only' etc. Use like:
|
|
155 |
# define forLinux
|
|
156 |
# cflags += -DLINUX
|
|
157 |
# class.sources += linuxthing.c
|
|
158 |
# endef
|
|
159 |
#
|
|
160 |
# makefiles and makefiledirs:
|
|
161 |
# Extra makefiles or directories with makefiles that should be made in sub-make
|
|
162 |
# processes.
|
|
163 |
#
|
|
164 |
# make-lib-executable:
|
|
165 |
# When this variable is defined 'yes' in your makefile or as command argument,
|
|
166 |
# Makefile.pdlibbuilder will try to build all classes into a single library
|
|
167 |
# executable (but it will force exit if lib.setup.sources is undefined).
|
|
168 |
# If your makefile defines 'make-lib-executable=yes' as the library default,
|
|
169 |
# this can still be overridden with 'make-lib-executable=no' as command argument
|
|
170 |
# to build individual class executables (the Makefile.pdlibbuilder default.)
|
|
171 |
#
|
|
172 |
# suppress-wunused:
|
|
173 |
# When this variable is defined ('yes' or any other value), -Wunused-variable,
|
|
174 |
# -Wunused-parameter, -Wunused-value and -Wunused-function are suppressed,
|
|
175 |
# but the other warnings from -Wall are retained.
|
|
176 |
#
|
|
177 |
# PDDIR:
|
|
178 |
# Root directory of 'portable' pd package. When defined, PDINCLUDEDIR and
|
|
179 |
# PDBINDIR will be evaluated as $(PDDIR)/src and $(PDDIR)/bin.
|
|
180 |
#
|
|
181 |
# PDINCLUDEDIR:
|
|
182 |
# Directory where Pd API m_pd.h should be found, and other Pd header files.
|
|
183 |
# Overrides the default search path.
|
|
184 |
#
|
|
185 |
# PDBINDIR:
|
|
186 |
# Directory where pd.dll should be found for linking (Windows only). Overrides
|
|
187 |
# the default search path.
|
|
188 |
#
|
|
189 |
# PDLIBDIR:
|
|
190 |
# Root directory for installation of Pd library directories. Overrides the
|
|
191 |
# default install location.
|
|
192 |
#
|
|
193 |
# DESTDIR:
|
|
194 |
# Prepended path component for staged install.
|
|
195 |
#
|
|
196 |
# CPPFLAGS:
|
|
197 |
# Preprocessor flags which are not strictly required for building.
|
|
198 |
#
|
|
199 |
# CFLAGS:
|
|
200 |
# Compiler flags which are not strictly required for building. Compiler flags
|
|
201 |
# defined by Makefile.pdlibbuilder for warning, optimization and architecture
|
|
202 |
# specification are overriden by CFLAGS.
|
|
203 |
#
|
|
204 |
# LDFLAGS:
|
|
205 |
# Linker flags which are not strictly required for building. Linker flags
|
|
206 |
# defined by Makefile.pdlibbuilder for architecture specification are overriden
|
|
207 |
# by LDFLAGS.
|
|
208 |
#
|
|
209 |
# CC and CXX:
|
|
210 |
# C and C++ compiler programs as defined in your build environment.
|
|
211 |
#
|
|
212 |
# INSTALL
|
|
213 |
# Definition of install program.
|
|
214 |
#
|
|
215 |
# STRIP
|
|
216 |
# Name of strip program. Default 'strip' can be overridden in cross compilation
|
|
217 |
# environments.
|
|
218 |
#
|
|
219 |
# objectsdir:
|
|
220 |
# Root directory for installation of Pd library directories, like PDLIBDIR but
|
|
221 |
# not overridable by environment. Supported for compatibility with pd-extended
|
|
222 |
# central makefile, but deprecated otherwise.
|
|
223 |
#
|
|
224 |
# pdincludepath, pdbinpath:
|
|
225 |
# As PDINCLUDEDIR and PDBINDIR but not overridable by environment. Deprecated
|
|
226 |
# as user variables.
|
|
227 |
#
|
|
228 |
#
|
|
229 |
#=== paths =====================================================================
|
|
230 |
#
|
|
231 |
#
|
|
232 |
# Source files in directories other than current working directory must be
|
|
233 |
# prefixed with their relative path. Do not rely on VPATH or vpath.
|
|
234 |
# Object (.o) files are built in the directory of their source files.
|
|
235 |
# Executables are built in current working directory.
|
|
236 |
#
|
|
237 |
# Default search path for m_pd.h and other API header files is platform
|
|
238 |
# dependent, and overridable by PDINCLUDEDIR:
|
|
239 |
#
|
|
240 |
# Linux: /usr/include/pd
|
|
241 |
#
|
|
242 |
# OSX: /Applications/Pd*.app/Contents/Resources/src
|
|
243 |
#
|
|
244 |
# Windows: %PROGRAMFILES%/Pd/src
|
|
245 |
# %PROGRAMFILES(X86)%/Pd/src (32 bit builds on 64 bit Windows)
|
|
246 |
#
|
|
247 |
# Default search path for binary pd.dll (Windows), overridable by PDBINDIR
|
|
248 |
#
|
|
249 |
# %PROGRAMFILES%/Pd/bin
|
|
250 |
# %PROGRAMFILES(X86)%/Pd/bin (32 bit builds on 64 bit Windows)
|
|
251 |
#
|
|
252 |
# Default location to install pd libraries is platform dependent, and
|
|
253 |
# overridable by PDLIBDIR:
|
|
254 |
#
|
|
255 |
# Linux: /usr/local/lib/pd-externals
|
|
256 |
# OSX: ~/Library/Pd
|
|
257 |
# Windows: %APPDATA%/Pd
|
|
258 |
#
|
|
259 |
# https://puredata.info/docs/faq/how-do-i-install-externals-and-help-files
|
|
260 |
# The rationale for not installing to ~/pd-externals by default on Linux
|
|
261 |
# is that some people share the home dir between 32 and 64 bit installations.
|
|
262 |
#
|
|
263 |
#
|
|
264 |
#=== targets ===================================================================
|
|
265 |
#
|
|
266 |
#
|
|
267 |
# all: build $(executables) plus optional post target
|
|
268 |
# post: target to build after $(executables)
|
|
269 |
# alldebug: build all with -g option turned on for debug symbols
|
|
270 |
# <classname>: force clean build of an individual class
|
|
271 |
# <sourcefile>.pre: make preprocessor output file in current working directory
|
|
272 |
# <sourcefile>.lst: make asm/source output file in current working directory
|
|
273 |
#
|
|
274 |
# install: install executables and data files
|
|
275 |
# clean: remove build products from source tree
|
|
276 |
#
|
|
277 |
# help: print help text
|
|
278 |
# vars: print makefile variables
|
|
279 |
# allvars: print all variables
|
|
280 |
# depend: print generated prerequisites
|
|
281 |
# coffee: dummy target
|
|
282 |
#
|
|
283 |
# Variable $(executables) expands to class executables plus optional shared lib,
|
|
284 |
# or alternatively to single lib executable when make-lib-executable=true.
|
|
285 |
# Targets pre and post can be defined by library makefile. Make sure to include
|
|
286 |
# Makefile.pdlibbuilder first so default target all will not be redefined.
|
|
287 |
#
|
|
288 |
#
|
|
289 |
#=== Pd-extended libdir concept ================================================
|
|
290 |
#
|
|
291 |
#
|
|
292 |
# For libdir layout as conceived by Hans-Christoph Steiner, see:
|
|
293 |
#
|
|
294 |
# https://puredata.info/docs/developer/Libdir
|
|
295 |
#
|
|
296 |
# Files README.txt, LICENSE.txt and <lib.name>-meta.pd are part of the libdir
|
|
297 |
# convention. Help patches for each class and abstraction are supposed to be
|
|
298 |
# available. Makefile.pdlibbuilder does not force the presence of these files
|
|
299 |
# however. It does not automatically include such files in libdir installations.
|
|
300 |
# Data files you want to include in distributions must be defined explicitly in
|
|
301 |
# your Makefile.
|
|
302 |
#
|
|
303 |
#
|
|
304 |
#=== Makefile.pdlibbuilder syntax conventions ==================================
|
|
305 |
#
|
|
306 |
#
|
|
307 |
# Makefile.pdlibbuilder variable names are lower case. Default make variables,
|
|
308 |
# environment variables, and standard user variables (CC, CXX, CFLAGS, DESTDIR)
|
|
309 |
# are upper case. Use target 'allvars' to print all variables and their values.
|
|
310 |
#
|
|
311 |
# 'Fields' in data variables are separated by dots, like in 'foo.class.sources'.
|
|
312 |
# Words in variables expressing a function or command are separated by dashes,
|
|
313 |
# like in 'make-lib-executable'.
|
|
314 |
#
|
|
315 |
#
|
|
316 |
#=== useful make options =======================================================
|
|
317 |
#
|
|
318 |
#
|
|
319 |
# Use 'make -d <target>' to print debug details of the make process.
|
|
320 |
# Use 'make -p <target>' to print make's database.
|
|
321 |
#
|
|
322 |
#
|
|
323 |
#=== TODO ======================================================================
|
|
324 |
#
|
|
325 |
#
|
|
326 |
# - decide whether to use -static-libgcc or shared dll in MinGW
|
|
327 |
# - cygwin support
|
|
328 |
# - android support
|
|
329 |
# - figure out how to handle '$' in filenames
|
|
330 |
# - add makefile template targets dpkg-source dist libdir distclean tags?
|
|
331 |
#
|
|
332 |
#
|
|
333 |
#=== end of documentation sections =============================================
|
|
334 |
#
|
|
335 |
#
|
|
336 |
################################################################################
|
|
337 |
################################################################################
|
|
338 |
################################################################################
|
|
339 |
|
|
340 |
|
|
341 |
# GNU make version 3.81 (2006) or higher is required because of the following:
|
|
342 |
# - function 'info'
|
|
343 |
# - variable '.DEFAULT_GOAL'
|
|
344 |
|
|
345 |
# force exit when make version is < 3.81
|
|
346 |
ifneq ($(firstword $(sort 3.81 $(MAKE_VERSION))), 3.81)
|
|
347 |
$(error GNU make version 3.81 or higher is required)
|
|
348 |
endif
|
|
349 |
|
|
350 |
# Relative path to externals root dir in multi-lib source tree like
|
|
351 |
# pd-extended SVN. Default is parent of current working directory. May be
|
|
352 |
# defined differently in including makefile.
|
|
353 |
externalsdir ?= ..
|
|
354 |
|
|
355 |
# variable you can use to check if Makefile.pdlibbuilder is already included
|
|
356 |
Makefile.pdlibbuilder = true
|
|
357 |
|
|
358 |
|
|
359 |
################################################################################
|
|
360 |
### variables: library name and version ########################################
|
|
361 |
################################################################################
|
|
362 |
|
|
363 |
|
|
364 |
# strip possibles spaces from lib.name, they mess up calculated file names
|
|
365 |
lib.name := $(strip $(lib.name))
|
|
366 |
|
|
367 |
# if meta file exists, check library version
|
|
368 |
metafile := $(wildcard $(lib.name)-meta.pd)
|
|
369 |
|
|
370 |
ifdef metafile
|
|
371 |
lib.version := $(shell sed -n \
|
|
372 |
's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' \
|
|
373 |
$(metafile))
|
|
374 |
endif
|
|
375 |
|
|
376 |
|
|
377 |
################################################################################
|
|
378 |
### variables: files ###########################################################
|
|
379 |
################################################################################
|
|
380 |
|
|
381 |
|
|
382 |
#=== sources ===================================================================
|
|
383 |
|
|
384 |
|
|
385 |
# (re)define <classname>.class.sources using file names in class.sources
|
|
386 |
|
|
387 |
define add-class-source
|
|
388 |
$(notdir $(basename $v)).class.sources += $v
|
|
389 |
endef
|
|
390 |
|
|
391 |
$(foreach v, $(class.sources), $(eval $(add-class-source)))
|
|
392 |
|
|
393 |
# derive class names from <classname>.class.sources variables
|
|
394 |
sourcevariables := $(filter %.class.sources, $(.VARIABLES))
|
|
395 |
classes := $(basename $(basename $(sourcevariables)))
|
|
396 |
|
|
397 |
# accumulate all source files specified in makefile
|
|
398 |
classes.sources := $(sort $(foreach v, $(sourcevariables), $($v)))
|
|
399 |
all.sources := $(classes.sources) $(lib.setup.sources) \
|
|
400 |
$(shared.sources) $(common.sources)
|
|
401 |
|
|
402 |
|
|
403 |
#=== object files ==============================================================
|
|
404 |
|
|
405 |
|
|
406 |
# construct object filenames from all C and C++ source file names
|
|
407 |
classes.objects := $(addsuffix .o, $(basename $(classes.sources)))
|
|
408 |
common.objects := $(addsuffix .o, $(basename $(common.sources)))
|
|
409 |
shared.objects := $(addsuffix .o, $(basename $(shared.sources)))
|
|
410 |
lib.setup.objects := $(addsuffix .o, $(basename $(lib.setup.sources)))
|
|
411 |
all.objects = $(classes.objects) $(common.objects) $(shared.objects) \
|
|
412 |
$(lib.setup.objects)
|
|
413 |
|
|
414 |
|
|
415 |
#=== executables ===============================================================
|
|
416 |
|
|
417 |
|
|
418 |
# use recursive variables here because executable extension is not yet known
|
|
419 |
|
|
420 |
# construct class executable names from class names
|
|
421 |
classes.executables = $(addsuffix .$(extension), $(classes))
|
|
422 |
|
|
423 |
# construct shared lib executable name if shared sources are defined
|
|
424 |
ifdef shared.sources
|
|
425 |
shared.lib = lib$(lib.name).$(shared.extension)
|
|
426 |
else
|
|
427 |
shared.lib =
|
|
428 |
endif
|
|
429 |
|
|
430 |
|
|
431 |
################################################################################
|
|
432 |
### platform detection #########################################################
|
|
433 |
################################################################################
|
|
434 |
|
|
435 |
|
|
436 |
#=== operating system ==========================================================
|
|
437 |
|
|
438 |
|
|
439 |
# The following systems are defined: Linux, Darwin, Windows. GNU and
|
|
440 |
# GNU/kFreeBSD are treated as Linux to get the same options.
|
|
441 |
|
|
442 |
uname := $(shell uname)
|
|
443 |
|
|
444 |
ifeq ($(findstring $(uname), Linux GNU GNU/kFreeBSD), $(uname))
|
|
445 |
system = Linux
|
|
446 |
endif
|
|
447 |
|
|
448 |
ifeq ($(uname), Darwin)
|
|
449 |
system = Darwin
|
|
450 |
endif
|
|
451 |
|
|
452 |
ifeq ($(filter MINGW% MSYS%, $(uname)), $(uname))
|
|
453 |
system = Windows
|
|
454 |
endif
|
|
455 |
|
|
456 |
# Unfortunately not all Mingw versions provide a link cc > gcc, therefore
|
|
457 |
# gcc is hardcoded here (but not if CC is redefined).
|
|
458 |
ifeq ($(system), Windows)
|
|
459 |
ifeq ($(origin CC), default)
|
|
460 |
CC = gcc
|
|
461 |
endif
|
|
462 |
endif
|
|
463 |
|
|
464 |
# evaluate possible system-specific multiline defines from library makefile
|
|
465 |
$(eval $(for$(system)))
|
|
466 |
|
|
467 |
|
|
468 |
# TODO: Cygwin, Android
|
|
469 |
|
|
470 |
|
|
471 |
#=== architecture ==============================================================
|
|
472 |
|
|
473 |
|
|
474 |
# native architecture of the build machine
|
|
475 |
build.arch := $(shell uname -m)
|
|
476 |
|
|
477 |
# Target architecture as reported by compiler. Give precedence to eventual
|
|
478 |
# user-defined compiler. The first field of <cpu>-<vendor>-<os> is extracted.
|
|
479 |
ifneq ($(origin CXX), default)
|
|
480 |
dumpmachine.cpu = $(firstword $(subst -, ,$(shell $(CXX) -dumpmachine)))
|
|
481 |
else
|
|
482 |
dumpmachine.cpu = $(firstword $(subst -, ,$(shell $(CC) -dumpmachine)))
|
|
483 |
endif
|
|
484 |
|
|
485 |
# Target architecture as reported by compiler is only used for Windows at the
|
|
486 |
# moment. For other systems this still has to be tested.
|
|
487 |
ifeq ($(system), Windows)
|
|
488 |
target.arch = $(dumpmachine.cpu)
|
|
489 |
else
|
|
490 |
target.arch = $(build.arch)
|
|
491 |
endif
|
|
492 |
|
|
493 |
|
|
494 |
################################################################################
|
|
495 |
### variables per platform #####################################################
|
|
496 |
################################################################################
|
|
497 |
|
|
498 |
|
|
499 |
#=== flags per architecture ====================================================
|
|
500 |
|
|
501 |
|
|
502 |
# Set architecture-dependent cflags, mainly for Linux. For Mac and Windows,
|
|
503 |
# arch.c.flags are overriden below.
|
|
504 |
|
|
505 |
# Raspberry Pi 1st generation
|
|
506 |
ifeq ($(target.arch), armv6l)
|
|
507 |
arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard
|
|
508 |
|
|
509 |
# Beagle, Udoo, RPi2 etc.
|
|
510 |
else ifeq ($(target.arch), armv7l)
|
|
511 |
arch.c.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard
|
|
512 |
|
|
513 |
# Intel 32 bit, build with SSE and SSE2 instructions
|
|
514 |
else ifeq ($(findstring $(target.arch), i386 i686), $(target.arch))
|
|
515 |
arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2
|
|
516 |
|
|
517 |
# Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions
|
|
518 |
else ifeq ($(findstring $(target.arch), x86_64), $(target.arch))
|
|
519 |
arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3
|
|
520 |
|
|
521 |
# if none of the above architectures detected
|
|
522 |
else
|
|
523 |
arch.c.flags =
|
|
524 |
endif
|
|
525 |
|
|
526 |
|
|
527 |
#=== flags and paths for Linux =================================================
|
|
528 |
|
|
529 |
|
|
530 |
ifeq ($(system), Linux)
|
|
531 |
prefix = /usr/local
|
|
532 |
libdir := $(prefix)/lib
|
|
533 |
pkglibdir = $(libdir)/pd-externals
|
|
534 |
pdincludepath := $(wildcard /usr/include/pd)
|
|
535 |
extension = pd_linux
|
|
536 |
cpp.flags := -DUNIX
|
|
537 |
c.flags := -fPIC
|
|
538 |
c.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags
|
|
539 |
c.ldlibs := -lc -lm
|
|
540 |
cxx.flags := -fPIC -fcheck-new
|
|
541 |
cxx.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags
|
|
542 |
cxx.ldlibs := -lc -lm -lstdc++
|
|
543 |
shared.extension = so
|
|
544 |
shared.ldflags := -rdynamic -fPIC -shared -Wl,-soname,$(shared.lib)
|
|
545 |
endif
|
|
546 |
|
|
547 |
|
|
548 |
#=== flags and paths for Darwin ================================================
|
|
549 |
|
|
550 |
|
|
551 |
# On OSX we try to build fat binaries by default. It is assumed that OSX i386
|
|
552 |
# can build for ppc and OSX x86_64 can't. TODO: try to refine this condition.
|
|
553 |
# LLVM-clang doesn't support -fcheck-new, therefore this flag is omitted for
|
|
554 |
# OSX x86_64.
|
|
555 |
|
|
556 |
|
|
557 |
ifeq ($(system), Darwin)
|
|
558 |
pkglibdir = $(HOME)/Library/Pd
|
|
559 |
pdincludepath := $(firstword $(wildcard \
|
|
560 |
/Applications/Pd*.app/Contents/Resources/src))
|
|
561 |
extension = pd_darwin
|
|
562 |
cpp.flags := -DUNIX -DMACOSX -I /sw/include
|
|
563 |
c.flags :=
|
|
564 |
c.ldflags := -undefined suppress -flat_namespace -bundle
|
|
565 |
c.ldlibs := -lc
|
|
566 |
cxx.ldflags := -undefined suppress -flat_namespace -bundle
|
|
567 |
cxx.ldlibs := -lc
|
|
568 |
shared.extension = dylib
|
|
569 |
shared.ldflags = -dynamiclib -undefined dynamic_lookup \
|
|
570 |
-install_name @loader_path/$(shared.lib) \
|
|
571 |
-compatibility_version 1 -current_version 1.0
|
|
572 |
version.flag := $(filter $(cflags), -mmacosx-version-min=%)
|
|
573 |
ifeq ($(target.arch), i386)
|
|
574 |
cxx.flags := -fcheck-new
|
|
575 |
arch := ppc i386 x86_64
|
|
576 |
version.flag = -mmacosx-version-min=10.4
|
|
577 |
endif
|
|
578 |
ifeq ($(target.arch), x86_64)
|
|
579 |
arch := i386 x86_64
|
|
580 |
version.flag = -mmacosx-version-min=10.6
|
|
581 |
endif
|
|
582 |
ifneq ($(filter -mmacosx-version-min=%, $(cflags)),)
|
|
583 |
version.flag := $(filter -mmacosx-version-min=%, $(cflags))
|
|
584 |
endif
|
|
585 |
arch.c.flags := $(addprefix -arch , $(arch)) $(version.flag)
|
|
586 |
arch.ld.flags := $(arch.c.flags)
|
|
587 |
endif
|
|
588 |
|
|
589 |
|
|
590 |
#=== flags and paths for Windows ===============================================
|
|
591 |
|
|
592 |
|
|
593 |
# Standard paths on Windows contain spaces, and GNU make functions treat such
|
|
594 |
# paths as lists, with unintended effects. Therefore we must use shell function
|
|
595 |
# ls instead of make's wildcard when probing for a path, and use double quotes
|
|
596 |
# when specifying a path in a command argument.
|
|
597 |
|
|
598 |
# Default paths in Mingw / Mingw-w64 environments. 'PROGRAMFILES' is standard
|
|
599 |
# location for builds with native architecture, 'ProgramFiles(x86)' for i686
|
|
600 |
# builds on x86_64 Windows (detection method by Lucas Cordiviola). Curly braces
|
|
601 |
# required because of parentheses in variable name.
|
|
602 |
ifeq ($(system), Windows)
|
|
603 |
pkglibdir := $(APPDATA)/Pd
|
|
604 |
ifeq ($(MINGW_CHOST), i686-w64-mingw32)
|
|
605 |
programfiles := ${ProgramFiles(x86)}
|
|
606 |
else
|
|
607 |
programfiles := $(PROGRAMFILES)
|
|
608 |
endif
|
|
609 |
pdbinpath := $(programfiles)/Pd/bin
|
|
610 |
pdincludepath := $(programfiles)/Pd/src
|
|
611 |
endif
|
|
612 |
|
|
613 |
# Store default path to pd.dll in PDBINDIR if the latter is not user-defined.
|
|
614 |
# For include path this is done in the platform-independent paths section below,
|
|
615 |
# but for PDBINDIR it is done here so ld flags can be evaluated as immediate
|
|
616 |
# variables.
|
|
617 |
ifeq ($(system), Windows)
|
|
618 |
ifdef PDDIR
|
|
619 |
PDBINDIR := $(PDDIR)/bin
|
|
620 |
endif
|
|
621 |
PDBINDIR ?= $(pdbinpath)
|
|
622 |
endif
|
|
623 |
|
|
624 |
# TODO: decide whether -mms-bitfields should be specified.
|
|
625 |
ifeq ($(system), Windows)
|
|
626 |
cpp.flags := -DMSW -DNT
|
|
627 |
ifeq ($(filter i%86 mingw32, $(target.arch)), $(target.arch))
|
|
628 |
arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse
|
|
629 |
else ifeq (x86_64, $(target.arch))
|
|
630 |
cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64
|
|
631 |
arch.c.flags := -march=core2 -msse -msse2 -msse3 -mfpmath=sse
|
|
632 |
else
|
|
633 |
arch.c.flags =
|
|
634 |
endif
|
|
635 |
extension = dll
|
|
636 |
c.flags :=
|
|
637 |
c.ldflags := -static-libgcc -shared \
|
|
638 |
-Wl,--enable-auto-import "$(PDBINDIR)/pd.dll"
|
|
639 |
c.ldlibs :=
|
|
640 |
cxx.flags := -fcheck-new
|
|
641 |
cxx.ldflags := -static-libgcc -static-libstdc++ -shared \
|
|
642 |
-Wl,--enable-auto-import "$(PDBINDIR)/pd.dll"
|
|
643 |
cxx.ldlibs :=
|
|
644 |
shared.extension = dll
|
|
645 |
shared.ldflags := -static-libgcc -shared "$(PDBINDIR)/pd.dll"
|
|
646 |
stripflags = --strip-all
|
|
647 |
endif
|
|
648 |
|
|
649 |
|
|
650 |
#=== paths =====================================================================
|
|
651 |
|
|
652 |
|
|
653 |
# Platform-dependent default paths are specified above, but overridable.
|
|
654 |
# Path variables in upper case can be defined as make command argument or in the
|
|
655 |
# environment. Variable 'objectsdir' is supported for compatibility with
|
|
656 |
# the build system that pd-l2ork has inherited from pd-extended.
|
|
657 |
|
|
658 |
PDINCLUDEDIR ?= $(pdincludepath)
|
|
659 |
PDLIBDIR ?= $(firstword $(objectsdir) $(pkglibdir))
|
|
660 |
|
|
661 |
ifdef PDDIR
|
|
662 |
PDINCLUDEDIR := $(wildcard $(PDDIR)/src)
|
|
663 |
endif
|
|
664 |
|
|
665 |
# base path where all components of the lib will be installed by default
|
|
666 |
installpath := $(DESTDIR)$(PDLIBDIR)/$(lib.name)
|
|
667 |
|
|
668 |
# check if include path contains spaces (as is often the case on Windows)
|
|
669 |
# if so, store the path so we can later do checks with it
|
|
670 |
pdincludepathwithspaces := $(if $(word 2, $(PDINCLUDEDIR)), $(PDINCLUDEDIR))
|
|
671 |
|
|
672 |
|
|
673 |
#=== accumulated build flags ===================================================
|
|
674 |
|
|
675 |
|
|
676 |
# From GNU make docs: 'Users expect to be able to specify CFLAGS freely
|
|
677 |
# themselves.' So we use CFLAGS to define options which are not strictly
|
|
678 |
# required for compilation: optimizations, architecture specifications, and
|
|
679 |
# warnings. CFLAGS can be safely overriden using a make command argument.
|
|
680 |
# Variables cflags, ldflags and ldlibs may be defined in including makefile.
|
|
681 |
|
|
682 |
optimization.flags = -O3 -ffast-math -funroll-loops -fomit-frame-pointer
|
|
683 |
warn.flags = -Wall -Wextra -Wshadow -Winline -Wstrict-aliasing
|
|
684 |
|
|
685 |
# suppress -Wunused-variable & Co if you don't want to clutter a build log
|
|
686 |
ifdef suppress-wunused
|
|
687 |
warn.flags += $(addprefix -Wno-unused-, function parameter value variable)
|
|
688 |
endif
|
|
689 |
|
|
690 |
CFLAGS = $(warn.flags) $(optimization.flags) $(arch.c.flags)
|
|
691 |
|
|
692 |
# preprocessor flags
|
|
693 |
cpp.flags := -DPD -I "$(PDINCLUDEDIR)" $(cpp.flags) $(CPPFLAGS)
|
|
694 |
|
|
695 |
# flags for dependency checking (cflags from makefile may define -I options)
|
|
696 |
depcheck.flags := $(cpp.flags) $(cflags)
|
|
697 |
|
|
698 |
# architecture specifications for linker are overridable by LDFLAGS
|
|
699 |
LDFLAGS := $(arch.ld.flags)
|
|
700 |
|
|
701 |
# now add the same ld flags to shared dynamic lib
|
|
702 |
shared.ldflags := $(shared.ldflags) $(LDFLAGS)
|
|
703 |
|
|
704 |
# accumulated flags for C compiler / linker
|
|
705 |
c.flags := $(cpp.flags) $(c.flags) $(cflags) $(CFLAGS)
|
|
706 |
c.ldflags := $(c.ldflags) $(ldflags) $(LDFLAGS)
|
|
707 |
c.ldlibs := $(c.ldlibs) $(ldlibs)
|
|
708 |
|
|
709 |
# accumulated flags for C++ compiler / linker
|
|
710 |
cxx.flags := $(cpp.flags) $(cxx.flags) $(cflags) $(CFLAGS)
|
|
711 |
cxx.ldflags := $(cxx.ldflags) $(ldflags) $(LDFLAGS)
|
|
712 |
cxx.ldlibs := $(cxx.ldlibs) $(ldlibs)
|
|
713 |
|
|
714 |
|
|
715 |
################################################################################
|
|
716 |
### variables: tools ###########################################################
|
|
717 |
################################################################################
|
|
718 |
|
|
719 |
|
|
720 |
# aliases so we can later define 'compile-$1' and set 'c' or 'cxx' as argument
|
|
721 |
compile-c := $(CC)
|
|
722 |
compile-cxx := $(CXX)
|
|
723 |
|
|
724 |
|
|
725 |
################################################################################
|
|
726 |
### checks #####################################################################
|
|
727 |
################################################################################
|
|
728 |
|
|
729 |
|
|
730 |
# At this point most variables are defined. Now do some checks and info's
|
|
731 |
# before rules begin.
|
|
732 |
|
|
733 |
# 'forward declaration' of default target, needed to do checks
|
|
734 |
all:
|
|
735 |
|
|
736 |
# To avoid unpredictable results, make sure the default target is not redefined
|
|
737 |
# by including makefile.
|
|
738 |
ifneq ($(.DEFAULT_GOAL), all)
|
|
739 |
$(error Default target must be 'all'.)
|
|
740 |
endif
|
|
741 |
|
|
742 |
# find out which target(s) will be made
|
|
743 |
ifdef MAKECMDGOALS
|
|
744 |
goals := $(MAKECMDGOALS)
|
|
745 |
else
|
|
746 |
goals := all
|
|
747 |
endif
|
|
748 |
|
|
749 |
# store path to Pd API m_pd.h if it is found
|
|
750 |
ifdef PDINCLUDEDIR
|
|
751 |
mpdh := $(shell ls "$(PDINCLUDEDIR)/m_pd.h")
|
|
752 |
endif
|
|
753 |
|
|
754 |
# store path to pd.dll; if not found, ls will give a useful error
|
|
755 |
ifeq ($(system), Windows)
|
|
756 |
pddll := $(shell ls "$(PDBINDIR)/pd.dll")
|
|
757 |
endif
|
|
758 |
|
|
759 |
# print Makefile.pdlibbuilder version
|
|
760 |
$(info ++++ info: using Makefile.pdlibbuilder version $(version))
|
|
761 |
|
|
762 |
# when making target all, check if m_pd.h is found and print info about it
|
|
763 |
ifeq ($(goals), all)
|
|
764 |
$(if $(mpdh), \
|
|
765 |
$(info ++++ info: using Pd API $(mpdh)), \
|
|
766 |
$(warning Where is Pd API m_pd.h? Do 'make help' for info.))
|
|
767 |
endif
|
|
768 |
|
|
769 |
# print target info
|
|
770 |
$(info ++++ info: making target $(goals) $(if $(lib.name),in lib $(lib.name)))
|
|
771 |
|
|
772 |
# when installing, print installpath info
|
|
773 |
$(if $(filter install install-lib, $(goals)), $(info ++++ info: \
|
|
774 |
installpath is '$(installpath)'))
|
|
775 |
|
|
776 |
|
|
777 |
#=== define executables ========================================================
|
|
778 |
|
|
779 |
|
|
780 |
# By default we build class executables, and optionally a shared dynamic link
|
|
781 |
# lib. When make-lib-executable=yes we build all classes into a single lib
|
|
782 |
# executable, on the condition that variable lib.setup.sources is defined.
|
|
783 |
|
|
784 |
ifeq ($(make-lib-executable),yes)
|
|
785 |
$(if $(lib.setup.sources), ,\
|
|
786 |
$(error Can not build library blob because lib.setup.sources is undefined))
|
|
787 |
executables := $(lib.name).$(extension)
|
|
788 |
else
|
|
789 |
executables := $(classes.executables) $(shared.lib)
|
|
790 |
endif
|
|
791 |
|
|
792 |
|
|
793 |
################################################################################
|
|
794 |
### rules: special targets #####################################################
|
|
795 |
################################################################################
|
|
796 |
|
|
797 |
|
|
798 |
# Disable built-in rules. If some target can't be built with the specified
|
|
799 |
# rules, it should not be built at all.
|
|
800 |
MAKEFLAGS += --no-builtin-rules
|
|
801 |
|
|
802 |
.PRECIOUS:
|
|
803 |
.SUFFIXES:
|
|
804 |
.PHONY: all post build-lib \
|
|
805 |
$(classes) $(makefiledirs) $(makefiles) \
|
|
806 |
install install-executables install-datafiles install-datadirs \
|
|
807 |
force clean vars allvars depend help
|
|
808 |
|
|
809 |
|
|
810 |
################################################################################
|
|
811 |
### rules: build targets #######################################################
|
|
812 |
################################################################################
|
|
813 |
|
|
814 |
|
|
815 |
# Target all forces the build of targets [$(executables) post] in
|
|
816 |
# deterministic order. Target $(executables) builds class executables plus
|
|
817 |
# optional shared lib or alternatively a single lib executable when
|
|
818 |
# make-lib-executable=true. Target post is optionally defined by
|
|
819 |
# library makefile.
|
|
820 |
|
|
821 |
all: post
|
|
822 |
post: $(executables)
|
|
823 |
|
|
824 |
all:
|
|
825 |
$(info ++++info: target all in lib $(lib.name) completed)
|
|
826 |
|
|
827 |
# build all with -g option turned on for debug symbols
|
|
828 |
alldebug: c.flags += -g
|
|
829 |
alldebug: cxx.flags += -g
|
|
830 |
alldebug: all
|
|
831 |
|
|
832 |
|
|
833 |
#=== class executable ==========================================================
|
|
834 |
|
|
835 |
|
|
836 |
# recipe for linking objects in class executable
|
|
837 |
# argument $1 = compiler type (c or cxx)
|
|
838 |
# argument $2 = class basename
|
|
839 |
define link-class
|
|
840 |
$(compile-$1) \
|
|
841 |
$($1.ldflags) $($2.class.ldflags) \
|
|
842 |
-o $2.$(extension) \
|
|
843 |
$(addsuffix .o, $(basename $($2.class.sources))) \
|
|
844 |
$(addsuffix .o, $(basename $(common.sources))) \
|
|
845 |
$($1.ldlibs) $($2.class.ldlibs) $(shared.lib)
|
|
846 |
endef
|
|
847 |
|
|
848 |
# general rule for linking object files in class executable
|
|
849 |
%.$(extension): $(shared.lib)
|
|
850 |
$(info ++++ info: linking objects in $@ for lib $(lib.name))
|
|
851 |
$(if $(filter %.cc %.cpp, $($*.class.sources)), \
|
|
852 |
$(call link-class,cxx,$*), \
|
|
853 |
$(call link-class,c,$*))
|
|
854 |
|
|
855 |
|
|
856 |
#=== library blob ==============================================================
|
|
857 |
|
|
858 |
|
|
859 |
# build all classes into single executable
|
|
860 |
build-lib: $(lib.name).$(extension)
|
|
861 |
$(info ++++ info: library blob $(lib.name).$(extension) completed)
|
|
862 |
|
|
863 |
# recipe for linking objects in lib executable
|
|
864 |
# argument $1 = compiler type (c or cxx)
|
|
865 |
define link-lib
|
|
866 |
$(compile-$1) \
|
|
867 |
$($1.ldflags) $(lib.ldflags) \
|
|
868 |
-o $(lib.name).$(extension) $(all.objects) \
|
|
869 |
$($1.ldlibs) $(lib.ldlibs)
|
|
870 |
endef
|
|
871 |
|
|
872 |
# rule for linking objects in lib executable
|
|
873 |
# declared conditionally to avoid name clashes
|
|
874 |
ifeq ($(make-lib-executable),yes)
|
|
875 |
$(lib.name).$(extension): $(all.objects)
|
|
876 |
$(if $(filter %.cc %.cpp, $(all.sources)), \
|
|
877 |
$(call link-lib,cxx), \
|
|
878 |
$(call link-lib,c))
|
|
879 |
endif
|
|
880 |
|
|
881 |
|
|
882 |
#=== shared dynamic lib ========================================================
|
|
883 |
|
|
884 |
|
|
885 |
# recipe for linking objects in shared executable
|
|
886 |
# argument $1 = compiler type (c or cxx)
|
|
887 |
define link-shared
|
|
888 |
$(compile-$1) \
|
|
889 |
$(shared.ldflags) \
|
|
890 |
-o lib$(lib.name).$(shared.extension) $(shared.objects) \
|
|
891 |
$($1.ldlibs) $(shared.ldlibs)
|
|
892 |
endef
|
|
893 |
|
|
894 |
# rule for linking objects in shared executable
|
|
895 |
# build recipe is in macro 'link-shared'
|
|
896 |
lib$(lib.name).$(shared.extension): $(shared.objects)
|
|
897 |
$(info ++++ info: linking objects in shared lib $@)
|
|
898 |
$(if $(filter %.cc %.cpp, $(shared.sources)), \
|
|
899 |
$(call link-shared,cxx), \
|
|
900 |
$(call link-shared,c))
|
|
901 |
|
|
902 |
|
|
903 |
#=== object files ==============================================================
|
|
904 |
|
|
905 |
|
|
906 |
# recipe to make .o file from source
|
|
907 |
# argument $1 is compiler type (c or cxx)
|
|
908 |
define make-object-file
|
|
909 |
$(info ++++ info: making $@ in lib $(lib.name))
|
|
910 |
$(compile-$1) \
|
|
911 |
$($1.flags) \
|
|
912 |
-o $@ -c $<
|
|
913 |
endef
|
|
914 |
|
|
915 |
# Three rules to create .o files. These are double colon 'terminal' rules,
|
|
916 |
# meaning they are the last in a rules chain.
|
|
917 |
|
|
918 |
%.o:: %.c
|
|
919 |
$(call make-object-file,c)
|
|
920 |
|
|
921 |
%.o:: %.cc
|
|
922 |
$(call make-object-file,cxx)
|
|
923 |
|
|
924 |
%.o:: %.cpp
|
|
925 |
$(call make-object-file,cxx)
|
|
926 |
|
|
927 |
|
|
928 |
#=== explicit prerequisites for class executables ==============================
|
|
929 |
|
|
930 |
|
|
931 |
# For class executables, prerequisite rules are declared in run time. Target
|
|
932 |
# 'depend' prints these rules for debugging purposes.
|
|
933 |
|
|
934 |
# declare explicit prerequisites rule like 'class: class.extension'
|
|
935 |
# argument $v is class basename
|
|
936 |
define declare-class-target
|
|
937 |
$v: $v.$(extension)
|
|
938 |
endef
|
|
939 |
|
|
940 |
# declare explicit prerequisites rule like 'class.extension: object1.o object2.o'
|
|
941 |
# argument $v is class basename
|
|
942 |
define declare-class-executable-target
|
|
943 |
$v.$(extension): $(addsuffix .o, $(basename $($v.class.sources))) \
|
|
944 |
$(addsuffix .o, $(basename $(common.sources)))
|
|
945 |
endef
|
|
946 |
|
|
947 |
# evaluate explicit prerequisite rules for all classes
|
|
948 |
$(foreach v, $(classes), $(eval $(declare-class-target)))
|
|
949 |
$(foreach v, $(classes), $(eval $(declare-class-executable-target)))
|
|
950 |
|
|
951 |
|
|
952 |
#=== implicit prerequisites for class executables ==============================
|
|
953 |
|
|
954 |
|
|
955 |
# Evaluating implicit prerequisites (header files) with help from the
|
|
956 |
# preprocessor is 'expensive' so this is done conditionally and selectively.
|
|
957 |
# Note that it is also possible to trigger a build via install targets, in
|
|
958 |
# which case implicit prerequisites are not checked.
|
|
959 |
|
|
960 |
# When the Pd include path contains spaces it will mess up the implicit
|
|
961 |
# prerequisites rules.
|
|
962 |
disable-dependency-tracking := $(strip $(pdincludepathwithspaces))
|
|
963 |
|
|
964 |
ifndef disable-dependency-tracking
|
|
965 |
must-build-everything := $(filter all, $(goals))
|
|
966 |
must-build-class := $(filter $(classes), $(goals))
|
|
967 |
must-build-sources := $(foreach v, $(must-build-class), $($v.class.sources))
|
|
968 |
endif
|
|
969 |
|
|
970 |
# declare implicit prerequisites rule like 'object.o: header1.h header2.h ...'
|
|
971 |
# argument $1 is input source file(s)
|
|
972 |
# dir is explicitly added because option -MM strips it by default
|
|
973 |
define declare-object-target
|
|
974 |
$(dir $1)$(filter %.o: %.h, $(shell $(CPP) $(depcheck.flags) -MM $1)) $(MAKEFILE_LIST)
|
|
975 |
endef
|
|
976 |
|
|
977 |
# evaluate implicit prerequisite rules when rebuilding everything
|
|
978 |
ifdef must-build-everything
|
|
979 |
$(if $(wildcard $(all.objects)), \
|
|
980 |
$(info ++++ info: evaluating implicit prerequisites in lib $(lib.name).....) \
|
|
981 |
$(foreach v, $(all.sources), $(eval $(call declare-object-target, $v))))
|
|
982 |
endif
|
|
983 |
|
|
984 |
# evaluate implicit prerequisite rules when selectively building classes
|
|
985 |
ifdef must-build-class
|
|
986 |
$(foreach v, $(must-build-sources), \
|
|
987 |
$(eval $(call declare-object-target, $v)))
|
|
988 |
$(foreach v, $(shared.sources), \
|
|
989 |
$(eval $(call declare-object-target, $v)))
|
|
990 |
endif
|
|
991 |
|
|
992 |
|
|
993 |
################################################################################
|
|
994 |
### rules: preprocessor and assembly files #####################################
|
|
995 |
################################################################################
|
|
996 |
|
|
997 |
|
|
998 |
# Preprocessor and assembly output files for bug tracing etc. They are not part
|
|
999 |
# of the build processes for executables. By default these files are created in
|
|
1000 |
# the current working directory. Dependency tracking is not performed, the build
|
|
1001 |
# is forced instead to make sure it's up to date.
|
|
1002 |
|
|
1003 |
force:
|
|
1004 |
|
|
1005 |
|
|
1006 |
#=== preprocessor file =========================================================
|
|
1007 |
|
|
1008 |
|
|
1009 |
# make preprocessor output file with extension .pre
|
|
1010 |
# argument $1 = compiler type (c or cxx)
|
|
1011 |
define make-preprocessor-file
|
|
1012 |
$(info ++++ info: making preprocessor output file $(notdir $*.pre) \
|
|
1013 |
in current working directory)
|
|
1014 |
$(compile-$1) -E $< $(c.flags) $($1.flags) -o $(notdir $*.pre)
|
|
1015 |
endef
|
|
1016 |
|
|
1017 |
%.pre:: %.c force
|
|
1018 |
$(call make-preprocessor-file,c)
|
|
1019 |
|
|
1020 |
%.pre:: %.cc force
|
|
1021 |
$(call make-preprocessor-file,cxx)
|
|
1022 |
|
|
1023 |
%.pre:: %.cpp force
|
|
1024 |
$(call make-preprocessor-file,cxx)
|
|
1025 |
|
|
1026 |
|
|
1027 |
#=== assembly file =============================================================
|
|
1028 |
|
|
1029 |
|
|
1030 |
# make C / assembly interleaved output file with extension .lst
|
|
1031 |
# argument $1 = compiler type (c or cxx)
|
|
1032 |
define make-assembly-file
|
|
1033 |
$(info ++++ info: making assembly output file $(notdir $*.lst) \
|
|
1034 |
in current working directory)
|
|
1035 |
$(compile-$1) \
|
|
1036 |
-c -Wa,-a,-ad -fverbose-asm \
|
|
1037 |
$($1.flags) \
|
|
1038 |
$< > $(notdir $*.lst)
|
|
1039 |
endef
|
|
1040 |
|
|
1041 |
%.lst:: %.c force
|
|
1042 |
$(call make-assembly-file,c)
|
|
1043 |
|
|
1044 |
%.lst:: %.cc force
|
|
1045 |
$(call make-assembly-file,cxx)
|
|
1046 |
|
|
1047 |
%.lst:: %.cpp force
|
|
1048 |
$(call make-assembly-file,cxx)
|
|
1049 |
|
|
1050 |
|
|
1051 |
################################################################################
|
|
1052 |
### rules: installation targets ################################################
|
|
1053 |
################################################################################
|
|
1054 |
|
|
1055 |
|
|
1056 |
#=== strip =====================================================================
|
|
1057 |
|
|
1058 |
|
|
1059 |
# Stripping of installed binaries will only be done when variable 'stripflags'
|
|
1060 |
# is defined non-empty. No default definition is provided except for Windows
|
|
1061 |
# where the unstripped binaries are large, especially in the case of Mingw-w64.
|
|
1062 |
|
|
1063 |
# Note: while stripping all symbols ('-s' or '--strip-all') is possible for
|
|
1064 |
# Linux and Windows, in the case of OSX only non-global symbols can be stripped
|
|
1065 |
# (option '-x' or '--discard-all').
|
|
1066 |
|
|
1067 |
# Make definition of strip command overridable so it can be defined in an
|
|
1068 |
# environment for cross-compilation.
|
|
1069 |
STRIP ?= strip
|
|
1070 |
|
|
1071 |
# Commands in 'strip-executables' will be executed conditionally in the rule for
|
|
1072 |
# target 'install-executables'.
|
|
1073 |
strip-executables = cd "$(installpath)" && \
|
|
1074 |
$(foreach v, $(executables), $(STRIP) $(stripflags) '$v';)
|
|
1075 |
|
|
1076 |
|
|
1077 |
#=== install ===================================================================
|
|
1078 |
|
|
1079 |
|
|
1080 |
# Install targets depend on successful exit status of target all because nothing
|
|
1081 |
# must be installed in case of a build error.
|
|
1082 |
|
|
1083 |
# -p = preserve time stamps
|
|
1084 |
# -m = set permission mode (as in chmod)
|
|
1085 |
# -d = create all components of specified directories
|
|
1086 |
INSTALL = install
|
|
1087 |
INSTALL_PROGRAM := $(INSTALL) -p -m 644
|
|
1088 |
INSTALL_DATA := $(INSTALL) -p -m 644
|
|
1089 |
INSTALL_DIR := $(INSTALL) -m 755 -d
|
|
1090 |
|
|
1091 |
# strip spaces from file names
|
|
1092 |
executables := $(strip $(executables))
|
|
1093 |
datafiles := $(strip $(datafiles))
|
|
1094 |
datadirs := $(strip $(datadirs))
|
|
1095 |
|
|
1096 |
# Do not make any install sub-target with empty variable definition because the
|
|
1097 |
# install program would exit with an error.
|
|
1098 |
install: $(if $(executables), install-executables)
|
|
1099 |
install: $(if $(datafiles), install-datafiles)
|
|
1100 |
install: $(if $(datadirs), install-datadirs)
|
|
1101 |
|
|
1102 |
install-executables: all
|
|
1103 |
$(INSTALL_DIR) -v "$(installpath)"
|
|
1104 |
$(foreach v, $(executables), \
|
|
1105 |
$(INSTALL_PROGRAM) '$v' "$(installpath)";)
|
|
1106 |
$(info ++++ info: executables of lib $(lib.name) installed \
|
|
1107 |
from $(CURDIR) to $(installpath))
|
|
1108 |
$(if $(stripflags), $(strip-executables),)
|
|
1109 |
|
|
1110 |
install-datafiles: all
|
|
1111 |
$(INSTALL_DIR) -v "$(installpath)"
|
|
1112 |
$(foreach v, $(datafiles), \
|
|
1113 |
$(INSTALL_DATA) '$(v)' "$(installpath)";)
|
|
1114 |
$(info ++++ info: data files of lib $(lib.name) installed \
|
|
1115 |
from $(CURDIR) to $(installpath))
|
|
1116 |
|
|
1117 |
install-datadirs: all
|
|
1118 |
$(foreach v, $(datadirs), $(INSTALL_DIR) "$(installpath)/$v";)
|
|
1119 |
$(foreach v, $(datadirs), \
|
|
1120 |
$(INSTALL_DATA) $(wildcard $v/*) "$(installpath)/$v";)
|
|
1121 |
$(info ++++ info: data directories of lib $(lib.name) installed \
|
|
1122 |
from $(CURDIR) to $(installpath))
|
|
1123 |
|
|
1124 |
|
|
1125 |
################################################################################
|
|
1126 |
### rules: distribution targets ################################################
|
|
1127 |
################################################################################
|
|
1128 |
|
|
1129 |
|
|
1130 |
# TODO
|
|
1131 |
# These targets are implemented in Makefile Template, but I have to figure out
|
|
1132 |
# how to do it under the not-so-strict conditions of Makefile.pdlibbuilder.
|
|
1133 |
|
|
1134 |
# make source package
|
|
1135 |
dist:
|
|
1136 |
@echo "target dist not yet implemented"
|
|
1137 |
|
|
1138 |
# make Debian source package
|
|
1139 |
dpkg-source:
|
|
1140 |
@echo "target dpkg-source not yet implemented"
|
|
1141 |
|
|
1142 |
$(ORIGDIR):
|
|
1143 |
|
|
1144 |
$(DISTDIR):
|
|
1145 |
|
|
1146 |
|
|
1147 |
################################################################################
|
|
1148 |
### rules: clean targets #######################################################
|
|
1149 |
################################################################################
|
|
1150 |
|
|
1151 |
|
|
1152 |
# delete build products from build tree
|
|
1153 |
clean:
|
|
1154 |
rm -f $(all.objects)
|
|
1155 |
rm -f $(classes.executables) $(lib.name).$(extension) $(shared.lib)
|
|
1156 |
rm -f *.pre *.lst
|
|
1157 |
|
|
1158 |
# remove distribution directories and tarballs from build tree
|
|
1159 |
distclean: clean
|
|
1160 |
@echo "target distclean not yet implemented"
|
|
1161 |
|
|
1162 |
|
|
1163 |
################################################################################
|
|
1164 |
### rules: submake targets #####################################################
|
|
1165 |
################################################################################
|
|
1166 |
|
|
1167 |
|
|
1168 |
# Iterate over sub-makefiles or makefiles in other directories.
|
|
1169 |
|
|
1170 |
# When 'continue-make=yes' is set, sub-makes will report 'true' to the parent
|
|
1171 |
# process regardless of their real exit status. This prevents the parent make
|
|
1172 |
# from being aborted by a sub-make error. Useful when you want to quickly find
|
|
1173 |
# out which sub-makes from a large set will succeed.
|
|
1174 |
ifeq ($(continue-make),yes)
|
|
1175 |
continue = || true
|
|
1176 |
endif
|
|
1177 |
|
|
1178 |
# These targets will trigger sub-make processes for entries in 'makefiledirs'
|
|
1179 |
# and 'makefiles'.
|
|
1180 |
all alldebug install clean distclean dist dkpg-source: \
|
|
1181 |
$(makefiledirs) $(makefiles)
|
|
1182 |
|
|
1183 |
# this expands to identical rules for each entry in 'makefiledirs'
|
|
1184 |
$(makefiledirs):
|
|
1185 |
$(MAKE) --directory=$@ $(MAKECMDGOALS) $(continue)
|
|
1186 |
|
|
1187 |
# this expands to identical rules for each entry in 'makefiles'
|
|
1188 |
$(makefiles):
|
|
1189 |
$(MAKE) --directory=$(dir $@) --makefile=$(notdir $@) $(MAKECMDGOALS) $(continue)
|
|
1190 |
|
|
1191 |
|
|
1192 |
################################################################################
|
|
1193 |
### rules: convenience targets #################################################
|
|
1194 |
################################################################################
|
|
1195 |
|
|
1196 |
|
|
1197 |
#=== show variables ============================================================
|
|
1198 |
|
|
1199 |
|
|
1200 |
# Several 'function' macro's cause errors when expanded within a rule or without
|
|
1201 |
# proper arguments. Variables which are set with the define directive are only
|
|
1202 |
# shown by name for that reason.
|
|
1203 |
functions = \
|
|
1204 |
add-class-source \
|
|
1205 |
declare-class-target \
|
|
1206 |
declare-class-executable-target \
|
|
1207 |
declare-object-target \
|
|
1208 |
link-class \
|
|
1209 |
link-lib \
|
|
1210 |
link-shared \
|
|
1211 |
make-object-file \
|
|
1212 |
make-preprocessor-file \
|
|
1213 |
make-assembly-file
|
|
1214 |
|
|
1215 |
|
|
1216 |
# show variables from makefiles
|
|
1217 |
vars:
|
|
1218 |
$(info ++++ info: showing makefile variables:)
|
|
1219 |
$(foreach v,\
|
|
1220 |
$(sort $(filter-out $(functions) functions, $(.VARIABLES))),\
|
|
1221 |
$(if $(filter file, $(origin $v)),\
|
|
1222 |
$(info variable $v = $($v))))
|
|
1223 |
$(foreach v, $(functions), $(info 'function' name: $v))
|
|
1224 |
@echo
|
|
1225 |
|
|
1226 |
# show all variables
|
|
1227 |
allvars:
|
|
1228 |
$(info ++++ info: showing default, automatic and makefile variables:)
|
|
1229 |
$(foreach v, \
|
|
1230 |
$(sort $(filter-out $(functions) functions, $(.VARIABLES))), \
|
|
1231 |
$(info variable ($(origin $v)) $v = $($v)))
|
|
1232 |
$(foreach v, $(functions), $(info 'function' name: $v))
|
|
1233 |
@echo
|
|
1234 |
|
|
1235 |
|
|
1236 |
#=== show dependencies =========================================================
|
|
1237 |
|
|
1238 |
|
|
1239 |
# show generated prerequisites rules
|
|
1240 |
depend:
|
|
1241 |
$(info ++++ info: generated prerequisite rules)
|
|
1242 |
$(foreach v, $(classes), $(info $(declare-class-target)))
|
|
1243 |
$(foreach v, $(classes), $(info $(declare-class-executable-target)))
|
|
1244 |
$(foreach v, $(all.sources), $(info $(call declare-object-target, $v)))
|
|
1245 |
@echo
|
|
1246 |
|
|
1247 |
|
|
1248 |
#=== show help text ============================================================
|
|
1249 |
|
|
1250 |
|
|
1251 |
# brief info about targets and paths
|
|
1252 |
|
|
1253 |
ifdef mpdh
|
|
1254 |
mpdhinfo := $(mpdh)
|
|
1255 |
else
|
|
1256 |
mpdhinfo := m_pd.h was not found. Is Pd installed?
|
|
1257 |
endif
|
|
1258 |
|
|
1259 |
help:
|
|
1260 |
@echo
|
|
1261 |
@echo " Main targets:"
|
|
1262 |
@echo " all: build executables (default target)"
|
|
1263 |
@echo " install: install all components of the library"
|
|
1264 |
@echo " vars: print makefile variables for troubleshooting"
|
|
1265 |
@echo " allvars: print all variables for troubleshooting"
|
|
1266 |
@echo " help: print this help text"
|
|
1267 |
@echo
|
|
1268 |
@echo " Pd API m_pd.h:"
|
|
1269 |
@echo " $(mpdhinfo)"
|
|
1270 |
@echo " You may specify your preferred Pd include directory as argument"
|
|
1271 |
@echo " to the make command, like 'PDINCLUDEDIR=path/to/pd/src'."
|
|
1272 |
@echo
|
|
1273 |
@echo " Path for installation of your libdir(s):"
|
|
1274 |
@echo " $(PDLIBDIR)"
|
|
1275 |
@echo " Alternatively you may specify your path for installation as argument"
|
|
1276 |
@echo " to the make command, like 'PDLIBDIR=path/to/pd-externals'."
|
|
1277 |
@echo
|
|
1278 |
@echo " Default paths are listed in the doc sections in Makefile.pdlibbuilder."
|
|
1279 |
@echo
|
|
1280 |
|
|
1281 |
|
|
1282 |
#=== dummy target ==============================================================
|
|
1283 |
|
|
1284 |
|
|
1285 |
coffee:
|
|
1286 |
@echo "Makefile.pdlibbuilder: Can not make coffee. Sorry."
|
|
1287 |
|
|
1288 |
|
|
1289 |
################################################################################
|
|
1290 |
### end of rules sections ######################################################
|
|
1291 |
################################################################################
|
|
1292 |
|
|
1293 |
|
|
1294 |
# for syntax highlighting in vim and github
|
|
1295 |
# vim: set filetype=make:
|
|
1296 |
|