HP3000-L Archives

October 1997, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Ross Scroggs <[log in to unmask]>
Reply To:
Ross Scroggs <[log in to unmask]>
Date:
Mon, 13 Oct 1997 10:07:26 PDT
Content-Type:
text/plain
Parts/Attachments:
text/plain (447 lines)
I have enclosed a replacement c89.ccg that does allow the following:
        c89 -c foo.c -o goo.o
This is a form that we use to compile foo.c multiple times with different
-D options in order to get custom object versions. Save your original
c89.ccg, plug this one in and check it out. Reply to me privately with
questions or problems.

---------- cut here ----------
##################################################################
#
#  Copyright 1985, 1990 by Mortice Kern Systems Inc.  All rights reserved.
#
#  This Software is unpublished, valuable, confidential property of
#  Mortice Kern Systems Inc.  Use is authorized only in accordance
#  with the terms and conditions of the source licence agreement
#  protecting this Software.  Any unauthorized use or disclosure of
#  this Software is strictly prohibited and will result in the
#  termination of the licence agreement.
#
#  If you have any questions, please consult your supervisor.
#
# Generic CCG file that understands all C89 options
# This file has been modified to support the MPE compiler environment
#
# C89 Options accepted:
#       -c              compile only, do not link
#       -g              debugging information
#       -llib           link with library lib.  The libraries will have
#                       canonical names across all systems, the CCG scripts
#                       will resolve them.
#       -o outfile      output in outfile
#       -Dname[=val]    define preprocessor macro
#       -E              preprocess only, don't compile
#       -Iincludedir    add dir to search path for #included files
#       -Llibpath       add dir to search path for libraries
#       -O              optimize
#       -Uname          undefine preprocessor macro
#       -s              strip output
#       -Wphase,arg...  allows arguments to be passed to other phases
#                       of compile. If "c" is specified for phase, the
#                       argument will be passed thru to the c compiler
#                       If p is "l", then the arg will be added to the
#                       link editor indirect file. If p is "L", then arg
#                       will be added to the link editor command line.
#
#    The following options are specific to MPE/iX
#
#       -Plistfile      produce a listing file
#       -T number       stack size
#       -A letter       compiler mode - legal values are a, c and p
#                       but we don't check - the compiler can do that
#
# Environment Variables:
#       ECHO            echo what we're doing in the script.
#       NORUN           don't run commands.
#       TMPDIR          directory to use to create temp files.
##################################################################
#
# DEFAULT DEFINITION SECTION
#
NullArray = {};
Outfile = "./a.out";            # default name of executable file
Stack = {};                     # Use system default stack size

# Underlying programs called by c89 and their default args
CC = "xeq ccomxl.pub.sys";      # name of C compiler
CCArgs = "";                    # default arguments to CC
LD = "xeq linkedit.pub.sys";    # name of linker/loader
LinkArgs = {};                  # linker options. note -
                                # the link editor automatically checks
                                # /lib and /usr/lib in that order
Lopts = "";                     # default linkeditor command line options
STRIP = "strip.pub.sys";        # name of strip utility
#
# END OF DEFAULT DEFINITION SECTION
#
##################################################################

# Import the environment variables
if (!ECHO) ECHO = getenv("ECHO"); fi
if (!NORUN) NORUN = getenv("NORUN"); fi
if ((TMPDIR = getenv("TMPDIR")) == "") TMPDIR="/tmp"; fi

objdir = TMPDIR;

usage = "usage: "|CMDNAME|" [-cgsEO] [-o outfile] [-D name[=value]] " |
           "[-I directory] [-L directory] [-T stacksize] [-U name] " |
           "-Wphase,args -P listfile files... [-llib ...]";

###########################################################
# utility routine that handles the case of -<opt><arg> or -<opt> <arg>
# and returns the result as a vector.
function do_opt(opt, vec)
{
        if (opt)
                opt |= " ";
        fi
        if ((oa = tail(arg)) == "")
                # POSIX style
                vec = { opt|read(ARGV) };
        else
                # historical style
                vec = { opt|oa };
        fi
        return (vec);
}

###########################################################
# utility routine that handles the case of -<opt><arg> or -<opt> <arg>
# but returns things as a string.
function do_sopt(opt, str)
{
        if (!opt)
                opt |= " ";
        fi
        if ((oa = tail(arg)) == "")
                # POSIX style
                str = opt|read(ARGV)|" ";
        else
                # historical style
                str = opt|oa|" ";
        fi
        return (str);
}

###########################################################
# utility routine used to check fatal condition; prints str and exits if true
function fatal(bool, str) {
        if (bool) println CMDNAME|": error: ", str -> "stderr"; exit 1; fi
}

