Difference between revisions of "Writing Makefiles"

From Apertium
Jump to navigation Jump to search
Line 8: Line 8:
 
Now let your <code>Makefile.am</code> include this:
 
Now let your <code>Makefile.am</code> include this:
 
<pre>
 
<pre>
  +
# Only include one mode file here, the rest will be built along with it (listing several leads to problems with parallell make):
 
noinst_DATA=modes/$(PREFIX1).mode
 
noinst_DATA=modes/$(PREFIX1).mode
   

Revision as of 18:23, 24 March 2014

Some tips for writing clean Makefile.am's in Apertium:

Modes

If you have apertium revision 51184 or higher, you can do this to simplify dealing with Modes files / modes.xml:

First add AP_MKINCLUDE to configure.ac in the language pair.

Now let your Makefile.am include this:

# Only include one mode file here, the rest will be built along with it (listing several leads to problems with parallell make):
noinst_DATA=modes/$(PREFIX1).mode

@ap_include@

install-data-local: install-modes

EXTRA_DIST: 
	modes.xml \
	# other files, typically .dix and .t1x

Nowhere else should modes be mentioned in the Makefile.am.

Use .deps/.d to say that the .deps directory must be created

Say you have several goals that put temporary files in .deps/, e.g.

.deps/apertium-wat-lol.lol.dix: apertium-wat-lol.lol.dix
	test -d .deps || mkdir .deps
	xsltproc lexchoicebil.xsl $< >$@

and so on. The .deps directory has to be created for the file in .deps to be created. If you put mkdir .deps in each such goal, you can get a race condition where two goals try to make .deps at the same time.

The solution is this: if a goal needs the .deps directory to be created, let it depend on the file .deps/.d. First put this in Makefile.am:

.deps/.d:
	test -d .deps || mkdir .deps
	touch $@

.PRECIOUS: .deps/.d

And then, instead of creating the dir in each goal, just depend on .deps/.d for those goals:

.deps/apertium-wat-lol.lol.dix: apertium-wat-lol.lol.dix .deps/.d
	xsltproc lexchoicebil.xsl $< >$@

(The PRECIOUS line prevents the .d file from being cleaned up and removed automatically.)

Removing directories on make clean

Say you want to remove .deps and modes on "make clean". Don't do CLEANFILES=-rf .deps modes file1 file2 …, it doesn't work everywhere.

A more portable solution is this:

CLEANFILES = $(TARGETS_COMMON)
clean-local: 
	-rm -rf .deps modes