/
wizshell/
wizshell/binsrc/
wizshell/binsrc/elvis-1.7/doc/
wizshell/docs/help/
wizshell/etc/
wizshell/src/util/
#include	<sys/types.h>
#include	<stdio.h>
#include	<sys/stat.h>
#include	<signal.h>

/*#define DEBUG		/* Provides extra debugging info */

int exists(file)
char *file;
{
	struct stat statbuf;

	if ( stat(file, &statbuf) == 0 )
		return(1);
	else
		return(0);
}


main()
{
	int  irix=0;
	char cflags[BUFSIZ], ldflags[BUFSIZ];
	char line[BUFSIZ];
	FILE *makefile;

	if ( exists("Makefile") )
	{
		fprintf(stderr, "Makefile already exists.  Continue?  [y/n] ");
		fgets(line, BUFSIZ-1, stdin);
		if ( line[0] == 'y' )
			printf("Continuing...\n");
		else
		{
			printf("Configuration aborted. Exiting.\n");
			exit(0);
		}
	}

	if ( (makefile=fopen("Makefile", "w")) == NULL )
	{
		perror("Can't create Makefile");
		printf("Configuration aborted. Exiting.\n");
		exit(2);
	}

#ifdef DEBUG
	strcpy(cflags, " -g -DDEBUG");
#else
	strcpy(cflags, " -O");
#endif
	ldflags[0]='\0';

	if ( grep("/usr/include/unistd.h", "_getpty") )
	{
		strcat(cflags, " -DIRIX");
		irix=1;
	}
	if ( exists("/hp-ux") )
		strcat(cflags, " -DHP_UX");
	if ( grep("/usr/include/utmp.h", "ut_host") )
		strcat(cflags, " -DHAVE_UTHOST");
	if ( exists("/usr/include/termio.h") )
		strcat(cflags, " -DHAVE_TERMIO_H");
	if ( exists("/usr/include/sys/bsdtty.h") )
		strcat(cflags, " -DHAVE_BSDTTY_H");
	if ( exists("/usr/include/sys/ioctl_compat.h") ) 
		strcat(cflags, " -DNEED_COMPAT_H");
	if ( exists("/usr/include/sys/inet.h") )
		strcat(cflags, " -DNEED_INET_H");
	if ( exists("/usr/include/sys/select.h") )
		strcat(cflags, " -DNEED_SELECT_H");

	/* Solaris 2.1 */
	if ( exists("/usr/lib/libsocket.a") )
	{
		strcat(ldflags, " -lsocket");
		strcat(cflags, " -g -DSOLARIS");
	}
	if ( exists("/usr/lib/libnet.a") )
		strcat(ldflags, " -lnet");
	if ( exists("/usr/lib/libnsl_s.a") )
		strcat(ldflags, " -lnsl_s");

	fprintf(makefile,"# This Makefile has been generated from the Configure script.\n# Shareware copyright 1993, by Sam Lantinga\n\n");
	sprintf(line, "\nCFLAGS = %s\nLIBS = %s\n\n", cflags, ldflags);
	fprintf(makefile, "%s", line);
	fprintf(makefile, "splitvt: splitvt.o misc.o vt100.o utmp.o vttest.o\n\tcc -o splitvt splitvt.o misc.o vt100.o utmp.o vttest.o $(LIBS)\n\nclean: \n\trm -f *.o core splitvt Makefile\n");

	fclose(makefile);
	exit(0);
}


/* Yeesh.  I have to write a word grep function.... */

int grep(file, word)
char *file;
char *word;
{
	FILE *fp;
	char *wptr, *ptr, buffer[BUFSIZ];

	if ( (fp=fopen(file, "r")) == NULL )
		return(0);
	ptr=word;

	while ( fgets(buffer, BUFSIZ-1, fp) != NULL )
	{
		for ( wptr=buffer; *wptr; ++wptr)
		{
			if ( *wptr == *ptr )
			{
				++ptr;
				if ( *ptr == '\0' )
				{
					(void) fclose(fp);
					return(1);
				}
			}
			else
				ptr=word;
		}
	}
	(void) fclose(fp);
	return(0);
}