yorick banner

Home

Manual

Packages

Global Index

Keywords

Quick Reference


/*
   MKDOC.I
   Alphabetize DOCUMENT comments and prepare for line printer.

   $Id: mkdoc.i,v 1.1 1993/08/27 18:50:06 munro Exp $
 */
/*    Copyright (c) 1994.  The Regents of the University of California.
                    All rights reserved.  */


func mkdoc (filename, outname, lpp)
/* DOCUMENT mkdoc, filename

         or mkdoc, filename, outname, lpp
     alphabetizes and indexes the DOCUMENT comments in FILENAME, and
     formats into "dictionary-like" pages for printing.  If OUTNAME
     is not given or nil, the output file will be FILENAME with ".doc"
     replacing the ".i".  If LPP is not given, it defaults to 58 --
     the maximum number of available lines per page of output.

     (Use 55 to be able to print with "l>ml#grow>grow, deplibs, d;

    list= where(instrucs(1,)=="NO-WRAPPERS");
    if (numberof(list)) nowrap++;
  }
  deplibs= grow(lib, deplibs);
  if (numberof(lib)>1)

    error, "new packages may specify at most one LIB in MAKE-INSTRUCTIONS";
  else if (numberof(lib)==1)
    lib= lib(1);
  code_library= lib;
  nsrcs= numberof(srcs);
  if (nowrap==n) nowrap= "";
  else nowrap= " ywrap.o";

  n= numberof(old_pkgs);
  for (i=1 ; i<=n ; ++i) {

    /* note: . is assumed to be Y_LAUNCH */
    f= find_file(old_pkgs(i),

		 ["./",Y_SITE+"i0/",Y_SITE+"contrib/"]);

    if (is_void(f)) { f=old_pkgs(i); goto oops; }

    get_keys, old_pkgs(i), f, s, l, d;

    if (is_void(l) && old_pkgs(i)!="matrix.i" && old_pkgs(i)!="fft.i")

      error,"package "+old_pkgs(i)+" specifies no LIB in MAKE-INSTRUCTIONS";
    grow, srcs, s;
    grow, deplibs, l, d;
  }

  srcs= strtok(srcs,".");
  ext= srcs(2,);
  srcs= srcs(1,);

  list= where((ext=="f") | (ext=="F"));
  fortran= (numberof(list)!=0);
  objs= srcs(1:nsrcs)+".o";

  if (!is_void(deplibs))

    deplibs= "-l"+undup_names(deplibs);


  if (open("Makefile","r",1)) rename, "Makefile", "Makefile.old";

  f= create("Makefile");

  write,f,format="# Makefile for %s\n",code_name;

  write,f,format="# generated by make.i     %s\n\n",timestamp();

  write,f,format="%s\n",
    "######################################################################";

  write,f,format="# %s\n\n","First section is definitions for Maketmpl";


  write,f,format="MAKE_TEMPLATE = %s%s\n\n",Y_HOME,"Maketmpl";

  write,f,format="C_OPTIMIZE = %s\nLD_OPTIMIZE = $(C_OPTIMIZE)\n","-O";

  if (fortran) write,f,format="F_OPTIMIZE = %s\n","-O";

  if (!is_void(code_library)) {

    write,f,format="\nCODE_NAME = %s\n", code_name;

    write,f,format="CODE_LIBRARY = lib%s.a\n", code_library;

    write,f,format="NON_SHARABLE = %s\n", "unused";
  } else {

    write,f,format="\nNON_SHARABLE = %s\n", code_name;

    write,f,format="CODE_NAME = %s\n", "unused";

    write,f,format="CODE_LIBRARY = %s\n", "unused2";
  }

  write,f,format="YWRAP_O =%s\n\n",nowrap;

  objlist= ["OBJS ="];
  tot= strlen(objlist(1));

  for (i=i0=1 ; i<=numberof(objs) ; ++i) {
    obj= objs(i);
    len= strlen(obj);
    if (tot+len+1 > 70) {
      objlist(i0)+= " \\";
      grow, objlist, ["      "];
      tot= strlen(objlist(0));
      ++i0;
    }
    objlist(i0)+= " "+obj;
    tot+= len+1;
  }
  write,f,format="%s",objlist;

  lib= "";

  for (i=1 ; i<=numberof(deplibs) ; ++i) lib+= " "+deplibs(i);

  write,f,format="\nPKG_LIBS =%s\n",lib;

  if (is_void(code_library))

    write,f,format="PKG_OBJS = %s\n","$(OBJS) $(YWRAP_O)"

  pkg= "";

  for (i=1 ; i<=numberof(new_pkgs) ; ++i) pkg+= " "+new_pkgs(i);

  write,f,format="\nY_INCLUDE =%s\n",pkg;
  pkg= "";

  for (i=1 ; i<=numberof(old_pkgs) ; ++i) pkg+= " "+old_pkgs(i);

  write,f,format="Y_OTHERS =%s\n\n",pkg;

  lib= fortran? " $(FORTRAN_LIBS)" : "";

  write,f,format="SYS_LIBS =%s\n", lib;

  if (fortran) write,f,format="FORTRAN_STYLE =%s\n", " $(WKS_FORTRAN)";


  write,f,format="\nCLEAN_UP = %s\n\n",code_name;

  write,f,format="%s\n",
    "######################################################################";

  write,f,format="# %s\n\n","Second section is targets for new package/code";


  if (is_void(code_library)) lib= "$(NON_SHARABLE)";
  else lib= "$(CODE_LIBRARY) $(CODE_NAME)";
  write,f,format="all:: %s\n\n", lib;


  write,f,format="%s\n%s\n%s\n%s\n%s\n\n",
    "# Add header dependencies or special compile instructions here, e.g.-",
    "#my_code1.o: my_code1.h   my_code.h",
    "#my_code2.o: my_code2.c my_code.h",
    "#\t$(CC) $(CFLAGS) -DSPECIAL_SWITCH -c my_code2.c",
    "#my_code3.o: my_code3.h   my_code1.h my_code.h";

  write,f,format="%s\n",
    "######################################################################";

  write,f,format="\n%s\n","include $(MAKE_TEMPLATE)";

  close,f;
  return;

