This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cpp doesn't define symbol i386


On 14 Oct 1997, Tkil the Morose wrote:

> 
> Ronald.Wahl@informatik.tu-chemnitz.de writes:
> 
> [regarding using a small shell script wrapper as 'cpp':]
>  
> > "gcc -E" is not equivalent to cpp because cpp read from stdin by default
> > and "gcc -E" needs the parameter "-" to force reading from stdin. But
> > hardcoding "-" in a shellscript will not be a solution due to cases where
> > cpp is called with an inputfile. Is it possible to change the behavior of
> > "gcc -E" so that it reads from stdin by default? 
> 
> Ronald:
> 
> does this do the trick?
> 
>    #!/bin/bash
>    gcc -E ${*:-'-'}

No, since if you call this script with -Dxxx it will not append "-". But
I have written a wrapper which seems to work. Here is the C code:

------------------ snip ---------------------------------------
#include <stdlib.h>
#include <unistd.h>

int isFile(char * arg)
{
	if ( arg[0] != 0 && ( ( arg[0] == '-' && arg[1] == 0 ) || arg[0] != '-' ) )
		return 1;
	return 0;
}

int main( int argc, char * argv[] )
{
	int     i, j, files;
	char ** cpp_argv = (char **) malloc( ( argc + 2 ) * sizeof( char * ) );

	j = 0;
	cpp_argv[j++] = "gcc";
	cpp_argv[j++] = "-E";
	
	/* if last parameter is not a file we have to add the parameter "-" to gcc */
	if ( argc > 1 ) {
		/*
		 *  copy commandline parameters
		 */
		for ( i = 1, files = 0; i < argc; i++ ) {
			if ( isFile( argv[i] ) )
				if ( ++files == 2 )
					/*
					 *  the second file is the outputfile
					 *  so we need to insert -o for gcc
					 */
					cpp_argv[j++] = "-o";
			cpp_argv[j++] = argv[i];
		}

		/*
		 *  if the last commandline parameter isn't a file
		 *  we have to add the parameter `-' to gcc
		 */
		if ( ! isFile( argv[argc - 1] ) )
			cpp_argv[j++] = "-";
	} else
		cpp_argv[j++] = "-";
	cpp_argv[j++] = NULL;

	execvp("gcc", cpp_argv);
	
	return 0;
}
------------------------- snip --------------------------------

ron

-- 
\ Ronald Wahl --- rwa@informatik.tu-chemnitz.de   \
 \ WWW: http://www.tu-chemnitz.de/~row             \
  \ Talk: rwa@goliath.csn.tu-chemnitz.de            \
   \ PGP key available by finger to my email address \




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]