/* * Spawn the Watcom wmake. Returns NMAKE_ERROR if wmake returned a bad * status code or if it could not be spawned, or else NMAKE_SUCCESS if * everything went smoothly. */ static int nmake( const OPT_STORAGE *cmdOpts, CmdLine *cmdLine ) /**************************************************************/ { char ** args; int rc; int count; char * cwd; char flagstmp[32] = {0}; /*** get value for MAKEDIR field ***/ cwd = getcwd( NULL, 0 ); /*** construct MAKEFLAGS field ***/ if( cmdOpts->a ) strcat(flagstmp, "A"); if( cmdOpts->c ) strcat(flagstmp, "C"); if( cmdOpts->d ) strcat(flagstmp, "D"); if( cmdOpts->e ) strcat(flagstmp, "E"); if( cmdOpts->nologo ) strcat(flagstmp, "L"); if( cmdOpts->n ) strcat(flagstmp, "N"); if( cmdOpts->p ) strcat(flagstmp, "P"); if( cmdOpts->r ) strcat(flagstmp, "R"); if( cmdOpts->s ) strcat(flagstmp, "S"); if( cmdOpts->u ) strcat(flagstmp, "U"); if( cmdOpts->y ) strcat(flagstmp, "Y"); /*** pass builtin macros to wmake, so nmake wrapper gets called in recursive actions ***/ AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKE=\"%s\"", "nmake" ); AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKEDIR=\"%s\"", cwd ); AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKEFLAGS=\"%s\"", flagstmp ); /*** merge commands ***/ AppendCmdLine( cmdLine, NMAKE_PROGNAME_SECTION, MAKE ); args = MergeCmdLine( cmdLine, INVALID_MERGE_CMDLINE ); /*** Spawn the wmake ***/ if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, MAKE, (const char **)args ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", MAKE ); } else { return( NMAKE_ERROR ); } } } DestroyCmdLine( cmdLine ); return( NMAKE_SUCCESS ); }
/* * Link any object and library files. Returns LINK_NOACTION if there was no * file to compile, LINK_ERROR if the linker returned a bad status code or * if the compiler could not be spawned, or else LINK_SUCCESS if everything * went smoothly. */ static int link( const OPT_STORAGE *cmdOpts, CmdLine *linkCmdLine ) /*****************************************************************/ { char ** args; char * filename; int fileType; int numFiles; int rc; char * defFile; char * prevDefFile = NULL; cmdOpts = cmdOpts; /*** Process all object and library file names ***/ for( numFiles=0; ; numFiles++ ) { filename = GetNextFile( &fileType, TYPE_OBJ_FILE, TYPE_LIB_FILE, TYPE_RES_FILE, TYPE_INVALID_FILE ); if( filename == NULL ) break; AppendCmdLine( linkCmdLine, CL_L_FILENAMES_SECTION, filename ); } /*** Process .def files ***/ for( ;; ) { defFile = GetNextFile( NULL, TYPE_DEF_FILE, TYPE_INVALID_FILE ); if( defFile == NULL ) break; if( prevDefFile != NULL ) { Warning( "Overriding %s with %s", prevDefFile, defFile ); } prevDefFile = defFile; }; if( prevDefFile != NULL ) { AppendFmtCmdLine( linkCmdLine, CL_L_OPTS_SECTION, "/DEF:%s", prevDefFile ); } else { if( numFiles == 0 ) return( LINK_NOACTION ); } /*** Spawn the linker ***/ AppendCmdLine( linkCmdLine, CL_L_PROGNAME_SECTION, LINKER ); args = MergeCmdLine( linkCmdLine, INVALID_MERGE_CMDLINE ); rc = spawnvp( P_WAIT, LINKER, (const char **)args ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", LINKER ); } else { return( LINK_ERROR ); } } return( LINK_SUCCESS ); }
/* * Spawn the resource compiler. */ static int res_compile( const OPT_STORAGE *cmdOpts, CmdLine *cmdLine ) /********************************************************************/ { char ** args; char * filename; char * nextFilename; int rc; int count; /*** Get the name of the .rc file to compiler ***/ filename = GetNextFile( NULL, TYPE_RC_FILE, TYPE_INVALID_FILE ); if( filename == NULL ) return( RC_NOACTION ); nextFilename = GetNextFile( NULL, TYPE_RC_FILE, TYPE_INVALID_FILE ); if( nextFilename != NULL ) { FatalError( "Can only compile one file at a time" ); } /*** Prepare to spawn the resource compiler ***/ AppendCmdLine( cmdLine, RC_PROGNAME_SECTION, RESCOMPILER ); AppendCmdLine( cmdLine, RC_FILENAMES_SECTION, filename ); args = MergeCmdLine( cmdLine, RC_PROGNAME_SECTION, RC_OPTS_SECTION, RC_FILENAMES_SECTION, INVALID_MERGE_CMDLINE ); /*** Spawn the compiler ***/ if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, RESCOMPILER, (const char **)args ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Error executing '%s'", RESCOMPILER ); } else { return( RC_ERROR ); } } } return( RC_SUCCESS ); }
/* * Spawn the Watcom linker. Returns LINK_NOACTION if there was no file to * link, LINK_ERROR if the linker returned a bad status code or if it could * not be spawned, or else LINK_SUCCESS if everything went smoothly. */ static int link( const OPT_STORAGE *cmdOpts, CmdLine *cmdLine ) /*************************************************************/ { char ** args; int rc; char * cmdFileName; FILE * fp; int count; CmdLine * spawnCmdLine; /*** Make the command file ***/ args = MergeCmdLine( cmdLine, INVALID_MERGE_CMDLINE ); cmdFileName = tmpnam( NULL ); if( !cmdOpts->noinvoke ) { fp = fopen( cmdFileName, "wt" ); if( fp == NULL ) { FatalError( "Cannot open temporary file '%s' -- aborting", cmdFileName ); } } for( count=0; args[count]!=NULL; count++ ) { if( !cmdOpts->noinvoke ) { fprintf( fp, "%s\n", args[count] ); } if( cmdOpts->showwopts ) { fprintf( stderr, "echo.%s%s%s\n", args[count], (count == 0 ? ">" : ">>"), cmdFileName ); } } if( !cmdOpts->noinvoke ) { fclose( fp ); } /*** Spawn the linker ***/ spawnCmdLine = InitCmdLine( LINK_NUM_SECTIONS ); AppendCmdLine( spawnCmdLine, LINK_PROGNAME_SECTION, LINKER ); AppendFmtCmdLine( spawnCmdLine, LINK_OPTS_SECTION, "@%s", cmdFileName ); args = MergeCmdLine( spawnCmdLine, INVALID_MERGE_CMDLINE ); if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, LINKER, (const char **)args ); } if( cmdOpts->showwopts ) { fprintf( stderr, "del %s\n", cmdFileName ); } if( !cmdOpts->noinvoke ) { remove( cmdFileName ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", LINKER ); } else { return( LINK_ERROR ); } } } DestroyCmdLine( spawnCmdLine ); return( LINK_SUCCESS ); }
/* * Compile any C and C++ files. Returns COMPILE_NOACTION if there was no * file to compile, COMPILE_ERROR if the compiler returned a bad status code * or if the compiler could not be spawned, or else COMPILE_SUCCESS if * everything went smoothly. */ static int compile( const OPT_STORAGE *cmdOpts, CmdLine *compCmdLine ) /********************************************************************/ { CmdLine * cloneCmdLine; char ** args = NULL; char * filename; int fileType; char * compiler = NULL; int rc; int alive = 1; int numCompiled = 0; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; char fullPath[_MAX_PATH]; int count; /*** Process all the source files, in the order they were given ***/ while( alive ) { filename = GetNextFile( &fileType, TYPE_C_FILE, TYPE_CPP_FILE, TYPE_INVALID_FILE ); if( filename == NULL ) break; /*** Prepare to spawn the compiler ***/ cloneCmdLine = CloneCmdLine( compCmdLine ); HandleFileTranslate( filename, cloneCmdLine, NULL ); switch( fileType ) { case TYPE_C_FILE: compiler = C_COMPILER; AppendCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, compiler ); AppendCmdLine( cloneCmdLine, CL_C_FILENAMES_SECTION, filename ); if( !cmdOpts->nowopts ) { AppendCmdLine( cloneCmdLine, CL_C_OPTS_SECTION, "-aa" ); } args = MergeCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, CL_C_MACROS_SECTION, CL_C_OPTS_SECTION, CL_C_FILENAMES_SECTION, INVALID_MERGE_CMDLINE ); break; case TYPE_CPP_FILE: compiler = CPP_COMPILER; AppendCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, compiler ); AppendCmdLine( cloneCmdLine, CL_C_FILENAMES_SECTION, filename ); args = MergeCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, CL_C_MACROS_SECTION, CL_C_OPTS_SECTION, CL_C_CPP_OPTS_SECTION, CL_C_FILENAMES_SECTION, INVALID_MERGE_CMDLINE ); break; default: Zoinks(); } /*** Spawn the compiler ***/ _splitpath( filename, drive, dir, fname, ext ); fprintf( stderr, "%s%s\n", fname, ext ); /* print name of file we're compiling */ if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, compiler, (const char **)args ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", compiler ); } else { return( COMPILE_ERROR ); } } } /*** Add the object file to the linker list, observe -Fo ***/ if( cmdOpts->Fo ) { AddFile( TYPE_OBJ_FILE, PathConvert( cmdOpts->Fo_value->data, '"' ) ); } else { _makepath( fullPath, NULL, NULL, fname, ".obj" ); AddFile( TYPE_OBJ_FILE, fullPath ); } /*** Prepare for the next iteration ***/ DestroyCmdLine( cloneCmdLine ); numCompiled++; } if( numCompiled > 0 ) { return( COMPILE_SUCCESS ); } else { return( COMPILE_NOACTION ); } }