#! /usr/bin/tcsh -f
# 
# Check makeisdc1.in agains ISDC environment VERSION file
#

cat >! tmp.nawk<<EOF
/^C_EXEC_1_LIBRARIES/ { 
    go_on=1; 
    printf("%s ","makefiles");
    printf("%s ","templates");
    printf("%s ","templates_v1");
    printf("%s ","isdc_errors");
    while (go_on) { 
	start = index(\$0,"-l"); 
	end   = index(\$0,"\\\\"); 
	if (0==end) {  
	    go_on = 0; 
	    end = length(\$0)+1; 
	} 
	libstring = substr(\$0,start,end-start); 
	if (index(libstring,"LAST_LIBS")) { 
	    sub("\\\\\$\\\{LAST_LIBS\\\}","-lreadline",libstring);
	}
	n_libs=split(libstring,libs,"-l"); 
	for (i_lib=1;i_lib<=n_libs;i_lib++) { 
	    printf("%s ",libs[i_lib]); 
	    if (index(libs[i_lib],"cfitsio")) { printf("%s ","cfortran"); }
	    if (index(libs[i_lib],"dal3aux")) { printf("%s ","sla_c"); }
	    if (index(libs[i_lib],"dal3hk")) { printf("%s ","hk_list"); }
	} 
	getline; 
    } 
} 
EOF

set libraries = (`nawk -f tmp.nawk makeisdc1.in`)
rm tmp.nawk
 
touch tmp.grep
foreach lib ($libraries)
    grep "^$lib " $ISDC_ENV/VERSION | cut -d'|' -f1 >> tmp.grep
end
sort tmp.grep | uniq
rm tmp.grep


