Subject: A General Compiling System

From: [email-masked] (Bill Ross )
Date: Wed, 24 Nov 1993 15:47:59 -0800

Since there has been some discussion of porting code to
different platforms, perhaps people would be interested
in the compilation system I devised for Amber, which I
have obtained permission to share. Source code developers 
can use it to hide machine dependencies from users compiling 
on different machines.  This describes the scheme in the 
yet-to-be-released 4.1 version of Amber.

Here is an example of compiling Amber:

% tar xof tarfile
% cd amber4/src
% cp Machine/Machine.iris4K MACHINE
% Makeall

As you can see, the machine-specific part is restricted to
a single step for the user. All machine-specific compilation
flags, directories and cpp definitions are contained in the 
Machine.xxx files. The Makefiles use a script called Compile
which recognizes different optimization levels and also can 
generate machine-targeted code for other Unix and non-Unix 
operating systems, using the machine dependency file. A script 
called sysdir is used by the Makefiles to extract system-specific
directories from the machine dependency file. A sys.a library
gets built in each system-specific directory, containing 
wrappers for things like the various timing calls one encounters.
A script called mksrc drives the Makefiles with alternate
machine dependency files.

The original set of system-specific files and machine compiler 
flags were written by George Seibel. I organized the 1-step
system using Makefiles and the shell scripts. There are also
tools for e.g. generating an ftp script that gives the equivalent
of "rcp -r" to a VMS system.

Obviously this is a system for developers to use in software
that is released in source version for users to compile (or
for in-house work, of course). Some details are outlined below.

It would be especially nice if it was adopted by a few other
widely distributed packages, so that the machine dependency 
handling might become a quasi standard.

Send mail to me if you want to get a copy or have ideas/suggestions
to share. At some point I will extract the necessary files into a
uuencoded compressed tar file and mail it out.

The only restriction on use will be that credits are maintained
in the scripts and documentation and that modifications are noted.

Bill Ross

The layout of the 'tools' and system libraries part is:

	amber4/src/Compile
	amber4/src/sysdir
	amber4/src/mksrc
	amber4/src/Machine/Machine.xxx		! MACHINE file
	amber4/src/Machine/xxx/Makefile
	amber4/src/Machine/xxx/sys.a		! wrappers
	amber4/src/lib/genlib.a			! wrappers

where 'xxx' roughly includes (not all are up-to-date):

iris	vm	Unicos	vms 	aix370	bsd	mflow
convex	mips	rs6000	ctss	sparc	fps500	hp
decstation      stlr           

(bsd is used for 'non-deviant' Unixes)

The routines in amber4/src/Machine/xxx/sys.a include generic
date(), flush(), hardware arithmetic info, and a timing wrappers.
The routines in amber4/src/lib/genlib.a include generic open()
and exit() wrappers.

A Machine file:

#------------------------------------------------------------------
# Copy this file to amber4/src/MACHINE to install.
#
# This file is appropriate for HP f77
#
# These aliases let us use the same command files for compilation
# on Unix systems with different names and/or flags for the fortran
# compiler.   Environment variables set here specify the location
# of system-specific source and control the use of Integer*2.
# See install.doc: "Setting Up the Configuration File"
#

setenv MACHINE "HP UX"
# HP recognizes cray style C$DIR compiler directivesCH HP

setenv MACHINEFLAGS "-DISTAR2 "

# SYSDIR is the name of the system-specific source directory for makemake
setenv SYSDIR Machine/hp

# COMPILER ALIASES:

# LOADER/LINKER:
setenv LOAD "f77 +T "
setenv LOADLIB " -lvec"

# little or no optimization:
setenv L0 "f77 -c -g +T +E4"

# standard optimization :
setenv L1 "f77 -c -O +T +E4"

# about the same as L1
setenv L2 "f77 -c +O3 +T +E4"

# highest optimization
setenv L3 "f77 -c  +OP -WP,-ur=1,-directives=c  +T +E4"

# ranlib, if it exists
setenv RANLIB "echo ranlib not needed"

#-------------------

The Makefiles look like this:

#------------------------------------------------------------------
SHELL=/bin/sh

OBJ=    giba.o gibb.o decnvh.o micst.o misc.o machinedep.o \
        nmr_strip.o slwadj.o veloc.o torcon.o rstin.o connrg.o \
        pratgr.o derivs.o derdlm.o fastwt.o tripl.o polars.o

SRC=	giba.f gibb.f decnvh.f micst.f misc.f machinedep.f \
        nmr_strip.f slwadj.f veloc.f torcon.f rstin.f connrg.f \
        pratgr.f derivs.f derdlm.f fastwt.f tripl.f polars.f

LIBSRC= ../lib/namlst90.f ../lib/mexit.f ../lib/amopen.f

gibbs:  	$(OBJ) genlib syslib
                SYSLIB=`csh ../sysdir lib` ; ../Compile LOAD -o gibbs \
                                $(OBJ) ../lib/genlib.a $$SYSLIB

bigsource:
                SYSDIR=`csh ../sysdir dir` ;  cd $$SYSDIR ; make sys.f
                SYSSRC=`csh ../sysdir src` ; \
                        ../Compile CPPONLY -P -o gibbs_all.for \
                                $(SRC) $(LIBSRC) $$SYSSRC

.f.o:           $<
                ../Compile L2 -P $<

giba.o:         giba.f
                ../Compile L1 -P $<

machinedep.o:   machinedep.f
                ../Compile L3 -P $<

#-----------LIBS

syslib::
                ( SYSDIR=`csh ../sysdir dir` ; echo sysdir is $$SYSDIR ; \
                cd $$SYSDIR ; make sys.a )

genlib::
                ( cd ../lib ; make genlib.a )

#-----------

#------------------------------------------------------------------