33.3 Code File Generation

The variable ASFILES (as given through the file src/Makefile.asfiles) specifies the source files with extension .as.nw that are considered to build the libraries. For each of these files two versions of .as files will be generated.

  1. One .as file that lies in the same directory as the corresponding .as.nw file. This version is used to generate the dependencies via tools/dependencies.pl.nw. Here the indentation of the code is as specified by the .as.nw file.
  2. The .as file with prefix LIBPREFIX will be generated into the directory src. That is why the variable SRCS should not contain duplicates.

    These files are used by the ALDOR compiler for the build of the project libraries. Here line numbers of the form

    #line LINENUMBER "FILENAME"

    are generated into the .as file. This is done by means of the ’-L’ option of NOTANGLE. The ’-L’ option, however, copies the indentation directly from the .as.nw file. There is no nested indentation as in the first case.

    By the script tools/aldordoc2codechunk.pl.nw, the contents of the +++ environments will be prepended by "+++ " and moved to the following code chunk before the file is piped to NOTANGLE.

Both versions differ only in indentation and the fact that the second version will have the line numbers from the .as.nw file added.

The reason for the generation of two versions is that it is easier to generate the dependencies from the source files that have a proper indentation (first version).

466code file generation 466  (462 542)  467
include $(PROJECTROOT)/Makefile.def
include Makefile.asfiles

Defines:
ASFILES, used in chunks 468, 470, 503, 508, 509b, and 547–49.

Uses PROJECTROOT 350.

The file src/Makefile.asfiles is generated by tools/asfiles.pl.nw (see Section 29.3) and looks as follows.

# Generated via  
# /home/hemmecke/SVK/HOME/trunk/projects/Software/allprose/tools/asfiles.pl \  
#   /home/hemmecke/SVK/HOME/trunk/projects/Software/allprose \  
#   myalps \  
#   src  
ASFILES=\  
  myalps/arith\  
  myalps/binpow\  
  myalps/copy\  
  myalps/prtype\  
  myalps/version

There is, in fact another Aldor source file that goes into the library, namely src/mymyalpsversion.as. It provides a domain implementation for the category VersionInformationType (defined in the library Aldor). However, since the information in this file can be generated from the information that is stored in Makefile.def.nw, we rather generate this file by the code below. The generated output can be found in Section 15.1.

467code file generation 466+   (462 542)  466  468a
${LIBPREFIX}${LIBRARYNAME}version.as: Makefile
        @echo ’Generate $@ ...’
        @echo ’-- Generated from src/Makefile’ > $@
        @echo ’#assert DontNeedLibrary$(PROJECTNAME)’ >> $@
        @echo ’#include "$(projectname)"’ >> $@
        @echo ’LibraryInformation$(PROJECTNAME): VersionInformationType == add {’ >> $@
        @echo ’        name: String == "$(PROJECTNAME)";’ >> $@
        @echo ’        version: String == "$(MAJORVERSION).$(MINORVERSION).$(PATCHVERSION)";’ >> $@
        @echo ’        major: MachineInteger == $(MAJORVERSION);’ >> $@
        @echo ’        minor: MachineInteger == $(MINORVERSION);’ >> $@
        @echo ’        patch: MachineInteger == $(PATCHVERSION);’ >> $@
        @echo ’        credits: List String == [$(CREDITS)];’ >> $@
        @echo ’}’ >> $@

Uses CREDITS 128, LIBPREFIX 127, LIBRARYNAME 127, MAJORVERSION 127, MINORVERSION 127, PATCHVERSION 127, PROJECTNAME 127, and projectname 127.

There should be no duplicates in SRCS. We want to compile the file src/mymyalpsversion.as first so that there will be an existing library when the other files are compiled.

468acode file generation 466+   (462 542)  467  468b
SRCS=$(LIBRARYNAME)version $(notdir $(ASFILES))
NOPREFIXFILES=Makefile
FILES=${NOPREFIXFILES} ${ASFILES:%=%.as}
DIRS =
include $(PROJECTROOT)/Makefile.inc

Defines:
SRCS, used in chunks 447a, 468b, 547, 548, and 555.

Uses ASFILES 466, DIRS 355a, FILES 355a, LIBRARYNAME 127, and PROJECTROOT 350.

In order to avoid to specify the paths of the .as.nw files, we use the vpath directive.

The generation of the .as files with prefix is given below. The generation of the .as files without prefix is the standard one as described in Section 29.4.

468bcode file generation 466+   (462 542)  468a  546
# The sort removes duplicates.
vpath %.as.nw $(sort $(dir ${ASFILES}))

${LIBPREFIX}%.as: %.as.nw $(TOOLS)/nwescape.pl
        $(PERL) $(TOOLS)/aldordoc2codechunk.pl $< |\
        $(NWESCAPE) | $(NOTANGLE) -L’--#line %L "$<"%N’ > $@

#redefine CODEFILES from Makefile.inc
CODEFILES += $(SRCS:%=$(LIBPREFIX)%.as)

Uses ASFILES 466, CODEFILES 436, LIBPREFIX 127, NOTANGLE 352, NWESCAPE 437a, nwescape.pl 437a, PERL 431b, SRCS 468a, and TOOLS 428b.
ToDo 22 Note that we use --#line above because the Aldor compiler in version 1.0.3 is not capable of dealing correctly with the #line directives.