/* * $Id$ *----------------------------------------------------------------------- * * (c) Copyright 1992-1997 by GATS, Inc., * 28 Research Drive, Hampton, Virginia, 23666. * * All Rights Reserved. No part of this software or publication may be * reproduced, stored in a retrieval system, or transmitted, in any form * or by any means, electronic, mechanical, photocopying, recording, or * otherwise without the prior written permission of GATS, Inc. * *----------------------------------------------------------------------- * * Module: s3_create_libraries.c * * Author: John Burton * * Date: Tue Apr 15 15:15:52 1997 * *----------------------------------------------------------------------- * * Modification History: * * $Log$ * *----------------------------------------------------------------------- * * Revsion Control Information: */ static char rcsid[] = "$Id$"; static char rcsrev[] = "$Revision$"; /* *----------------------------------------------------------------------- * Include Files: *----------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include "s3_machdep.h" #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_globals.h" /* *----------------------------------------------------------------------- * Defines and Macros: *----------------------------------------------------------------------- */ /* *----------------------------------------------------------------------- * Global Variables: *----------------------------------------------------------------------- */ static char *Makefile = NULL; static FILE *Make_fp = NULL; /* *----------------------------------------------------------------------- * Makefile Generation Routines: *----------------------------------------------------------------------- */ static void write_makefile_header(FILE *fp,char *fname) { int i; char *datetimestr; char *username; long now; #ifdef _AIX extern char *getlogin(); #endif time(&now); datetimestr = ctime(&now); username = getlogin(); i = strlen(datetimestr); while((i>=0) && (datetimestr[i] != '\n')) i--; if(i > 0) datetimestr[i] = ' '; fprintf(fp,"#-------------------------------------------------------------------------------\n"); fprintf(fp,"# \n"); fprintf(fp,"# \n"); fprintf(fp,"# \n"); fprintf(fp,"# (c) Copyright 1992 - 1997 by GATS, Inc., \n"); fprintf(fp,"# 28 Research Drive, Hampton, Virginia, 23666. \n"); fprintf(fp,"# \n"); fprintf(fp,"# All Rights Reserved. No part of this software or publication may be \n"); fprintf(fp,"# reproduced, stored in a retrieval system, or transmitted, in any form \n"); fprintf(fp,"# or by any means, electronic, mechanical, photocopying, recording, or \n"); fprintf(fp,"# otherwise without the prior written permission of G & A Technical \n"); fprintf(fp,"# Software, Inc. \n"); fprintf(fp,"# \n"); fprintf(fp,"# \n"); fprintf(fp,"# \n"); fprintf(fp,"# This file was generated by %s \n",progname); fprintf(fp,"# \n"); fprintf(fp,"# File: %s \n",fname); fprintf(fp,"# User: %s \n",username); fprintf(fp,"# Date: %s \n",datetimestr); fprintf(fp,"# \n"); fprintf(fp,"#-------------------------------------------------------------------------------*/\n\n"); fflush(fp); } static void write_makefile_defines(FILE *fp, char *basename) { File_list *libs; extern File_list *s3_GetLibList(); libs = s3_GetLibList(); fprintf(fp,"CC = %s\n",CC); fprintf(fp,"CFLAGS = %s %s\n",Cflags,CC_FLAGS); fprintf(fp,"FC = %s\n",FC); fprintf(fp,"FFLAGS = %s %s\n",Fflags,FC_FLAGS); fprintf(fp,"AR = %s\n",AR); fprintf(fp,"ARFLAGS = %s\n",ARFLAGS); fprintf(fp,"SHFLAGS = %s\n",SHFLAGS); fprintf(fp,"LDOPTS = %s\n",LDOPTS); fprintf(fp,"USR_LIBS = "); while(libs != NULL) { fprintf(fp,"%s ",libs->name); libs = libs->next; } fprintf(fp,"\n"); fprintf(fp,"LIBDIRS = %s\n",LIBDIRS); fprintf(fp,"SYS_LIBS = %s %s\n",F77_LIBS,SYS_LIBS); fprintf(fp,"LIB = %s/lib%s.a\n",shlibdir,basename); fprintf(fp,"SHOBJ = %s/lib%s.so\n",shlibdir,basename); fprintf(fp,"MAIN_SRC = s3_%s.c\n",basename); fprintf(fp,"MAIN_EXE = %s\n",basename); fprintf(fp,"\n\n"); fprintf(fp,".c.a:\n"); fprintf(fp,"\t$(CC) $(CFLAGS) $(CPPFLAGS) -c $<\n"); fprintf(fp,"\t$(AR) $(ARFLAGS) $@ $*.o\n"); fprintf(fp,"\t$(RM) $*.o\n\n"); fprintf(fp,".f.a:\n"); fprintf(fp,"\t$(FC) $(FFLAGS) $(CPPFLAGS) -c $<\n"); fprintf(fp,"\t$(AR) $(ARFLAGS) $@ $*.o\n"); fprintf(fp,"\t$(RM) $*.o\n\n"); fprintf(fp,".f.o:\n"); fprintf(fp,"\t$(FC) $(FFLAGS) -c $<\n"); fflush(fp); } static void write_makefile_targets(FILE *fp) { fprintf(fp,"$(LIB):\t$(OBJS)\n"); #ifdef _BROKEN_MAKE fprintf(fp,"\t$(AR) $(ARFLAGS) $(LIB) $(OBJS)\n"); #endif fprintf(fp,"\tranlib $(LIB)\n\n"); fprintf(fp,"lib:\t$(LIB)\n\n"); #ifdef _SHARED_OBJS_OK fprintf(fp,"$(SHOBJ):\t$(LIB)\n"); fprintf(fp,"\tmkdir tmpso; cd tmpso; $(AR) x ../$(LIB)\n"); fprintf(fp,"\t$(CC) $(SHFLAGS) $(LIBDIRS) -o $(SHOBJ) ./tmpso/*.o $(SYS_LIBS)\n" ); fprintf(fp,"\t$(RM) -rf ./tmpso\n\n"); fprintf(fp,"dynamic:\t$(SHOBJ)\n\n"); #endif fprintf(fp,"$(MAIN_EXE):\t$(MAIN_SRC) $(LIB)\n"); fprintf(fp,"\t$(CC) $(CFLAGS) $(LDOPTS) -o $@ $(MAIN_SRC) $(LIBDIRS) $(LIB) $(USR_LIBS) $(SYS_LIBS)\n\n"); fprintf(fp,"static:\t$(MAIN_EXE)\n\n"); fflush(fp); } static void write_makefile_objects(FILE *fp) { File_list *objs; extern File_list *s3_GetObjList(); objs = s3_GetObjList(); fprintf(fp,"OBJS = "); while(objs != NULL) { #ifdef _BROKEN_MAKE fprintf(fp,"%s ",objs->name); #else fprintf(fp,"$(LIB)(%s) ",objs->name); #endif objs = objs->next; } fprintf(fp,"\n\n"); fflush(fp); } void s3_init_create_libraries(char *basename) { struct stat buff; char tmp[128]; int len, result; Makefile = strsave2(strsave2(S3_Dir,"/"),strsave2(basename,".mak")); if(stat(S3_Dir,&buff)) { sprintf(tmp,"mkdir %s",S3_Dir); result = system(tmp); } if((Make_fp = fopen(Makefile,"w")) == NULL) s3_error(SYS,"Cannot open file %s for writing",Makefile); write_makefile_header(Make_fp,Makefile); write_makefile_defines(Make_fp,basename); write_makefile_objects(Make_fp); write_makefile_targets(Make_fp); fclose(Make_fp); if(stat(shlibdir,&buff)) { sprintf(tmp,"mkdir %s",shlibdir); result = system(tmp); } } void s3_make_lib(char *basename) { char tmp[128],buff[80]; int result; FILE *pipe, *fp; fprintf(fperr,"Creating Library: %s/lib%s.a ... ",shlibdir,basename); sprintf(tmp,"make lib -f %s",Makefile); if(logfile == NULL) fp = stderr; else if((fp = fopen(logfile,"a")) == NULL) s3_error(SYS,"Cannot open file %s for writing",logfile); pipe = popen(tmp,"r"); while(fgets(buff,80,pipe) != NULL) fputs(buff,fp); result = pclose(pipe); if(fp != stderr) fclose(fp); fprintf(fperr,"Done\n"); } void s3_make_dynamic(char *basename) { char tmp[128],buff[80]; int result; FILE *pipe, *fp; fprintf(fperr,"Creating Shared Object: %s/lib%s.so ... ",shlibdir,basename); sprintf(tmp,"make dynamic -f %s",Makefile); if(logfile == NULL) fp = stderr; else if((fp = fopen(logfile,"a")) == NULL) s3_error(SYS,"Cannot open file %s for writing",logfile); pipe = popen(tmp,"r"); while(fgets(buff,80,pipe) != NULL) fputs(buff,fp); result = pclose(pipe); fflush(fp); if(fp != stderr) fclose(fp); fprintf(fperr,"Done\n"); } void s3_make_static(char *basename) { char tmp[128],buff[80]; int result; FILE *pipe, *fp; fprintf(fperr,"Creating Executable: %s ... ",basename); sprintf(tmp,"make static -f %s",Makefile); if(logfile == NULL) fp = stderr; else if((fp = fopen(logfile,"a")) == NULL) s3_error(SYS,"Cannot open file %s for writing",logfile); pipe = popen(tmp,"r"); while(fgets(buff,80,pipe) != NULL) fputs(buff,fp); result = pclose(pipe); fflush(fp); if(fp != stderr) fclose(fp); fprintf(fperr,"Done\n"); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_setup_shared_library(char *basename) { s3_init_create_libraries(basename); s3_make_lib(basename); s3_make_dynamic(basename); } void s3_compile_static(char *basename) { s3_init_create_libraries(basename); s3_make_lib(basename); s3_make_static(basename); }