home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MAKEMAKE.ZIP / MAKEMAK.PRT < prev    next >
Encoding:
Text File  |  1988-02-21  |  12.5 KB  |  331 lines

  1.  
  2.  
  3.  
  4.                                 Makemak.c                                 Page 1
  5.  
  6.  
  7.  
  8.                Makemak.c is a program intended to ease the chore of
  9.           establishing dependency lists for the Microsoft Make program. The
  10.           output is suitable for building C or MASM programs or a
  11.           combination of both. The resulting output file will may not be
  12.           100% usable but it will be close. I find that only a small amount
  13.           of editing is usually necessary to use the make file.
  14.  
  15.                Makemak is invoked in the following manner:
  16.  
  17.                makemak [options] filename
  18.  
  19.                
  20.  
  21.                Where options are:
  22.                -d        show make style dependency list
  23.                -v        verbose output
  24.                -s        show times of all checked files
  25.  
  26.                and filename is the name of the target file that make will
  27.           generate. A make file will not be generated if any options are
  28.           given. The make file is sent to the CRT and can be redirected to
  29.           a file.
  30.  
  31.                Several make macro definitions are also generated. The
  32.           source of these definitions can come from several places. First,
  33.           a set of default definitions are built into the program. Second,
  34.           three environment variables, "CL, LINK, and MASM" are checked and
  35.           any values there become macro definitions. Lastly, a
  36.           configuration, "MAKEMAK.CFG" file is checked and any definitions
  37.           there will be included. This last set will override any
  38.           definitions set internally or from the environment. The program
  39.           looks for "MAKEMAK.CFG" in the current directory. If found, the
  40.           values in it will be used. If "MAKEMAK.CFG" is not found in the
  41.           current directory, an environment variable, "CONFIG" is searched.
  42.           This variable should specify a single directory to search for
  43.           "MAKEMAK.CFG".  If the file is found, it's values will be used.
  44.  
  45.                The format of "MAKEMAK.CFG" file is as follows:
  46.           
  47.                cc = C compile command
  48.                c_opts = options used with the C compiler
  49.                cdefs = definitions defined to the C compiler
  50.                mc = ASM compile command
  51.                m_opts = options used with the assembler
  52.                mdefs = definitions defined to the assembler
  53.                lc = link command
  54.                l_opts = options used with the linker
  55.                lmap = name of map file generated by the linker
  56.                libs = library names that the linker searches
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.                                 Makemak.c                                 Page 2
  71.  
  72.  
  73.                The default settings for all of these macro definitions are:
  74.           
  75.                CC = cl
  76.                C_OPTS =  /Zi /Od /c
  77.                CDEFS =
  78.                MC = masm
  79.                M_OPTS = /Zi
  80.                MDEFS =
  81.                LC = link
  82.                L_OPTS = /CO
  83.                LMAP = NUL
  84.                LIBS =
  85.  
  86.                Remember that the definitions in the MAKEMAK.CFG file will
  87.           override both the defaults and the values of the LINK, CL and
  88.           MASM environment variables. Also, the values from the LINK, CL
  89.           and MASM environment variables get mapped into L_OPTS, C_OPTS and
  90.           M_OPTS respectively. Any line that starts with a word that is not
  91.           one of the key words listed above is considered a comment. Any
  92.           key word that is not defined in the config file is assigned the
  93.           default value.
  94.  
  95.                For an example, see the MAKEMAK.CFG file that should have
  96.           accompanied this documentation.
  97.           
  98.           Some rules to follow when using MAKEMAK:
  99.  
  100.                All C, ASM and H files are considered to belong to the
  101.           target executable built by make. This means that the target
  102.           executable will be dependant on all files in the current
  103.           directory with extensions of .C, .ASM and .H. If you have sloppy
  104.           directories that are filled with all sorts of files with these
  105.           extensions, you will end up doing a lot of editing on your make
  106.           file. This may not be what you had intended. To keep things
  107.           clean, give the program you are working on has it's own
  108.           directory. Then you will get a nice, simple make file that may
  109.           not require any editing at all.
  110.  
  111.                Assembler .INCLUDE files are not included in the dependency
  112.           list. To do so requires quite a few modifications to the
  113.           check_for_include and figure_out_include functions. I do not use
  114.           assembler often enough to want that feature anyway. Feel free to
  115.           modify the source if this is a desirable feature for you. Also
  116.           send me a copy of the modified source if you can. If Microsoft
  117.           would standardize it's programming languages the way UNIX
  118.           languages are, the #include directive would serve to find the v
  119.           of C, MASM, PASCAL, FORTRAN, COBOL and other languages with only
  120.           a check of the extension instead of writing a separate
  121.           figure_out_include for each language.
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.                                 Makemak.c                                 Page 3
  137.  
  138.  
  139.                I believe there is a problem which will require editing of
  140.           the generated make file when the list of header, objects and
  141.           sources becomes to long. It seems the linker does not like the
  142.           long line that is generated with too many files. I have not yet
  143.           bothered to figure out what's wrong. If you find out what's going
  144.           on in these cases, again, try to send me a copy of the modified
  145.           source.
  146.  
  147.                I have found that MAKEMAK will perform acceptably with
  148.           little to no editing of the generated make file for most of my
  149.           small programming tasks. Updating of libraries is the one
  150.           function that I often have to add to the make file.
  151.  
  152.                Parts of this program are based on an article by Dave Taylor
  153.           in the February, 1988 issue of Computer Language. It has been
  154.           extensively modified for DOS. The getopt function is from Augie
  155.           Hansens's book "Proficient C".
  156.  
  157.                Compiled under Microsoft C 5.0
  158.  
  159.                Loran W. Richardson
  160.                7083 Fairways Drive
  161.                Longmont, CO 80501
  162.                (303) 939-9743
  163.                CIS 70441,3037
  164.  
  165.                                     HOW IT WORKS
  166.                                     ____________
  167.  
  168.                Input options are checked via the Unix style getopt
  169.           function. Error messages are generated for illegal or no options.
  170.           Once the options and/or file name are determined, make macros are
  171.           setup in mak_cfg. Two arrays are generated here. The first,
  172.           mak_macs[] is an array of pointers to strings with the *keywords
  173.           (e.g. C_OPTS) for the macro definitions. The second, defaults[],
  174.           is an array of pointers to strings of the macro definitions
  175.           themselves (without the keyword prefix). During the call to
  176.           mak_cfg, the both arrays are initialized to the program's built
  177.           in definitions. Then a check of the CL, MASM and LINK environment
  178.           variables is made and any values found there will overwrite the
  179.           C_OPTS, M_OPTS and L_OPTS values in the defaults array. The
  180.           mak_macs array will not change. Next, the "MAKEMAK.CFG" file is
  181.           searched for using the C 5.0 _searchenv function. If a
  182.           "MAKEMAK.CFG" file is found, it is read in a line at a time and
  183.           the first word of the line is successively compared to the
  184.           keyword strings in the mak_macs array. If a match is found, the
  185.           rest of the line is copied to the corresponding element of the
  186.           defaults array. This is what sets up the precedence rules for
  187.           defining the macros. (In case you did not follow that, the
  188.           precedence rules are, internal, environment, "MAKEMAK.CFG")
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.                                 Makemak.c                                 Page 4
  204.  
  205.  
  206.                Once the macros are defined, all files names in the current
  207.           directory are read into an array, directory[MAXFILES], again
  208.           using C 5.0 language extensions (_dos_findfirst and
  209.           _dos_findnext). There is an internally defined limit of 250 files
  210.           that can be operated on. More files than this and warning message
  211.           is generated, but program execution continues.
  212.  
  213.                If a make file is being generated, the macro definitions for
  214.           the make file are then generated and sent to the screen. Three of
  215.           the macros are HDRS, SRCS, OBJS. These are generated by looking
  216.           at the extension of each file and adding the file name to on or
  217.           more of the three macros definitions. This part is skipped if any
  218.           options were specified on the command line.
  219.  
  220.                If the -s (show times) option was specified, a list of C,
  221.           ASM and H files are printed with the last modification date.
  222.  
  223.                If the verbose option (or no option) is specified, the
  224.           extension of each file is checked to see if it is of an
  225.           appropriate type. If it is, figure_out_includes is called.
  226.  
  227.                Figure_out_includes starts by printing a dependency list  of
  228.           the form base_name.obj: base_name.c (or .asm). It then scans the
  229.           file for #include directives. If a #include is found,
  230.           check_for_include is called to verify that the directive has the
  231.           form
  232.           '#include "fname"'. Note that it rejects directives like
  233.           '#include "\myincs\fname"' and '#include <fname>'. In other
  234.           words, the only files we are concerned with will be in the
  235.           current directory. Then a check is made of the array of file
  236.           names to verify that the include file is indeed in the current
  237.           directory. If not a warning message is printed.
  238.  
  239.                If check_for_include returns with a valid include file, this
  240.           file name is printed as part of the dependency list we started
  241.           earlier. Then figure_out_includes is called recursively to see if
  242.           the include file includes another file. And so on.
  243.  
  244.                Once the first file is completely checked, a newline and
  245.           compile command with macros is printed for the file. Then the
  246.           next file is scanned for includes.
  247.  
  248.                Finally, the tail end of the make file is printed. This line
  249.           looks like:
  250.           $(TARGET):     $(HDRS) $(SRCS) ($OBJS)
  251.                $(LC) $(L_OPTS) $(OBJS), $(TARGET), $(LMAP), $(LIBS);
  252.  
  253.                The final notes are a description of my compile environment:
  254.                CL=/AS /Zi /Od
  255.                LIBS=d:\lib;d:\lib\local;d:.
  256.                LINK=/CO
  257.                MASM=/Zi
  258.                CONFIG=c:\util\configs
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.                                 Makemak.c                                 Page 5
  270.  
  271.  
  272.                And of course we need to have a packing list so that you
  273.           know what other stuff you should have recieved with this program.
  274.           
  275.                makemak.exe    the whole point of this exercise
  276.                makemak.c      main source code for the above
  277.                mak_cfg.c      configuration setter upper for makemak
  278.                mak_help.c     a small help file for makemak
  279.                makemak.h      include file for makemak
  280.                makemak.mak    make file that generated makemak
  281.                makemak.cfg    a sample configuration file
  282.                getopt.c       a Unix style getopt function that I keep in a
  283.                               library called SUTIL.lib
  284.                getpname.c     a function to extract the program name from   
  285.                               the command line if _osmajor >= 3.
  286.                SUTIL.LIB      The lib with the above two files.
  287.                makemak.prt    this file
  288.                makemak.arc    all of the above files
  289.                
  290.  
  291.                Have fun. Oh, and please, do send me your modifications if
  292.           you can. Also try to distribute the whole archive. Thanks.
  293.                                               whole                 
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.