29.7 Building the Libraries

  29.7.1 Aldor Compiler Flags
  29.7.2 Building the Variants of the Library

There are, in fact, several libraries that should be build. First of all Aldor distinguishes between platform-independent (extension .al) and platform-dependent (extension .a) libraries. ALLPROSE will build both libraries by default whose name is given through the variable LIBRARYNAME.

Additionally, ALLPROSE builds platform-independent and platform-dependent testcases libraries, named through the variable TCLIBRARYNAME. They are used when building and running a testsuite, see test/TestSuite.as and check.

The variables and targets below describe how to build the .al and .a form of a library. The actual name of the library is given through the variable SUBLIBRARYNAME which is either equal to LIBRARYNAME as in Section 33.1 or TCLIBRARYNAME as in Section 41.1.

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

$(MAKE) SUBLIBRARYNAME=$(LIBRARYNAME) SUBLIBPREFIX=$(LIBPREFIX) libraryvariants

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

Such a call appears in src/Makefile.nw for the generation of the project libraries and in test/Makefile.nw for the generation of the testcases libraries.

442building the libraries 442  (427)
common Aldor compiler flags 443a
flags for compilation from .as to .ao 443b
flags for compilation from .ao to .o 444a
generic library built 444b
compilation of .al and .a library 447a
compilation from .as to .ao 447b
compilation from .ao to .o 448

29.7.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. These flags are put the command line for the compilation of the .al and the .a libraries as well as for the compilation of an executable.
  2. The flags that are common for each call of the ALDOR compiler.
    443acommon Aldor compiler flags 443a  (442)
    ALDORFLAGS= \
      -Y $(PROJECTROOT)/src -Y . -Y $(ALDORROOT)/lib \
      -I $(PROJECTROOT)/include -I $(ALDORROOT)/include

    Defines:
    ALDORFLAGS, used in chunks 446 and 454.

    Uses ALDORROOT 429 and PROJECTROOT 350.
  3. The flags that are to be put for every compilation of .as to .ao files. The name FLAGSal was chosen in order to unify the target libraries.
    443bflags for compilation from .as to .ao 443b  (442)
    FLAGSal= \
      -fao \
      -dMacros$(PROJECTNAME) \
      -Mno-mactext -M2 -Mno-abbrev

    Defines:
    FLAGSal, never used.

    Uses PROJECTNAME 127.
  4. The flags that are to be put for every compilation of .ao to .o files. The name FLAGSa was chosen in order to unify the target libraries.
    444aflags for compilation from .ao to .o 444a  (442)
    FLAGSa=-fo -csmax=0

    Defines:
    FLAGSa, never used.

29.7.2 Building the Variants of the Library

The target libraryvariants is used to build a .al and .a library of every variant given through the variable VARIANTSTOBUILD.

444bgeneric library built 444b  (442)  445
libraryvariants: $(VARIANTSTOBUILD:%=libraryvariant.%)

Defines:
libraryvariants, used in chunks 463 and 543.

Uses libraryvariant 445 and VARIANTSTOBUILD 131.

From now on we assume that the variable VARIANT is set and build the platform-independent .al and the platform-dependent .a libraries.

The target libraryvariant% is very similar to executablevariant%.

The variable VARIANTADDITIONALFLAGSxxx can be used to give additional flags. It is used in ALLPROSE to add more libraries for the compilation of the testsuite.

445generic library built 444b+   (442)  444b  446
libraryvariant.%:
        $(MAKE) VARIANT=$* \
            VARIANTPOSTFIX="$(VARIANTPOSTFIX$*)" \
            VARIANTFLAGS="$(VARIANTADDITIONALFLAGS$*) \
                          -l$(LIBRARYNAME)$(VARIANTPOSTFIX$*) \
                          $(VARIANTASSERTION$*) \
                          $(VARIANTFLAGS$*)" \
            LIB="lib$(SUBLIBRARYNAME)$(VARIANTPOSTFIX$*)" \
          LIBRARY.al LIBRARY.a

Defines:
LIB, used in chunks 446–48, 509b, 513, 516, 517, 533, and 551.
libraryvariant, used in chunk 444b.

