Difference between revisions of "Talk:Writing Makefiles"

From Apertium
Jump to navigation Jump to search
(pre)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Deprecated modes tips==
==Avoid duplicating install="yes" (modes.xml) in Makefile.am==
These are not necessary after revision 51184 of apertium.

===Only one modes goal===
The command <code>apertium-gen-modes</code> creates _all_ modes files at once. So one goal is sufficient (and several can lead to problems with e.g. make -j2) when creating your debug modes.

So, make one goal for a mode you know it creates, and then put that goal into noinst_DATA:
<pre>
modes/$(PREFIX1).mode: modes.xml
apertium-validate-modes modes.xml
apertium-gen-modes modes.xml
cp *.mode modes/

noinst_DATA=modes/$(PREFIX1).mode
</pre>
(noinst_DATA is for listing stuff that you want built, but not installed or distributed. Don't list the mode in TARGETS_COMMON or EXTRA_DIST, debug modes should not be installed or distributed.)

===Avoid ending up with root-owned modes files===
When you do "sudo make install", some Makefiles.am still have a bug where they'll leave around root-owned modes files. Then on the next "make", you see a "Permission denied" error, since it tries to create the same filenames again as non-root. (The installable mode files have paths pointing to e.g. /usr/local, while the non-install mode files have paths that point to your source development directory. You want the latter to hang around so you can do <code>apertium -d . fie-bar</code>.)

A workaround is this: when doing make install, first stash away any already existing development modes directory, the generate the install modes, then clean up the root-owned stuff and unstash the old modes directory:
<pre>
install-data-local:
mv modes modes.bak
apertium-gen-modes modes.xml $(BASENAME)
rm -rf modes
mv modes.bak modes
test -d $(DESTDIR)$(apertium_modesdir) || mkdir $(DESTDIR)$(apertium_modesdir)
$(INSTALL_DATA) $(PREFIX1).mode $(DESTDIR)$(apertium_modesdir)
$(INSTALL_DATA) $(PREFIX2).mode $(DESTDIR)$(apertium_modesdir)
rm $(PREFIX1).mode $(PREFIX2).mode
</pre>
This method leaves no root-owned files hanging around.

(It might look odd that we "rm -rf modes" there after gen-modes, but "apertium-gen-modes somedir" creates both apertium-foo-bar/foo-bar.mode and non-installable debug modes in apertium-foo-bar/modes/ – perhaps tihs could be fixed in apertium-gen-modes so we can avoid this makefile workaround.)


===Avoid duplicating install="yes" (modes.xml) in Makefile.am===
Most language pairs have lines like
Most language pairs have lines like
<pre>
<pre>
Line 7: Line 44:
for every mode that has install="yes" in modes.xml. So setting install="yes" doesn't actually install the mode, it just creates an installable mode. This is redundant and confusing.
for every mode that has install="yes" in modes.xml. So setting install="yes" doesn't actually install the mode, it just creates an installable mode. This is redundant and confusing.


To actually install on install="yes", we might do something like this (untested and probably wrong makefile syntax):
To actually install all and only those with install="yes", you can do this:
<pre>
<pre>
install-data-local:
install-data-local:
Line 15: Line 52:
mv modes.bak modes
mv modes.bak modes
test -d $(DESTDIR)$(apertium_modesdir) || mkdir $(DESTDIR)$(apertium_modesdir)
test -d $(DESTDIR)$(apertium_modesdir) || mkdir $(DESTDIR)$(apertium_modesdir)
files=`xmllint --xpath '//mode[@install="yes"]/@name' modes.xml | sed 's/ *name="\([^"]*\)"/\1.mode /g' `
modes=`xmllint --xpath '//mode[@install="yes"]/@name' modes.xml | sed 's/ *name="\([^"]*\)"/\1.mode /g'`; \
$(INSTALL_DATA) $files $(DESTDIR)$(apertium_modesdir)
$(INSTALL_DATA) $$modes $(DESTDIR)$(apertium_nn_modesdir); \
rm $files
rm $$modes
</pre>
</pre>

(xmllint and sed are prerequisites of apertium/lttoolbox, and the sed line is portable, so it doesn't add any dependencies.)

Latest revision as of 15:54, 24 March 2014

Deprecated modes tips[edit]

These are not necessary after revision 51184 of apertium.

Only one modes goal[edit]

The command apertium-gen-modes creates _all_ modes files at once. So one goal is sufficient (and several can lead to problems with e.g. make -j2) when creating your debug modes.

So, make one goal for a mode you know it creates, and then put that goal into noinst_DATA:

modes/$(PREFIX1).mode: modes.xml
	apertium-validate-modes modes.xml
	apertium-gen-modes modes.xml
	cp *.mode modes/

noinst_DATA=modes/$(PREFIX1).mode

(noinst_DATA is for listing stuff that you want built, but not installed or distributed. Don't list the mode in TARGETS_COMMON or EXTRA_DIST, debug modes should not be installed or distributed.)

Avoid ending up with root-owned modes files[edit]

When you do "sudo make install", some Makefiles.am still have a bug where they'll leave around root-owned modes files. Then on the next "make", you see a "Permission denied" error, since it tries to create the same filenames again as non-root. (The installable mode files have paths pointing to e.g. /usr/local, while the non-install mode files have paths that point to your source development directory. You want the latter to hang around so you can do apertium -d . fie-bar.)

A workaround is this: when doing make install, first stash away any already existing development modes directory, the generate the install modes, then clean up the root-owned stuff and unstash the old modes directory:

install-data-local:
	mv modes modes.bak
	apertium-gen-modes modes.xml $(BASENAME)
	rm -rf modes
	mv modes.bak modes
	test -d $(DESTDIR)$(apertium_modesdir) || mkdir $(DESTDIR)$(apertium_modesdir)
	$(INSTALL_DATA) $(PREFIX1).mode $(DESTDIR)$(apertium_modesdir)
	$(INSTALL_DATA) $(PREFIX2).mode $(DESTDIR)$(apertium_modesdir)
	rm $(PREFIX1).mode $(PREFIX2).mode

This method leaves no root-owned files hanging around.

(It might look odd that we "rm -rf modes" there after gen-modes, but "apertium-gen-modes somedir" creates both apertium-foo-bar/foo-bar.mode and non-installable debug modes in apertium-foo-bar/modes/ – perhaps tihs could be fixed in apertium-gen-modes so we can avoid this makefile workaround.)


Avoid duplicating install="yes" (modes.xml) in Makefile.am[edit]

Most language pairs have lines like

	$(INSTALL_DATA) $(PREFIX1).mode $(DESTDIR)$(apertium_modesdir)
	rm $(PREFIX1).mode

for every mode that has install="yes" in modes.xml. So setting install="yes" doesn't actually install the mode, it just creates an installable mode. This is redundant and confusing.

To actually install all and only those with install="yes", you can do this:

install-data-local:
	mv modes modes.bak
	apertium-gen-modes modes.xml $(BASENAME)
	rm -rf modes
	mv modes.bak modes
	test -d $(DESTDIR)$(apertium_modesdir) || mkdir $(DESTDIR)$(apertium_modesdir)
	modes=`xmllint --xpath '//mode[@install="yes"]/@name' modes.xml | sed 's/ *name="\([^"]*\)"/\1.mode /g'`; \
		$(INSTALL_DATA) $$modes $(DESTDIR)$(apertium_nn_modesdir); \
		rm $$modes

(xmllint and sed are prerequisites of apertium/lttoolbox, and the sed line is portable, so it doesn't add any dependencies.)