# Make

This chapter shortly describes a popular, but nearly unusable tool called `make`, which can be used to solve project management tasks when using `hsc`. This is not the only tool which is able to do so, but it should exist on most platforms.

## What is Make?

Let's start with a quote from the documentation to `GNUmake`:

> The `make' utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. [...]

> You can use `make' with any programming language whose compiler can be run with a shell command. Indeed, `make' is not limited to programs. You can use it to describe any task where some files must be updated automatically from others whenever the others change. [...]

> To prepare to use `make', you must write a file called the "makefile" that describes the relationships among files in your program and provides commands for updating each file.

As of it's general purpose design, `make` also fits to be used in combination with `hsc`. So far for the good part.

## Which Make to Use

One of the worst things about `make` is that - as far as I know - it comes from the fossil Unix world, with the usual results. There are several programs with the same name, but different features. Furthermore, you will have to bother with many occurrences of cryptic looking characters.

This documentation will always refer to a version of make commonly known as `GNUmake`, as it is freely distributable, exists as source code and has been ported to most platforms.

(For Amigoids: A tool called `smake` has become very popular under this system. Not because it is so powerful - on the contrary - but because it was shipped with the SAS/c package. You can put away this tool for `hsc`, probably not a single example given within this manual or the supporting material will work.)

## Why Make Sucks

One thing nearly all `make`-tools have in common is the inability to produce useful error messages - if any at all.

Most of them are very picky about blanks and tabs (which can be created by pressing the `TAB` key). Tabs in plain text file are one of the most brain-damaged concept the (so called) modern computer industry has established. Of course it is easy for a machine to distinguish between spaces and tabs by their ASCII code. But the user will see a blank space on the screen in both cases.

This becomes even worse, as many editor applications do not care about tabs and replace them by spaces, normally without notifying the user about that. This can not only be annoying, as these editors in most cases are not sure if they should replace a tab by four or eight space characters, often resulting in an unexpected looking display. Even worse, picky tools (like most `make` tools) will interpret the Makefile as trashed. So make sure you are using a decent editor. For example, `memacs` coming with the standard Workbench does a good job on this.

## Makefiles and Pattern Rules

As already mentioned above, you will have to write a so called Makefile. This is by far the funniest part of `make` (apart from interpreting esoteric error messages). Basically, you have to specify rules how a target depending on specifics source is created. For `hsc`, the target is usually the HTML document, and the sources are all those files with the `.hsc` extension needed to create the document.

As it would be dull to tell `make` exactly what to do for every single target, you can specify so called pattern rules, which tell `make` how to generally handle whole groups of files.

Ancient versions of `make` often only support a rather impotent way for such pattern rules. An example of such an outdated rule:

    .c.o:
        $(CC) $(CFLAGS) -c $<

The first line tells `make` that now a rule will follow how to create a target with a ```.o`'' extension from a file with a ```.c`'' extension. You shouldn't bother too much about the second line. The only thing you will have to know: You can forget these kind of rules for `hsc`. They did a good job for the ridiculous bunch of C-programmers and their ridiculous compilers, but they are useless for everything more sophisticated. However, many `make`-tools still only support such rules.

The equivalent pattern rule in a more reasonable syntax look like this:

    %.o : %.c
        $(CC) $(CFLAGS) -c $<

This should give you a clue which sections of the manual of `make` should be relevant for you. Within the next chapter, you will find some remarks about how to write a Makefile for `hsc`, but there probably still will be no way around at least giving a glimpse to the manual of `make`.

## So Why Make?

After reading the above, one might think no one uses `make` as long there any alternative left. See, and there is the problem: If you want to have something quite powerful and flexible, which is available for most platforms and is freeware, there currently is no alternative.

If you know of any, tell me and I will kick the whole chapter about `make` and Makefiles immediately.

## Where to Get Make

See also the section about Related Stuff where to obtain the version of `make` recommended for use with `hsc`.