Uses LIBRARYNAME 127, VARIANTADDITIONALFLAGS 543, VARIANTASSERTION 134, VARIANTFLAGS 134, and VARIANTPOSTFIX 134.

The name of the library must be given through the variable SUBLIBRARYNAME. Filenames are prepended by some prefix which must be given through the variable SUBLIBPREFIX.

Furthermore the variable SRCS should list the names of the Aldor source files (without prefix) that lie in the current directory. These files are taken to update the library.

All of these variables should be set in src/Makefile.nw and test/Makefile.nw.

The dependencies in src/Makefile.dep and test/Makefile.dep are intended to be used for the platform-independent .al and the platform-dependent .a library. Therefore FILEEXTENSION is set to either ao or o and LIBPOSTFIX reflects the value of the postfix to SUBLIBRARYNAME together with the extension .al or .a.

The variable FLAGS collects all the commandline parameters for the call of the ALDOR compiler.

446generic library built 444b+   (442)  445
FILEEXTENSIONal=ao
FILEEXTENSIONa =o
LIBRARY.%:
        $(MAKE) LIBPOSTFIX="$(VARIANTPOSTFIX).$*" \
                FILEEXTENSION="$(FILEEXTENSION$*)" \
                FLAGS="$(ALDORFLAGS) $(VARIANTFLAGS) $(FLAGS$*)" \
                LIBEXTENSION=$* \
            BUILDTEXT $(LIB).$*
BUILDTEXT:
        @echo
        @echo "======= Building ${LIB}.$(LIBEXTENSION) with FLAGS ======="
        @echo "$(FLAGS)"
        @echo "======= Building ${LIB}.$(LIBEXTENSION)  end FLAGS ======="

Defines:
FILEEXTENSION, used in chunk 533.
FLAGS, used in chunks 447b, 448, 453, and 454.
LIBPOSTFIX, used in chunk 533.

Uses ALDORFLAGS 443a, LIB 445, VARIANTFLAGS 134, and VARIANTPOSTFIX 134.

An object library as specified by LIB is built if all its members have been updated.

447acompilation of .al and .a library 447a  (442)
LIBALMEMBERS=$(SRCS:%=${LIB}.al(${SUBLIBPREFIX}%.ao))
${LIB}.al: $(LIBALMEMBERS)
${LIB}.a:  $(SRCS:%=${LIB}.a(${SUBLIBPREFIX}%.o))
        ${RANLIB} $@

Defines:
LIBALMEMBERS, used in chunk 551.

Uses LIB 445, RANLIB 432, and SRCS 468a.

The actual compilation of the .al library looks now relatively easy. Call the ALDOR compiler, move the compiled file to the library replacing an already existing one, and cleaning up.

A member depends on the corresponding .as file and the explicitly listed dependencies in the generated file src/Makefile.dep or test/Makefile.dep. In case of the testcases library with name TCLIBRARYNAME there is another dependency on the generated .signatures.as files as specified in test/Makefile.nw, see Section 41.4.3.

Note that the % below includes the SUBLIBPREFIX.

447bcompilation from .as to .ao 447b  (442)
${LIB}.al(%.ao): %.as
        @echo Compiling $*.as ... ;
        $(ALDOR) $(FLAGS) $*.as
        ${ARREPLACE} ${LIB}.al $*.ao
        $(RM) $*.ao

Uses ALDOR 429, ARREPLACE 432, FLAGS 446, and LIB 445.

A member depends on the corresponding .ao file in the .al library and the explicitly listed dependencies in the generated file src/Makefile.dep or test/Makefile.dep.

Note that the % below includes the SUBLIBPREFIX.

448compilation from .ao to .o 448  (442)
${LIB}.a(%.o): ${LIB}.al(%.ao)
        @echo Compiling $*.ao --> $*.o ... ;
        ${AREXTRACT} ${LIB}.al $*.ao;
        ${ALDOR} $(FLAGS) $*.ao;
        $(RM) $*.ao;
        ${ARREPLACE} ${LIB}.a $*.o
        $(RM) $*.o

Uses ALDOR 429, AREXTRACT 432, ARREPLACE 432, FLAGS 446, and LIB 445.