📄 gener.c
字号:
#include "cl.h"
#define MAKEFILE "MAKEFILE."
static FILE *frsp;
static void open_rsp(void) {
frsp = fopen( MAKEFILE, "wt" );
if ( frsp == NULL ) {
fprintf( stderr, "Error open file : '%s'\n", MAKEFILE );
exit(-1);
}
}
static void close_rsp( void ) {
fclose( frsp );
}
static void exec( char *prg, char *arg ) {
int err;
static char *args[3];
args[0] = prg;
args[1] = arg;
args[2] = NULL;
err = spawnvp( P_OVERLAY, prg, args );
if ( err > 0 ) {
fprintf( stderr, "'%s' exit code = %Xh\n", prg, err );
exit(err);
}
else if ( err < 0 ) {
perror( prg );
exit( -1 );
}
}
static void make_cpp(char *data) {
fprintf( frsp, "### %s\n", data );
fprintf( frsp, "%s : %s\n", file2curdir( data, ".OBJ" ), data );
fprintf( frsp, "\t $(CC) $(CC_OPT) %s\n", data );
fprintf( frsp, "\t $(AS) $(AS_OPT)" );
switch ( assembler ) {
case ASSEMBLER_TASM:
case ASSEMBLER_TASMX:
case ASSEMBLER_TASM32:
if ( options & _OPT_LSTFILE )
fprintf( frsp, " /la" );
fprintf( frsp, " %s,", file2curdir( data, ".ASM" ) );
fprintf( frsp, " %s,", file2curdir( data, ".OBJ" ) );
if ( options & _OPT_LSTFILE )
fprintf( frsp, " %s,NUL", file2curdir( data, ".LST" ) );
else
fprintf( frsp, " NUL,NUL", file2curdir( data, ".LST" ) );
break;
case ASSEMBLER_NASM:
if ( options & _OPT_LSTFILE )
fprintf( frsp, " -l %s", file2curdir( data, ".LST" ) );
fprintf( frsp, " %s", file2curdir( data, ".ASM" ) );
break;
case ASSEMBLER_MASM:
if ( options & _OPT_LSTFILE )
fprintf( frsp, " /la" );
fprintf( frsp, " %s,", file2curdir( data, ".ASM" ) );
fprintf( frsp, " %s,", file2curdir( data, ".OBJ" ) );
if ( options & _OPT_LSTFILE )
fprintf( frsp, " %s,NUL", file2curdir( data, ".LST" ) );
else
fprintf( frsp, " NUL,NUL", file2curdir( data, ".LST" ) );
break;
case ASSEMBLER_ML6X:
if ( options & _OPT_LSTFILE )
fprintf( frsp, " /Fl" );
fprintf( frsp, " %s", file2curdir( data, ".ASM" ) );
break;
case ASSEMBLER_LASM:
if ( options & _OPT_LSTFILE )
fprintf( frsp, " /L" );
fprintf( frsp, " %s", file2curdir( data, ".ASM" ) );
break;
case ASSEMBLER_WASM:
if ( options & _OPT_LSTFILE )
fprintf( frsp, " -fe" );
fprintf( frsp, " %s", file2curdir( data, ".ASM" ) );
break;
}
fprintf( frsp, "\n\n" );
}
static void make_asm( char *data, int temp ) {
if ( temp )
return;
fprintf( frsp, "### %s\n", data );
fprintf( frsp, "%s : %s\n", file2curdir( data, ".OBJ" ), data );
fprintf( frsp, "\t $(AS) $(AS_OPT)" );
if ( assembler == ASSEMBLER_NASM ) {
if ( options & _OPT_LSTFILE )
fprintf( frsp, " -l" );
fprintf( frsp, " -o %s", file2curdir( data, ".OBJ" ) );
fprintf( frsp, " %s", file2curdir( data, ".ASM" ) );
}
else {
if ( options & _OPT_LSTFILE )
fprintf( frsp, " /la" );
fprintf( frsp, " %s,", file2curdir( data, ".ASM" ) );
fprintf( frsp, " %s,", file2curdir( data, ".OBJ" ) );
if ( options & _OPT_LSTFILE )
fprintf( frsp, " %s,NUL", file2curdir( data, ".LST" ) );
else
fprintf( frsp, " NUL,NUL", file2curdir( data, ".LST" ) );
}
fprintf( frsp, "\n\n" );
}
static int first = 0;
static void make_path(char *data) { fprintf( frsp, "%c%s", first ? ' ' : ';', data ); first = 0; }
static void make_list(char *data) { fprintf( frsp, "%s \\\n", data ); }
static void compiler_opt( char *opt ) { fprintf( frsp, " %s", opt ); }
static void compiler_def( char *opt ) { fprintf( frsp, " -D%s", opt ); }
static void tasm_def( char *def ) { fprintf( frsp, " /d%s", def ); }
static void masm_def( char *def ) { fprintf( frsp, " /D%s", def ); }
static void nasm_def( char *def ) { fprintf( frsp, " -d%s", def ); }
static void wlink_obj( char *data ) { fprintf( frsp, "\tfile %s \n", data ); }
static void wlink_lib( char *data ) { fprintf( frsp, "\tlibrary %s \n", data ); }
static char *libpath = NULL;
static void linker_libpath( char *data ) { if ( libpath == NULL ) libpath = data; }
static void delete_file( char *data, int temp ) {
if (temp) fprintf( frsp, "\t Del %s\n", data);
}
void make( void ) {
// static char args[ 12 ];
open_rsp();
fprintf( frsp, "#\n# generate MK386\n#\n\n" );
fprintf( frsp, "### INCLUDE paths\n" );
first = 1;
fprintf( frsp, "PATH_INC=" );
iter0( PATH_INC, make_path );
fprintf( frsp, "\n\n" );
fprintf( frsp, "### C compiler\n" );
switch ( compiler ) {
case COMPILER_CC386:
fprintf( frsp, "CC = CC386\n" );
break;
default:
fprintf( stderr, "Use unknow compiler!\n" );
exit(-1);
}
fprintf( frsp, "CC_OPT = /c %ci %ce %cl %cA",
( ( options & _OPT_PPRFILE ) ? '+' : '-' ),
( ( options & _OPT_ERRFILE ) ? '+' : '-' ),
( ( options & _OPT_LSTFILE ) ? '+' : '-' ),
( ( options & _OPT_EXTEND ) ? '-' : '+' ) );
iter0( OPT_CPP, compiler_opt );
if ( assembler == ASSEMBLER_NASM )
fprintf( frsp, " -C+N");
else if (assembler == ASSEMBLER_MASM ||
assembler == ASSEMBLER_ML6X ||
assembler == ASSEMBLER_WASM ||
assembler == ASSEMBLER_LASM )
fprintf( frsp, " -C+M");
else
fprintf( frsp, " -C-N");
iter0( DEFINED, compiler_def );
fprintf( frsp, " \"-I$(PATH_INC)\"\n\n" );
fprintf( frsp, "### Assembler\n" );
switch ( assembler ) {
case ASSEMBLER_TASM:
fprintf( frsp, "AS = TASM\n" );
fprintf( frsp, "AS_OPT = /t /ml /m9 /z%c /i$(PATH_INC)",
( ( options & _OPT_DEBUG ) ? 'i' : 'n' ) );
iter0( DEFINED, tasm_def );
break;
case ASSEMBLER_TASMX:
fprintf( frsp, "AS = TASMX\n" );
fprintf( frsp, "AS_OPT = /t /ml /m9 /z%c /i$(PATH_INC)",
( ( options & _OPT_DEBUG ) ? 'i' : 'n' ) );
iter0( DEFINED, tasm_def );
break;
case ASSEMBLER_TASM32:
fprintf( frsp, "AS = TASM32\n" );
fprintf( frsp, "AS_OPT = /t /ml /m9 /z%c /i$(PATH_INC)",
( ( options & _OPT_DEBUG ) ? 'i' : 'n' ) );
iter0( DEFINED, tasm_def );
break;
case ASSEMBLER_MASM:
fprintf( frsp, "AS = MASM\n" );
fprintf( frsp, "AS_OPT = /t /Ml %s /I$(PATH_INC)",
( ( options & _OPT_DEBUG ) ? "/Zi" : "" ) );
iter0( DEFINED, masm_def );
break;
case ASSEMBLER_NASM:
fprintf( frsp, "AS = NASM\n" );
fprintf( frsp, "AS_OPT = -f obj \"-i$(PATH_INC)\"" );
iter0( DEFINED, nasm_def );
break;
case ASSEMBLER_ML6X:
fprintf( frsp, "AS = ML\n" );
fprintf( frsp, "AS_OPT = /nologo /c /Cp %s /I$(PATH_INC)",
( ( options & _OPT_DEBUG ) ? "/Zi /Zd" : "" ) );
iter0( DEFINED, masm_def );
break;
case ASSEMBLER_LASM:
fprintf( frsp, "AS = LASM\n" );
fprintf( frsp, "AS_OPT = /G1 /O /S /U /Y %s /I$(PATH_INC)",
( ( options & _OPT_DEBUG ) ? "/ZH" : "" ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -