% Copyright (C) 1989, 1992 Digital Equipment Corporation 
% All rights reserved.
% See the file COPYRIGHT for a full description.
% 
% Last Modified On Wed Oct 11 13:36:35 PDT 1995 By najork  
%      Modified On Wed Jun 14 13:37:09 PDT 1995 By kalsow  
%      Modified On Thu Apr  8 13:45:49 PDT 1993 by muller
% 
% Standard configuration file for LINUX
%

% HISTORY
% 16-Dec-97  Przemek Pardyak (pardy) at the University of Washington
%	Fixed a bug in finding m3tohtml.perl.
%
# 11-Nov-97  David Becker (becker) at the University of Washington
#	Use new make.conf BSD_PREFIX var
#
# 31-May-97  David Becker at the University of Washington
#	Added S_source() for assembly that needs a cpp pass first
#	Fixed M3 var to use the right local path
#	Changed CC_args to use the new sal paths
#
% 30-Jan-97  Wilson Hsieh (whsieh) at the University of Washington
%	add BASETARGET
%
# 25-Sep-96  Marc Fiuczynski (mef) at the University of Washington
#	Moved the domain management and conf/rc file code into SPINCOMMON.
#


%-------------------------------------------------- compilation environment ---

_quiet = "quiet" % if defined, be quiet, else be verbose

if equal(TARGET, "TARGET")
  readonly TARGET = "IX86_SPIN"
end
#readonly BUILD_ARCH = "LINUXELFFreeBSD2" # not yet
readonly BASETARGET = "IX86_SPIN"
readonly BUILD_ARCH = "LINUXELF"
readonly DEFAULT_BUILD_DIR = TARGET

BUILD_DIR = TARGET % XXX Do I need this.

include ("PLATFORMS")  % get the target-dependent mappings
include (OS_TYPE)      % get the OS-dependent functions
include (OS_TYPE & "COMMON") % get the OS-common functions

proc generateExtensionCodehooks() is
	write("__main() {}", CR)
end


readonly NAMING_CONVENTIONS = "0"
%                                        object files       libraries
%  0=Unix                          =>  .o   .io    .mo       libXX.a
%  1=Unix with a grumpy C compiler =>  .o   _i.o   _m.o      libXX.a
%  2=Windows/NT                    =>  .obj .io    .mo       XX.lib
%

%------------------------------------------------------------- export paths ---
% During the installation, destination directories that do not exist
% will be created.  You need the necessary permissions to do so; otherwise,
% the installation will fail, but can be restarted after you have 
% fixed the permissions.

% changed from "/usr/local"

if not defined("INSTALL_ROOT")
    include("INSTALL_ROOT")
    OLD_INSTALL = INSTALL_ROOT
    INSTALL_ROOT = INSTALL_ROOT & TARGET & SL
end

if not defined ("_quiet")
  write("INSTALL_ROOT is ", INSTALL_ROOT, CR)
end

%-- handy for installations that keep all M3 stuff together

BIN_INSTALL   = INSTALL_ROOT &  "/bin"                % executables
LIB_INSTALL   = INSTALL_ROOT &  "/lib/m3/" & BUILD_ARCH   % libraries
DOC_INSTALL   = INSTALL_ROOT &  "/lib/m3/doc"         % documents
PKG_INSTALL   = INSTALL_ROOT &  "/lib/m3/pkg"         % packages
EMACS_INSTALL = INSTALL_ROOT &  "/lib/elisp"          % emacs lisp code
MAN_INSTALL   = INSTALL_ROOT &  "/man"                % man pages
HTML_INSTALL  = INSTALL_ROOT &  "/lib/m3/www"         % public hypertext

% The manual pages normally go in subdirectories man{1,...8} of
% the MAN_INSTALL directory.  If you prefer to have them all in
% a single section, define MAN_SECTION to be that section's name.
% MAN_SECTION = "l"

% On some systems (e.g. AFS) you must install public files in a different
% place from where you use them.  If that is the case for your system,
% specify the "use" location here, otherwise leave them alone.
BIN_USE   = BIN_INSTALL
LIB_USE   = OLD_INSTALL & BUILD_ARCH & "/lib/m3/" & BUILD_ARCH
PKG_USE   = PKG_INSTALL

