2
= Test Antimake EMBED_SUBDIRS =
5
Antimake variable `EMBED_SUBDIRS` list names of directories that
6
contains Makefile fragmants that are to be embedded into current
9
- Plus: Proper dependencies, work well with parallel Make.
10
- Minus: Cannot go into subdir and run make there.
11
- Minus: Fragments are not stand-alone, so need some care when writing.
14
== Intro to EMBED_SUBDIRS ==
17
To better understand what EMBED_SUBDIRS does, let\'s start with simple
18
case - single Makefile that references files under subdir:
20
---------------------------------
22
$ cp ../../antimake.mk .
23
---------------------------------
26
-----------------------------------
27
bin_PROGRAMS = src/myprog
28
src_myprog_SOURCES = src/myprog.c
30
-----------------------------------
33
-----------------------------------
41
-----------------------------------
42
---------------------------------
50
---------------------------------
52
Now you can put the lines that reference files under `src/`
53
also into `src` and include that from top-level Makefile:
55
.File: src/Makefile.inc
56
-----------------------------------
57
bin_PROGRAMS = src/myprog
58
src_myprog_SOURCES = src/myprog.c
59
-----------------------------------
62
-----------------------------------
63
include src/Makefile.inc
65
-----------------------------------
66
---------------------------------
72
---------------------------------
74
This works but the problem is that although the Makefile is local,
75
it still sees files from top-Makefile-level. So that is what `EMBED_SUBDIRS`
76
helps with - it allow to use local filenames in Makefile fragment,
77
and it converts them to top-level filenames when including. It knows
78
only few type of variables it needs to convert:
80
- target filenames in primares lists (*_PROGRAMS, *_LIBRARIES, etc)
81
- target_SOURCES: foo_SOURCES -> sub_dir_foo_SOURCES with filename conversion
82
- other target variables: `foo_*` -> `sub_dir_foo_*` without filename conversion
83
- EXTRA_DIST, CLEANFILES, DISTCLEANFILES, MAINTAINERCLEANFILES
85
Any other variables stay untouched, and obviously they can mess up top-level variables.
86
So the included Makefile should be as clean as possible.
89
== Setup source tree for EMBED_SUBDIRS ==
92
Setup directories, install Antimake
94
---------------------------------
95
$ mkdir -p lib1/sublib lib2
96
$ cp ../../antimake.mk .
97
---------------------------------
103
-----------------------------------
118
-----------------------------------
121
-----------------------------------
128
-----------------------------------
129
.File: lib1/sublib/func2.c
131
-----------------------------------
138
-----------------------------------
141
-----------------------------------
148
-----------------------------------
154
-----------------------------------
155
PACKAGE_NAME = test-subdirs
156
PACKAGE_VERSION = 1.0
158
EMBED_SUBDIRS = lib1 lib1/sublib lib2
161
prog_SOURCES = main.c
162
prog_LDADD = lib1/func1.a lib1/sublib/func2.a lib2/func3.a
164
EXTRA_DIST = Makefile antimake.mk
167
-----------------------------------
168
.File: lib1/Makefile.am
169
-----------------------------------
170
noinst_LIBRARIES = func1.a
171
func1_a_SOURCES = func1.c
173
EXTRA_DIST = Makefile.am
174
-----------------------------------
175
.File: lib1/sublib/Makefile.am
176
-----------------------------------
177
noinst_LIBRARIES = func2.a
178
func2_a_SOURCES = func2.c
179
EXTRA_DIST = Makefile.am
180
-----------------------------------
181
.File: lib2/Makefile.am
182
-----------------------------------
183
noinst_LIBRARIES = func3.a
184
func3_a_SOURCES = func3.c
186
EXTRA_DIST = Makefile.am
187
-----------------------------------
194
---------------------------------
200
CC lib1/sublib/func2.c
201
AR lib1/sublib/func2.a
202
RANLIB lib1/sublib/func2.a
208
Makefile antimake.mk lib1 lib2 main.c prog src
214
---------------------------------
216
We can now install it:
218
---------------------------------
219
$ make install prefix=/opt DESTDIR=./inst
220
INSTALL prog ./inst/opt/bin
223
---------------------------------
225
Now we can create package that can be given to others.
227
---------------------------------
230
MKDIR test-subdirs-1.0
231
COPY test-subdirs-1.0
232
PACK test-subdirs-1.0.tar.gz
234
Makefile inst lib2 prog test-subdirs-1.0.tar.gz
235
antimake.mk lib1 main.c src
236
$ tar tzf test-subdirs-1.0.tar.gz | sort
238
test-subdirs-1.0/Makefile
239
test-subdirs-1.0/antimake.mk
240
test-subdirs-1.0/lib1/
241
test-subdirs-1.0/lib1/Makefile.am
242
test-subdirs-1.0/lib1/func1.c
243
test-subdirs-1.0/lib1/sublib/
244
test-subdirs-1.0/lib1/sublib/Makefile.am
245
test-subdirs-1.0/lib1/sublib/func2.c
246
test-subdirs-1.0/lib2/
247
test-subdirs-1.0/lib2/Makefile.am
248
test-subdirs-1.0/lib2/func3.c
249
test-subdirs-1.0/main.c
250
---------------------------------
254
---------------------------------
258
CLEAN lib1/sublib/func2.a
262
Makefile antimake.mk inst lib1 lib2 main.c src test-subdirs-1.0.tar.gz
263
---------------------------------