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

462code file generation 462  (458 539)  463
include $(PROJECTROOT)/Makefile.def
include Makefile.asfiles

Defines:
ASFILES, used in chunks 464, 466, 499, 504, 505b, and 545–47.

Uses PROJECTROOT 346.

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.

463code file generation 462+   (458 539)  462  464a
${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 125, LIBPREFIX 124, LIBRARYNAME 124, MAJORVERSION 124, MINORVERSION 124, PATCHVERSION 124, PROJECTNAME 124, and projectname 124.

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.

464acode file generation 462+   (458 539)  463  464b
SRCS=$(LIBRARYNAME)version $(notdir $(ASFILES))
NOPREFIXFILES=Makefile
FILES=${NOPREFIXFILES} ${ASFILES:%=%.as}
DIRS =
include $(PROJECTROOT)/Makefile.inc

Defines:
SRCS, used in chunks 443a, 464b, 545, 546, and 553.

Uses ASFILES 462, DIRS 351a, FILES 351a, LIBRARYNAME 124, and PROJECTROOT 346.

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.

464bcode file generation 462+   (458 539)  464a  544
# 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 462, CODEFILES 432, LIBPREFIX 124, NOTANGLE 348, NWESCAPE 433a, nwescape.pl 433a, PERL 427b, SRCS 464a, and TOOLS 423b.