* the same distribution terms that you use for the rest of that program.
*/
+#include <sys/types.h>
#include <stdio.h> /* printf */
#include <stdlib.h> /* exit */
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include "ltopts.h"
#include "ltstr.h"
+static char* pzTarget = NULL;
+static char* pzSource = NULL;
+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;
+
+ switch (ch) {
+ case '\0':
+ goto scan_done;
+
+ case '\'':
+ do {
+ strcpy( pz, "\\'" );
+ pz += 2;
+ } while (*pzArg == '\'');
+ *(pz++) = '\'';
+ break;
+
+ 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;
+
+ tCC** newArgv = xmalloc( sizeof( char* ) * (argc + 1) );
+ int newCt = 0;
+
+ tCC* pzCmd = NULL;
+ int i;
+
+ for (i=0; i<argc; i++) {
+ if (strncmp( argv[i], "-o", 2 ) == 0) {
+ if (pzTarget != NULL) {
+ fprintf( stderr, zTooManyTargets, libtoolOptions.pzProgPath );
+ exit( EXIT_FAILURE );
+ }
+ if (argv[i][2] != '\0')
+ pzTarget = (argv[i]) + 2;
+ else {
+ pzTarget = argv[ ++i ];
+ if (pzTarget == NULL) {
+ fprintf( stderr, zNoTarget, libtoolOptions.pzProgPath );
+ exit( EXIT_FAILURE );
+ }
+ }
+
+ } else if (strcmp( argv[i], "-static" ) == 0) {
+ oldLibs = 1;
+
+ } else if (strcmp( argv[i], "-prefer-pic" ) == 0) {
+ pzPicMode = "yes";
+
+ } else if (strcmp( argv[i], "-prefer-non-pic" ) == 0) {
+ pzPicMode = "no";
+
+ } else if (strcmp( argv[i], "-Xcompiler" ) == 0) {
+ if (argv[++i] == NULL) {
+ fprintf( stderr, zNoXcompile, libtoolOptions.pzProgPath );
+ exit( EXIT_FAILURE );
+ }
+ pzCmd = newArgv[ newCt++ ] = makeShellSafe( argv[i] );
+
+ } else if (argv[i][0] == '-') {
+ if (pzCmd == NULL) {
+ fprintf( stderr, zEarlyOpts, libtoolOptions.pzProgPath );
+ exit( EXIT_FAILURE );
+ }
+ newArgv[ newCt++ ] = makeShellSafe( argv[i] );
+
+ } else if (pzCmd == NULL) {
+ pzCmd = newArgv[ newCt++ ] = makeShellSafe( argv[i] );
+
+ } else {
+ if (pzSource != NULL)
+ newArgv[ newCt++ ] = makeShellSafe( pzSource );
+ pzSource = argv[i];
+ }
+ }
+
+ if (pzSource == NULL) {
+ fprintf( stderr, "%s compile: error: no source file to compile\n",
+ libtoolOptions.pzProgName );
+ exit( EXIT_FAILURE );
+ }
+
+ newArgv[ newCt ] = NULL;
+ *pArgc = newCt;
+ *pArgv = (char**)newArgv;
+}
+
void
emitCompile( argc, argv )
# define CLOSEOK if (signalReceived != 0) { closeScript( fp ); return; }
+ parseCompileOpts( &argc, &argv );
+
/*
* Emit the default configuration set up at program configuration time
*/
* IF we have DYNAMIC or STATIC, then we override the configured
* values. We emitted the configured values with `z_ltconfig'.
*/
- if (HAVE_OPT( DYNAMIC ))
+ if (HAVE_OPT( DYNAMIC ) && (oldLibs == 0))
fprintf( fp, zDynFmt, ENABLED_OPT( DYNAMIC ) ? "yes" : "no" );
- if (HAVE_OPT( STATIC ))
- fprintf( fp, zStatic, ENABLED_OPT( STATIC ) ? "yes" : "no" );
+ if (HAVE_OPT( STATIC ) || oldLibs)
+ fprintf( fp, zStatic, ENABLED_OPT( STATIC )
+ ? "yes" : (oldLibs ? "yes" : "no") );
if (HAVE_OPT( DEBUG )) {
fprintf( stderr, "%s: enabling shell trace mode\n",
* that one of the command scripts depends upon.
*/
fprintf( fp, zModeName, libtoolOptions.pzProgName,
- libtoolOptions.pOptDesc[ OPT_VALUE_MODE ].pz_Name );
+ libtoolOptions.pOptDesc[ OPT_VALUE_MODE ].pz_Name );
CKSERV;
fprintf( fp, zMode, libtoolOptions.pzProgName );
CKSERV;
- /*
- * Emit the real command. The original shell script shifts off the
- * command name before it realizes what it has done. We emulate
- * that behavior by setting `nonopt' to the command name and inserting
- * the remaining arguments as arguments via `set -- $@'.
- */
- fprintf( fp, zCmdName, argv[0] );
+ if (pzTarget == NULL) {
+ pzTarget = strrchr( pzSource, '/' );
+ if (pzTarget == NULL)
+ pzTarget = pzSource;
+ else
+ pzTarget++;
+ }
+
+ fprintf( fp, "libobj='%s'\n", makeShellSafe( pzTarget ));
CKSERV;
- while (--argc > 0) {
- fputc( ' ', fp );
- emitShellArg( *(++argv), fp );
+ fprintf( fp, "build_old_libs=%s\n", oldLibs ? "yes" : "no" );
+ CKSERV;
+
+ fprintf( fp, "pic_mode=%s\n", pzPicMode );
+ CKSERV;
+
+ fputs( "base_compile='", fp );
+ for (;;) {
+ fputs( *(argv++), fp );
CKSERV;
+ if (--argc <= 0)
+ break;
+ fputc( ' ', fp );
}
- fputc( '\n', fp );
- fflush( fp );
- CKSERV;
+ {
+ struct stat stbf;
- /*
- * Up to now, we are just initializing variables. Here, we write
- * a large chunk of text to the pipe and the shell may exit before
- * we are done. If that happens, we get a SIGPIPE. The `CLOSEOK'
- * macro will detect that, call closeScript() and return so as to
- * avoid segfaults and more SIGPIPEs.
- */
- fputs( apz_mode_cmd[ OPT_VALUE_MODE ], fp );
- CLOSEOK;
+ if (stat( pzSource, &stbf ) != 0) do {
+ char* pz = getenv( "source" );
+ if ( (pz != NULL)
+ && (stat( pz, &stbf ) == 0)) {
+ pzSource = pz;
+ break;
+ }
+
+ pz = getenv( "srcdir" );
+ if (pz == NULL)
+ pz = getenv( "VPATH" );
- fputc( '\n', fp );
- CLOSEOK;
+ if (pz != NULL) {
+ char* p = xmalloc( strlen( pz ) + strlen( pzSource ) + 2 );
+ sprintf( p, "%s/%s", pz, pzSource );
+ if (stat( p, &stbf ) == 0)
+ pzSource = p;
+ else
+ free( p );
+ }
+ } while (0);
- fflush( fp );
+ fprintf( fp, "'\nsrcfile='%s'\n", pzSource );
+ }
- if (fp != stdout)
- closeScript( fp );
+ emitCommands( fp, apz_mode_cmd[ OPT_VALUE_MODE ]);
}
+/*
+ * Local Variables:
+ * c-file-style: "stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * end of ltcompile.c */
#define LIBTOOL_CONFIG_TEXT 1
static const char z_ltconfig[] = "\n\
-LTCONFIG_VERSION=\"1.4a\"\n\
+SED=sed\n\
SHELL=\"/bin/sh\"\n\
build_libtool_libs=yes\n\
-build_libtool_need_lc=yes\n\
build_old_libs=yes\n\
+build_libtool_need_lc=no\n\
fast_install=yes\n\
-host_alias=i586-pc-linux-gnu\n\
-host=i586-pc-linux-gnu\n\
+host_alias=\n\
+host=i686-pc-linux-gnu\n\
echo=\"echo\"\n\
AR=\"ar\"\n\
AR_FLAGS=\"cru\"\n\
-LTCC=\"gcc\"\n\
CC=\"gcc\"\n\
with_gcc=yes\n\
LD=\"/usr/i486-suse-linux/bin/ld\"\n\
objext=\"o\"\n\
libext=\"a\"\n\
exeext=\"\"\n\
-pic_flag=\" -fPIC -DPIC\"\n\
+pic_flag=\" -fPIC\"\n\
pic_mode=default\n\
-max_cmd_len=73729\n\
compiler_c_o=\"yes\"\n\
+compiler_o_lo=\"yes\"\n\
need_locks=\"no\"\n\
need_lib_prefix=no\n\
need_version=no\n\
-dlopen_support=yes\n\
-dlopen_self=yes\n\
-dlopen_self_static=no\n\
+dlopen_support=unknown\n\
+dlopen_self=unknown\n\
+dlopen_self_static=unknown\n\
link_static_flag=\"-static\"\n\
no_builtin_flag=\" -fno-builtin -fno-rtti -fno-exceptions\"\n\
export_dynamic_flag_spec=\"\\${wl}--export-dynamic\"\n\
postuninstall_cmds=\"\"\n\
old_striplib=\"strip --strip-debug\"\n\
striplib=\"strip --strip-unneeded\"\n\
-predep_objects=\"\"\n\
-postdep_objects=\"\"\n\
-predeps=\"\"\n\
-postdeps=\"\"\n\
-compiler_lib_search_path=\"\"\n\
deplibs_check_method=\"pass_all\"\n\
-file_magic_cmd=\"\"\n\
+file_magic_cmd=\"\\$MAGIC_CMD\"\n\
allow_undefined_flag=\"\"\n\
no_undefined_flag=\"\"\n\
finish_cmds=\"PATH=\\\\\\\"\\\\\\$PATH:/sbin\\\\\\\" ldconfig -n \\$libdir\"\n\
finish_eval=\"\"\n\
-global_symbol_pipe=\"sed -n -e 's/^.*[ ]\\\\([ABCDGISTW][ABCDGISTW]*\\\\)[ ][ ]*\\\\(\\\\)\\\\([_A-Za-z][_A-Za-z0-9]*\\\\)\\$/\\\\1 \\\\2\\\\3 \\\\3/p'\"\n\
+global_symbol_pipe=\"sed -n -e 's/^.*[ \t]\\\\([ABCDGISTW][ABCDGISTW]*\\\\)[ \t][ \t]*\\\\(\\\\)\\\\([_A-Za-z][_A-Za-z0-9]*\\\\)\\$/\\\\1 \\\\2\\\\3 \\\\3/p'\"\n\
global_symbol_to_cdecl=\"sed -n -e 's/^. .* \\\\(.*\\\\)\\$/extern char \\\\1;/p'\"\n\
+global_symbol_to_c_name_address=\"sed -n -e 's/^: \\\\([^ ]*\\\\) \\$/ {\\\\\\\"\\\\1\\\\\\\", (lt_ptr) 0},/p' -e 's/^[BCDEGRST] \\\\([^ ]*\\\\) \\\\([^ ]*\\\\)\\$/ {\\\"\\\\2\\\", (lt_ptr) \\\\&\\\\2},/p'\"\n\
runpath_var=LD_RUN_PATH\n\
shlibpath_var=LD_LIBRARY_PATH\n\
shlibpath_overrides_runpath=no\n\
export_symbols_cmds=\"\\$NM \\$libobjs \\$convenience | \\$global_symbol_pipe | sed 's/.* //' | sort | uniq > \\$export_symbols\"\n\
extract_expsyms_cmds=\"\"\n\
exclude_expsyms=\"_GLOBAL_OFFSET_TABLE_\"\n\
-include_expsyms=\"\"\n";
+include_expsyms=\"\"\n\
+exec_cmd=\n\
+Xsed='sed -e 1s/^X//'\n\
+sed_quote_subst='$sed_quote_subst'\n\
+relink_command=\\\"$relink_command\\\"\n\
+dlname='$tdlname'\n\
+library_names='$library_names'\n\
+old_library='$old_library'\n\
+dependency_libs='$dependency_libs'\n\
+current=$current\n\
+age=$age\n\
+revision=$revision\n\
+installed=$installed\n\
+dlopen='$dlfiles'\n\
+dlpreopen='$dlprefiles'\n\
+libdir='$install_libdir'\"\n\
+relink_command=\\\"$relink_command\\\"\"\n";
const char* pz_ltconfig = z_ltconfig;
const char* pz_shell = "/bin/sh";