#!/usr/bin/perl -w use English; use strict; use Data::Dumper; #- Get list of all files from ./libntp/ opendir(DIR, "./libntp"); my @cfiles = grep(/\.c$/, readdir(DIR)); closedir(DIR); #- Read ./libntp/Makefile my $makelibntp = "./libntp/Makefile"; open(DAT, "<$makelibntp") || die("Could not open $makelibntp"); my @make_list = ; close(DAT); print Dumper \@cfiles; foreach my $cfile (@cfiles){ $cfile =~ s{ # Substitue... \.c # ...a '.c' } {}gxms; # Raplace it with a single space chomp($cfile); #- Skip this file to avoid "multiple definition" errors next if( $cfile eq "systime_s" ); &prepareMakefile($makelibntp, \@make_list, $cfile); system("cd ./libntp/; make"); my $answer = &promptUser("Continue?", "yes/no"); if( $answer eq "no"){ print "Exit.\n"; exit(0); } else{ print "Continue...\n"; } } system("make clean; make"); exit(0); ###################### END OF MAIN ##################### sub promptUser { # two possible input arguments - $promptString, and $defaultValue # make the input arguments local variables. my ($promptString,$defaultValue) = @_; # if there is a default value, use the first print statement; if # no default is provided, print the second string. if ($defaultValue) { print $promptString, "[", $defaultValue, "]: "; } else { print $promptString, ": "; } $| = 1; # force a flush after our print my $input = ; # get the input from STDIN (presumably the keyboard) # remove the newline character from the end of the input the user gave us chomp($input); # if we had a $default value, and the user gave us input, then # return the input; if we had a default, and they gave us no # no input, return the $defaultValue. # # if we did not have a default value, then just return whatever # the user gave us. if they just hit the key, # the calling routine will have to deal with that. if ("$defaultValue") { return $input ? $input : $defaultValue; # return $input if it has a value } else { return $input; } } sub prepareMakefile() { my ($make_file, $make_aref, $cfile) = @_; my $make_file_new = "./libntp/Makefile_new"; open(DAT, ">$make_file_new"); foreach my $makeline (@$make_aref){ if( $makeline =~ /^PROG\s+=\s+\w+/ ){ print DAT "PROG = $cfile\n"; } else{ print DAT $makeline; } } close(DAT); system("mv $make_file_new $make_file"); }