###########################################################
# utility routine used to check condition; prints warning string and continues
function warn(bool, str) {
        if (bool) println CMDNAME|": warning: ", str -> "stderr"; fi
}

###########################################################
# this function returns a fully-qualified pathname
function fullpath(name)
{
        if (name[0]  == "/")
                return (name);
        elif (substr(name,1,2) == "./")
                return (getcwd() | substr(name,2));
        else
                return (getcwd() | "/" | name);
        fi
}

###########################################################
# return name with file portion stripped off
function basename(name, i)
{
        if ((i = rindex(name,"/")) == 0)
                return (name);
        else
                return (substr(name, i+1));
        fi
}

###########################################################
# split a string into an array on using the specified character
# as the field separator
function split(str, sc, i, t, a)
{
        a = {};
        for (i in str) do
                if (i == sc)
                        a |= { t };
                        t = "";
                else
                        t |= i;
                fi
        done
        if (t)
                a |= { t };
        fi
        return (a);
}


##########################################################################
#
# MAINLINE BEGINS...
#

FileCount=0;
Srcs = Objs = {};
obj = "";
while (arg = read(ARGV)) do
        # if the argument is "--" then this is the end of options
        if (arg == "--")
                done_opts++;
                arg = read(ARGV);
        fi

        if (read(arg) != "-" || (done_opts && read(arg) != "l"))
                # if arg is not a full pathname, then prefix it with
                # ./ so that MPE will recognize it as a POSIX pathname
                if (substr(arg,1,1) != "/" && substr(arg,1,2) != "./" &&
                   substr(arg,1,3) != "../")
                        arg = "./" | arg;
                fi
                if (substr(arg, -2) == ".o" || substr(arg, -2) == ".a")
                        Objs |= arg;
                elif (substr(arg, -2) == ".c")
                        Srcs |= arg;
                        if (obj == "")
                                obj = "./"|basename(arg);
                                obj = substr(obj, 1, length(obj)-2)|".o";
                                Objs |= obj;
                        fi
                else
                        println CMDNAME|": unknown file extension: " |
                                arg -> "stderr";
                        exit (1);
                fi
                FileCount++;
        else
                rewind(arg);
                read(arg);
                opt = read(arg);
                while (opt) do
                        if   (opt == "l") Objs |= do_sopt("-l"); break;
                        elif (opt == "c") nolink = true;
                        elif (opt == "g") debug = true;
                        elif (opt == "s") strip = true;
                        elif (opt == "E") preprocess = true;
                        elif (opt == "O") optimize = true;
                        elif (opt == "D") CCArgs |= do_sopt("-D"); break;
                        elif (opt == "I") CCArgs |= do_sopt("-I"); break;
                        elif (opt == "U") CCArgs |= do_sopt("-U"); break;
                        elif (opt == "o")
                                if (nolink)
                                        obj = do_sopt("./");
                                        Objs |= obj;
                                else
                                        LinkArgs |= do_opt("-o");
                                fi;
                                break;
                        elif (opt == "L")
                                LinkArgs |= do_opt("-L");
                                break;
                        # non-standard MPE option to set stack size
                        elif (opt == "T") Stack = do_opt(); break;
                        # non-standard MPE option to produce a listing
                        elif (opt == "P") Listfile = do_sopt(); break;
                        elif (opt == "W")
                                wopt = substr(do_sopt(),2);
                                if (substr(wopt,1,2) == "c,")
                                        CCArgs |= split(substr(wopt, 3), ",");
                                elif (substr(wopt, 1, 2) == "L,")
                                        Lopts |= substr(wopt, 3);
                                elif (substr(wopt, 1, 2) == "l,")
                                        LinkArgs |= split(substr(wopt, 3), ",");
                                else
                                        warn(1, "unrecognized phase specified" |
                                                " for W opt: '"|wopt|
                                                "' - ignored");
                                fi
                                break;
                        elif (opt == "A")
                                aopt = do_sopt();
                                aopt = substr(aopt, 2, length(aopt)-2);
                                println "'"|aopt|"'";
                                if (aopt == "p" || aopt == "pc")
                                        Aopt |= "-A"|aopt;
                                else
                                        warn(1, "unrecognized mode specified" |
                                                " for A opt: '"|aopt|
                                                "' - ignored");
                                fi
                                break;
                        else
                                println CMDNAME|": unrecognized option:", opt
                                        -> "stderr";
                                println usage -> "stderr";
                                exit (1);
                        fi
                        opt = read(arg);
                done
        fi
done
if (!Aopt)
        CCArgs = "-Ap " | CCArgs;
else
        CCArgs = Aopt | CCArgs;
fi

##################################################################
#
# The following conditions check for option conflicts
#
fatal(strip && debug, "cannot mix -g and -s options");
warn(debug && optimize, "cannot mix -g and -O, -O ignored");
if (debug && optimize)
        optimize = 0;
