home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 529b.lha / BMake_v1.1 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-03  |  4.7 KB  |  235 lines

  1. /*    main.c
  2.  *    (c) Copyright 1991 by Ben Eng, All Rights Reserved
  3.  *
  4.  */
  5.  
  6. #include <ctype.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <exec/execbase.h>
  10.  
  11. #include <intuition/intuitionbase.h>
  12. #include <graphics/gfxbase.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/dos_protos.h>
  16.  
  17. extern struct GfxBase *GfxBase;
  18. extern struct IntuitionBase *IntuitionBase;
  19.  
  20. #include "make.h"
  21. #include "depend.h"
  22.  
  23. /* Globals */
  24. struct globals Global = {
  25.     NULL,    /* me */
  26.     NULL,    /* logfile */
  27.  
  28.     {
  29.     (struct Node *)&Global.targetlist.lh_Tail,    /* lh_Head */
  30.     (struct Node *)NULL,                        /* lh_Tail */
  31.     (struct Node *)&Global.targetlist.lh_Head,    /* lh_TailPred */
  32.     (UBYTE)NT_USER,
  33.     (UBYTE)0
  34.     },    /* targetlist */
  35.     {
  36.     (struct Node *)&Global.speciallist.lh_Tail,    /* lh_Head */
  37.     (struct Node *)NULL,                        /* lh_Tail */
  38.     (struct Node *)&Global.speciallist.lh_Head,    /* lh_TailPred */
  39.     (UBYTE)NT_USER,
  40.     (UBYTE)0
  41.     },    /* speciallist */
  42.     {
  43.     (struct Node *)&Global.patternlist.lh_Tail,    /* lh_Head */
  44.     (struct Node *)NULL,                        /* lh_Tail */
  45.     (struct Node *)&Global.patternlist.lh_Head,    /* lh_TailPred */
  46.     (UBYTE)NT_USER,
  47.     (UBYTE)0
  48.     },    /* patternlist */
  49.     {
  50.     (struct Node *)&Global.macrolist.lh_Tail,    /* lh_Head */
  51.     (struct Node *)NULL,                        /* lh_Tail */
  52.     (struct Node *)&Global.macrolist.lh_Head,    /* lh_TailPred */
  53.     (UBYTE)NT_USER,
  54.     (UBYTE)0
  55.     },    /* macrolist */
  56.     0,    /* builtin flag */
  57.     0,    /* recursion level */
  58.     0L    /* oldcwd */
  59. };
  60.  
  61. static int
  62. open_libraries( void )
  63. {
  64. #ifndef _DCC
  65.     if( !( IntuitionBase = OpenLibrary( "intuition.library", 33 ))) {
  66.         return( 1 );
  67.     }
  68.     if( !( GfxBase = OpenLibrary( "graphics.library", 33 ))) {
  69.         return( 1 );
  70.     }
  71. #endif
  72.     return( 0 );
  73. }
  74.  
  75. static void
  76. close_libraries( void )
  77. {
  78. #ifndef _DCC
  79.     if( IntuitionBase )
  80.         CloseLibrary( IntuitionBase );
  81.  
  82.     if( GfxBase )
  83.         CloseLibrary( GfxBase );
  84. #endif
  85. }
  86.  
  87. static int
  88. new_globals( struct globals *globptr )
  89. {
  90.     globptr->me = (struct Process *) FindTask( NULL ); /* find this task */
  91.     return( 0 );
  92. death:
  93.     printf( "problem initializing globals\n" );
  94.     return( 1 );
  95. }
  96.  
  97. static int
  98. delete_globals( struct globals *globptr )
  99. {
  100.     if( Global.oldcwd ) {
  101.         UnLock( CurrentDir( Global.oldcwd ));
  102.     }
  103.  
  104.     memset( globptr, 0, sizeof(struct globals));
  105.  
  106.     /*    just allow exit() to take care of free()ing all of our
  107.      *    allocations, because I don't feel like doing it right now
  108.      */
  109.     NewList( &globptr->targetlist );
  110.     NewList( &globptr->speciallist );
  111.     NewList( &globptr->patternlist );
  112.     NewList( &globptr->macrolist );
  113. }
  114.  
  115.  
  116. static void
  117. die( void )
  118. {
  119.     delete_params();
  120.  
  121.     close_logfile();
  122.  
  123.     delete_globals( &Global );
  124.     close_libraries();
  125. }
  126.  
  127. static int
  128. init( void )
  129. {
  130.     if( open_libraries()) goto death;
  131.     if( new_globals( &Global )) goto death;
  132.  
  133.     return( 0 );
  134. death:
  135.     return( 1 );
  136. }
  137.  
  138. static long
  139. do_cl_macro( struct string_node *one )
  140. {
  141.     long retval;
  142.     int made;
  143.  
  144.     if( strchr( one->data, '=' )) {
  145.         logprintf( "\t%s\n", one->data );
  146.         process_macroline( one->data );
  147.         Remove( &one->node );
  148.         delete_snode( one );
  149.     }
  150.     return( 0 );
  151. }
  152.  
  153. static long
  154. run_one( struct string_node *one )
  155. {
  156.     long retval;
  157.     int made;
  158.  
  159.     debugprintf( 2, ("\n** run_one Make %s **\n", one->data ));
  160.     retval = (long) make_filename( one->data, &made );
  161.     if( !retval && !made ) {
  162.         logprintf( "\"%s\" is up to date\n", one->data );
  163.     }
  164.     return( retval );
  165. }
  166.  
  167. static void
  168. run_it( void )
  169. {
  170.     long retval;
  171.     int made;
  172.  
  173.     if( Param.filelist.lh_Head->ln_Succ )
  174.         (void)for_list( &Param.filelist, do_cl_macro );
  175.     if( Param.filelist.lh_Head->ln_Succ ) {
  176.         (void)for_list( &Param.filelist, run_one );
  177.     }
  178.     else {
  179.         struct target *first_goal;
  180.         for( first_goal = (struct target *)Global.targetlist.lh_Head;
  181.             first_goal->node.ln_Succ;
  182.             first_goal = first_goal->node.ln_Succ ) {
  183.             if( !(first_goal->flags & (TF_PATTERN|TF_BUILTIN ))) break;
  184.         }
  185.         if( first_goal->node.ln_Succ ) {
  186.             debugprintf( 2, ("\n** first_goal Make %s **\n",
  187.                 first_goal->name ));
  188.             retval = make_filename( first_goal->name, &made );
  189.             if( !retval && !made ) {
  190.                 logprintf( "\"%s\" is up to date\n", first_goal->name );
  191.             }
  192.         }
  193.     }
  194.     logprintf( "\tMake done.\n" );
  195. }
  196.  
  197. int
  198. main( int argc, char *argv[] )
  199. {
  200. /*    Allow it to work with limitations on xsystem() and scdir()
  201.     if( GfxBase->LibNode.lib_Version < 36L ) {
  202.         printf( "This program requires Amiga OS 2.0\n" );
  203.         return( 20 );
  204.     }
  205. */
  206.     atexit( die );    /* add die() to normal exit procedure */
  207.  
  208.     if( parse_parameters( argc, argv )) goto bailout;
  209.  
  210.     logprintf( "%s\n", version_string+7 );
  211.     logprintf( "%s\n", copyright_string );
  212.  
  213.     if( init() ) goto bailout;
  214.     Global.builtin_flag = 1;
  215.     if( init_builtins()) goto bailout;
  216.     Global.builtin_flag = 0;
  217.     if( Param.filelist.lh_Head->ln_Succ )
  218.         (void)for_list( &Param.filelist, do_cl_macro );
  219.  
  220.     if( input_makefile( Param.makefile )) goto bailout;
  221. #if DEBUG
  222.     if( Param.print_database ) dump_all();
  223.     else run_it();
  224. #else
  225.     run_it();
  226. #endif
  227.  
  228.     return( 0 );
  229.  
  230. bailout:
  231.     /* die(); is called by atexit */
  232.     return( 20 );
  233. }
  234.  
  235.