diff options
Diffstat (limited to 'jam-files/engine/jam.c')
-rw-r--r-- | jam-files/engine/jam.c | 310 |
1 files changed, 152 insertions, 158 deletions
diff --git a/jam-files/engine/jam.c b/jam-files/engine/jam.c index 09faf8522..1c80eec50 100644 --- a/jam-files/engine/jam.c +++ b/jam-files/engine/jam.c @@ -5,17 +5,18 @@ * * This file is part of jam. * - * License is hereby granted to use this software and distribute it - * freely, as long as this copyright notice is retained and modifications - * are clearly marked. + * License is hereby granted to use this software and distribute it freely, as + * long as this copyright notice is retained and modifications are clearly + * marked. * * ALL WARRANTIES ARE HEREBY DISCLAIMED. */ -/* This file is ALSO: - * Copyright 2001-2004 David Abrahams. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) +/* This file is ALSO: + * Copyright 2001-2004 David Abrahams. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ /* @@ -50,8 +51,8 @@ * filesys * * - * The support routines are called by all of the above, but themselves - * are layered thus: + * The support routines are called by all of the above, but themselves are + * layered thus: * * variable|expand * / | | @@ -72,8 +73,8 @@ * builtins.c - jam's built-in rules * command.c - maintain lists of commands * compile.c - compile parsed jam statements - * execunix.c - execute a shell script on UNIX - * file*.c - scan directories and archives on * + * exec*.c - execute a shell script on a specific OS + * file*.c - scan directories and archives on a specific OS * hash.c - simple in-memory hashing routines * hdrmacro.c - handle header file parsing for filename macro definitions * headers.c - handle #includes in source files @@ -85,7 +86,7 @@ * object.c - string manipulation routines * option.c - command line option processing * parse.c - make and destroy parse trees as driven by the parser - * path*.c - manipulate file names on * + * path*.c - manipulate file names on a specific OS * hash.c - simple in-memory hashing routines * regexp.c - Henry Spencer's regexp * rules.c - access to RULEs, TARGETs, and ACTIONs @@ -93,50 +94,42 @@ * search.c - find a target along $(SEARCH) or $(LOCATE) * timestamp.c - get the timestamp of a file or archive member * variable.c - handle jam multi-element variables - * - * 05/04/94 (seiwald) - async multiprocess (-j) support - * 02/08/95 (seiwald) - -n implies -d2. - * 02/22/95 (seiwald) - -v for version info. - * 09/11/00 (seiwald) - PATCHLEVEL folded into VERSION. - * 01/10/01 (seiwald) - pathsys.h split from filesys.h */ #include "jam.h" -#include "option.h" #include "patchlevel.h" -/* These get various function declarations. */ -#include "lists.h" -#include "parse.h" -#include "variable.h" -#include "compile.h" #include "builtins.h" -#include "rules.h" -#include "object.h" -#include "scan.h" -#include "timestamp.h" -#include "make.h" -#include "strings.h" -#include "filesys.h" -#include "output.h" -#include "search.h" #include "class.h" -#include "execcmd.h" +#include "compile.h" #include "constants.h" +#include "filesys.h" #include "function.h" -#include "pwd.h" #include "hcache.h" +#include "lists.h" +#include "make.h" +#include "object.h" +#include "option.h" +#include "output.h" +#include "parse.h" +#include "cwd.h" +#include "rules.h" +#include "scan.h" +#include "search.h" +#include "strings.h" +#include "timestamp.h" +#include "variable.h" /* Macintosh is "special" */ #ifdef OS_MAC - #include <QuickDraw.h> +# include <QuickDraw.h> #endif /* And UNIX for this. */ #ifdef unix - #include <sys/utsname.h> - #include <signal.h> +# include <sys/utsname.h> +# include <signal.h> #endif struct globs globs = @@ -152,7 +145,8 @@ struct globs globs = { 0, 1 }, /* debug ... */ #endif 0, /* output commands, not run them */ - 0 /* action timeout */ + 0, /* action timeout */ + 0 /* maximum buffer size zero is all output */ }; /* Symbols to be defined as true for use in Jambase. */ @@ -165,27 +159,27 @@ static char * othersyms[] = { OSMAJOR, OSMINOR, OSPLAT, JAMVERSYM, 0 }; */ #ifdef OS_MAC - #define use_environ arg_environ - #ifdef MPW - QDGlobals qd; - #endif +# define use_environ arg_environ +# ifdef MPW + QDGlobals qd; +# endif #endif /* on Win32-LCC */ #if defined( OS_NT ) && defined( __LCC__ ) - #define use_environ _environ +# define use_environ _environ #endif -# if defined( __MWERKS__) - #define use_environ _environ +#if defined( __MWERKS__) +# define use_environ _environ extern char * * _environ; #endif #ifndef use_environ - #define use_environ environ - #if !defined( __WATCOM__ ) && !defined( OS_OS2 ) && !defined( OS_NT ) - extern char **environ; - #endif +# define use_environ environ +# if !defined( __WATCOM__ ) && !defined( OS_OS2 ) && !defined( OS_NT ) + extern char **environ; +# endif #endif #if YYDEBUG != 0 @@ -195,10 +189,10 @@ static char * othersyms[] = { OSMAJOR, OSMINOR, OSPLAT, JAMVERSYM, 0 }; #ifndef NDEBUG static void run_unit_tests() { -#if defined( USE_EXECNT ) +# if defined( USE_EXECNT ) extern void execnt_unit_test(); execnt_unit_test(); -#endif +# endif string_unit_test(); } #endif @@ -216,32 +210,32 @@ int anyhow = 0; void regex_done(); -const char *saved_argv0; +char const * saved_argv0; int main( int argc, char * * argv, char * * arg_environ ) { int n; char * s; - struct bjam_option optv[N_OPTS]; + struct bjam_option optv[ N_OPTS ]; char const * all = "all"; int status; int arg_c = argc; char * * arg_v = argv; - char const * progname = argv[0]; + char const * progname = argv[ 0 ]; module_t * environ_module; - saved_argv0 = argv[0]; + saved_argv0 = argv[ 0 ]; BJAM_MEM_INIT(); -# ifdef OS_MAC - InitGraf(&qd.thePort); -# endif +#ifdef OS_MAC + InitGraf( &qd.thePort ); +#endif --argc; ++argv; - if ( getoptions( argc, argv, "-:l:d:j:p:f:gs:t:ano:qv", optv ) < 0 ) + if ( getoptions( argc, argv, "-:l:m:d:j:p:f:gs:t:ano:qv", optv ) < 0 ) { printf( "\nusage: %s [ options ] targets...\n\n", progname ); @@ -251,6 +245,7 @@ int main( int argc, char * * argv, char * * arg_environ ) /* printf( "-g Build from newest sources first.\n" ); */ printf( "-jx Run up to x shell commands concurrently.\n" ); printf( "-lx Limit actions to x number of seconds after which they are stopped.\n" ); + printf( "-mx Maximum target output saved (kb), default is to save all output.\n" ); printf( "-n Don't actually execute the updating actions.\n" ); printf( "-ox Write the updating actions to file x.\n" ); printf( "-px x=0, pipes action stdout and stderr merged into action output.\n" ); @@ -266,20 +261,22 @@ int main( int argc, char * * argv, char * * arg_environ ) /* Version info. */ if ( ( s = getoptval( optv, 'v', 0 ) ) ) { - printf( "Boost.Jam " ); - printf( "Version %s. %s.\n", VERSION, OSMINOR ); - printf( " Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. \n" ); + printf( "Boost.Jam Version %s. %s.\n", VERSION, OSMINOR ); + printf( " Copyright 1993-2002 Christopher Seiwald and Perforce " + "Software, Inc.\n" ); printf( " Copyright 2001 David Turner.\n" ); printf( " Copyright 2001-2004 David Abrahams.\n" ); printf( " Copyright 2002-2008 Rene Rivera.\n" ); printf( " Copyright 2003-2008 Vladimir Prus.\n" ); - return EXITOK; } /* Pick up interesting options. */ if ( ( s = getoptval( optv, 'n', 0 ) ) ) - globs.noexec++, globs.debug[2] = 1; + { + ++globs.noexec; + globs.debug[ 2 ] = 1; + } if ( ( s = getoptval( optv, 'p', 0 ) ) ) { @@ -287,11 +284,10 @@ int main( int argc, char * * argv, char * * arg_environ ) * stdout and stderr. */ globs.pipe_action = atoi( s ); - if ( ( 3 < globs.pipe_action ) || ( globs.pipe_action < 0 ) ) + if ( globs.pipe_action < 0 || 3 < globs.pipe_action ) { - printf( - "Invalid pipe descriptor '%d', valid values are -p[0..3].\n", - globs.pipe_action ); + printf( "Invalid pipe descriptor '%d', valid values are -p[0..3]." + "\n", globs.pipe_action ); exit( EXITBAD ); } } @@ -305,10 +301,11 @@ int main( int argc, char * * argv, char * * arg_environ ) if ( ( s = getoptval( optv, 'j', 0 ) ) ) { globs.jobs = atoi( s ); - if (globs.jobs == 0) + if ( globs.jobs < 1 || globs.jobs > MAXJOBS ) { - printf("Invalid value for the '-j' option.\n"); - exit(EXITBAD); + printf( "Invalid value for the '-j' option, valid values are 1 " + "through %d.\n", MAXJOBS ); + exit( EXITBAD ); } } @@ -318,6 +315,9 @@ int main( int argc, char * * argv, char * * arg_environ ) if ( ( s = getoptval( optv, 'l', 0 ) ) ) globs.timeout = atoi( s ); + if ( ( s = getoptval( optv, 'm', 0 ) ) ) + globs.max_buf = atoi( s ) * 1024; /* convert to kb */ + /* Turn on/off debugging */ for ( n = 0; ( s = getoptval( optv, 'd', n ) ); ++n ) { @@ -339,12 +339,13 @@ int main( int argc, char * * argv, char * * arg_environ ) /* n turns on levels 1-n. */ /* +n turns on level n. */ if ( *s == '+' ) - globs.debug[i] = 1; + globs.debug[ i ] = 1; else while ( i ) - globs.debug[i--] = 1; + globs.debug[ i-- ] = 1; } constants_init(); + cwd_init(); { PROFILE_ENTER( MAIN ); @@ -385,7 +386,12 @@ int main( int argc, char * * argv, char * * arg_environ ) #endif /* Set JAMDATE. */ - var_set( root_module(), constant_JAMDATE, list_new( outf_time(time(0)) ), VAR_SET ); + { + timestamp current; + timestamp_current( ¤t ); + var_set( root_module(), constant_JAMDATE, list_new( outf_time( + ¤t ) ), VAR_SET ); + } /* Set JAM_VERSION. */ var_set( root_module(), constant_JAM_VERSION, @@ -415,7 +421,15 @@ int main( int argc, char * * argv, char * * arg_environ ) object_new( u.machine ) ), VAR_SET ); } } -#endif /* unix */ +#endif /* unix */ + + /* Set JAM_TIMESTAMP_RESOLUTION. */ + { + timestamp fmt_resolution[ 1 ]; + file_supported_fmt_resolution( fmt_resolution ); + var_set( root_module(), constant_JAM_TIMESTAMP_RESOLUTION, list_new( + object_new( timestamp_timestr( fmt_resolution ) ) ), VAR_SET ); + } /* Load up environment variables. */ @@ -438,7 +452,7 @@ int main( int argc, char * * argv, char * * arg_environ ) /* Load up variables set on command line. */ for ( n = 0; ( s = getoptval( optv, 's', n ) ); ++n ) { - char *symv[2]; + char * symv[ 2 ]; symv[ 0 ] = s; symv[ 1 ] = 0; var_defines( root_module(), symv, 1 ); @@ -448,9 +462,8 @@ int main( int argc, char * * argv, char * * arg_environ ) /* Set the ARGV to reflect the complete list of arguments of invocation. */ for ( n = 0; n < arg_c; ++n ) - { - var_set( root_module(), constant_ARGV, list_new( object_new( arg_v[n] ) ), VAR_APPEND ); - } + var_set( root_module(), constant_ARGV, list_new( object_new( + arg_v[ n ] ) ), VAR_APPEND ); /* Initialize built-in rules. */ load_builtins(); @@ -466,16 +479,14 @@ int main( int argc, char * * argv, char * * arg_environ ) } else { - OBJECT * target = object_new( arg_v[ n ] ); + OBJECT * const target = object_new( arg_v[ n ] ); mark_target_for_updating( target ); object_free( target ); } } if ( list_empty( targets_to_update() ) ) - { mark_target_for_updating( constant_all ); - } /* Parse ruleset. */ { @@ -483,15 +494,13 @@ int main( int argc, char * * argv, char * * arg_environ ) frame_init( frame ); for ( n = 0; ( s = getoptval( optv, 'f', n ) ); ++n ) { - OBJECT * filename = object_new( s ); + OBJECT * const filename = object_new( s ); parse_file( filename, frame ); object_free( filename ); } if ( !n ) - { parse_file( constant_plus, frame ); - } } status = yyanyerrors(); @@ -499,7 +508,7 @@ int main( int argc, char * * argv, char * * arg_environ ) /* Manually touch -t targets. */ for ( n = 0; ( s = getoptval( optv, 't', n ) ); ++n ) { - OBJECT * target = object_new( s ); + OBJECT * const target = object_new( s ); touch_target( target ); object_free( target ); } @@ -516,52 +525,37 @@ int main( int argc, char * * argv, char * * arg_environ ) } /* The build system may set the PARALLELISM variable to override -j - options. */ + * options. + */ { - LIST *p = L0; - p = var_get ( root_module(), constant_PARALLELISM ); + LIST * const p = var_get( root_module(), constant_PARALLELISM ); if ( !list_empty( p ) ) { - int j = atoi( object_str( list_front( p ) ) ); - if ( j == -1 ) - { - printf( "Invalid value of PARALLELISM: %s\n", object_str( list_front( p ) ) ); - } + int const j = atoi( object_str( list_front( p ) ) ); + if ( j < 1 || j > MAXJOBS ) + printf( "Invalid value of PARALLELISM: %s. Valid values " + "are 1 through %d.\n", object_str( list_front( p ) ), + MAXJOBS ); else - { globs.jobs = j; - } } } /* KEEP_GOING overrides -q option. */ { - LIST *p = L0; - p = var_get( root_module(), constant_KEEP_GOING ); + LIST * const p = var_get( root_module(), constant_KEEP_GOING ); if ( !list_empty( p ) ) - { - int v = atoi( object_str( list_front( p ) ) ); - if ( v == 0 ) - globs.quitquick = 1; - else - globs.quitquick = 0; - } + globs.quitquick = atoi( object_str( list_front( p ) ) ) ? 0 : 1; } /* Now make target. */ { PROFILE_ENTER( MAIN_MAKE ); - - LIST * targets = targets_to_update(); + LIST * const targets = targets_to_update(); if ( !list_empty( targets ) ) - { status |= make( targets, anyhow ); - } else - { status = last_update_now_status; - } - PROFILE_EXIT( MAIN_MAKE ); } @@ -571,7 +565,7 @@ int main( int argc, char * * argv, char * * arg_environ ) if ( DEBUG_PROFILE ) profile_dump(); - + #ifdef OPT_HEADER_CACHE_EXT hcache_done(); #endif @@ -579,15 +573,15 @@ int main( int argc, char * * argv, char * * arg_environ ) clear_targets_to_update(); /* Widely scattered cleanup. */ + property_set_done(); file_done(); rules_done(); - stamps_done(); + timestamp_done(); search_done(); class_done(); modules_done(); regex_done(); - exec_done(); - pwd_done(); + cwd_done(); path_done(); function_done(); list_done(); @@ -607,56 +601,56 @@ int main( int argc, char * * argv, char * * arg_environ ) return status ? EXITBAD : EXITOK; } + +/* + * executable_path() + */ + #if defined(_WIN32) -#include <windows.h> -char *executable_path(const char *argv0) { - char buf[1024]; - DWORD ret = GetModuleFileName(NULL, buf, sizeof(buf)); - if (ret == 0 || ret == sizeof(buf)) return NULL; - return strdup (buf); +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +char * executable_path( char const * argv0 ) +{ + char buf[ 1024 ]; + DWORD const ret = GetModuleFileName( NULL, buf, sizeof( buf ) ); + return ( !ret || ret == sizeof( buf ) ) ? NULL : strdup( buf ); } #elif defined(__APPLE__) /* Not tested */ -#include <mach-o/dyld.h> -char *executable_path(const char *argv0) { - char buf[1024]; - uint32_t size = sizeof(buf); - int ret = _NSGetExecutablePath(buf, &size); - if (ret != 0) return NULL; - return strdup(buf); +# include <mach-o/dyld.h> +char *executable_path( char const * argv0 ) +{ + char buf[ 1024 ]; + uint32_t size = sizeof( buf ); + return _NSGetExecutablePath( buf, &size ) ? NULL : strdup( buf ); } -#elif defined(sun) || defined(__sun) /* Not tested */ -#include <stdlib.h> - -char *executable_path(const char *argv0) { - return strdup(getexecname()); +#elif defined(sun) || defined(__sun) /* Not tested */ +# include <stdlib.h> +char * executable_path( char const * argv0 ) +{ + return strdup( getexecname() ); } #elif defined(__FreeBSD__) -#include <sys/sysctl.h> -char *executable_path(const char *argv0) { - int mib[4]; - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PATHNAME; - mib[3] = -1; - char buf[1024]; - size_t size = sizeof(buf); - sysctl(mib, 4, buf, &size, NULL, 0); - if (size == 0 || size == sizeof(buf)) return NULL; - return strndup(buf, size); +# include <sys/sysctl.h> +char * executable_path( char const * argv0 ) +{ + int mib[ 4 ] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + char buf[ 1024 ]; + size_t size = sizeof( buf ); + sysctl( mib, 4, buf, &size, NULL, 0 ); + return ( !size || size == sizeof( buf ) ) ? NULL : strndup( buf, size ); } #elif defined(__linux__) -#include <unistd.h> -char *executable_path(const char *argv0) { - char buf[1024]; - ssize_t ret = readlink("/proc/self/exe", buf, sizeof(buf)); - if (ret == 0 || ret == sizeof(buf)) return NULL; - return strndup(buf, ret); +# include <unistd.h> +char * executable_path( char const * argv0 ) +{ + char buf[ 1024 ]; + ssize_t const ret = readlink( "/proc/self/exe", buf, sizeof( buf ) ); + return ( !ret || ret == sizeof( buf ) ) ? NULL : strndup( buf, ret ); } #else -char *executable_path(const char *argv0) { - /* If argv0 is absolute path, assume it's the right absolute path. */ - if (argv0[0] == '/') - return strdup(argv0); - return NULL; +char * executable_path( char const * argv0 ) +{ + /* If argv0 is an absolute path, assume it is the right absolute path. */ + return argv0[ 0 ] == '/' ? strdup( argv0 ) : NULL; } #endif |