February 2005
The make utility commonly used for handling software building can also be employed in a variety of ways a lot of people (including developers) never really think about. It can even be used to manage cvs.
A lot of documenation requires the ability to reparse text written in one form to another. The most complicated of texts are likely (but not limited to) XML and TeX reformatting. It can, however, be used in other ways. A simple rule for dumping html into lynx output is a good one; which often comes in handy when an original document is in HTML format and it often arises that a conversion to text might be handy after an update to it. Here is a simple Makefile that does the chore.
# Resume Makefile LYNX=lynx RESUME=resume HTML=$(RESUME).html TEXT=$(RESUME).txt text: $(LYNX) -dump $(HTML) > $(TEXT)
While that is a rather simplistic demonstration, it proves the point that make can be used for a wide variety of things. Here is an example of a somewhat more elaborate Makefile that handles html to postscript convserions and postscript to pdf.
# Resume Makefile RESUME=resume HTML=$(RESUME).html TEXT=$(RESUME).txt POSTSCRIPT=$(RESUME).ps PDF=$(RESUME).pdf LYNX=lynx HTML_PS=html2ps PS_PDF=ps2pdf all: text postscript pdf text: $(LYNX) -dump $(HTML) > $(TEXT) postscript: $(HTML_PS) $(HTML) -o $(POSTSCRIPT) pdf: postscript $(PS_PDF) $(POSTSCRIPT) > $(PDF) clean: rm -f $(PDF) $(POSTSCRIPT) $(TEXT)
Now the resume, originally in html format can be updated to
other formats without much effort. Note that the pdf
target has a dependancy, the postscript target
since ps2pdf uses the postscript formatted document as input.
Another use for make is managing some tasks where it might make sense.
In the following scenario, a $HOME is being archived and
sent off to an archive directory (which could be an NFS, smbmount or
other filesystem).
# A $HOME Archiver without a shell script home_archive: tar czvf /mnt/arhives/current/home.tgz /home/jdoe
Of course, the above is a bit too simple and a wee bit ambiguous. Now for something slightly more refined.
USER=jdoe HOMEDIR=/home/$USER ARCHIVE_NAME=$USER.tgz TAR=/bin/tar TAR_ARGS=czvf DESTDIR=/mnt/archives home_archive: $(TAR) $(TAR_ARGS) $(DESTDIR/$ARCHIVE_NAME) $(HOMEDIR)
For multiple home directories, using a lot of macros can save time and simplifying where appropiate.
HOMEDIR=/home TAR="/bin/tar czvf" DESTDIR=/mnt/archives/current all: john_doe jane_doe webmin john_doe: $(TAR) $(DESTDIR/$@.tgz) $HOMEDIR/$@) jane_doe: $(TAR) $(DESTDIR/$@.tgz) $HOMEDIR/$@) webmin: $(TAR) $(DESTDIR/$@.tgz) $HOMEDIR/$@)
Make, while ultimately designed for program build management can also be used for a variety of other tasks such as document conversion and maintenance, running frequent processes and even file management.