readonly INSTALL_IMPLS = "TRUE"
% "TRUE"
%    => save all source files during the install
%    => makes debugging easier and browsing more fruitful
% "" (i.e. FALSE)
%    => save only the exported interfaces and templates 
%    => makes the installed system slightly smaller.

readonly NEED_OBJECTS = "TRUE"
% "TRUE"
%    => accumulate a list of derived objects in COMPILE_OBJECTS
%    => for building shared libraries in the library_hooks function below
% ""
%    => don't bother

%---------------------------------------------------------------------- X11 ---
% If you have X11R4 installed and would like the X11R4 binding interfaces
% to be built, define the procedure "import_X11R4" to import the libraries
% that are needed.  Otherwise, define "import_X11R4" to be an empty procedure.
%
% If you use the MIT server with DECnet support, you need X11 and dnet,
% otherwise X11 should be enough.
% 
% Since X11R5 is an extension of X11R4, you can use the X11R5 libraries
% instead of X11R4.  However, the Modula-3 binding interfaces have not
% yet been upgraded to X11R5.
%
% "import_X11R4" is called from the X11R4 package.
% "import_Motif" is called from the motif package.
% "import_DECPEX" is called from the PEX package.
% "import_OpenGL" is called from the opengl package.
% "import_TCP" is called from the tcp package.

% removed "/elf" from the end of library pathnames
readonly proc import_X11R4() is
  import_lib("Xaw",  "/usr/X11/lib")
  import_lib("Xmu",  "/usr/X11/lib")
  import_lib("Xext", "/usr/X11/lib")
  import_lib("Xt",   "/usr/X11/lib")
  import_lib("SM",   "/usr/X11/lib")
  import_lib("ICE",  "/usr/X11/lib")
  import_lib("X11",  "/usr/X11/lib")
end

readonly proc import_Motif() is
  import_lib("Xm",   "/usr/X11/lib")
end

readonly proc import_DECPEX() is
  % DEC PEX differs from MIT PEX, and is only supported on Digital machines.  
end

readonly proc import_OpenGL() is
  % import_lib (GLU,  "/usr/lib")
  % import_lib (GL,   "/usr/lib")
  % import_lib (Xext, "/usr/lib")
end

readonly proc import_TCP() is
end

readonly PLATFORM_SUPPORTS_X      = "TRUE"
readonly PLATFORM_SUPPORTS_MOTIF  = "TRUE"
readonly PLATFORM_SUPPORTS_DECPEX = ""
readonly PLATFORM_SUPPORTS_OPENGL = ""

%-------------------------------------------------------------------- emacs ---
% If you have emacs and want to compile ".el" files to ".elc" files,
% fill in the function below.  Otherwise, comment out or delete the
% entire function.  Note, the distributed code assumes gnuemacs version 19
% or later.

readonly proc emacs_compile (el) is
  exec ("emacs -batch -f batch-byte-compile", el)
end

%---------------------------------------------------- C compiler and linker ---
% The following definitions are used to compile and link C modules.
% Note that these definitions can be overridden on the m3build command
% line with "-D".  (e.g.  m3build -DCC=gcc)
%
% _ifdef(a,b,c) == if defined(a) return b else return c
%
% The actual definitions must be kept on one line due to finicky details
% of the bootstrap process.

CC = _ifdef ("CC", CC, [ BSD_PREFIX & "cc", "-B" & BSD_PREFIX ])
%--- C compiler with flags for compiling a single ".c" file

LINK = _ifdef ("LINK", LINK, [ BSD_PREFIX & "cc", "-B" & BSD_PREFIX ])
%--- C compiler with flags for linking

MAKELIB = _ifdef ("MAKELIB", MAKELIB, [ BSD_PREFIX & "ar" , "cr" ])
%--- program to build library archives

RANLIB = _ifdef ("RANLIB", RANLIB, [ "touch" ])
%--- program to index libraries

ASM = _ifdef ("ASM", ASM, [ BSD_PREFIX & "as" ])
%--- assembler

% The boostrap code is not PIC
BOOT_CC = "gcc"

%------------------------------------------------------------- GNU variants ---
% The two large pieces of GNU software used by the Modula-3 system
% gcc(=m3cc) and gdb(=m3gdb) often require slightly different C compilers
% or flags.  They are specified here.  Note that they may be overridden
% from the m3build command line.
%
% To use the GNU defaults for CC and CFLAGS, specify "*".
%

