-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathantimake.txt
More file actions
474 lines (334 loc) · 13.1 KB
/
antimake.txt
File metadata and controls
474 lines (334 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
= antimake.mk(5) =
== NAME ==
antimake - Minimal Automake syntax on plain GNU Make
== DESCRIPTION ==
Antimake makes possible to use GNU Automake conventions
to describe builds in ordinary Makefiles for GNU Make.
It's main abstractions are target lists and target variables.
Target list describes target type and where to install.
Target variables give source files and additional flags for build.
== EXAMPLE ==
-------------------
# target list
bin_PROGRAMS = prog
# target variables for 'prog'
prog_SOURCES = prog.c prog.h
prog_LDADD = libutil.a
# target list
noinst_LIBRARIES = libutil.a
# target variables for 'libutil.a'
libutil_a_SOURCES = util.c util.h
# load Antimake
include antimake.mk
-------------------
== Terminology ==
Primary::
target type, describes how to build and install particular type of targets.
Target::
a file that needs to be built and/or installed.
Distribute::
Include file in source .tar.gz. Non-distributed files are skipped
when building .tar.gz and are cleaned during `make distclean`.
Source::
Source files are files that appear in `..._SOURCES` per-target variable.
They are distributed by default. They may or may not result in object files.
It's fine to put both `.h` and `.c` files into _SOURCES.
== TARGET LISTS ==
Target lists are variables that contain file names that need to be
built and installed. They are specially named so that the name also describes how they
are built, how and where they will be installed.
The target list name contains 3 parts, separated with underscore, in following order:
1. Optional flags. Flags are: `nodist`, `dist`, `nobase`, `base`. (Default: `base`, `nodist`)
2. Destination directory name. Destination directory called *bin* actual
location is stored in Make variable `$(bindir)`. Some common values:
`bin`, `lib`, `include`. There are more and the list can be extended.
Special name `noinst` means the target file should not be installed.
3. Target type, also called "primary". This will describe how the target
needs to be built. Common values: `PROGRAMS`, `LIBRARIES`, `DATA`
For details, what the various values mean, see next sections.
.Examples:
----------------
bin_PROGRAMS = prog1 prog2
# flags: base, nodist
# dest: $(bindir)
# type: PROGRAMS
noinst_LIBRARIES = lib1.a lib2.a
# flags: base, nodist
# dest: noinst
# type: LIBRARIES
nobase_dist_doc_DATA = docs/README
# flags: dist, nobase
# dest: $(docdir)/docs
# type: DATA
----------------
=== Primaries ===
`PROGRAMS`::
executable programs, linked together from objects built from source files
`LIBARIES`::
static libraries, linked together from objects built from source files
`LTLIBRARIES`::
dynamic or static libraries, linked together from objects built from source files
`HEADERS`::
header files, no default build method, the target files have `dist` flag by default.
`MANS`::
man pages, no default build method, installed into manX subdir.
`SCRIPTS`::
scripts, executable file, no default build method
`DATA`::
data, non-executable file, no default build method
=== Target list flags ===
`dist`::
The target should be distributed with other sources.
Default for `HEADERS` type, others have `nodist` by default.
`nodist`::
Target is not distributed and should be cleaned with distclean.
Default for all primaries, except `HEADERS`.
`base`::
On install relative path is ignored, all files
end up in destination directory. Always default.
`nobase`::
On install relative path is kept. Eg: if `includedir=/usr/include`
then `nobase_include_HEADERS=mylib/common.h`
is installed to `/usr/include/mylib/common.h`.
`noinst`::
Target is built as part of build process, but is not installed.
`EXTRA`::
Targets in such list are not built, nor installed.
Useful to make sure that sources for dynamically configured targets
will end up in source tarball. Unlike other target list ariables,
`EXTRA_<primary>` may contain targets already defined in other
target lists, they will be filtered out from this list then.
== Target variables ==
Only big targets take additional variables: `PROGRAMS`/`LIBRARIES`/`LTLIBRARIES`.
`<tgt>_SOURCES`::
All source files, *.c *.h *.cpp *.hpp.
`nodist_<tgt>_SOURCES`::
Source files that should not be distributed.
`EXTRA_<tgt>_SOURCES`::
In case tgt_SOURCES is dynamic, here is non-dynamic
list of sources for distribution. Only dynamic sources
need to be listed here.
`<tgt>_DEPENDENCIES`::
Add dependencies that need to be build before target build will start.
`<tgt>_CFLAGS`, `<tgt>_CPPFLAGS`, `<tgt>_LDFLAGS`, `<tgt>_LIBTOOLFLAGS`::
Override corresponging AM_xx variable
`<tgt>_LDADD`::
Add dependencies that are used during linking.
For PROGRAMS only.
They will be added to linker command line.
`<tgt>_LIBADD`::
Add dependencies that are used during linking.
For LIBRARIES/LTLIBRARIES only.
They will be added to linker command line.
`<tgt>_AR`::
Overrides $(AR) $(ARFLAGS).
For LIBRARIES only.
.Example:
-------------------
bin_PROGRAMS = prog
prog_SOURCE = main.c util.c util.h
prog_CFLAGS = $(GTK_CFLAGS)
prog_LDADD = $(GTK_LIBS)
-------------------
== Global variables ==
They can be set before `antimake.mk` inclusion to change
build behaviour.
EXTRA_DIST::
Additional files to include in source archive.
CLEANFILES::
Additional files to `make clean`.
DISTCLEANFILES::
Additional files to `make distclean`.
MAINTAINERCLEANFILES::
Additional files to `make maintainer-clean`.
SUBDIRS::
Subdirectories of current directory where Make
needs to be recursively launched. If subdirectory
`Makefile` is Antimake-base, it should set `SUBLOC`.
SUBLOC::
Current diretory location in overall source tree.
This can stay unset in top directory. Needed for
subdirectiories entered with `SUBDIRS` to find
its position in source tree.
DIST_SUBDIRS::
Subdirs that only `make dist`, `make distclean` and `make maintainer-clean`
will enter.
EMBED_SUBDIRS::
Subdirectories that are built non-recursively: they need to contain `Makefile.am`
that contains makefile-fragment with Antimake syntax
that describes local targets using relative filenames.
The fragment is included in main makefile and file
and variable names are converted and merged with top-level targets.
AM_FEATURES::
List of extensions to load. Extensions are Makefile fragments
that are loaded before actual rules are generated, so they
can change or add targets.
=== More details on EMBED_SUBDIRS ===
It acts like `include $(dir)/Makefile.am` for each directory, except it converts
file and variable names. Example:
---------------------
Makefile:
EMBED_SUBDIRS = src
src/Makefile.am:
bin_PROGRAMS = hello
hello_SOURCES = main.c
hello_CPPFLAGS = -I./include
---------------------
Conversion results as if top-level `Makefile` had contained following rows:
----------------------
bin_PROGRAMS += src/hello
src_hello_SOURCES = src/main.c
src_hello_CPPFLAGS = -I./src/include
----------------------
Variables, where file names are converted:
* SUBDIRS, DIST_SUBDIRS, EMBED_SUBDIRS
* DISTFILES, CLEANFILES, DISTCLEANFILES, MAINTAINERCLEANFILES
* target lists
* <tgt>_SOURCES, <tgt>_LDADD, <tgt>_LIBADD
Variables, where -L and -I flags are converted:
* <tgt>_CFLAGS
* <tgt>_CPPFLAGS
* <tgt>_LDFLAGS
Makefile should be written in a way that those conversions
would be enough.
=== Global variables for current location ===
* srcdir, builddir - relative path to source dir and build dir.
* top_srcdir, top_builddir - relative path to top-level source and build dir.
* abs_srcdir, abs_builddir - absolute path to source and build dir
* abs_top_srcdir, abs_top_builddir - absolute path to top-level source and build dir
* nosub_top_srcdir, nosub_top_builddir - relative path from top of builddir to srcdir and builddir.
=== Global variables that target can override ===
- AM_CPPFLAGS
- AM_CFLAGS
- AM_LDFLAGS
- AM_LIBTOOLFLAGS
- AM_DEFS
- AM_MAKEFLAGS
=== Global variables from autoconf ===
These variables come usually from autoconf,
but also have reasonable defaults:
CC, DEFS, CPPFLAGS, CFLAGS, LDFLAGS, LIBS,
LIBTOOL, LIBTOOLFLAGS, AR, ARFLAGS, RANLIB,
CXX, CXXFLAGS, INSTALL, MKDIR_P, LN_S
=== Global variables for extending Antimake ===
AM_DIST_DEFAULT::
Default format(s) for `make dist` target. One or more of:
`gzip`, `bzip2`, `xz`, `zip`. Default: `gzip`.
AM_DESTINATIONS::
Additional directory names to consider as valid
destinations. Expects corresponding `dir`-variable to be set.
AM_SMALL_PRIMARIES::
Additional single-file primaries. (Builtin: HEADERS, SCRIPTS, DATA, MANS)
AM_BIG_PRIMARIES::
Additional primaries built from objects. (Builtin: PROGRAMS, LIBRARIES, LTLIBRARIES)
AM_LANGUAGES::
Additional language names. Antimake expects variables
`AM_LANG_$(name)_SRCEXTS`, `AM_LANG_$(name)_COMPILE` and
`AM_LANG_$(name)_LINK` to be set.
=== Variables for command-line usage ===
DESTDIR::
Relocate installation root.
AM_TRACE::
Turns on function-call debug info. Can be set from command-line.
=== Hacking variables ===
GNUMAKE380, GNUMAKE381, GNUMAKE382::
If we have at least that version of GNU Make. GNUMAKE380 is always
set, others may not be. If Makefile uses features from newer GNU Make
it would be good idea to use those flags and error out with clear
error message, instead having mysterious failures.
=== Libtool flags ===
Useful http://www.gnu.org/software/libtool/manual/html_node/Link-mode.html[Libtool]
flags that can be put int tgt_LDFLAGS for a LTLIBRARY:
* -export-dynamic
* -export-symbols symfile
* -export-symbols-regex regex
* -module
See libtool http://www.gnu.org/software/libtool/manual/html_node/Versioning.html["Versioning"] chapter about those:
* -avoid-version
* -version-info current[:revision[:age]]
* -version-number major[:minor[:revision]]
* -release major[:minor[:revision]]
== Top-level pseudo-targets ==
=== all ===
The default target when no other target is given on command-line. Builds all target files.
==== Simple targets ====
These are simple - either the file already exists,
or the user needs to give build command.
==== Object-based targets ====
The targets in primaries PROGRAMS, LIBRARIES and LTLIBRARIES consist of multiple source
files that need to be compiled into objects. Then the objects need to be
linked into final target. The process is roughly following:
. Dependencies are built (_LDADD, _LIBADD, _DEPENDENCIES).
. Source list is filtered for extensions that can be compiled into object files,
object file list is created based on them. The rest of files are used and
dependencies for target, but otherwise ignored.
. Object files are built.
. Linker is picked based on source files - as there can be files in multiple languages,
the most advanced language wins (the one that appears later in `AM_LANGUAGES`)
. Final executable is linked.
=== install ===
Install all targets to their destination directories, which is mentioned
in their target list variable name. Eg. `bin_PROGRAMS` will be installed
to `$(bindir)`. If destination is named `noinst`, it will not be installed.
If the flag `nobase` is given, the relative filename is kept, otherwise
basename is taken and it will appear directly under destination directory.
.Example:
------
include_HEADERS = func1.h lib/func2.h
# Files will end up in:
# $(includedir)/func1.h
# $(includedir)/func2.h
nobase_include_HEADERS = func1.h lib/func2.h
# Files will end up in:
# $(includedir)/func1.h
# $(includedir)/lib/func2.h
------
=== clean ===
- Remove files in `$(CLEANFILES)`
- Remove built objects.
- Remove target files, unless they are marked as `dist`.
(Note: `HEADERS` primary is `dist` by default, all other are `nodist`)
=== distclean ===
- Remove files in `$(DISTCLEANFILES)`
- Remove sources tagged with `nodist`. All sources as `dist` by default.
=== maintainer-clean ===
- Remove files in `$(MAINTAINERCLEANFILES)`
=== help ===
Describe top-level targets.
=== am-test ===
Regression test for low-level Antimake functions.
=== am-debug ===
Show Antimake internal state.
== FEATURES ==
Done:
- Big primaries: PROGRAMS, LIBRARIES, LTLIBRARIES
- Small primaries: DATA, SCRIPTS, MANS, HEADERS
- Flags: base nobase dist nodist noinst EXTRA
- Target vars: SOURCES, CPPFLAGS, CFLAGS, LDFLAGS, LDADD/LIBADD
- Separate build dir
- Per-target objects
- Languages: C, CXX
- SUBDIRS, DIST_SUBDIRS
- EMBED_SUBDIRS
Todo:
- Improve docs
- Standardize and document how to extend
- Deps with non-gcc?
- Long if-s to support `O=` seems to break GNU Make 3.80.
Drop `O=` or drop 3.80?
Probably out of scope:
- `make uninstall`
- `make distcheck`
- `make dist` from separate build dir
- `install-(exec|data)-hook` - based on dir not primary
- Default file list for `EXTRA_DIST`. (Problem: distclean / maintainer-clean)
Definitely out of scope:
- automake conditionals
- automake extras (autoconf macros, ltdl)
- automake nanny mode (gnu/gnits)
== SEE ALSO ==
GNU Make Reference: http://www.gnu.org/software/make/manual/make.html#Quick-Reference[]
Recursive Make Considered Harmful: http://miller.emu.id.au/pmiller/books/rmch/[]
Paul's Rules of Makefiles: http://make.mad-scientist.us/rules.html[]
Small BSD-ish build system: https://webkeks.org/hg/buildsys/[]
GNU Make Standard Library: http://sourceforge.net/projects/gmsl/[]