home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / makemak.lzh / MAKEMAK.PRT < prev    next >
Text File  |  1988-02-21  |  13KB  |  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.                Input options are checked via the Unix style getopt
  168.           function. Error messages are generated for illegal or no options.
  169.           Once the options and/or file name are determined, make macros are
  170.           setup in mak_cfg. Two arrays are generated here. The first,
  171.           mak_macs[] is an array of pointers to strings with the *keywords
  172.           (e.g. C_OPTS) for the macro definitions. The second, defaults[],
  173.           is an array of pointers to strings of the macro definitions
  174.           themselves (without the keyword prefix). During the call to
  175.           mak_cfg, the both arrays are initialized to the program's built
  176.           in definitions. Then a check of the CL, MASM and LINK environment
  177.           variables is made and any values found there will overwrite the
  178.           C_OPTS, M_OPTS and L_OPTS values in the defaults array. The
  179.           mak_macs array will not change. Next, the "MAKEMAK.CFG" file is
  180.           searched for using the C 5.0 _searchenv function. If a
  181.           "MAKEMAK.CFG" file is found, it is read in a line at a time and
  182.           the first word of the line is successively compared to the
  183.           keyword strings in the mak_macs array. If a match is found, the
  184.           rest of the line is copied to the corresponding element of the
  185.           defaults array. This is what sets up the precedence rules for
  186.           defining the macros. (In case you did not follow that, the
  187.           precedence rules are, internal, environment, "MAKEMAK.CFG")
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.                                 Makemak.c                                 Page 4
  203.  
  204.  
  205.                Once the macros are defined, all files names in the current
  206.           directory are read into an array, directory[MAXFILES], again
  207.           using C 5.0 language extensions (_dos_findfirst and
  208.           _dos_findnext). There is an internally defined limit of 250 files
  209.           that can be operated on. More files than this and warning message
  210.           is generated, but program execution continues.
  211.  
  212.                If a make file is being generated, the macro definitions for
  213.           the make file are then generated and sent to the screen. Three of
  214.           the macros are HDRS, SRCS, OBJS. These are generated by looking
  215.           at the extension of each file and adding the file name to on or
  216.           more of the three macros definitions. This part is skipped if any
  217.           options were specified on the command line.
  218.  
  219.                If the -s (show times) option was specified, a list of C,
  220.           ASM and H files are printed with the last modification date.
  221.  
  222.                If the verbose option (or no option) is specified, the
  223.           extension of each file is checked to see if it is of an
  224.           appropriate type. If it is, figure_out_includes is called.
  225.  
  226.                Figure_out_includes starts by printing a dependency list  of
  227.           the form base_name.obj: base_name.c (or .asm). It then scans the
  228.           file for #include directives. If a #include is found,
  229.           check_for_include is called to verify that the directive has the
  230.           form
  231.           '#include "fname"'. Note that it rejects directives like
  232.           '#include "\myincs\fname"' and '#include <fname>'. In other
  233.           words, the only files we are concerned with will be in the
  234.           current directory. Then a check is made of the array of file
  235.           names to verify that the include file is indeed in the current
  236.           directory. If not a warning message is printed.
  237.  
  238.                If check_for_include returns with a valid include file, this
  239.           file name is printed as part of the dependency list we started
  240.           earlier. Then figure_out_includes is called recursively to see if
  241.           the include file includes another file. And so on.
  242.  
  243.                Once the first file is completely checked, a newline and
  244.           compile command with macros is printed for the file. Then the
  245.           next file is scanned for includes.
  246.  
  247.                Finally, the tail end of the make file is printed. This line
  248.           looks like:
  249.           $(TARGET):     $(HDRS) $(SRCS) ($OBJS)
  250.                $(LC) $(L_OPTS) $(OBJS), $(TARGET), $(LMAP), $(LIBS);
  251.  
  252.                The final notes are a description of my compile environment:
  253.                CL=/AS /Zi /Od
  254.                LIBS=d:\lib;d:\lib\local;d:.
  255.                LINK=/CO
  256.                MASM=/Zi
  257.                CONFIG=c:\util\configs
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.                                 Makemak.c                                 Page 5
  269.  
  270.  
  271.                And of course we need to have a packing list so that you
  272.           know what other stuff you should have recieved with this program.
  273.           
  274.                makemak.exe    the whole point of this exercise
  275.                makemak.c      main source code for the above
  276.                mak_cfg.c      configuration setter upper for makemak
  277.                mak_help.c     a small help file for makemak
  278.                makemak.h      include file for makemak
  279.                makemak.mak    make file that generated makemak
  280.                makemak.cfg    a sample configuration file
  281.                getopt.c       a Unix style getopt function that I keep in a
  282.                               library called SUTIL.lib
  283.                getpname.c     a function to extract the program name from   
  284.                               the command line if _osmajor >= 3.
  285.                SUTIL.LIB      The lib with the above two files.
  286.                makemak.prt    this file
  287.                makemak.arc    all of the above files
  288.                
  289.  
  290.                Have fun. Oh, and please, do send me your modifications if
  291.           you can. Also try to distribute the whole archive. Thanks.                                              whole                 
  292.  
  293.  
  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.