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.
446building the executables 446  (422)
flags for compilation from .as to an executable 447
compilation from .as to an executable 448

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.
    447flags for compilation from .as to an executable 447  (446)
    FLAGSx= \
      -fx=$(EXECUTABLEVARIANTPOSTFIX) \
      -dMacros$(PROJECTNAME) \
      -Mno-mactext -M2 -Mno-abbrev \
      -csmax=0

    Uses EXECUTABLEVARIANTPOSTFIX 449 and PROJECTNAME 124.
  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.

448compilation from .as to an executable 448  (446)  449
executablevariants: $(VARIANTSTOBUILD:%=executablevariant.%)

Defines:
executablevariants, used in chunk 451a.

Uses executablevariant 449 and VARIANTSTOBUILD 128.

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.%.

449compilation from .as to an executable 448+   (446)  448  450
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 448 and 553.
EXECUTABLEVARIANTPOSTFIX, used in chunks 447 and 450.

Uses binaryexecutable 450, FLAGS 442, LIBRARYNAME 124, VARIANTADDITIONALFLAGS 540, VARIANTASSERTION 131, VARIANTEXECUTABLEFLAGS 131, VARIANTFLAGS 131, and VARIANTPOSTFIX 131.

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.

450compilation from .as to an executable 448+   (446)  449  451a
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 449.
BUILDEXEC, never used.
EXECFLAGS, used in chunk 451a.

Uses ALDORFLAGS 439, EXECUTABLEVARIANTPOSTFIX 449, FLAGS 442, VARIANTEXECUTABLEFLAGS 131, and VARIANTFLAGS 131.

We want to allow

make NAMEOFEXECUTABLE

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

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

Uses ALDOR 425, EXECFLAGS 450, executablevariants 448, PROJECTROOT 346, and VARIANTPOSTFIX 131.

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.

451bcompilation from .as to an executable 448+   (446)  451a
$(PROJECTROOT)/lib:
        cd $(PROJECTROOT) && $(MAKE) all

Uses all 346 and PROJECTROOT 346.