home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0210 - 0219 / ibm0210-0219 / ibm0213.tar / ibm0213 / HAM_W32.ZIP / SAMPLES / CL.CSH < prev    next >
Encoding:
Text File  |  1994-05-12  |  9.3 KB  |  324 lines

  1. #    Compile and link .c, .obj and/or .lib files for Windows NT, Release 2.1.p
  2. #    Copyright (c) 1992-1993 by Hamilton Laboratories.  All rights reserved.
  3.  
  4. #    If CPU == MIPS, either the old MIPS compiler or the new hybrid Microsoft/
  5. #    MIPS compiler may be used.  By default on NTVersion < 404 (not March beta),
  6. #    the old MIPS compiler is used; on NTVersion >= 404, the new compiler is
  7. #    the default.  You may explicitly specify old or new using the -old or
  8. #    -new options.
  9.  
  10. #    If CPU == ALPHA, either the old Alpha compiler or the new hybrid Microsoft/
  11. #    DEC compiler may be used.  By default on NTVersion < 404 (not March beta),
  12. #    the old ALPHA compiler is used; on NTVersion >= 404, the new compiler is
  13. #    the default.  You may explicitly specify old or new using the -old or
  14. #    -new options.
  15.  
  16. #  By default or if the -console flag is specified, cl will assume it's
  17. #    building a console application.  If -GUI is specified, it expects to
  18. #    build a graphical application.
  19.  
  20. #    By default, cl will compile and link using the following options:
  21.  
  22. #        i386 Compile:        -c -Od -Zi -W4 -DNT -D_MT -Di386=1 -D_X86_=1 -DWIN32
  23. #                                -Dend=EndOfData
  24.  
  25. #        MIPS Compile:
  26. #            using MIPS:        -c -std -O -o $i:b.obj -EL -DNT -D_MT -DMIPS=1
  27. #                                -D_MIPS_=1 -DWIN32 -Dend=EndOfData
  28. #            using new MS:    -c -Od -Zi -W4 -DNT -D_MT -DMIPS=1 -D_MIPS_=1 -DWIN32
  29. #                                -Dend=EndOfData
  30.  
  31. #        ALPHA Compile:
  32. #            using DEC:        -c -std -G 0 -o $i:b.obj -checkstack 4096 -00 -EL
  33. #                                -Dend=EndOfData -DNT -D_MT -DALPHA=1 -DWIN32 -excpt
  34. #                                -DDEVL=1 -I<include directories>
  35. #            using new MS:    -c -Od -Zi -W4 -DNT -D_MT -DALPHA=1 -D_ALPHA_=1
  36. #                                -DWIN32 -Dend=EndOfData -D__stdcall= -D_cdecl=
  37.  
  38. #        Console Link:        -subsystem:console -entry:mainCRTStartup -debug:full
  39. #                                -debugtype:both
  40.  
  41. #        GUI Link:            -subsystem:windows -entry:WinMainCRTStartup -debug:full
  42. #                                -debugtype:both
  43.  
  44. #    All the output is filtered thru ferr which filters out nuisance
  45. #    error messages such as the warnings about no modules extracted from
  46. #    a given .lib file or about assignments inside conditional tests.
  47. #    The list of nuisance messages is kept in skip file pointed to by the
  48. #    skip variable.  If skip isn't set or doesn't point to a real file, cl.csh
  49. #    wil attempt to look for a skip file in the same directory with this
  50. #    script.
  51.  
  52. if (! $?skip || ! -e $skip) then
  53.     #    Look for the filter file in the same directory with this cl.csh script.
  54.     set s = `whereis cl.csh`
  55.     if ($#s && -e $s[0]:h\skip) then
  56.         set skip = $fullpath($s[0]:h\skip)
  57.         alias ferr fgrep -vqf $skip
  58.     else
  59.         echo -2 Warning:  Output filter file not found!  No filtering will be done.
  60.         alias ferr cat
  61.     end
  62. else
  63.     alias ferr    fgrep -vqf $skip
  64. end
  65.  
  66. proc cl(args)
  67.     local i, j, ^
  68.             debug, c_only, O_opt, O_opt_specified, options, ^
  69.             c_files, obj_files, res_files, rc_files, lib_files, ^
  70.             exe, ldir, stdlibs, ntdll, use_old_cc, GUI_app, linker
  71.  
  72.     switch (upper(CPU))
  73.         case "MIPS":
  74.             @ O_opt = (use_old_cc = NTVersion < 404) ? "-O" : "-Od"
  75.             break
  76.         case "ALPHA":
  77.             @ O_opt = (use_old_cc = NTVersion < 404) ? "-O0" : "-Od"
  78.             break
  79.         default:
  80.             @ O_opt = "-Od"
  81.     end
  82.  
  83.     @ c_only = 0
  84.     for i = 0 to $#args - 1 do
  85.         @ j = substr(args[i], 1, 1)
  86.         if (j == '-' || j == '/') then
  87.             if (substr(args[i], 2) == 'c') then
  88.                 @ c_only = 1
  89.             else
  90.                 if (substr(args[i], 2, 1) == 'O') then
  91.                     set O_opt = $args[i]
  92.                     @ O_opt_specified = 1
  93.                 else
  94.                     switch (substr(args[i], 2))
  95.                         case "old":
  96.                             @ use_old_cc = 1
  97.                             if (!O_opt_specifed) then
  98.                                 switch (upper(CPU))
  99.                                     case "MIPS":
  100.                                         @ O_opt = "-O"
  101.                                         break
  102.                                     case "ALPHA":
  103.                                         @ O_opt = "-O0"
  104.                                 end
  105.                             end
  106.                             break
  107.                         case "new":
  108.                             @ use_old_cc = 0
  109.                             if (!O_opt_specifed) then
  110.                                 switch (upper(CPU))
  111.                                     case "MIPS":
  112.                                         @ O_opt = "-Od"
  113.                                         break
  114.                                     case "ALPHA":
  115.                                         @ O_opt = "-Od"
  116.                                 end
  117.                             end
  118.                             break
  119.                         case "console":
  120.                             @ GUI_app = 0
  121.                             break
  122.                         case "GUI":
  123.                             @ GUI_app = 1
  124.                             break
  125.                         default:
  126.                             set options = $options $args[i]
  127.                     end
  128.                 end
  129.             end
  130.         else
  131.             switch ($args[i]:e)
  132.                 case 'c':
  133.                 case 'cxx':
  134.                 case 'cpp':
  135.                     set c_files = $c_files $args[i]
  136.                     set obj_files = $obj_files $args[i]:b.obj
  137.                     break
  138.                 case 'obj':
  139.                 case 'rbj':
  140.                     set obj_files = $obj_files $args[i]
  141.                     break
  142.                 case 'exe':
  143.                     set exe = $args[i]
  144.                     break
  145.                 case 'rc':
  146.                     set rc_files = $rc_files $args[i]
  147.                     break
  148.                 case 'res':
  149.                     set res_files = $res_files $args[i]
  150.                     break
  151.                 case 'lib':
  152.                 default:
  153.                     set lib_files = $lib_files $args[i]
  154.             end
  155.         end
  156.     end
  157.  
  158.     #    Run the resource compiler and cvtres on each .rc file
  159.     foreach i ($rc_files)
  160.         echo rc -r $i
  161.         rc -r $i
  162.         echo cvtres -$CPU $i:b.res -o $i:b.rbj
  163.         cvtres -$CPU $i:b.res -o $i:b.rbj
  164.         set obj_files = $obj_files $i:b.rbj
  165.     end
  166.  
  167.     #    Run cvtres on each .res file
  168.     foreach i ($res_files)
  169.         echo cvtres -$CPU $i -o $i:b.rbj
  170.         cvtres -$CPU $i -o $i:b.rbj
  171.         set obj_files = $obj_files $i:b.rbj
  172.     end
  173.  
  174.     #    Run the compile step on each .c file.
  175.     (switch (upper(CPU))
  176.         case "MIPS":
  177.             if (use_old_cc) then
  178.                 foreach i ($c_files)
  179.                     echo cc -c -std -O -o $i:b.obj -EL -DNT -DMIPS=1 -D_MIPS_=1 ^
  180.                             -DWIN32 -Dend=EndOfData $options $i
  181.                     cc -c -std -O -o $i:b.obj -EL -DNT -DMIPS=1 -D_MIPS_=1 ^
  182.                             -DWIN32 -Dend=EndOfData $options $i
  183.                     if ($status) return
  184.                     echo mip2coff $i:b.obj
  185.                     mip2coff $i:b.obj
  186.                     if ($status) return
  187.                 end
  188.             else
  189.                 foreach i ($c_files)
  190.                     echo mcl -c $O_opt -Zi -W4 -DNT -DMIPS=1 -D_MIPS_=1 -DWIN32 ^
  191.                             -Dend=EndOfData $options $i
  192.                     mcl -c $O_opt -Zi -W4 -DNT -DMIPS=1 -D_MIPS_=1 -DWIN32 ^
  193.                             -Dend=EndOfData $options $i
  194.                     if ($status) return
  195.                 end
  196.             end
  197.             break
  198.  
  199.         case "ALPHA":
  200.             if (use_old_cc) then
  201.                 if (NTVersion < 522) then
  202.                     #    Alpha compiler doesn't handle the INCLUDE environment
  203.                     #    variable properly -- it has to be passed on the command
  204.                     #    line.
  205.                     set Inc = -I$INCLUDE:gs/;/ -I/
  206.                     if (NTVersion < 404) set options = -EL -excpt -DDEVL=1 $options
  207.                 end
  208.                 foreach i ($c_files)
  209.                     echo acc -c -std -G 0 -o $i:b.obj -checkstack 4096            ^
  210.                             $O_opt -Dend=EndOfData -DNT -DALPHA=1 -D_ALPHA_=1    ^
  211.                             -DWIN32 $options $Inc $i
  212.                     acc -c -std -G 0 -o $i:b.obj -checkstack 4096                ^
  213.                             $O_opt -Dend=EndOfData -DNT -DALPHA=1 -D_ALPHA_=1    ^
  214.                             -DWIN32 $options $Inc $i
  215.                     if ($status) return
  216.                     echo a2coff $i:b.obj
  217.                     a2coff $i:b.obj
  218.                     if ($status) return
  219.                 end
  220.             else
  221.                 foreach i ($c_files)
  222.                     echo claxp -c $O_opt -Zi -W4 -DNT -DALPHA=1 -D_ALPHA_=1    ^
  223.                             -DWIN32 -Dend=EndOfData -D__stdcall= -D_cdecl=        ^
  224.                             $options $i
  225.                     claxp -c $O_opt -Zi -W4 -DNT -DALPHA=1 -D_ALPHA_=1 -DWIN32 ^
  226.                             -Dend=EndOfData -D__stdcall= -D_cdecl= $options $i
  227.                     if ($status) return
  228.                 end
  229.             end
  230.             break
  231.  
  232.         default:
  233.             foreach i ($c_files)
  234.                 echo cl386 -c $O_opt -Zi -W4 -DNT -Di386=1 -D_X86_=1 -DWIN32 ^
  235.                         -Dend=EndOfData $options $i
  236.                 cl386 -c $O_opt -Zi -W4 -DNT -Di386=1 -D_X86_=1 -DWIN32 ^
  237.                         -Dend=EndOfData $options $i
  238.                 if ($status) return
  239.             end
  240.     end
  241.  
  242.     if (! $c_only) then
  243.  
  244.         #    If no .exe file was specified, name the output to match the
  245.         #    first .c or .obj file on the command line.
  246.         if (exe == '') then
  247.             @ exe = $#c_files == 0 ? $obj_files[0]:b.exe : $c_files[0]:b.exe
  248.         end
  249.  
  250.         if (NTVersion >= 404) then
  251.  
  252.             #    Figure out whether ntdll.lib exists on this build.
  253.             if (LIB =~ "*;*") then
  254.                 foreach i ($LIB:gs/;/ /)
  255.                     if (-e $i\ntdll.lib) then
  256.                         set ntdll = ntdll.lib
  257.                         break;
  258.                     else
  259.                         if (CPU == "ALPHA" && -e $i\alpha\ntdll.lib) then
  260.                             set ntdll = ntdll.lib
  261.                         end
  262.                     end
  263.                 end
  264.             else
  265.                 if (-e $LIB\ntdll.lib) set ntdll = ntdll.lib
  266.             end
  267.             set linker = link32
  268.             if (GUI_app) then
  269.                 set stdlibs = libcmt.lib $ntdll kernel32.lib ^
  270.                     user32.lib gdi32.lib winspool.lib comdlg32.lib
  271.             else
  272.                 set stdlibs = libcmt.lib $ntdll kernel32.lib
  273.             end
  274.  
  275.         else
  276.  
  277.             #    Figure out where libcmt.lib lives on the LIB path.
  278.             if (LIB =~ "*;*") then
  279.                 foreach i ($LIB:gs/;/ /)
  280.                     if (-e $i\libcmt.lib) then
  281.                         @ ldir = i
  282.                         break
  283.                     else
  284.                         if (CPU == "ALPHA" && -e $i\alpha\libcmt.lib) then
  285.                             set ldir = $i\alpha
  286.                             break
  287.                         end
  288.                     end
  289.                 end
  290.             else
  291.                 @ ldir = LIB
  292.             end
  293.  
  294.             set linker = coff -link
  295.  
  296.             if (CPU == "ALPHA") then
  297.                 if (GUI_app) then
  298.                     set stdlibs = $ldir\{libcmt,ntdll,kernel32}.lib ^
  299.                         $ldir\{user32,gdi32,winspool,comdlg32}.lib
  300.                 else
  301.                     set stdlibs = $ldir\{libcmt,ntdll,kernel32}.lib
  302.                 end
  303.             else
  304.                 set stdlibs = $ldir\libcmt.lib $ldir\^*.lib
  305.             end
  306.         end
  307.  
  308.         #    Run the link step, with debug info.
  309.         if (GUI_app) then
  310.             echo $linker -subsystem:windows -entry:WinMainCRTStartup -debug:full    ^
  311.                 -debugtype:both -out:$exe $obj_files $lib_files "$stdlibs"
  312.             $linker -subsystem:windows -entry:WinMainCRTStartup -debug:full        ^
  313.                 -debugtype:both -out:$exe $obj_files $lib_files $stdlibs
  314.         else
  315.             echo $linker -subsystem:console -entry:mainCRTStartup -debug:full    ^
  316.                 -debugtype:both -out:$exe $obj_files $lib_files "$stdlibs"
  317.             $linker -subsystem:console -entry:mainCRTStartup -debug:full        ^
  318.                 -debugtype:both -out:$exe $obj_files $lib_files $stdlibs
  319.         end
  320.     end) | ferr
  321. end
  322.  
  323. cl $argv
  324.