oops:

  write, "new packages must be in current directory";

  write, "old packages must be in "+Y_SITE+"{i0,contrib}";
  error, "unable to find package: "+f;
}


func undup_names (names)
{

  /* remove duplicates from a list of names (or numbers) */

  if (numberof(names)<2) return names;
  require, "msort.i";
  order= msort(names);
  sorted= names(order);

  list= where(sorted(1:-1)==sorted(2:0));
  if (numberof(list)) {

    names(order(list))= structof(names)(0);
    names= names(where(names));
  }
  return names;
}


func get_keys (name, f, &srcs, &lib, &deplibs)
{

  instrucs= get_instructions(f);
  if (is_void(instrucs))

    error, "no MAKE-INSTRUCTIONS comment found in "+name;

  srcs= get_list(instrucs, "SRCS");
  if (is_void(srcs))

    error, "no SRCS in MAKE-INSTRUCTIONS comment found in "+name;
  lib= get_list(instrucs, "LIB");

  deplibs= get_list(instrucs, "DEPLIBS");
  return instrucs;
}


func get_list (instrucs, keyword)
{

  /* get keyword= from instruction lines returned by get_instructions

   * return value is array of token strings
   * -- allow for \ continuation of long lines */
  list= where(instrucs(,1)==keyword);
  if (!numberof(list)) return [];
  i= list(1);
  instrucs= instrucs(i:0,2);

  list= array(pointer, numberof(instrucs));

  len= array(0, numberof(list));

  line= tokenize_line(instrucs(1), " \t=");

  if (numberof(line)<2) return [];
  line= line(2:0);

  for (i=1 ; numberof(line)>=1 ; ++i) {
    cont= (line(0)=="\\");
    len(i)= n= numberof(line)-cont;
    if (n) list(i)= &line(1:n);

    if (!cont || i+1>=numberof(instrucs)) break;

    line= tokenize_line(instrucs(i+1), " \t=");
  }
  n= sum(len);
  if (!n) return [];
  line= array(string, n);
  for (i=1,j=0 ; j<n ; j+=len(i++)) {
    if (!len(i)) continue;
    line(j+1:j