2003-01-20 05:58:50 +08:00
|
|
|
|
/*
|
|
|
|
|
Copyright (C) 2002 FPMD group
|
|
|
|
|
This file is distributed under the terms of the
|
|
|
|
|
GNU General Public License. See the file `License'
|
|
|
|
|
in the root directory of the present distribution,
|
|
|
|
|
or http://www.gnu.org/copyleft/gpl.txt .
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<ctype.h>
|
|
|
|
|
#include<strings.h>
|
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
#define MAXFILES 5000
|
|
|
|
|
#define NAMELEN 80
|
|
|
|
|
#define MODLEN 32
|
|
|
|
|
#define MAXMOD 500
|
|
|
|
|
#define DEBUG 0
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
|
|
char str[BUFSIZ];
|
2003-01-23 07:24:13 +08:00
|
|
|
|
|
|
|
|
|
struct module_list {
|
|
|
|
|
char filename[NAMELEN];
|
|
|
|
|
int nmodules;
|
|
|
|
|
char modules[MAXMOD][MODLEN];
|
|
|
|
|
};
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
|
|
int used_name(char *str, char *module)
|
|
|
|
|
{
|
|
|
|
|
int i=0,j=0,k;
|
2003-01-23 07:24:13 +08:00
|
|
|
|
|
|
|
|
|
/* skip blanks */
|
|
|
|
|
while( isspace( str[i] ) ) i++;
|
|
|
|
|
|
|
|
|
|
/* convert to lowercase */
|
|
|
|
|
for( k = i; k < i+4; k++ ) str[k] = tolower( str[k] );
|
|
|
|
|
|
|
|
|
|
/* check if we found a module */
|
|
|
|
|
if( ! strncmp( &str[i], "use ", 4 ) ) {
|
|
|
|
|
i += 4; /* skip "use " */
|
|
|
|
|
while( isspace(str[i]) ) i++; /* skip blanks */
|
|
|
|
|
while( str[i]!=' ' && str[i]!= ',' && str[i]!='\n' && j<(MODLEN-1) ) {
|
|
|
|
|
module[j++] = tolower(str[i++]); /* get module name */
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
|
|
|
|
module[j] = '\0';
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
int module_unit(char *str, char *module)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
{
|
|
|
|
|
int i=0,j=0,k;
|
|
|
|
|
while(isspace(str[i])) i++;
|
|
|
|
|
for(k=i;k<i+7;k++) str[k] = tolower(str[k]);
|
|
|
|
|
if(!strncmp(&str[i],"module ",7)) {
|
|
|
|
|
i = i+7;
|
|
|
|
|
while(isspace(str[i])) i++;
|
2003-01-23 07:24:13 +08:00
|
|
|
|
while( str[i]!=' ' && str[i]!='\n' && j<(MODLEN-1) ) module[j++] = tolower(str[i++]);
|
2003-01-20 05:58:50 +08:00
|
|
|
|
module[j] = '\0';
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
int used_modules(char *filename, char modules[][MODLEN])
|
2003-01-20 05:58:50 +08:00
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
2003-01-23 07:24:13 +08:00
|
|
|
|
char module_name[MODLEN];
|
|
|
|
|
int i=0, nused = 0, ok;
|
2003-01-20 05:58:50 +08:00
|
|
|
|
fp=fopen(filename,"r");
|
|
|
|
|
while(fgets(str,BUFSIZ-1,fp)) {
|
2003-01-23 07:24:13 +08:00
|
|
|
|
if( used_name( str, module_name ) ) {
|
|
|
|
|
ok = 1;
|
|
|
|
|
for( i = 0; i < nused; i ++ ) {
|
|
|
|
|
if( ! strcmp( module_name, modules[ i ] ) ) {
|
|
|
|
|
ok = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( ok ) {
|
|
|
|
|
strcpy( modules[ nused ], module_name );
|
|
|
|
|
nused ++;
|
|
|
|
|
}
|
|
|
|
|
if( nused == MAXMOD ) {
|
|
|
|
|
fprintf(stderr,"\n maximum number of modules exceded\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
2003-01-23 07:24:13 +08:00
|
|
|
|
return nused;
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
int defined_modules(char *filename, char modules[][MODLEN])
|
2003-01-20 05:58:50 +08:00
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
2003-01-23 07:24:13 +08:00
|
|
|
|
char module_name[MODLEN];
|
|
|
|
|
int i=0, ndef = 0, ok;
|
|
|
|
|
|
|
|
|
|
fp = fopen(filename,"r");
|
|
|
|
|
|
2003-01-20 05:58:50 +08:00
|
|
|
|
while(fgets(str,BUFSIZ-1,fp)) {
|
2003-01-23 07:24:13 +08:00
|
|
|
|
if( module_unit( str, module_name ) ) {
|
|
|
|
|
ok = 1;
|
|
|
|
|
for( i = 0; i < ndef; i ++ ) {
|
|
|
|
|
if( ! strcmp( module_name, modules[ i ] ) ) {
|
|
|
|
|
ok = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( ok ) {
|
|
|
|
|
strcpy( modules[ ndef ], module_name );
|
|
|
|
|
ndef ++;
|
|
|
|
|
}
|
|
|
|
|
if( ndef == MAXMOD ) {
|
|
|
|
|
fprintf(stderr,"\n maximum number of modules exceded\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
2003-01-23 07:24:13 +08:00
|
|
|
|
return ndef;
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
|
2003-01-20 05:58:50 +08:00
|
|
|
|
int change_extension(char sour[], char dest[], char new_extension[])
|
|
|
|
|
{
|
|
|
|
|
int i,len;
|
|
|
|
|
len = (int)strlen(sour);
|
|
|
|
|
for(i=0; i<len; i++ ) { dest[i] = sour[i]; }
|
|
|
|
|
for(i=len-1; i>0 && dest[i]!= '.' ; i-- ) ;
|
|
|
|
|
dest[i] = '\0';
|
|
|
|
|
strcat(dest,new_extension);
|
|
|
|
|
return strlen(dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc,char *argv[])
|
|
|
|
|
{
|
2003-01-23 07:24:13 +08:00
|
|
|
|
int i, nm, j, k, len, lobj, ntarget, ndepend;
|
2003-01-20 05:58:50 +08:00
|
|
|
|
char object[BUFSIZ];
|
2003-01-23 07:24:13 +08:00
|
|
|
|
FILE * target_list;
|
|
|
|
|
FILE * depend_list;
|
|
|
|
|
char targets[MAXFILES][NAMELEN]; /* list of targets file <20>*/
|
|
|
|
|
char depends[MAXFILES][NAMELEN]; /* list of files upon which the targets may depend <20>*/
|
|
|
|
|
struct module_list * use;
|
|
|
|
|
struct module_list * module;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
target_list = fopen( argv[1], "r" );
|
|
|
|
|
depend_list = fopen( argv[2], "r" );
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
i = 0;
|
|
|
|
|
while( ( fscanf( target_list, "%s", targets[i] ) == 1 ) && ( i < MAXFILES ) ) i++ ;
|
|
|
|
|
ntarget = i;
|
|
|
|
|
use = ( struct module_list * ) malloc( sizeof( struct module_list ) * ntarget );
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while( ( fscanf( depend_list, "%s", depends[i] ) == 1 ) && ( i < MAXFILES ) ) i++ ;
|
|
|
|
|
ndepend = i;
|
|
|
|
|
module = ( struct module_list * ) malloc( sizeof( struct module_list ) * ndepend );
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
for( i = 0; i < ntarget; i++ ) {
|
|
|
|
|
change_extension( targets[i], use[i].filename, ".o");
|
|
|
|
|
use[i].nmodules = used_modules( targets[i], use[i].modules );
|
|
|
|
|
if( DEBUG ) printf("%s %d\n", targets[i], use[i].nmodules );
|
|
|
|
|
}
|
|
|
|
|
if( DEBUG ) printf("ntarget = %d",ntarget);
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < ndepend; i++ ) {
|
|
|
|
|
change_extension( depends[i], module[i].filename, ".o");
|
|
|
|
|
module[i].nmodules = defined_modules( depends[i], module[i].modules );
|
|
|
|
|
if( DEBUG ) printf("%s %d\n", depends[i], module[i].nmodules );
|
|
|
|
|
}
|
|
|
|
|
if( DEBUG ) printf("ndepend = %d",ndepend);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < ntarget; i++ ) {
|
|
|
|
|
printf("\n%s : ", use[i].filename );
|
|
|
|
|
len = strlen( use[i].filename ) + 3;
|
|
|
|
|
for( nm = 0; nm < use[i].nmodules; nm ++ ) {
|
|
|
|
|
for( j = 0; j < ndepend; j++ ) {
|
2003-01-25 00:55:36 +08:00
|
|
|
|
if( strcmp( use[i].filename, module[j].filename ) ) {
|
|
|
|
|
for( k = 0; k < module[j].nmodules; k ++ ) {
|
|
|
|
|
if( DEBUG ) printf("%s %s\n",use[i].modules[nm], module[j].modules[k]);
|
|
|
|
|
if( ! strcmp( use[i].modules[nm], module[j].modules[k] ) ) {
|
|
|
|
|
lobj = strlen( module[j].filename );
|
|
|
|
|
if( (len+lobj) > 70 ) { printf(" \\\n "); len = 4; }
|
|
|
|
|
printf("%s ", module[j].filename );
|
|
|
|
|
len += lobj;
|
|
|
|
|
}
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
2003-01-23 07:24:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
2003-01-23 07:24:13 +08:00
|
|
|
|
printf("\n");
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-23 07:24:13 +08:00
|
|
|
|
|
|
|
|
|
fclose( target_list );
|
|
|
|
|
fclose( depend_list );
|
2003-01-20 05:58:50 +08:00
|
|
|
|
}
|