www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/29/08:45:11

Xref: news2.mv.net comp.os.msdos.djgpp:6527
From: fnunez AT cs DOT uct DOT ac DOT za (Fabian Nunez)
Newsgroups: comp.os.msdos.djgpp
Subject: gxx replacement
Date: 29 Jul 1996 08:01:14 GMT
Organization: University of Cape Town
Lines: 113
Message-ID: <4thr4a$db0@groa.uct.ac.za>
NNTP-Posting-Host: unagi.cs.uct.ac.za
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Yesterday I got sick and tired of remembering to add "-liostr -lm" to my
makefiles for a non-GPL program I'm writing (I kept on forgetting 8) and so
I decided to write a quick replacement for gxx.  It adds all the libraries
you can use in C++ and still keep your program GPL free.  After doing this
I thought other people would find it useful so I commented it (now it's
newbie-friendly :) and here it is!

Enjoy
Fabian

---CUT-HERE---------------------------------------------------------
/*
 * gpp.c
 *
 * Quick wrapper for C++ compilation under DJGPP using only free C++ libs
 * (Use instead of gxx if you don't want your program to be GPL'd)
 * 
 * NOTE: Some symbols in libgpp.a are not in libiostr.a or libstdcx.a
 *       Use of those will give you linker errors if you try to compile
 *       with gpp but not with gxx. (eg. the BitString or list classes).
 *       In that case, you are using Gnu functions/classes and your
 *       program does fall under the Gnu GPL.
 *       Workaround - write the missing functions yourself! ;)
 * 
 * NOTE2:You need the compiler distribution file lgp271b.zip dated
 *       22-Feb-96, earlier ones don't have libstdcx.a!
 * 
 * Program by Fabian Nunez (fnunez AT cs DOT uct DOT ac DOT za)
 * 
 * This program comes with NO GUARANTEE and is in the public domain
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <crt0.h>

#define GCCEXEC "gcc.exe"
#define CPPLIBS " -liostr -lstdcx -lm"  /* link streams, std C++, math */

typedef enum { false, true } bool;

/* dummy functions for startup stuff we don't use (reduces exe size) */
void __crt0_load_environment_file(char *a) {}   /* no environment file */
char **__crt0_glob_function(char *a) { return NULL; } /* pass args as-is */

int main(int argc,char *argv[])
{
   char *buffer;
   int i,length,retval;
   bool nofiles = true,partial = false,verbose = false;

   fnsplit(argv[0],NULL,NULL,argv[0],NULL);  /* get rid of path from argv[0] */
   
   length = strlen(GCCEXEC CPPLIBS) + 1; /* add 1 for terminating '\0' */
   for (i = 1;i < argc;i++)
   {	
      length += (strlen(argv[i]) + 1);   /* add 1 for separating space */
      
      if (*argv[i] != '-')  /* have we specified any files? */
	nofiles = false;    /* yes! */
      
      if ((strcmp(argv[i],"-c") == 0) ||  /* partial compilation? */
	  (strcmp(argv[i],"-S") == 0) ||
	  (strcmp(argv[i],"-E") == 0))
	partial = true;
      
      if (strcmp(argv[i],"-v") == 0)      /* verbose? */
	verbose = true;
   }
   
   if (!(buffer = (char *)malloc(length)))
   {
      fprintf(stderr,"%s.exe: %s\n",argv[0],strerror(ENOMEM));
      return 1;
   }
   
   /* build the command line to call gcc (assumes gcc.exe is in the PATH) */
   strcpy(buffer,GCCEXEC);
   for (i = 1;i < argc;i++)
   {	
      strcat(buffer," ");
      strcat(buffer,argv[i]);
   }
   
   if (!nofiles && !partial)
     strcat(buffer,CPPLIBS);

   if (verbose)
     fprintf(stderr," %s\n",buffer);
   
   retval = system(buffer);
   
   free(buffer);
   
   if (retval)
   {
      fprintf(stderr,"%s.exe: Error during compilation (return code %d)\n",
	      argv[0],retval);
      
      return 1;
   }

   return 0;
}

---CUT-HERE---------------------------------------------------------
--
Fabian Nunez, Bachelor of Computer Science, University of Cape Town
email:fnunez AT cs DOT uct DOT ac DOT za   web:http//www.cs.uct.ac.za/~fnunez
----------------------------------------------------------------             
Any technology distinguishable from magic is insufficiently advanced

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019