GNU_CC     = _ifdef ("GNU_CC",     GNU_CC,     "gcc")
GNU_CFLAGS = _ifdef ("GNU_CFLAGS", GNU_CFLAGS, "-O")
GNU_MAKE   = _ifdef ("GNU_MAKE",   GNU_MAKE,   "make")

%-------------------------------------------------------- Modula-3 compiler ---
% The syntax for the values passed to most of the M3_CONFIG options is
% "@pgm@arg1@...@argn@" where "@" is an arbitrary character.  The
% separator character must begin and end the value.

% Where is the driver?
M3=THISTREE &"/local/" &BUILD_ARCH &"/lib/m3/" &BUILD_ARCH &"/m3"
if stale(M3,M3)
  M3=FULLTREE &"/local/" &BUILD_ARCH &"/lib/m3/" &BUILD_ARCH &"/m3"
end
if stale(M3,M3)
  M3 = LIB_USE & "/m3"
end

% Where is the backend?
M3BACKEND=THISTREE & "/local/" & BUILD_ARCH & "/bin/m3cgc1"
if stale(M3BACKEND,M3BACKEND)
  M3BACKEND=FULLTREE & "/local/" & BUILD_ARCH & "/bin/m3cgc1"
end
if stale(M3BACKEND,M3BACKEND)
  M3BACKEND = BIN_USE & "/m3cgc1"
end

% Where is the m3tohtml.perl
M3TOHTML=THISTREE & "/local/" & BUILD_ARCH  & "/bin/m3tohtml.perl"
if stale(M3TOHTML,M3TOHTML)
  M3TOHTML=FULLTREE & "/local/" & BUILD_ARCH  & "/bin/m3tohtml.perl"
end
if stale(M3TOHTML,M3TOHTML)
  M3BACKEND = BIN_USE & "/m3tohtml.perl"
end

% What are the standard flags?
M3OPTIONS = [ "-w1", "-why", "-g", "-O2"]

% Set SECONDARY_ROOT to point to where secondary compiler files are kept.
SECONDARY_ROOT = THISTREE & "/local/" & BUILD_ARCH
SECONDARY_LIB_USE = SECONDARY_ROOT & "lib/m3/" & BUILD_ARCH

M3_CONFIG = [
   "-Y1" & _pack_args (CC),
   "-Y2" & _pack_args (LINK),
   "-Y3" & _pack_args (MAKELIB),
   "-Y4" & _pack_args (RANLIB),
   "-Y7" & _pack_args (ASM),

   "-Y6@" & M3BACKEND & "@-quiet@",
   % --- the Modula-3 IL to assembly language pass

   "-z2@-lm@",  % --- libraries systematically linked with all programs

   "-z3" & LIB_USE & SL & "report_coverage.o",
   % --- library linked in programs compiled with "-Z" coverage option

   "-z5" & NAMING_CONVENTIONS,
   % Set the host naming conventions.

   "-z60",
   % Values of "-z6":
   %   "0" => the m3 driver will split library names and pass -L/-l
   %          arguments to the linker
   %   "1" => the m3 driver will pass libraries with full path names
   %   "2" => like "0" except that for shared libraries, the driver
   %          passes -Rdir as well as -Ldir to the linker

   "-zA0",
   % The "-zA" option specifies the maximum size (in megabytes) that Pass0
   % is allowed to reach as a persistent server before the driver kills it.
   % Setting it to zero disables server mode.
   % NOTE: the current compiler is buggy, leave "-zA" alone!

   "-zB@-O@",  % --- pass 1 options implied by "-O"
   "-zC@-O@",  % --- pass 6 options implied by "-O"
   "-zD@@",    % --- pass 7 options implied by "-O"

   "-zE@-g@",  % --- pass 1 options implied by "-g"
   "-zF@-g@",  % --- pass 6 options implied by "-g"
   "-zG@@",    % --- pass 7 options implied by "-g"

   "-zH" & NAMING_CONVENTIONS,
   % --- the target's naming conventions

   "-zI" & BASETARGET,
   % --- the target architecture

   % "-zJ10",
   % The option "-zJx1" specifies that pass "x" is "noisy", "-zJx0"
   % specifices that it's not.  The default is to assume that passes
   % are not noisy.  The driver collects the standard output of noisy
   % passes in a file and then deletes the file, unless "-keep" or
   % "-verbose" is specified.

   "-zK0",
   % --- Set the value of "-zK" to "1" if you want the m3 driver to
   %     supply -Bdynamic/-Bstatic options to the linker, "0" otherwise.

   "-Bdynamic",
   % --- libraries are shared by default.  If you give -zK1 you should
   %     also provide an initial -Bdynamic or -Bstatic.

   "-zL0"
   % --- Set the value of "-zL" to "1" if you want .M3LINK files produced
   %     for a dynamic loader
]

