home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / DiceC / doc / dmake.doc < prev    next >
Text File  |  1994-02-01  |  11KB  |  386 lines

  1.  
  2.                  DMAKE.DOC
  3.  
  4.               RELEASE V1.0 3-Feb-1989
  5.  
  6.     DMake (c)Copyright 1989 by Matthew Dillon, All Rights Reserved
  7.  
  8.     Matthew Dillon
  9.     891 Regal Rd.
  10.     Berkeley, Ca. 94708
  11.     USA
  12.  
  13.     dillon@postgres.berkeley.edu
  14.     ..!ucbvax!dillon
  15.  
  16.     You MUST be familar with 'make' to understand these instructions.
  17.     Please read the bug list at the end.
  18.  
  19.     The default file is 'DMakefile'.  Options are:
  20.  
  21.     -a            force all time comparisons to fail
  22.     -f filename        use this instead of DMakefile
  23.     -n            don't actually execute the lines
  24.     -v    (debugging, have fun)
  25.     -d    (debugging, have lots of fun)
  26.     -s            silent .. don't display startup copyright notice
  27.  
  28.  
  29.                 CONTROL FILE
  30.  
  31.     The control file, DMakefile by default, is made up of macros,
  32.     dependancies, and comments.  A macro looks like this:
  33.  
  34.     <macroname> = <string>
  35.     CFLAGS = +L
  36.  
  37.     A dependancy looks like this:  Note that commands may have an
  38.     optional '-' in front of them telling DMake to ignore the exit
  39.     code.
  40.  
  41.     <left1> <left2> <left3> .. : <right1> <right2> <right3>
  42.         [-]<command>
  43.         [-]<command>
  44.     blank-line
  45.  
  46.     a.o b.o c.o : a.c b.c c.c
  47.         cc $(CFLAGS) %(right) -o %(left)
  48.         Echo "hi!"
  49.  
  50.     d.o e.o f.o : d.x e.x f.x
  51.         ...
  52.  
  53.     Any line may be 'continued' onto the next line by specifying a backslash
  54.     at the end of the line:
  55.  
  56.     a.o b.o c.o : \
  57.     a.c b.c c.c
  58.     Echo "ha %(left) %(right)"
  59.     #    Echo "this line commented out"
  60.  
  61.     Any line my be commented out with a # at the beginning (The hash must
  62.     occur at the beginning of a line and will not work in the middle of
  63.     a continued line).
  64.  
  65.     #    This is a comment
  66.  
  67.               SPECIFICATIONS OF DEPENDANCIES
  68.  
  69.     A dependancy consists of one or more left-hand-sides and zero or more
  70.     right-hand-sides.  Each element on the left is matched to an associated
  71.     element on the right singly.  that is:
  72.  
  73.     a.o b.o c.o : a.c b.c c.c
  74.         <cmdlist>
  75.  
  76.     Is equivalent to:
  77.  
  78.     a.o : a.c
  79.         <cmdlist>
  80.  
  81.     b.o : b.c
  82.         <cmdlist>
  83.  
  84.     c.o : c.c
  85.         <cmdlist>
  86.  
  87.     Extra elements on the left are disallowed except for the special case
  88.     where there are NO elements on the right (i.e.  all :   ).  Each extra
  89.     element on the right is applied to EVERY element on the left.  That is:
  90.  
  91.     a.o b.o c.o : a.c b.c c.c x.h y.h
  92.         <cmdlist>
  93.  
  94.     is equivalent to:
  95.  
  96.     a.o : a.c x.h y.h
  97.         <cmdlist>
  98.  
  99.     b.o : b.c x.h y.h
  100.         <cmdlist>
  101.  
  102.     ...
  103.  
  104.                WILDCARDS IN SPECIFICATION
  105.  
  106.     You may specify wildcards for dependancies:
  107.  
  108.     *.o x.o y.o : *.c x.q y.q
  109.         <cmdlist>
  110.  
  111.     equivalent to:
  112.     *.o : *.c
  113.         <cmdlist>
  114.  
  115.     x.o : x.q
  116.         <cmdlist>
  117.  
  118.     y.o : y.q
  119.         <cmdlist>
  120.  
  121.     expanded to: (assume a.c, b.c, and c.c exist).  Note that the .o's are
  122.     not scanned for, just the .c's, and then a reverse mapping is applied
  123.     to generate the .o's.  For this reason, any *'s and ?'s in the right
  124.     hand side wildcard must have associated *'s and ?'s in the left hand
  125.     side wildcard.
  126.  
  127.     a.o : a.c
  128.         <cmdlist>
  129.  
  130.     b.o : b.c
  131.         <cmdlist>
  132.  
  133.     c.o : c.c
  134.         <cmdlist>
  135.  
  136.     ...
  137.  
  138.  
  139.     When these dependancies are executed by DMake, each right hand side
  140.     wildcard will be directory-scanned for and the associated left hand
  141.     side wildcard will be GENERATED.  THE LEFT HAND SIDE WILDCARD IS NOT
  142.     SEARCHED FOR BY A DIRECTORY SCAN, BUT GENERATED FROM THE RESULTS OF THE
  143.     RIGHT HAND SIDE.  There are several exceptions to the general case
  144.     mentioned above:
  145.  
  146.     <nonwildcard> : <wildcard>        Right hand side expanded and results
  147.                     all applied to the left hand side element.
  148.  
  149.     all : *.c   ->    all : a.c b.c c.c
  150.  
  151.     <wildcard> : <nonwildcard>        Left hand side expanded (the only time
  152.                     the left hand side is ever expanded,
  153.                     and then only if there is no right hand
  154.                     side in that wildcard) and the results
  155.                     applied to the right hand side element.
  156.  
  157.     *.c : syms  -> a.c : syms, b.c : syms, c.c : syms
  158.  
  159.     To be more specific, the moment some wildcard is expanded, ALL other
  160.     occurances of that wildcard will be expanded.
  161.  
  162.  
  163.                  MACROS AND COLLECTIONS
  164.  
  165.     Macros are referenced like this:  $(MACNAME).  Usage is straight
  166.     forward.  Note that ENV: will be searched if a macro name could not
  167.     be found otherwise.
  168.  
  169.     Collections are a different matter entirely.  Collections are a means
  170.     of accessing the left hand side and elements in the right hand side of
  171.     dependancies at command-execution time.  A collection reference is
  172.     specified with a % instead of a $.    There are two predefined collection
  173.     variables called %(left) and %(right).  %(left) references the left
  174.     hand side (there is always only one element on the left hand side), and
  175.     %(right) references the right hand side:
  176.  
  177.     all : *.o symbols libs
  178.     Echo %(left)                Echo all
  179.     Echo "%(right)"             Echo "a.o b.o c.o symbols libs"
  180.  
  181.     Individual wildcarded elements on the right can be referenced in the
  182.     same way:
  183.  
  184.     Echo "%(*.o)"               Echo "a.o b.o c.o"
  185.  
  186.     Additionaly, you can specify a collection reference wildcard and if
  187.     that collection doesn't exist under that exact wildcard, the entire
  188.     right hand side collection will be searched for elements that match the
  189.     wildcard:
  190.  
  191.     a.o b.o c.o : a.c b.c c.c *.h
  192.         Echo "%(right)"
  193.         cc %(*.c) -o %(left)
  194.  
  195.     Results in (at execution time):
  196.  
  197.     Echo "a.c x.h y.h"
  198.     cc a.c -o a.o
  199.     Echo "b.c x.h y.h"
  200.     cc b.c -o b.o
  201.     Echo "c.c x.h y.h"
  202.     cc c.c -o c.o
  203.  
  204.     Unlike the ALL: line in the previous example, where *.o was an actual
  205.     collection variable, here *.c is NOT a collection variable (unless you
  206.     had specified *.o : *.c, which you didn't), so the right hand side
  207.     is searched for elements matching the wildcard.
  208.  
  209.     Now pay careful attention:
  210.  
  211.     SRCS = *.c
  212.     OBJS = T:*.o
  213.  
  214.     all: $(OBJS)
  215.         ln %(OBJS) -o executable        (ln a.o b.o c.o -o executable)
  216.         Echo "$(OBJS)"                  (Echo "*.o"                  )
  217.         Echo "%(OBJS)"                  (Echo "a.o b.o c.o"          )
  218.  
  219.     $(OBJS): $(SRCS)
  220.         cc %(right) -o %(left)
  221.  
  222.     Note that $(MacName) results in the exact macro string, wildcard or not,
  223.     while %(MacName) find the macro and then finds the collection associated
  224.     with the macro's name.
  225.  
  226.             MULTIPLE DEPENDANCIES W/ SAME LEFT HAND SIDE
  227.  
  228.     all: *.o
  229.         ln %(*.o) -o executable
  230.  
  231.     *.o : *.c
  232.         cc $(CFLAGS) %(right) -o %(left)
  233.  
  234.     *.o : *.asm
  235.         as $(CFLAGS) %(right) -o %(left)
  236.  
  237.     Now, recall that the right hand side wildcards are scanned for and the
  238.     left hand side generated.
  239.  
  240.     *.o : *.c  -> the .C's are scanned for, say, a.c b.c c.c, and
  241.           a.o b.o c.o are placed in the *.o collection
  242.  
  243.     *.o : *.asm -> the .ASM's are scanned for, say, i.asm j.asm, and
  244.           i.o j.o are placed in the *.o collection
  245.  
  246.     all: *.o    -> The *.o's are NOT scanned for because they have already
  247.           been generated by the other two dependancies.  The
  248.           collection consists of:
  249.  
  250.           a.o b.o c.o i.o j.o
  251.  
  252.     The fact that the left hand side is not scanned for except for the
  253.     case <wildcard> : <nonwildcard>, plus the fact that any wildcard
  254.     that is already a collection (*.o in the above example) will not be
  255.     scanned for (all : *.o in the above example) has many advantages, the
  256.     least of which is that DMake will not get confused by extra object files
  257.     in whatever directory you choose to place the objects.
  258.  
  259.  
  260.               VARIABLE MODIFICATION
  261.  
  262.     Both macro and collection specs may be modified with a reference of
  263.     the following form:
  264.  
  265.     %/$(NAME:"srcwc":"destwc")
  266.  
  267.     SRCS = a.c b.c c.c            -> a.c b.c c.c
  268.     OBJS = $(SRCS:"*.c":"ram:*.o")      -> ram:a.o ram:b.o ram:c.o
  269.  
  270.     SRCPAT = *.c
  271.     DSTPAT = ram:*.o
  272.     OBJS = $(SRCS:"$(SRCPAT)":"$(DSTPAT)")      (equivalent)
  273.  
  274.     SRCPAT = "*.c"
  275.     DSTPAT = "ram:*.o"
  276.     OBJS = $(SRCS:$(SRCPAT):$(DSTPAT))          (equivalent)
  277.  
  278.     CONVPAT = "*.c":"ram:*.o"
  279.     OBJS = $(SRCS:$(CONVPAT))                   (equivalent)
  280.  
  281.     Whether you use % or $ depends on whether you want an explicit
  282.     replacement or a collection replacement.  Again, refer to a
  283.     couple of examples back where we had:
  284.  
  285.     all: $(OBJS)            -> all: *.o
  286.         ln %(OBJS)          -> ln %(*.o) -> ln a.o b.o c.o
  287.  
  288.  
  289.                 ORDER OF EXECUTION
  290.  
  291.     Execution order is based on precedence.  Theoretically a Depth-First
  292.     order beginning at the leaf of each tree and then running backwards.
  293.     If you have :
  294.  
  295.     all: symbols $(OBJS)
  296.  
  297.     Dependancies associated with 'symbols' will be executed before those
  298.     associated with $(OBJS).  Directory-Searching for wildcards in
  299.     dependancies is done in execution order as well, so you could easily
  300.     have this:
  301.  
  302.     all: arced* *.o
  303.         ln %(*.o) -o ram:file
  304.  
  305.     *.o : *.c
  306.         cc $(CFLAGS) %(right) -o %(left)
  307.  
  308.     *.o : *.asm
  309.         as $(AFLAGS) %(right) -o %(left)
  310.  
  311.     #   Note here that arced* is a wildcard dummy.    If we had just
  312.     #   used 'arced', the 'arc' command would have been executed once
  313.     #   with ALL the .arc files as arguments instead of being executed
  314.     #   once for each .arc file.
  315.  
  316.     arced* : *.arc
  317.         arc x %(*.arc)
  318.  
  319.     In anycase, the assumption that the arc files may contain .C and .ASM
  320.     files and these will be included in the *.o : *.c and *.o : *.asm
  321.     dependancies is absolutely correct.
  322.  
  323.  
  324.                 COMMON MISTAKES
  325.  
  326.  
  327.     ram:*.o ram:library.o : /dir2/*.c library.c        RIGHT
  328.         cc %(right) -o %(left)
  329.  
  330.     ram:*.o ram:*.o : /dir2/*.c library.c            WRONG
  331.         cc %(right) -o %(left)
  332.  
  333.     The dependancy labeled WRONG should be quite apparent if you break it
  334.     up manually:
  335.  
  336.     ram:*.o : /dir2/*.c
  337.         <commands>
  338.  
  339.     ram:*.o : library.c
  340.         <commands>
  341.  
  342.     The problem is the last one ... here you are saying that ALL the object
  343.     files depend on a single source file, which is wrong.
  344.  
  345.  
  346.                  COMMAND EXECUTION
  347.  
  348.     The CD command is an internal command.  Specifying CD with no arguments
  349.     returns you to the initial directory that DMake was run from.  This
  350.     is incredibly useful:
  351.  
  352.     OBJS = ram:*.o
  353.     SRCS = *.c
  354.  
  355.     $(EXE): $(OBJS)
  356.         cd ram:
  357.         ln %(right:"ram:*":"*") -lc32 -o $(EXE)
  358.         cd
  359.  
  360.     $(OBJS): $(SRCS)
  361.         cc %(right) -o %(left)
  362.  
  363.  
  364.     Commands are limited to ~200 chars in length (BCPL limitation) when
  365.     executed.  DMake has an internal limit of 4K long command command/
  366.     dependancy lines.
  367.  
  368.     There are two solutions to the problem.  (1) If your object list isn't
  369.     too big you can use the CD trick to CD into the object directory and
  370.     then remove the directory prefix for the object files on the link line.
  371.     (2) You can use a shell or equivalent and have it generate a file of
  372.     the expanded names, and then use the common -f option for the linker
  373.     (link from file list).
  374.  
  375.     all: $(OBJS)
  376.         shell -c "echo $(OBJS) >ram:linktmp"
  377.         ln -f ram:linktmp $(LINKLIBS) -o executable
  378.         Delete ram:linktmp
  379.  
  380.     Note that in running the shell command (dillon/drew shell), I specified
  381.     $(OBJS) instead of %(OBJS) ... passed the shell the explicit wildcard
  382.     instead of the over-long collection list.
  383.  
  384.  
  385.  
  386.