fi
fatal(strip && preprocess, "cannot mix -s and -E");
warn((preprocess  || nolink) && Outfile != "./a.out", "-o ignored");
fatal(!FileCount, "no files specified");
warn(length(Libs) != 0 && (preprocess  || nolink), "-l ignored");

##################################################################
#
# Build the compiler argument array based on the settings of the
# various flags.
#
if (preprocess) CCArgs |= "-E "; fi
if (debug) CCArgs |= "-g "; fi
if (optimize) CCArgs |= "-O "; fi

# Compile each of the files named in the Srcs array.
for (i in Srcs) do
        # convert the source name to the object name
        src=i;
        if (obj == "")
                obj = "./"|basename(src);
                obj = substr(obj, 1, length(obj)-2)|".o";
        fi
        # STUB - delete the object file first because of DR2 rename problem
        delete obj;
        # set up the file equations for the compiler
        callci("file cctext="|src, ">", 2);
        callci("file ccobj="|obj, ">", 2);
        if (Listfile)
                if (Listfile == "- ")
                        callci("file cclist=$stdlist", ">", 2);
                else
                        callci("file cclist="|Listfile, ">", 2);
                fi
        else
                callci("file cclist=$null", ">", 2);
        fi
        # now call the compiler
        result = callci(CC|";info=\"" | CCArgs | "\";parm=7", ">", 2);
        # remove the file equations
        callci("reset cctext", ">", 2);
        callci("reset ccobj", ">", 2);
        callci("reset cclist", ">", 2);
        # check the result of the compile
        warn(compile_failed = result, "compile of '"|src|"' failed");
done

# if one or more of the compiles failed and linking has been requested
# issue an error and exit at this point
fatal(compile_failed, "one or more compiles failed; aborted");

# if the options specify not continuing, then stop here
if ((preprocess  || nolink) && !strip) exit 0; fi


##################################################################
#
# Build the linker argument array based on the settings of the
# various flags.

# write the various linker options to the response file. Make a special
# check for -o - this must be mapped to linkeditor command line option.
# It can't go into the response file.
rfile = tempfile("c89");
delete rfile;
for (arg in LinkArgs) do
        if (substr(arg,1,2) == "-o")
                i=2;
                while (arg[i] == " ") do
                         i++;
                done
                Outfile = substr(arg, i+1);
                if (Outfile == "")
                        warn(1, "missing filename for -o, ignored");
                        Outfile = "./a.out";
                else
                        if (substr(Outfile,1,1) != "/" &&
                           substr(Outfile,1,2) != "./")
                                Outfile = "./" | Outfile;
                        fi
                fi
        else
                println arg -> rfile;
        fi
done
# now write out all of the object modules to link
for (i in Objs) do
        println i -> rfile;
done

if (debug)
        println "/SYS/LIB/XDBEND" -> rfile;
fi

# write out all of the libraries to link to
for (i in DLibs) do
        println "-l " | i -> rfile;
done
# finally add in the default "c" library which is always linked last.
println "/SYS/LIB/LIBCRAND" -> rfile;
println "-l c" -> rfile;
close rfile;

# delete the target file first - this is necessary
# because of a bug in DR2 rename()
delete Outfile;

# Run the link command
link_cmd = LD | " \"link";
if (strip)
        link_cmd |= ";nodebug";
fi
if (Stack)
        link_cmd |= ";nmstack=" | Stack;
fi

# if the ECHO flag is on, then print out the contents of the linker
# response file
if (ECHO)
        println "CONTENTS OF LINKEDIT INDIRECT FILE:";
        norun_save = NORUN;
        echo_save = ECHO;
        NORUN=ECHO=0;
        exec("callci PRINT " | rfile);
        NORUN = norun_save;
        ECHO = echo_save ;
        println "END OF INDIRECT FILE";
fi
# if no loader options have been specified, then add at least sufficient
# capabiliities to run programs. This is the most useful default for
# the posix environment
if (!Lopts)
        Lopts = "cap=ph";
fi
link_cmd |= ";from=^"|rfile|";to=" |Outfile|";posix;share;"|Lopts|"\";parm=7";
result = callci(link_cmd, ">", 2);
# delete the response file
delete(rfile);
fatal(result, "link failed");
fatal(result, "link failed");
---------- cut here ----------
--
--------------------------------------------------------------------
Ross Scroggs                         email: [log in to unmask]
Telamon, Inc.                          CIS: 76011,2234
492 Ninth Street, Suite 310          voice: 510-987-7700
Oakland, CA 94607-4098                 fax: 510-987-7009
--------------------------------------------------------------------

ATOM RSS1 RSS2