130 char *ptr,*
p,**
pp,**pp1,**pp2,*directory=0,*libpath=0;
133 int i,optl=0,optm=0,swapping,
c,rargc;
136 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
137 char *ntg4tmp=0,*ntg4tmp1=0;
147 struct libmap_ *next;
150 struct libmap_ *libmap=0,*libmapPtr=0,*libmapPtr1=0,*libmapPtr2=0,
151 *prevPtr1,*prevPtr2,*tmpp,*userLibmapPtr;
153 while((c=getopt(argc,argv,
"ld: m:"))!=EOF)
193 " ERROR: If you specify a directory don't also specify files\n");
198 if(optl)fprintf(stderr,
" Reading library name map file...\n");
203 if(feof(stdin))
break;
204 if (strlen(buffer) >=
BUFSIZE-1)
207 " Internal ERROR: BUFSIZE too small to read library name map file\n");
211 if ( buffer[strlen(buffer)-1] ==
'\n')
212 { buffer[strlen(buffer)-1]=
'\0'; }
214 ptr=strtok(buffer,
":\n");
217 for(libmapPtr1=libmap;libmapPtr1;libmapPtr1=libmapPtr1->next)
219 if(strcmp(libmapPtr1->lib,ptr)==0)
221 fprintf(stderr,
" ERROR: Duplicate library name: %s\n",ptr);
223 " Perhaps a duplicate subdirectory with"
224 " a GNUmakefile with the same library name.\n"
232 libmapPtr->next=(
struct libmap_*) malloc(
sizeof(
struct libmap_));
233 libmapPtr=libmapPtr->next;
237 libmap=(
struct libmap_*) malloc(
sizeof(
struct libmap_));
241 libmapPtr->lib=strdup(ptr);
243 libmapPtr->uses=(
char**)calloc(
NLIBMAX,
sizeof(
char*));
251 ptr=strtok(NULL,
" \n");
256 ptr=strtok(NULL,
" \n");
265 if (strlen(buffer) >=
BUFSIZE-1)
268 " Internal ERROR: BUFSIZE too small to read directory name\n");
272 if ( buffer[strlen(buffer)-1] ==
'\n')
273 { buffer[strlen(buffer)-1]=
'\0'; }
275 ptr=strtok(buffer,
"/");
278 fprintf(stderr,
" ERROR: \"/\" before \"source\" expected.\n");
281 while(ptr&&strcmp (ptr,
"source"))ptr=strtok(NULL,
"/");
282 ptr=strtok(NULL,
"/");
285 fprintf(stderr,
" ERROR: \"source\" expected.\n");
288 libmapPtr->trigger=(
char*)malloc(
TRIGSIZE);
291 fprintf(stderr,
" ERROR: String overflow for: %s\n", ptr);
294 strcpy(libmapPtr->trigger,ptr);
295 ptr=strtok(NULL,
"/");
296 while(ptr&&strcmp(ptr,
"GNUmakefile"))
298 strncat(libmapPtr->trigger,
"/",1);
299 strncat(libmapPtr->trigger,ptr,strlen(ptr));
300 ptr=strtok(NULL,
"/");
306 " ERROR: \"source/<unique-sub-path>/GNUmakefile\" expected.\n");
312 if(optl)fprintf(stderr,
" Reading dependency files...\n");
314 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
315 ntg4tmp=getenv(
"G4TMP");
318 fprintf(stderr,
" ERROR: Cannot find environment variable G4TMP\n");
321 ntg4tmp1=strdup(ntg4tmp);
326 fp=fopen(rargv[i],
"r");
329 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
330 ptr=strchr(ntg4tmp1,
':');
332 while ( ptr=strchr(buffer,
'\\') ) *ptr=
'/';
334 while (ntg4tmp1!=NULL && (ptr=strstr(buffer,ntg4tmp1))!=NULL )
336 for(nti=0;nti<strlen(ntg4tmp1);nti++) ptr[nti]=
' ';
341 ptr=strtok(buffer,
":");
344 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
346 if(strlen(libmapPtr->lib)>256)
348 fprintf(stderr,
" ERROR: String overflow for: %s\n", libmapPtr->lib);
351 strcpy(workbuf,libmapPtr->lib);
353 strncat(workbuf,
"/",1);
354 if(strstr(ptr,workbuf))
break;
358 userLibmapPtr=libmapPtr;
368 bufferPtr=strtok(NULL,
"\n");
371 fprintf(stderr,
" WARNING: It seems there is nothing after \':\' in dependency file %s.\n", rargv[i]);
376 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
379 if(strlen(libmapPtr->trigger)>256)
381 fprintf(stderr,
" ERROR: String overflow for: %s\n", libmapPtr->trigger);
384 strcpy(workbuf,libmapPtr->trigger);
385 strncat(workbuf,
"/include",8);
386 ptr=strstr(bufferPtr,workbuf);
387 if(ptr && (userLibmapPtr != libmapPtr))
392 for(pp=userLibmapPtr->uses;*pp;pp++)
394 if(strcmp(*pp,libmapPtr->lib)==0)
break;
396 if(!*pp)*pp=libmapPtr->lib;
405 if(strlen(libmapPtr->lib)>256)
407 fprintf(stderr,
" ERROR: String overflow for: %s\n", libmapPtr->lib);
410 strcpy(workbuf,libmapPtr->lib);
411 strncat(workbuf,
"/",1);
412 ptr=strstr(bufferPtr,workbuf);
413 if(ptr && (userLibmapPtr != libmapPtr))
418 for(pp=userLibmapPtr->uses;*pp;pp++)
420 if(strcmp(*pp,libmapPtr->lib)==0)
break;
422 if(!*pp)*pp=libmapPtr->lib;
429 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
430 while ( ptr=strchr(buffer,
'\\') ) *ptr=
'/';
432 while (ntg4tmp1 && (ptr=strstr(buffer,ntg4tmp1)) )
434 for(nti=0;nti<strlen(ntg4tmp1);nti++) ptr[nti]=
' ';
444 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
451 fprintf(stderr,
" Checking for circular dependencies...\n");
452 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
454 for(pp=libmapPtr->uses;*pp;pp++)
456 for(libmapPtr1=libmap;libmapPtr1!=libmapPtr;
457 libmapPtr1=libmapPtr1->next)
459 if(strcmp(libmapPtr1->lib,*pp)==0)
461 for(pp1=libmapPtr1->uses;*pp1;pp1++)
463 if(strcmp(*pp1,libmapPtr->lib)==0)
break;
469 " WARNING: %s and %s use each other.\n",
501 fprintf(stderr,
" Reordering according to dependencies...\n");
506 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
508 for(pp=libmapPtr->uses;*pp;pp++)
511 for(libmapPtr1=libmap;libmapPtr1!=libmapPtr;
512 libmapPtr1=libmapPtr1->next)
514 if(strcmp(libmapPtr1->lib,*pp)==0)
517 for(pp1=libmapPtr1->uses;*pp1;pp1++)
519 if(strcmp(*pp1,libmapPtr->lib)==0)
break;
527 prevPtr1->next=libmapPtr;
536 tmpp=libmapPtr->next;
537 if(libmapPtr1->next==libmapPtr)
539 libmapPtr->next=libmapPtr1;
543 libmapPtr->next=libmapPtr1->next;
547 if(libmapPtr1->next!=libmapPtr)
549 prevPtr2->next=libmapPtr1;
552 libmapPtr1->next=tmpp;
565 fprintf(stderr,
" Writing new library map file...\n");
566 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
568 printf(
"%s:",libmapPtr->lib);
569 for(pp=libmapPtr->uses;*pp;pp++)
574 printf(
"source/%s/GNUmakefile\n",libmapPtr->trigger);
580 int libname_usable_size=24;
581 if ( ! libname ) libname=malloc(libname_usable_size+16);
584 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
586 if ( strlen(libpath)+strlen(libmapPtr->lib) > libname_usable_size ) {
587 libname_usable_size=(strlen(libpath)+strlen(libmapPtr->lib))*2;
589 libname=malloc(libname_usable_size+16);
594 sprintf(libname,
"%s/lib%s.a", libpath, libmapPtr->lib);
595 if (access(libname,R_OK))
597 sprintf(libname,
"%s/lib%s.so", libpath, libmapPtr->lib);
598 if (!access(libname,R_OK))
600 printf(
"-l%s ",libmapPtr->lib);
604 sprintf(libname,
"%s/lib%s.dylib", libpath, libmapPtr->lib);
605 if (!access(libname,R_OK))
607 printf(
"-l%s ",libmapPtr->lib);
613 printf(
"-l%s ",libmapPtr->lib);
615 libmapPtr=libmapPtr->next;
621 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
625 for(pp=libmapPtr->uses;*pp;pp++)
627 for(libmapPtr1=libmap;libmapPtr1;libmapPtr1=libmapPtr1->next)
629 if(strcmp(libmapPtr1->lib,*pp)==0)
639 for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
643 printf(
"-l%s ",libmapPtr->lib);
char ** parsedir(char *directory, int *argc)