29.8 Building Executables

  29.8.1 Aldor Compiler Flags
  29.8.2 Building the Variants of the Executables

Similar to the build of libraries we also support several variants of executables which are compiled using different compiler options.

Most importantly, the targets in this section are used to compile the generated file test/TestSuite.as, see 41.5.

The actual name of the executable should be given through the variable EXECUTABLE.

A typical call to build all the variants (Section 15.2) of the libraries would be the following.

$(MAKE) EXECUTABLE=TestSuite executablevariants

It will build all the variants as specified through the variable VARIANTSTOBUILD.

Such a call appears in test/Makefile.nw for the generation of the TestSuite executables.

ToDo 20 Check: The source file for the executable should lie in the same directory from where the above MAKE is called. See target check.
450building the executables 450  (427)
flags for compilation from .as to an executable 451
compilation from .as to an executable 452

29.8.1 Aldor Compiler Flags

The flags that go to the command line of the ALDOR compiler calls are separated into four classes.

  1. The flags given by VARIANTFLAGSxxx. Which variant is put onto the command line depends on the variant that is currently processed by the Makefile.
  2. The flags that are common for each call of the ALDOR compiler. They have already been specified in Section 29.7.1.
  3. The flags that are to be put for every compilation of a .as file to an executable. The variable EXECUTABLEVARIANTPOSTFIX is specified further below.
    451flags for compilation from .as to an executable 451  (450)
    FLAGSx= \
      -fx=$(EXECUTABLEVARIANTPOSTFIX) \
      -dMacros$(PROJECTNAME) \
      -Mno-mactext -M2 -Mno-abbrev \
      -csmax=0

    Uses EXECUTABLEVARIANTPOSTFIX 453 and PROJECTNAME 127.
  4. The flags that may depend on the specific executable.
    ToDo 21 Expand this item. Here we would like to describe
    VARIANT${EXECUTABLE}FLAGS$*

29.8.2 Building the Variants of the Executables

The target executablevariants is used to build an executable of every variant given through the variable VARIANTSTOBUILD.

452compilation from .as to an executable 452  (450)  453
executablevariants: $(VARIANTSTOBUILD:%=executablevariant.%)

Defines:
executablevariants, used in chunk 455a.

Uses executablevariant 453 and VARIANTSTOBUILD 131.

From now on we assume that the variable VARIANT is set and we build the platform-dependent executables. The target executablevariant.% is very similar to libraryvariant.%.

453compilation from .as to an executable 452+   (450)  452  454
executablevariant.%:
        $(MAKE) VARIANT=$* \
            VARIANTPOSTFIX="$(VARIANTPOSTFIX$*)" \
            VARIANTFLAGS="$(VARIANTADDITIONALFLAGS$*) \
                          -l$(LIBRARYNAME)$(VARIANTPOSTFIX$*) \
                          $(VARIANTASSERTION$*) \
                          $(VARIANTFLAGS$*)" \
            VARIANTEXECUTABLEFLAGS="$(VARIANT${EXECUTABLE}FLAGS$*)\
                $(VARIANTEXECUTABLEFLAGS$*)" \
            EXECUTABLEVARIANTPOSTFIX="$(EXECUTABLE)$(VARIANTPOSTFIX$*)" \
          binaryexecutable

Defines:
executablevariant, used in chunks 452 and 555.
EXECUTABLEVARIANTPOSTFIX, used in chunks 451 and 454.

Uses binaryexecutable 454, FLAGS 446, LIBRARYNAME 127, VARIANTADDITIONALFLAGS 543, VARIANTASSERTION 134, VARIANTEXECUTABLEFLAGS 134, VARIANTFLAGS 134, and VARIANTPOSTFIX 134.

The name of the executable must be given through the variable EXECUTABLE.

The variable EXECFLAGS is similar to FLAGS and collects all the commandline parameters for the call of the ALDOR compiler.

454compilation from .as to an executable 452+   (450)  453  455a
EXECFLAGS= \
  $(ALDORFLAGS) \
  $(VARIANTEXECUTABLEFLAGS) \
  $(VARIANTFLAGS) \
  $(FLAGSx)

binaryexecutable: BUILDEXEC $(EXECUTABLEVARIANTPOSTFIX)

BUILDEXEC:
        @echo
        @echo "======= Building ${EXECUTABLEVARIANTPOSTFIX} with FLAGS ======="
        @echo "$(EXECFLAGS)"
        @echo "======= Building ${EXECUTABLEVARIANTPOSTFIX}  end FLAGS ======="

Defines:
binaryexecutable, used in chunk 453.
BUILDEXEC, never used.
EXECFLAGS, used in chunk 455a.

Uses ALDORFLAGS 443a, EXECUTABLEVARIANTPOSTFIX 453, FLAGS 446, VARIANTEXECUTABLEFLAGS 134, and VARIANTFLAGS 134.

We want to allow

make NAMEOFEXECUTABLE

and, therefore, check whether the variable EXECUTABLE has been set.

455acompilation from .as to an executable 452+   (450)  454  455b
%$(VARIANTPOSTFIX): %.as $(PROJECTROOT)/lib
        (if [ -z "$(EXECUTABLE)" ]; then \
                $(MAKE) EXECUTABLE="$*" executablevariants;\
        else \
                $(ALDOR) $(EXECFLAGS) $<; \
        fi)

Uses ALDOR 429, EXECFLAGS 454, executablevariants 452, PROJECTROOT 350, and VARIANTPOSTFIX 134.

If the lib directory does not exist, it indicates that the library has not yet been built. So we are going to build it by making all on the top-level.

Since the lib directory is rebuilt each time the library has been compiled (see target all), it can be used as a time stamp for the previous target.

455bcompilation from .as to an executable 452+   (450)  455a
$(PROJECTROOT)/lib:
        cd $(PROJECTROOT) && $(MAKE) all

Uses all 350 and PROJECTROOT 350.