In close collaboration with Seoul National University's Structural Complexity Laboratory

# Makefiles

Makefiles are command files used by the “make” or “gmake” system to create a software system (or sometimes other object, such as documentation) from sources.

The important thing for users to remember is

##### Never Execute a Makefile

The syntax is fairly different from shell or other scripts; nevertheless, it occurs surprisingly often that a shell interpreter is able to 'interpret' the first few lines of a makefile. If, as often occurs, the first template happens to be one for uninstalling the package, the results can be disastrous. For example, if the variables $dir,$base and $ext haven't been initialised in a way the shell can understand, then rm$dir/$base*$ext

might well get interpreted as

rm /*

The important thing for developers to remember is

##### Always protect Users from Executing a Makefile

For the reasons above, I strongly recommend, if you are writing a makefile, to include as early as possible in your file something like:

# Template to protect users against accidentally
# executing a makefile - skipped if called by make
# if called as a script,
# it should barf on the unexpected "ifeq",
# but even if it manages to ignore that,
# it should print and exit
# Note that this protection is needed, because makefiles
# can sometimes be valid shell scripts - witness the
# standard XMILL makefile that manages to skip errors
# till it gets to
# clean:
#	rm -r -f $(TMP)/*$(TARGETS)
# when executed in most unix shells -
# which isn't very nice if \$(TMP) is undefined...
ifeq (1,0)
echo "THIS IS NOT A SHELL SCRIPT!!!!"
echo "IT IS A CONFIGURATION FILE FOR THE make SYSTEM"
echo "DO NOT EXECUTE IT"
exit 1
endif

This won't affect the execution of the makefile at all, because 1 will never equal 0 (so the nested part will never even be seen by make)

It works as a protection in all unix shells I have tried; it may not work as well in DOS, but I assume it would at least cause an abort.