home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / iconc / ccomp.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  6KB  |  268 lines

  1. /*
  2.  * ccomp.c - routines for compiling and linking the C program produced
  3.  *   by the translator.
  4.  */
  5. #include "::h:gsupport.h"
  6. #include "cglobals.h"
  7. #include "ctrans.h"
  8. #include "ctree.h"
  9. #include "ccode.h"
  10. #include "csym.h"
  11. #include "cproto.h"
  12.  
  13. extern char *refpath;
  14.  
  15. /*
  16.  * The following code is operating-system dependent [@tccomp.01].  Definition
  17.  *  of ExeFlag and LinkLibs.
  18.  */
  19.  
  20. #if PORT
  21.    /* something is needed */
  22. Deliberate Syntax Error
  23. #endif                        /* PORT */
  24.  
  25. #if UNIX || AMIGA || ATARI_ST || MACINTOSH || MSDOS || MVS || VM || OS2
  26. #define ExeFlag "-o"
  27. #define LinkLibs " -lm"
  28. #endif                        /* UNIX ... */
  29.  
  30. #if VMS
  31. #include file
  32. #define ExeFlag "link/exe="
  33. #define LinkLibs ""
  34. #endif                        /* VMS */
  35.  
  36. /*
  37.  * End of operating-system specific code.
  38.  */
  39.  
  40. /*
  41.  * Structure to hold the list of Icon run-time libraries that must be
  42.  *  linked in.
  43.  */
  44. struct lib {
  45.    char *libname;
  46.    int nm_sz;
  47.    struct lib *next;
  48.    };
  49. static struct lib *liblst;
  50. static int lib_sz = 0;
  51.  
  52. /*
  53.  * addlib - add a new library to the list the must be linked.
  54.  */
  55. novalue addlib(libname)
  56. char *libname;
  57.    {
  58.    static struct lib **nxtlib = &liblst;
  59.    struct lib *l;
  60.  
  61.    l = NewStruct(lib);
  62.  
  63. /*
  64.  * The following code is operating-system dependent [@tccomp.02].
  65.  *   Change path syntax if necessary.
  66.  */
  67.  
  68. #if PORT
  69.    /* something is needed */
  70. Deliberate Syntax Error
  71. #endif                        /* PORT */
  72.  
  73. #if UNIX || AMIGA || ATARI_ST || MACINTOSH || MSDOS || MVS || OS2 || VM
  74.    l->libname = libname;
  75.    l->nm_sz = strlen(libname);
  76. #endif                        /* UNIX ... */
  77.  
  78. #if VMS
  79.    /* change directory string to VMS format */
  80.    {
  81.       struct fileparts *fp;
  82.       char   *newlibname = alloc(strlen(libname) + 20);
  83.  
  84.       strcpy(newlibname, libname);
  85.       fp = fparse(libname);
  86.       if (strcmp(fp->name, "rt") == 0 && strcmp(fp->ext, ".olb") == 0)
  87.          strcat(newlibname, "/lib/include=data");
  88.       else
  89.      strcat(newlibname, "/lib");
  90.       l->libname = newlibname;
  91.       l->nm_sz = strlen(newlibname);
  92.       }
  93. #endif                        /* VMS */
  94.  
  95. /*
  96.  * End of operating-system specific code.
  97.  */
  98.  
  99.    l->next = NULL;
  100.    *nxtlib = l;
  101.    nxtlib = &l->next;
  102.    lib_sz += l->nm_sz + 1;
  103.    }
  104.  
  105. /*
  106.  * ccomp - perform C compilation and linking.
  107.  */
  108. int ccomp(srcname, exename)
  109. char *srcname;
  110. char *exename;
  111. #if MSDOS
  112.    {
  113.    return NormalExit;            /* can't do from inside */
  114.    }
  115. #else                    /* MSDOS */
  116.    {
  117.    struct lib *l;
  118.    char sbuf[MaxFileName];        /* file name construction buffer */
  119.    char *buf;
  120.    char *s;
  121.    char *dlrgint;
  122.    int cmd_sz, opt_sz, flg_sz, exe_sz, src_sz;
  123.  
  124.    /*
  125.     * Compute the sizes of the various parts of the command line
  126.     *  to do the compilation.
  127.     */
  128.    cmd_sz = strlen(c_comp);
  129.    opt_sz = strlen(c_opts);
  130.    flg_sz = strlen(ExeFlag);
  131.    exe_sz = strlen(exename);
  132.    src_sz = strlen(srcname);
  133.    lib_sz += strlen(LinkLibs);
  134.    if (!largeints) {
  135.       dlrgint = makename(sbuf, refpath, "dlrgint", ObjSuffix);
  136.       lib_sz += strlen(dlrgint) + 1;
  137.       }
  138.  
  139. /*
  140.  * The following code is operating-system dependent [@tccomp.03].
  141.  *  Construct the command line to do the compilation.
  142.  */
  143.  
  144. #if PORT
  145.    /* something is needed */
  146. Deliberate Syntax Error
  147. #endif                        /* PORT */
  148.  
  149. #if AMIGA || ATARI_ST || MACINTOSH || MSDOS || MVS || VM || OS2
  150.    /* something may be needed */
  151. Deliberate Syntax Error
  152. #endif                        /* AMIGA || ... */
  153.  
  154. #if UNIX
  155.  
  156. #ifdef Graphics
  157.    lib_sz += strlen(" -L") +
  158.              strlen(refpath) +
  159.          strlen(" -lXpm ");
  160.    lib_sz += strlen(ICONC_XLIB);
  161. #endif                        /* Graphics */
  162.  
  163.    buf = alloc((unsigned int)cmd_sz + opt_sz + flg_sz + exe_sz + src_sz +
  164.                  lib_sz + 5);
  165.    strcpy(buf, c_comp);
  166.    s = buf + cmd_sz;
  167.    *s++ = ' ';
  168.    strcpy(s, c_opts);
  169.    s += opt_sz;
  170.    *s++ = ' ';
  171.    strcpy(s, ExeFlag);
  172.    s += flg_sz;
  173.    *s++ = ' ';
  174.    strcpy(s, exename);
  175.    s += exe_sz;
  176.    *s++ = ' ';
  177.    strcpy(s, srcname);
  178.    s += src_sz;
  179.    if (!largeints) {
  180.       *s++ = ' ';
  181.       strcpy(s, dlrgint);
  182.       s += strlen(dlrgint);
  183.       }
  184.    for (l = liblst; l != NULL; l = l->next) {
  185.       *s++ = ' ';
  186.       strcpy(s, l->libname);
  187.       s += l->nm_sz;
  188.       }
  189.  
  190. #ifdef Graphics
  191.    strcpy(s," -L");
  192.    strcat(s, refpath);
  193.    strcat(s," -lXpm ");
  194.    strcat(s, ICONC_XLIB);
  195.    s += strlen(s);
  196. #endif                        /* Graphics */
  197.  
  198.    strcpy(s, LinkLibs);
  199.  
  200.    if (system(buf) != 0)
  201.       return ErrorExit;
  202.    strcpy(buf, "strip ");
  203.    s = buf + 6;
  204.    strcpy(s, exename);
  205.    system(buf);
  206. #endif                        /* UNIX ... */
  207.  
  208. #if VMS
  209.  
  210. #ifdef Graphics
  211. #ifdef HaveXpmFormat
  212.    lib_sz += strlen(refpath) + strlen("Xpm/lib,");
  213. #endif                        /* HaveXpmFormat */
  214.    lib_sz += 1 + strlen(refpath) + strlen("X11.opt/opt");
  215. #endif                        /* Graphics */
  216.  
  217.    buf = alloc((unsigned int)cmd_sz + opt_sz + flg_sz + exe_sz + src_sz +
  218.                  lib_sz + 5);
  219.    strcpy(buf, c_comp);
  220.    s = buf + cmd_sz;
  221.    strcpy(s, c_opts);
  222.    s += opt_sz;
  223.    *s++ = ' ';
  224.    strcpy(s, srcname);
  225.  
  226.    if (system(buf) == 0)
  227.       return ErrorExit;
  228.    strcpy(buf, ExeFlag);
  229.    s = buf + flg_sz;
  230.    strcpy(s, exename);
  231.    s += exe_sz;
  232.    *s++ = ' ';
  233.    strcpy(s, srcname);
  234.    s += src_sz - 1;
  235.    strcpy(s, "obj");
  236.    s += 3;
  237.    if (!largeints) {
  238.       *s++ = ',';
  239.       strcpy(s, dlrgint);
  240.       s += strlen(dlrgint);
  241.       }
  242.    for (l = liblst; l != NULL; l = l->next) {
  243.       *s++ = ',';
  244.       strcpy(s, l->libname);
  245.       s += l->nm_sz;
  246.       }
  247. #ifdef Graphics
  248.    strcat(s, ",");
  249. #ifdef HaveXpmFormat
  250.    strcat(s, refpath);
  251.    strcat(s, "Xpm/lib,");
  252. #endif                        /* HaveXpmFormat */
  253.    strcat(s, refpath);
  254.    strcat(s, "X11.opt/opt");
  255. #endif                        /* Graphics */
  256.  
  257.    if (system(buf) == 0)
  258.       return ErrorExit;
  259. #endif                        /* VMS */
  260.  
  261. /*
  262.  * End of operating-system specific code.
  263.  */
  264.  
  265.    return NormalExit;
  266.    }
  267. #endif                    /* MSDOS */
  268.