From: Alexandre Oliva Date: Sun, 3 Mar 2002 17:00:28 +0000 (+0000) Subject: fix up the mode naming and mode-specific usage X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa674b44ff2bdd4a3b7ff1e52a993a802dc1d6ab;p=thirdparty%2Flibtool.git fix up the mode naming and mode-specific usage --- diff --git a/exe/ltcompile.c b/exe/ltcompile.c index 9434d9ec0..78710b81a 100644 --- a/exe/ltcompile.c +++ b/exe/ltcompile.c @@ -42,157 +42,22 @@ static int oldLibs = 0; static char* pzPicMode = "default"; static int xCompile = 0; -static void* -xmalloc( size_t s ) -{ - void* p = malloc( s ); - if (p == NULL) { - fprintf( stderr, "%s error: cannot allocate %d bytes\n", - libtoolOptions.pzProgPath ); - exit( EXIT_FAILURE ); - } - return p; -} - -tCC* -makeShellSafe( pzArg ) - tCC* pzArg; -{ - tSCC zSpecial[] = "\\\"$`[~#^&*(){}|;<>?' \t|]"; - tSCC* pzProt = zSpecial + 4; - - size_t len = strlen( pzArg ); - char* pz; - - if (strcspn( pzArg, zSpecial ) == len) - return pzArg; - - pz = strchr( pzArg, '\'' ); - if (pz == NULL) - return pzArg; - - do { - len += 3; - pz = strchr( pz+1, '\'' ); - } while (pz != NULL); - - { - char* pzRes = malloc( len + 1 ); - pz = pzRes; - for (;;) { - char ch = *(pzArg++); - *(pz++) = ch; +/* BEGIN-STATIC-FORWARD */ +LOCAL tCC* +makeShellSafe LT_PARAMS(( + tCC* pzArg )); - switch (ch) { - case '\0': - goto scan_done; - - case '\'': - do { - strcpy( pz, "\\'" ); - pz += 2; - } while (*pzArg == '\''); - *(pz++) = '\''; - break; +LOCAL void +parseCompileOpts LT_PARAMS(( + int* pArgc, + char*** pArgv )); - default: - break; - } - } scan_done:; - - return pzRes; - } -} - - -static void -parseCompileOpts( pArgc, pArgv ) - int* pArgc; - char*** pArgv; -{ - tSCC zTooManyTargets[] = - "%s compile: you cannot specify `-o' more than once\n"; - tSCC zNoTarget[] = - "%s compile: `-o' must specify an output file name\n"; - tSCC zNoXcompile[] = - "%s compile: `-Xcompiler' must specify a cross compiler\n"; - tSCC zEarlyOpts[] = - "%s compile: error: you cannot supply options before the command\n"; - - int argc = *pArgc; - char** argv = *pArgv; +/* END-STATIC-FORWARD */ - tCC** newArgv = xmalloc( sizeof( char* ) * (argc + 1) ); - int newCt = 0; - - tCC* pzCmd = NULL; - int i; - - for (i=0; i?' \t|]"; + tSCC* pzProt = zSpecial + 4; + + size_t len = strlen( pzArg ); + char* pz; + + if (strcspn( pzArg, zSpecial ) == len) + return pzArg; + + pz = strchr( pzArg, '\'' ); + if (pz == NULL) + return pzArg; + + do { + len += 3; + pz = strchr( pz+1, '\'' ); + } while (pz != NULL); + + { + char* pzRes = malloc( len + 1 ); + pz = pzRes; + for (;;) { + char ch = *(pzArg++); + *(pz++) = ch; + + switch (ch) { + case '\0': + goto scan_done; + + case '\'': + do { + strcpy( pz, "\\'" ); + pz += 2; + } while (*pzArg == '\''); + *(pz++) = '\''; + break; + + default: + break; + } + } scan_done:; + + return pzRes; + } +} + + +LOCAL void +parseCompileOpts( pArgc, pArgv ) + int* pArgc; + char*** pArgv; /*end-decl*/ +{ + tSCC zTooManyTargets[] = + "%s compile: you cannot specify `-o' more than once\n"; + tSCC zNoTarget[] = + "%s compile: `-o' must specify an output file name\n"; + tSCC zNoXcompile[] = + "%s compile: `-Xcompiler' must specify a cross compiler\n"; + tSCC zEarlyOpts[] = + "%s compile: error: you cannot supply options before the command\n"; + + int argc = *pArgc; + char** argv = *pArgv; + + tCC** newArgv = xmalloc( sizeof( char* ) * (argc + 1) ); + int newCt = 0; + + tCC* pzCmd = NULL; + int i; + + for (i=0; ipzProgName, - pOpts->pOptDesc[ OPT_VALUE_MODE ].pz_Name ); - pOpts->pzProgName = z; - pOpts->pzExplain = apz_mode_explain[ OPT_VALUE_MODE ]; - } - optionUsage( pOpts, exitCode ); -} - - - void +LOCAL void validateMode( argct, argvec ) int argct; - char** argvec; + char** argvec; /*end-decl*/ { char* pzCmd = *argvec; char* pzEnd = pzCmd + strlen( pzCmd ); @@ -191,10 +284,10 @@ validateMode( argct, argvec ) } - void +EXPORT void emitShellQuoted( pzArg, outFp ) tCC* pzArg; - FILE* outFp; + FILE* outFp; /*end-decl*/ { for (;;) { char ch = *(pzArg++); @@ -217,10 +310,10 @@ emitShellQuoted( pzArg, outFp ) } - void +EXPORT void emitShellArg( pzArg, outFp ) tCC* pzArg; - FILE* outFp; + FILE* outFp; /*end-decl*/ { tSCC zMetas[] = "<>{}()[]|&^#~*;?$`'\"\\ \t\v\f\r\n"; @@ -240,10 +333,10 @@ emitShellArg( pzArg, outFp ) } - void +EXPORT void emitScript( argc, argv ) - int argc; - char** argv; + int argc; + char** argv; /*end-decl*/ { tSCC zDbgFmt[] = "set -x\n"; tSCC zQuiet[] = "run=\nshow=%s\n"; @@ -330,7 +423,7 @@ else echo='%s --echo --' ; fi\n"; * that one of the command scripts depends upon. */ fprintf( fp, zModeName, libtoolOptions.pzProgName, - libtoolOptions.pOptDesc[ OPT_VALUE_MODE ].pz_Name ); + apzModeName[ OPT_VALUE_MODE ]); CKSERV; fprintf( fp, zMode, libtoolOptions.pzProgName ); CKSERV; @@ -354,8 +447,10 @@ else echo='%s --echo --' ; fi\n"; } -void -emitCommands( FILE* fp, tCC* pzCmds ) +EXPORT void +emitCommands( fp, pzCmds ) + FILE* fp; + tCC* pzCmds; /*end-decl*/ { fputc( '\n', fp ); fflush( fp ); @@ -374,109 +469,6 @@ emitCommands( FILE* fp, tCC* pzCmds ) if (fp != stdout) closeScript( fp ); } - - - int -main( argc, argv ) - int argc; - char** argv; -{ - pzHost = getenv( "host" ); - if (pzHost == (char*)NULL) - pzHost = zUnkn; - - /* - * Process the options, removing them from the arg list. - * Make sure the resulting state is sane. - */ - { - int ct = optionProcess( &libtoolOptions, argc, argv ); - argc -= ct; - argv += ct; - if (! HAVE_OPT( MODE )) - validateMode( argc, argv ); - } - - switch (OPT_VALUE_MODE) { - case MODE_EXECUTE: - case MODE_CLEAN: - case MODE_FINISH: - case MODE_INSTALL: - case MODE_UNINSTALL: - /* - * Options prohibited for all states except link & compile - */ - if (HAVE_OPT( OUTPUT_FILE )) { - fprintf( stderr, zBadOpt, libtoolOptions.pzProgName, "output-file" ); - USAGE( EXIT_FAILURE ); - /* NOTREACHED */ - } - if (HAVE_OPT( STATIC )) { - fprintf( stderr, zBadOpt, libtoolOptions.pzProgName, "static" ); - USAGE( EXIT_FAILURE ); - /* NOTREACHED */ - } - if (HAVE_OPT( DYNAMIC )) { - fprintf( stderr, zBadOpt, libtoolOptions.pzProgName, "dynamic" ); - USAGE( EXIT_FAILURE ); - /* NOTREACHED */ - } - - /* - * dlopen is allowed for execute, but nothing else. So, for - * other modes, fall through and check for DLOPEN. - */ - if (OPT_VALUE_MODE == MODE_EXECUTE) - break; - /* FALLTHROUGH */ - - case MODE_LINK: - case MODE_COMPILE: - if (HAVE_OPT( DLOPEN )) { - fprintf( stderr, zBadOpt, libtoolOptions.pzProgName, "dlopen" ); - USAGE( EXIT_FAILURE ); - /* NOTREACHED */ - } - break; - - case MODE_ECHO: - /* - * We ignore all conflicts for echo mode - */ - for (;;) { - fputs( *(argv++), stdout ); - if (--argc <= 0) - break; - fputc( ' ', stdout ); - } - - fputc( '\n', stdout ); - return EXIT_SUCCESS; - - default: - fprintf( stderr, zBadMode, libtoolOptions.pzProgName ); - USAGE( EXIT_FAILURE ); - /* NOTREACHED */ - } - - pz_cmd_name = argv[0]; - signal( SIGPIPE, handleSignal ); - signal( SIGBUS, handleSignal ); - signal( SIGSEGV, handleSignal ); - - assert( OPT_VALUE_MODE < MODE_CT ); - { - emitScriptProc* pEP = ap_emitProc[ OPT_VALUE_MODE ]; - if (pEP == NULL) { - fprintf( stderr, "We're in the wrong mode: %d\n", - OPT_VALUE_MODE ); - USAGE( EXIT_FAILURE ); - } - (*pEP)( argc, argv ); - } - - return scriptStatus; -} /* * Local Variables: * c-file-style: "stroustrup" diff --git a/exe/ltmain.mk b/exe/ltmain.mk index cd56ecce9..8c03108d7 100644 --- a/exe/ltmain.mk +++ b/exe/ltmain.mk @@ -39,3 +39,16 @@ gen : ltmain.in ltstr.c ltopts.c libtool : ltmain ./ltmain --mode=link $(CC) -o $@ $(OBJ) -lopts + +fwd: + for f in `egrep -l '^LOCAL ' *.c` ; do \ + ( sed '/BEGIN-STATIC-FORWARD/q' $$f ; \ + sed -n '1,/END-STATIC-FORWARD/d;/^LOCAL /,/^{/p' $$f | \ + sed 's/^\([a-zA-Z0-9_]*\)(.*/\1 LT_PARAMS((/;\ + s/;/,/;\ + s=,[ \t]*/\*end-decl.*= ));=;\ + s/^{//' ;\ + echo '/* END-STATIC-FORWARD */';\ + sed '1,/END-STATIC-FORWARD/d' $$f ) > XXX ; \ + if cmp XXX $$f > /dev/null ; then rm -f XXX ; else mv -f XXX $$f ; fi ; \ + done diff --git a/exe/ltopts.def b/exe/ltopts.def index 046ec7ab7..9079a6953 100644 --- a/exe/ltopts.def +++ b/exe/ltopts.def @@ -30,7 +30,9 @@ one of the following values: \tlink create a library or an executable \trelink (synonym for `link') \tuninstall remove libraries from an installed directory -\techo the program behaves as a reimplementation of echo"; +\techo the program behaves as a reimplementation of echo + +Use --mode=xxx before the --help option to get more help on one of the modes."; include = @@ -56,6 +58,8 @@ flag = { arg_type = keyword; arg_name = mode; settable; + immediate; /* must be able to take effect before ``--help'' */ + no-preset; descrip = "ltmain's operational mode"; /* @@ -72,7 +76,9 @@ flag = { doc = "This enumerates all of the libtool operational modes.\n" "If this option is not specified, then this program tries to infer\n" - "it from the command name or the name of the file being operated on."; + "it from the command name or the name of the file being operated on.\n" + "If this option is set before the ``--help'' option on the command line,\n" + "then explanitory text for that mode will be included in the usage text."; }; flag = { diff --git a/exe/ltstr.tpl b/exe/ltstr.tpl index 87e0609ed..226f594ad 100644 --- a/exe/ltstr.tpl +++ b/exe/ltstr.tpl @@ -116,7 +116,7 @@ ENDIF c/h suffix =] [=IF (== (suffix) "h")=]extern [= - ENDIF=]tCC* apz_mode_explain[ MODE_CT ][= + ENDIF=]tCC* apzModeExplain[ MODE_CT ][= IF (== (suffix) "c") =] = {[= FOR string , =] @@ -132,7 +132,7 @@ IF (== (suffix) "c") =] = {[= ENDIF =]; [=IF (== (suffix) "h")=]extern [= - ENDIF=]tCC* apz_mode_cmd[ MODE_CT ][= + ENDIF=]tCC* apz_mode_cmd[ MODE_CT ][= IF (== (suffix) "c") =] = { [=(shellf "columns -I4 -S, <<_EOF_\n%s_EOF_" cmd-list) =] }[= @@ -145,18 +145,43 @@ IF (== (suffix) "c") =] = {[= FOR string , =] [=?% call-proc "%s" emitScript=][= ENDFOR =] -};[= +}[= + +ENDIF =]; + +[=IF (== (suffix) "h")=]extern [= + ENDIF=]tCC* apzModeName[ MODE_CT+1 ][= +IF (== (suffix) "c") =] = { NULL[= + + FOR string =], + "[=str-name=]"[= + ENDFOR =] +}[= + +ENDIF =];[= -ELSE =]; +IF (== (suffix) "h") =] + +#define EXPORT +#ifdef DEBUG +# define LOCAL +#else +# define LOCAL static +#endif extern int signalReceived; extern int scriptStatus; - -extern void closeScript LT_PARAMS(( FILE* fp )); -extern void modalUsage LT_PARAMS(( tOptions* pOpts, int exitCode )); -extern void emitShellQuoted LT_PARAMS(( tCC* pzArg, FILE* outFp )); -extern void emitShellArg LT_PARAMS(( tCC* pzArg, FILE* outFp )); -extern void emitCommands LT_PARAMS(( FILE* fp, tCC* pzCmds )); +[=` +for f in \`egrep -l '^EXPORT ' *.c\` +do + sed -n '/^EXPORT /,/^{/p' $f +done | \ +sed ' + s/EXPORT /extern / + s/^\\([a-zA-Z0-9_]*\\)(.*/\\1 LT_PARAMS((/ + s/;/,/ + s=,[ \t]*/\\*end-decl.*= ));= + s/^{//' `=] #endif /* [=(. header-guard)=] */[= diff --git a/exe/ltversion.c b/exe/ltversion.c index fe39129e3..5e339d036 100644 --- a/exe/ltversion.c +++ b/exe/ltversion.c @@ -52,7 +52,7 @@ #include #include -#include "options.h" +#include "ltstr.h" #include "ltopts.h" tSCC zAO[] = @@ -64,11 +64,13 @@ tSCC zBadArg[] = \t'c' - version and copyright\n\ \t'n' - version and copyright notice\n"; +/* BEGIN-STATIC-FORWARD */ +/* END-STATIC-FORWARD */ - void +EXPORT void doVersion( pOpts, pOD ) tOptions* pOpts; - tOptDesc* pOD; + tOptDesc* pOD; /*end-decl*/ { char swCh; @@ -117,8 +119,29 @@ doVersion( pOpts, pOD ) exit( EXIT_SUCCESS ); } + + +EXPORT void +modalUsage( pOpts, exitCode ) + tOptions* pOpts; + int exitCode; /*end-decl*/ +{ + char z[ 256 ]; + + if (OPT_VALUE_MODE != MODE_UNDEFINED) { + tSCC zFmt[] = "%s --mode=%s"; + + sprintf( z, zFmt, pOpts->pzProgName, apzModeName[ OPT_VALUE_MODE ]); + pOpts->pzProgName = z; + pOpts->pzExplain = apzModeExplain[ OPT_VALUE_MODE ]; + } + + optionUsage( pOpts, exitCode ); +} /* * Local Variables: * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * tab-width: 4 * End: * version.c ends here */