/************************************************************************* * * (c) Copyright 1992,1993,1994 by G & A Technical Software, 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 G & A Technical * Software, Inc. * ************************************************************************* * * Filename: * * Purpose: * * Author: John Burton * * Date: 5/31/94 * ************************************************************************* * * Modification History: * * $Log: s3_parser_emt_functions.c,v $ * Revision 2.1 1994/07/08 17:52:24 jcburt * Updated typedefs, defines and function protypes to allow recursive * parsing of pct files. Enabled use of sub-PDT files and scoping of * datasets. Datasets used in a pct must be defined either in the * associated pdt file or the pdt file associated with the direct * ancestors of the current pct file. * * DataSet functions and subroutines now have an additional parameter * passed to them, indicating the number of parameters passed in the * dataset list, i.e. was: function(DataSet **dl) * now: function(int nargs, DataSet **dl) * Parameters passed to the dataset routines from the PCT level are all * still contained in the dataset list, nargs is during the function or * subroutine call from s3_exec_enode * * Revision 2.0.0.1 1994/06/28 18:48:28 jcburt * S3 Version 2.0 Initial Source * * ************************************************************************* * * Revision Control Information: */ static char rcsid[] = "$Id: s3_parser_emt_functions.c,v 2.1 1994/07/08 17:52:24 jcburt Exp $"; static char rcsrev[] = "$Revision: 2.1 $"; /************************************************************************* * * Include Files * *************************************************************************/ #include #include #include #include #include #include #include #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_externals.h" #include "s3_globals.h" #include "s3_parser.tab.h" #include "s3_parser_globals.h" /************************************************************************* * * Defines and Macros * *************************************************************************/ /************************************************************************* * * Global Variables * *************************************************************************/ File_list *lib_list = NULL; File_list *obj_list = NULL; char *loadflags = D_LOADFLAGS; char *applib = NULL; char *shapplib = NULL; static char *libname = NULL; char *uliblist = NULL; static char *uobjlist = NULL; static char *Make_cmd = NULL; static char *Export_file = NULL; static char *exports = NULL; static int build_shared_lib = FALSE; void s3_init_parser_emt(char *basename) { struct stat buff; char tmp[128]; int len, result; libname = strsave2("lib",strsave2(basename,".a")); applib = strsave2(strsave2(shlibdir,"/lib"),strsave2(basename,".a")); shapplib = strsave2(strsave2(shlibdir,"/lib"),strsave2(basename,".so")); Export_file = strsave2(strsave2(shlibdir,"/"),strsave2(progname,".exp")); if(stat(shlibdir,&buff)) { sprintf(tmp,"mkdir %s",shlibdir); result = system(tmp); } len = strlen(MAKE_COMMAND) + strlen(Cflags) + strlen(Fflags) + 25; Make_cmd = (char *)xmalloc(len*sizeof(char)); sprintf(Make_cmd,"%s CFLAGS=\"%s\" FFLAGS=\"%s\"", MAKE_COMMAND,Cflags,Fflags); lib_list = s3_add_file(lib_list,applib); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_setup_pnode(char *name ,char *fname) { ST_entry *entry; if((entry = s3_add_symbol(name)) == NULL) s3_parse_warning("symbol %s previously defined",name); else { entry->pn.type = PNODE; entry->pn.parsed = FALSE; entry->pn.NE = 0; entry->pn.EOI = 0; entry->pn.EOL = NULL; entry->pn.description = NULL; entry->pn.filename = strsave(fname); entry->pn.breakpt = NULL; entry->pn.elkey = NULL; entry->pn.elist = NULL; entry->pn.NDS = 0; entry->pn.dslist = NULL; } } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_setup_enode(int type, ST_entry **entry, int count) { int i,j,result; char *tmp,*etmp; if((type == DFUNC)||(type == DSUBR)) return; etmp = strsave(""); emt_info->exe_list = s3_add_to_list(emt_info->exe_list,entry, &(emt_info->nexe),count); for(i=0;ien.name); etmp = stringcat(etmp,"\n"); entry[i]->ss.type = type; entry[i]->en.NDS = UNDEFINED; entry[i]->en.function = NULL; entry[i]->en.filename = strsave(shapplib); } if(exports == NULL) exports = strsave(etmp); else exports = stringcat(exports,etmp); xfree(etmp); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void add_object_to_archive(char *archive, char *object) { char *tmp; int len,result; struct stat buff1,buff2,objbuf; if(uobjlist == NULL) uobjlist = strsave2(strsave2(shlibdir,"/"),object); else uobjlist = strsave2(strsave2(uobjlist," "),strsave2(strsave2(shlibdir,"/"),object)); if(Check_Modules) { len = strlen(Make_cmd) + strlen(archive) + 2 * strlen(object) + strlen(logfile) + 16; tmp = (char *)xmalloc(len*sizeof(char)); #ifdef _BROKEN_MAKE sprintf(tmp,"%s %s >>%s",Make_cmd,object,logfile); result = system(tmp); sprintf(tmp,"ar r %s %s >>%s",archive,object,logfile); #else sprintf(tmp,"%s \"%s(%s)\" >>%s", Make_cmd,archive,object,logfile); #endif build_shared_lib = build_shared_lib || (stat(object,&buff1)!=0); result = system(tmp); build_shared_lib = build_shared_lib || (stat(object,&buff2)!=0) || (buff1.st_mtime != buff2.st_mtime); if(result < 0) s3_error(SYS,"add_object_to_archive: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"add_object_to_archive: system call returned %d for command %s",result,tmp); xfree(tmp); } } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_add_objects_to_list(File_list *flist) { File_list *tmp; if(flist == NULL) { s3_parse_warning("No files specified"); return; } tmp = flist; fprintf(fperr,"Checking Object Files "); while(tmp != NULL) { fprintf(fperr,"."); add_object_to_archive(applib,tmp->name); tmp = tmp->next; } fprintf(fperr," done\n"); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_add_libs_to_list(File_list *flist) { File_list *tmp; char *lst,*ctmp; int len,result; struct stat buff1,buff2; if(flist == NULL) { s3_parse_warning("No libraries specified"); return; } lst = strsave(" "); tmp = flist; lib_list->next = flist; if(Check_Modules) build_shared_lib = TRUE; fprintf(fperr,"Checking Libraries "); while((tmp != NULL)&&(Check_Modules)) { fprintf(fperr,"."); /* len = strlen(tmp->name)+strlen(Make_cmd)+strlen(logfile) + 5; ctmp = (char *)xmalloc(len*sizeof(char)); sprintf(ctmp,"%s %s >>%s",Make_cmd,tmp->name,logfile); build_shared_lib = build_shared_lib || (stat(tmp->name,&buff1)!=0); result = system(ctmp); build_shared_lib = build_shared_lib || (stat(tmp->name,&buff2)!=0) || (buff1.st_mtime < buff2.st_mtime); if(result < 0) s3_error(SYS,"add_libs_to_list: fork or exec system call failed for command %s",ctmp); if(result > 0) s3_error(SYS,"add_libs_to_list: system call returned %d for command %s",result,ctmp); xfree(ctmp); */ /* s3_put_file_module(tmp->name); */ lst = stringcat(lst,tmp->name); lst = stringcat(lst," "); tmp = tmp->next; } fprintf(fperr," done\n"); if(uliblist == NULL) uliblist = strsave(lst+1); else uliblist = stringcat(uliblist,lst); xfree(lst); } /************************************************************************* * * Module: * * Description: * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void s3_setup_shared_library() { int len,ulen,result; char *tmp,*etmp; char *libs; FILE *fpexp; void *vptr; struct stat sbuf,abuf; #ifdef linux build_shared_lib = build_shared_lib || (stat(shapplib,&sbuf)!=0) || (stat(applib,&abuf)!=0) || (sbuf.st_mtime < abuf.st_mtime); if((Check_Modules)&&(build_shared_lib)) { fprintf(fperr,"Building Shared Library - linux %s\n",shapplib); uobjlist = (uobjlist == NULL) ? strdup(" ") : uobjlist; uliblist = (uliblist == NULL) ? strdup(" ") : uliblist; ulen = strlen(uliblist) + strlen(uobjlist) + 1; len = strlen(Cflags) + strlen(shapplib) + ulen + strlen(D_LOADFLAGS) + 80; tmp = (char *)xmalloc(len*sizeof(char)); sprintf(tmp,"cd %s; ar -x %s; cd ..",shlibdir,libname); fprintf(fperr,"==> %s \n",tmp); result = system(tmp); if(result < 0) s3_error(SYS,"s3_setup_shared_library: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"s3_setup_shared_library: system call returned %d for command %s",result,tmp); sprintf(tmp,"cc %s -shared -o %s %s %s %s", Cflags,shapplib,uobjlist,uliblist,D_LOADFLAGS); fprintf(fperr,"==> %s \n",tmp); result = system(tmp); if(result < 0) s3_error(SYS,"s3_compile_static: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"s3_compile_static: system call returned %d for command %s",result,tmp); sprintf(tmp,"rm %s",uobjlist); fprintf(fperr,"==> %s \n",tmp); result = system(tmp); if(result < 0) s3_error(SYS,"s3_compile_static: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"s3_compile_static: system call returned %d for command %s",result,tmp); xfree(tmp); s3_put_file_module(shapplib); #else /* s3_put_file_module(shapplib); */ if((Check_Modules)&&(build_shared_lib)) { vptr = NULL; fprintf(fperr,"Building Shared Library %s\n",shapplib); if((fpexp = fopen(Export_file,"w")) == NULL) s3_error(SYS,"Cannot open file %s for writing",Export_file); fprintf(fpexp,"#! %s\n%s",shapplib,exports); fflush(fpexp); fclose(fpexp); uliblist = (uliblist == NULL) ? strdup(" ") : uliblist; ulen = (uliblist != NULL) ? strlen(uliblist) : 0; len = strlen(shapplib) + 2*strlen(applib) + ulen + 80; tmp = (char *)xmalloc(len*sizeof(char)); #endif /* if(Link_Method == DYNAMIC) { sprintf(tmp,"cc %s -o %s -bM:SRE -bE:%s -e _nostart %s %s -lxlf -lm -lc",Cflags,shapplib,etmp,applib,uliblist); sprintf(tmp,"cc %s -o %s *.o %s %s -lm -lc",Cflags,shapplib,applib,uliblist); } else { s3_setup_static(emt_info,progname); sprintf(tmp,"xlc %s -o %s s3_%s.c /usr/local/bin/s3exec %s %s -lxlf -lm -lc", Cflags,progname,progname,applib,uliblist); } result = system(tmp); if(result < 0) s3_error(SYS,"setup_shared_library: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"setup_shared_library: system call returned %d for command %s",result,tmp); xfree(etmp); xfree(tmp); */ } else fprintf(fperr,"Shared Library %s is up to date.\n",shapplib); /* if((Link_Method == DYNAMIC) && ((vptr = dlopen(shapplib,1)) == NULL)) s3_error(SYS,"setup_shared_library: %s",dlerror()); */ } void s3_compile_static(char *progname) { int len, ulen, result; char *tmp, cmd[80]; uobjlist = (uobjlist == NULL) ? strdup(" ") : uobjlist; uliblist = (uliblist == NULL) ? strdup(" ") : uliblist; ulen = strlen(uliblist) + strlen(uobjlist) + 1; len = strlen(Cflags) + 2*strlen(progname) + ulen + strlen(S_LOADFLAGS) + 80; tmp = (char *)xmalloc(len*sizeof(char)); sprintf(tmp,"cd %s; ar -x %s; cd ..",shlibdir,libname); result = system(tmp); if(result < 0) s3_error(SYS,"s3_compile_static: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"s3_compile_static: system call returned %d for command %s",result,tmp); sprintf(tmp,"cc %s -o %s s3_%s.c %s %s %s", Cflags,progname,progname,uobjlist,uliblist,S_LOADFLAGS); result = system(tmp); if(result < 0) s3_error(SYS,"s3_compile_static: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"s3_compile_static: system call returned %d for command %s",result,tmp); sprintf(tmp,"rm %s",uobjlist); result = system(tmp); if(result < 0) s3_error(SYS,"s3_compile_static: fork or exec system call failed for command %s",tmp); if(result > 0) s3_error(SYS,"s3_compile_static: system call returned %d for command %s",result,tmp); xfree(tmp); }