
On Wed, Sep 18, 2013 at 12:39:45AM +1000, David wrote:
But then, why use a makefile?
because make is a good tool to use whenever you need to automate creating or updating one or more files that are dependent on other files being created or changed. it's not just for programming, it's a general purpose tool you can use to define relationships between particular files, or between *types* of files, and have certain actions taken based on changes in files. The most common use is to create object or executable files whenever one or more of the source files has changed or a new source file created and, *just as importantly*, do nothing if nothing has changed. another common use is to generate config files. e.g. automation of an apache include file to define virtual hosts with a script to do the work, a simple text file containing details (like domain name, ip address, directory, etc) and a Makefile to say that the include file is dependant on the script and the text file. running make will update the include file if either changes, or do nothing if neither has changed. the point is that the simple text file contains *only* the variable details in a very simple, easily edited and easily parsed format (e.g. one entry per line, tab or comma or colon delimited. or a .ini file). the script contains a template to generate the actual "<VirtualHost ...> ... </VirtualHost>" config fragment for each vhost. this same simple text file is also used by other scripts - e.g. to generate a web page listing all the virtual hosts with clickable links, to run a web log analyser on every vhost, or a link checker like webcheck, or a search engine like htdig. the simple text file is an easily parsed authoritative single-source of information about every vhost on the system. theoretically, you could parse the same information out of the apache config file itself, but it's much harder to do that. i've used this technique repeatedly over the years to automate many repetitive tasks (incl. apache config, mailing lists, bind zone files, virtual mail domains, MTA junk maps, spamassassin rules, bulk-creation of the current semester's student accounts on a HPC cluster, and more). anything that would otherwise be a copy/paste/edit job. automating it makes it simpler, faster, reduces typing, and eliminates most sources of human error. of course, this kind of automation doesn't require Make. you could do the same things entirely in shell or perl or python or whatever - but you'd have to implement your own method of detecting if any source files had changed or been created, and possibly your own language for defining relationship rules. craig -- craig sanders <cas@taz.net.au>