# include "jam.h"
# include "option.h"
# include "make.h"
# ifdef FATFS
# include "patchlev.h"
# else
# include "patchlevel.h"
# endif
# include "lists.h"
# include "parse.h"
# include "variable.h"
# include "compile.h"
# include "rules.h"
# include "newstr.h"
# include "scan.h"
# ifdef FATFS
# include "timestam.h"
# else
# include "timestamp.h"
# endif
# ifdef macintosh
# include <QuickDraw.h>
# else
# include <stdarg.h>
# endif
struct globs globs = {
0,
1,
0,
#ifdef APPLE_EXTENSIONS
0,
0,
NULL,
#endif
# ifdef macintosh
{ 0, 0 }
# else
{ 0, 1 }
# endif
} ;
#ifdef APPLE_EXTENSIONS
int pbx_printf( const char * category_tag, const char * format, ... )
{
va_list args;
int result = 0;
va_start(args, format);
if (category_tag != NULL)
printf("[%s]", category_tag);
result = vprintf(format, args);
va_end(args);
return result;
}
#endif
static char *othersyms[] = { OSSYMS OSPLATSYM, JAMVERSYM, 0 } ;
# ifndef __WATCOM__
# ifndef __OS2__
# ifndef NT
extern char **environ;
# endif
# endif
# endif
# ifdef macintosh
char** demakeifyArguments( int argc, char **argv )
# else
char** demakeifyArguments( argc, argv )
char **argv;
# endif
{
char** newArgvBuffer = (char**)calloc(sizeof(char*), argc);
int i;
int lastOption = 0;
int j;
for (i=0; i<argc; i++)
{
#ifdef DEBUG_JAM_INPUT_ARGUMENTS
printf("argv[%2u]='%s'\n", i, argv[i]);
#endif
newArgvBuffer[i] = NULL;
}
for (i=0; i<argc; i++) {
if (argv[i][0] == '-')
lastOption = i+1;
else if (strchr (argv[i], '=')) {
char* old = argv[i];
char* new = malloc(strlen(old)+3);
sprintf(new, "-s%s", old);
for (j=i; j>lastOption; j--)
argv[j] = argv[j-1];
newArgvBuffer[lastOption] = old;
argv[lastOption++] = new;
}
}
return newArgvBuffer;
}
# ifdef macintosh
void remakeifyArguments( int argc, char **argv , char** newArgvBuffer )
# else
void remakeifyArguments( argc, argv, newArgvBuffer )
char **argv;
char **newArgvBuffer;
# endif
{
int i;
for (i=0; i<argc; i++) if (newArgvBuffer[i] != NULL) {
free (argv[i]);
argv[i] = newArgvBuffer[i];
}
free (newArgvBuffer);
}
# ifdef macintosh
int main( int argc, char **argv, char **environ )
# else
int main( argc, argv )
char **argv;
# endif
{
const unsigned realArgc = argc;
char **newArgvBuffer;
int n;
char *s;
struct option optv[N_OPTS];
char *all = "all";
int anyhow = 0;
int status;
# ifdef macintosh
InitGraf(&qd.thePort);
# endif
argc--, argv++;
newArgvBuffer = demakeifyArguments(argc, argv);
if( ( n = getoptions( argc, argv, "d:j:f:s:t:aknv", optv ) ) < 0 )
{
printf( "\nusage: jam [ options ] targets...\n\n" );
printf( "-a Build all targets, even if they are current.\n" );
printf( "-dx Set the debug level to x (0-9).\n" );
printf( "-fx Read x instead of Jambase.\n" );
printf( "-jx Run up to x shell commands concurrently.\n" );
printf( "-k Ignore build errors.\n" );
printf( "-n Don't actually execute the updating actions.\n" );
printf( "-sx=y Set variable x=y, overriding environment.\n" );
printf( "-tx Rebuild x, even if it is up-to-date.\n" );
printf( "-v Print the version of jam and exit.\n\n" );
exit( EXITBAD );
}
argc -= n, argv += n;
if( ( s = getoptval( optv, 'v', 0 ) ) )
{
printf( "Jam/MR " );
printf( "Version %s.%s. ", VERSION, PATCHLEVEL );
printf( "Copyright 1993, 1997 Christopher Seiwald.\n" );
#ifdef APPLE_EXTENSIONS
printf( "with Apple ProjectBuilder Extensions\n" );
#endif
return EXITOK;
}
if( ( s = getoptval( optv, 'n', 0 ) ) )
globs.noexec++, globs.debug[2] = 1;
if( ( s = getoptval( optv, 'k', 0 ) ) )
globs.ignore++;
if( ( s = getoptval( optv, 'a', 0 ) ) )
anyhow++;
if( ( s = getoptval( optv, 'j', 0 ) ) )
globs.jobs = atoi( s );
#ifdef APPLE_EXTENSIONS
if( getenv( "NATIVE_ARCH" ) != NULL ) {
globs.apple_jam_extensions = 1;
}
if( getenv( "ENABLE_APPLE_JAM_OUTPUT_ANNOTATION" ) != NULL ) {
globs.parsable_output = 1;
}
#endif
for( n = 0; (s = getoptval( optv, 'd', n )) != NULL; n++ )
{
int i;
if( !n )
for( i = 0; i < DEBUG_MAX; i++ )
globs.debug[i] = 0;
i = atoi( s );
if( i < 0 || i >= DEBUG_MAX )
{
printf( "Invalid debug level '%s'.\n", s );
continue;
}
if( *s == '+' )
globs.debug[i] = 1;
else while( i )
globs.debug[i--] = 1;
}
{
char *date;
time_t clock;
time( &clock );
date = newstr( ctime( &clock ) );
if( strlen( date ) == 25 )
date[ 24 ] = 0;
var_set( "JAMDATE", list_new( L0, newstr( date ) ), VAR_SET, 1 );
}
var_defines( environ, 0 );
var_defines( othersyms, 1 );
globs.cmdline_defines = (const char **)malloc(sizeof(char *) * (realArgc + 1));
for( n = 0; (s = getoptval( optv, 's', n )) != NULL; n++ )
{
char *symv[2];
symv[0] = s;
symv[1] = 0;
var_defines( symv, 1 );
#ifdef APPLE_EXTENSIONS
globs.cmdline_defines[n] = s;
#endif
}
globs.cmdline_defines[n] = NULL;
compile_builtins();
for( n = 0; (s = getoptval( optv, 'f', n )) != NULL; n++ )
parse_file( s );
if( !n )
parse_file( "+" );
status = yyanyerrors();
for( n = 0; (s = getoptval( optv, 't', n )) != NULL; n++ )
touchtarget( s );
if( !argc )
status |= make( 1, &all, anyhow );
else
status |= make( argc, argv, anyhow );
var_done();
donerules();
donestamps();
donestr();
#ifndef APPLE_EXTENSIONS
remakeifyArguments(argc, argv, newArgvBuffer);
#endif
return status ? EXITBAD : EXITOK;
}