Compiler Problems

All (large) software projects have bugs. This includes compilers and other tools used to build your code. Typically these come in the form of optimization errors, where your code fails to compile, or produces bad output, when built with certain compiler flags. For example, building all code with gcc -O3 -fast could lead to problems.

To fix this, we typically want to build some modules with different compiler flags to other modules. We can do this in a makefile as shown:

# gcc bug #11234: dapple.c fails to compile
# with normal -O3 flags
dapple.o: dapple.c
$(CC) -c -O2 -fno-fast-math dapple.c

Note that:

  • We include a special rule for dapple.c, not using the standard $(CFLAGS), etc.
  • We log the bug, and include the bug number! We should always report bugs as we find them. If possible, include a URL to the bug report.
  • Always comment `strange code' to explain why it exists and why we're making this exception. Later, if the compiler bug is fixed, we can track down and remove this unnecessary code; otherwise your program will become littered with obsolete cruft as time passes.

If this only happens on one platform, we will only want to include this rule on that platform. To do this, we can include files in our makefile.

Here we include separate makefile fragments in subdirectories if they exist. The - sign before the include means that the make is not to fail if the included file does not exist: in each directory there may be a file$(ARCH), which is included if it exists. The dapple.o fragment above may be in that file, for example.

# root source of make setup environment

# general architecture specific defaults
include $(MKARCH)

# local setup locations and files
MKLOC := loc

# experiment specific defaults for architecture
MKSETUP := $(DIR)/Makefile.setup.$(BUILDARCH).$(TASK)
-include $(MKSETUP)