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.

438building the libraries 438  (422)
common Aldor compiler flags 439
flags for compilation from .as to .ao 440a
flags for compilation from .ao to .o 440b
generic library built 441a
compilation of .al and .a library 443a
compilation from .as to .ao 443b
compilation from .ao to .o 444

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.
    439common Aldor compiler flags 439  (438)
    ALDORFLAGS= \
      -Y $(PROJECTROOT)/src -Y . -Y $(ALDORROOT)/lib \
      -I $(PROJECTROOT)/include -I $(ALDORROOT)/include

    Defines:
    ALDORFLAGS, used in chunks 442 and 450.

    Uses ALDORROOT 425 and PROJECTROOT 346.
  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.
    440aflags for compilation from .as to .ao 440a  (438)
    FLAGSal= \
      -fao \
      -dMacros$(PROJECTNAME) \
      -Mno-mactext -M2 -Mno-abbrev

    Defines:
    FLAGSal, never used.

    Uses PROJECTNAME 124.
  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.
    440bflags for compilation from .ao to .o 440b  (438)
    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.

441ageneric library built 441a  (438)  441b
libraryvariants: $(VARIANTSTOBUILD:%=libraryvariant.%)

Defines:
libraryvariants, used in chunks 459 and 540.

Uses libraryvariant 441b and VARIANTSTOBUILD 128.

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.

441bgeneric library built 441a+   (438)  441a  442
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 442–44, 505b, 510, 513, 514, 530, and 549.
libraryvariant, used in chunk 441a.

Uses LIBRARYNAME 124, VARIANTADDITIONALFLAGS 540, VARIANTASSERTION 131, VARIANTFLAGS 131, and VARIANTPOSTFIX 131.

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.

442generic library built 441a+   (438)  441b
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 530.
FLAGS, used in chunks 443b, 444, 449, and 450.
LIBPOSTFIX, used in chunk 530.

Uses ALDORFLAGS 439, LIB 441b, VARIANTFLAGS 131, and VARIANTPOSTFIX 131.

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

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

Defines:
LIBALMEMBERS, used in chunk 549.

Uses LIB 441b, RANLIB 428, and SRCS 464a.

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.

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

Uses ALDOR 425, ARREPLACE 428, FLAGS 442, and LIB 441b.

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.

444compilation from .ao to .o 444  (438)
${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 425, AREXTRACT 428, ARREPLACE 428, FLAGS 442, and LIB 441b.