#!/usr/local/bin/perl -w
#
# listobj.prl
#
# This simple utility generates a macro for make, with a
# list of objects to be created from the c-files in the
# directory.  It is to be used in conjunction with a very
# simple makefile for CODAS libraries.
#
#
#           Eric Firing
#           Tue  96/12/03
#
#   Substitute the following if your perl version does
#   not produce a nice sorted list of *.c files from the
#   <*.c> construct.
#$c_files = `ls *.c`;
#$c_files =~ s/\s+/\n/g;
#$c_files =~ s/.c\n/.o \\\n/g;
#$c_files = join("\n",sort(split(/\n/,$c_files)));
use Cwd;

$dir = cwd();

if (@ARGV) { chdir $ARGV[0]; }


@c_files = <*.c>;
$c_files = join(" \\\n",@c_files);
$c_files =~ s/\.c/\$(OBJ)/g;

open(LST, ">objects.lst") || die "Can't open objects.lst.\n";
print(LST "OBJECTS = ");
print(LST $c_files);
print(LST "\n");
close(LST);

$c_files =~ s/(.*)\$\(OBJ\)/+$1/g;
$c_files =~ tr/\\/&/;
open(RSP, ">tlib.rsp") || die "Can't open tlib.rsp.\n";
print(RSP $c_files);
close(RSP);

chdir $dir;