proc build_standalone() is
   % --- reset the linker to avoid shared libraries.
   M3_CONFIG += "-Y1@gcc@"
   M3_CONFIG += "-Y2@gcc@-static@"
end

proc build_shared() is
   % --- reset the linker to use shared libraries.
   M3_CONFIG += "-Y1@gcc@-fPIC@"
   M3_CONFIG += "-Y2@gcc@-shared@"
end

%-------------------------------------------------------------------- hooks ---
% These are the "last chance" hooks that are called each time a library
% or program is built.  They might build shared libraries or strip
% executables...

proc before_library_hooks(x) is
end

% SPIN does not use shared libraries

proc after_library_hooks(x) is
	write ("Done building ", format("lib%s.a", x), CR)
end

proc before_program_hooks(x) is
end

proc after_program_hooks(x) is
end

%------------------------------------------------------------- installation ---
% "install_file" is called during an "m3ship" for
% each file that needed to be externally exported.

readonly proc install_file (src, dest, mode) is
  Note_install (src, dest)
  exec ("@cp -p", src, dest)
  % exec ("@install -m", mode, "-u", $USER, "-f", dest, src)
end


%---------------------------------------------- the rest of the environment ---

if defined("_bootstrap") include("COMMON.BOOT") end
include ("COMMON")

%---------------------------------------------- domain import package ---

SFLAGS = [ "-nostdinc", 
	"-I" & THISTREE & "/kernel/sal/i386_freebsd",
	"-I" & FULLTREE & "/kernel/sal/i386_freebsd",
	"-DSPIN", "-DKERNEL", "-traditional", "-$" ]

proc S_source(x) is
	if stale(x & ".s", path_of(x & ".S"))
		exec(BSD_PREFIX & "cpp", SFLAGS, path_of(x & ".S"), ">", x & ".s")
	end
	derived_s(x)
end

% SPIN C template

#
# template for compiling C files for the kernel
#
#

# in sal/SPIN the cc line is:
# cc  -c -O2   -DLANGUAGE_C -g3 -G 4 -I -I. -I.. -I../include
#	-I../include/alpha -I../arch/alpha -I../arch -I../../sys -DIDENT=SPIN
#	-DDEC2100_A50 -DDEC3000_300 -DDEC3000_500 -DSWAPTYPE=1
#	-DRELEASE='"'0.0'"' -DVERSION='"'0'"' -DMACH -DOSF -DCOMPAT_43 -DSPIN
#	-DUFS -DKERNEL -D_KERNEL -D_BSD -signed  -no_excpt -Wco,-nofloat
#	-Olimit	1500 -D__alpha -Umips -UMIPS ioconf.c

CFLAGS = ["-O2","-g","-I","-DIDENT=SPIN","-DRELEASE=\"0.0\"","-DVERSION=\"0\"",
          "-DSPIN","-DKERNEL" , "-nostdinc" ]
includes = ["./", "../../", "./include"]
           
readonly proc add_CC_args(prefix,x) is
	foreach e in x
		m3_option("-X1@" & prefix & e & "@")
	end
end	

if equal (THISTREE, "") and equal (FULLTREE, "")
  error ("Cannot compile kernel c_sources without defining FULLTREE or THISTREE", CR)
end

add_CC_args("",CFLAGS)		

if not equal (THISTREE, "")
  add_CC_args("-I" & THISTREE & "/kernel/sal/i386_freebsd/",includes)
  add_CC_args("","-I" & THISTREE & "/kernel")
end
if not equal (FULLTREE, "")
  add_CC_args("-I" & FULLTREE & "/kernel/sal/i386_freebsd/",includes)
  add_CC_args("","-I" & FULLTREE & "/kernel")
end
