#! /usr/local/bin/perl5 -w # sim: Perl script like 'sc' for LUND Simula v4.15 # ====== # # - Allows for Compile, Link & GO (inspired by 'cc' and 'sc') # - Simplifies the use of OBJECT (class) LIBRARIES # - version for Sun & SGI tested on NIL and DERBY # # Jean Vaucher (jan. 1996) # ( Dag Langmyhr, IFI: author of sc which I converted for sim # and from which I learned PERL ) # ----------------------------------------------------------------- $Prog = "sim"; $Version = "v4"; # Useful constants: $False = ""; $True = 1; # Standard utilities $Uname = "uname"; $C_compiler = "cc"; $Assembler = "as"; $Linker = "ld"; # Current architecture and operating system: $OSname = `$Uname -s`; chop($OSname); # ===================================================== # Directories # ===================================================== # Universite de Montreal local set-up # for JSP & IRO # ===================================================== $LUND = "/usr/local/simulabin" ; # Lund HOME for librairies $Lund_compiler = "$LUND/simula"; if ($OSname eq "SunOS") { $INFO = "/home/nil/vaucher/simulatools"; # Info dept. HOME } elsif ($OSname eq "IRIX") { $INFO = "/usr/local/simulatools"; # Info dept. HOME $Symbolic = $True ; } # Global variables: $Errors = 0; $Verbosity = 1; $Run_opt = $True; # And now: the main program: @Sim_files = () ; @O_files = () ; @Ld_params = () ; &Scan_params; &Done if $Errors; if ( $Verbosity >= 3 ) { print "$Prog: OSname=$OSname, Version=$Version .\n"; print "Sim_files=", @Sim_files, ", O_files=", @O_files, ", Other_files=", @C_files, @Ld_params, ".\n" ; } ; &Compile; &Done if $Errors || $Compile_only; $Sim_prog = &basename((@Sim_files,@C_files,@O_files)[0]) unless $Sim_prog; &Link; &Done if $Errors; push(@Temp_files, $Sim_prog) if $Run_opt; &Check_system_prog; &Run if $Run_opt; &Done; #================================= # Global parameters # # $Check_compile # $Compile_only # $Debug # $Verbosity # $Run_opt # @L_array: list of -L paths # @I_array: list of -I lib names # @Ld_params: stuff to pass on to 'ld' (-Lxxx -lxxx yy.o zz.a zz.so) # $Link_Lund # $Link_Diro # $X_libs # $Socket_libs # @Sim_files, # @C_files # @O_files # # $Sim_prog # # @Ld_params #================================= # Scan_params () # ----------- # Scan the parameter list, and place the parameters and options in # suitable global variables. # sub Scan_params { PARAM: while (@ARGV) { $_ = shift @ARGV; print("Parameter: $_ \n") if $Verbosity >1; /^-C$/ && do { $Check_compile = $True; next PARAM; }; /^-c$/ && do { $Compile_only = $True; next PARAM; }; /^-d$/ && do { $Debug = $True; if ( $Verbosity < 2 ) { $Verbosity = 2; } next PARAM; }; (/^-help$/ || /^-h$/) && do { &Give_help; next PARAM; }; /^-L=/ && do { s/^-L=//; push( @L_array, split(/:/,$_) ); next PARAM; }; /^-I=/ && do { s/^-I=//; push( @I_array, split(/:/,$_) ); next PARAM; }; if (/^-L$/ || /^-l$/ ) { $Temp = $_; push(@Ld_params, $Temp . shift(@ARGV) ); next PARAM; }; if (/^-L/ || /^-l/ ) { push(@Ld_params, $_); next PARAM; }; # Class library options /^-simwin$/ && do { $X_libs = $True; }; /^-simxlib$/ && do { $X_libs = $True; }; /^-simsocket$/ && do { $$Socket_libs = $True; }; /^-all$/ && do { $Link_Lund = $True; push( @I_array, "simxlib","simsocket","simioprocess", "libsim","simlib"); $X_libs = $True; $Socket_libs = $True; next PARAM; }; if ( /^-simlib$/ || /^-libsim$/ || /^-simioprocess$/ || /^-simsocket$/ || /^-simxlib$/ ) { $Link_Lund = $True; s/^-// ; push( @I_array, $_); next PARAM; }; if ( /^-diro$/ || /^-simwin$/) { $Link_Diro = $True; next PARAM; }; /^-o$/ && do { $Sim_prog = shift @ARGV; next PARAM; }; /^-q/ && do { $Verbosity = 0; next PARAM; }; if (/^-v$/ || /^-vv$/) { $Verbosity = 3; next PARAM; }; /^-nr$/ && do { $Run_opt = $False; next PARAM; }; /^-r$/ && do { $Run_opt = $True; next PARAM; }; /^-/ && do { print "$Prog: Unknown option $_ ignored.\n"; next PARAM; }; &Note_filename($_); }; #while if (@Sim_files + @C_files + @O_files == 0) { $Errors++; print "Usage: $Prog [option...] file-name...\n"; print "Try `$Prog -help' for more information.\n\n"; } } # Scan_params # Note_filename (File_name) # ------------- # Check that File_name (or File_name.sim or File_name.cim) exists, # and save name in the proper list. # sub Note_filename { if (/\.sim$/) { s/\.sim$//; push(@Sim_files, $_); } elsif (-r ($_ . ".sim")) { push(@Sim_files, $_ ); } elsif (/\.c$/ || /\.s$/) { push(@C_files, $_); } elsif (/\.o$/) { push(@O_files, $_); } elsif (/\.a$/ || /\.so$/) { push(@Ld_params, $_ ); } else { print "$Prog: Unknown file type $_ ignored.\n"; } } # Note_filename # basename (File_name) # -------- # Find the base part of the file name (no /-s and no final .xxx). # sub basename { local($_) = $_[0]; m|/$| && chop; s|.*/||; s|(.+)\..*|$1|; # s|(.+)\..*|\1|; .... old line $_; } # Give_help () # --------- # Give the user information on how to use this program. # Exit afterwards. # sub Give_help { print "Usage: $Prog [option...] file-name...\n\n"; print "The following options are available: -c Omit linking...just compile. -C Compile only the files that really need recompiling. -d Include the debugger. -help Print this help message and exit. -o file Name of compiled program file. -q Make $Prog more quiet. -v State version and make $Prog more verbose. -r Run the program and remove temp. files (default). -nr Don't run the program. Object Librairies: ------------------ -diro Include the basic DIRO object libraries. -simwin Include the 'windowtools' library. -simlib Include the 'simlib' library (Lund). -libsim Include the 'libsim' library (Lund). -simsocket ...other -simioprocess libraries -simxlib from Lund -all Include all the Lund libraries. Linker options: -l get external modules from 'lib.a' or 'lib.so' -L look in for .a and .so libraries Search Paths: -L=path1:path2.... -I=lib1:lib2... These 'simcomp' mechanisms are supported and extended to linking. SIMULA DOCUMENTATION: Don't forget to use man & simman ! % man simula cim sc % simman simula % simman simlib "; &Done; } # Give_help # Compile () # ------- # Compile the various files. sub Compile { local($F, $FB); local(@Options); local($Must_compile) = ! $Check_compile; local($FC, $Fsim, $Fo, $FoC, $Fatr, $FatrC); if ($Verbosity == 0) { push(@Options, "-w"); } elsif ($Verbosity > 1) { push(@Options, "-f"); } if ($Verbosity > 2) { push(@Options, "-p"); } if ($Symbolic) { push(@Options, "-s","-n"); }; @List = @L_array; push(@List, "$LUND") if $Link_Lund ; push(@List, "$INFO/lund") if $Link_Diro ; if (@List>0) { $LPATH = join(":", @List); push(@Options,"-L=$LPATH"); } @List = @I_array; push(@List, "diro") if $Link_Diro ; if (@List + @L_array >0) { $IPATH = join(":", @List); push(@Options,"-I=$IPATH:"); } foreach $F (reverse @Sim_files) { $FB = &basename($F) ; # checking timestamps to avoid compilations $Fsim = $FB . ".sim"; $Fo = $FB . ".o"; $Fatr = $FB . ".atr"; $Must_compile = $True if (! -e $Fo || ! -e $Fatr); if (! $Must_compile) { $FC = -C $Fsim; $FoC = -C $Fo; $FatrC = -C $Fatr; $Must_compile = ($FC < $FoC || $FC < $FatrC); printf("%s: Timestamps %s:%.4f, %s:%.4f, %s:%.4f\n", $Prog, $Fsim, $FC, $Fo, $FoC, $Fatr, $FatrC) if $Verbosity >= 3; }; if ($Must_compile || $Debug) { if ($Verbosity>2) { print "Compiling: simula @Options $F\n" ; } elsif ($Verbosity>0) { print "Compiling: $F\n" ; } ; if ( system($Lund_compiler, @Options, $F) ) { print "Compile Errors\n"; $Errors++ ; } push(@Temp_files, &basename($F) . ".o") unless $Compile_only || $Check_compile; push(@Temp_files, &basename($F) . ".atr") unless $Compile_only || $Check_compile || $Debug; if ($Symbolic && $Errors == 0) { @As_opts = ("-o", $FB . ".o", $FB . ".s"); print "Assembling: @As_opts\n" if $Verbosity>0; system($Assembler, @As_opts); unlink($FB . ".s"); }; } else { print "Compilation of $F not necessary\n" if $Verbosity>0; }; }; foreach $F (@Sim_files) { push(@O_files, &basename($F) . ".o"); } &Compile_others if @C_files; } # Compile # Compile_others () # -------------- # Compile all the non-Simula files. sub Compile_others { local($F); print "$Prog: Compiling: cc -c @C_files\n" if $Verbosity>0; system($C_compiler, "-c", @C_files); foreach $F (@C_files) { push(@Temp_files, &basename($F) . ".o") unless $Compile_only || $Check_compile; }; } # Compile_others # Link () # --------- # Link the files produced by the Lund compiler. sub Link { local (@Options); if ($OSname eq "IRIX") { @Options = ("-elf", "-_SYSTYPE_SVR4", "-require_dynamic_link", "_rld_new_interface", "-no_unresolved", "-Wx,-G", "0", "-call_shared", "-g0", "-KPIC", "-nocount", "/usr/lib/crt1.o"); } elsif ($OSname eq "SunOS") { @Options = ("-dy", "-s", "/usr/local/lang/SUNWspro/SC3.0.1/lib/crt1.o"); } push(@Options, "-o", "$Sim_prog"); push(@Options, "-count") if $OSname eq "IRIX" ; push(@Options, @O_files); push(@Options, @Ld_params); # -L -l xx.a yy.so parameters push(@Options, "-nocount") if $OSname eq "IRIX" ; push(@Options, "-L$LUND/lib"); if ( $Link_Diro ) { push(@Options, "-L$INFO/lund"); push(@Options, "-ldiro"); } ; while (@L_array) { $_ = shift @L_array; push(@Options, "-L$_") ; } ; while (@I_array) { $_ = shift @I_array; push(@Options, "-l$_") ; } ; push(@Options, "-L/usr/openwin/lib", "-lX11") if ($X_libs) ; push(@Options, "-lsocket", "-lnsl") if ($Socket_libs); push(@Options, "-lsimdeb") if $Debug; push(@Options, "-lsimula", "-lc") ; push(@Options, "/usr/lib/crtn.o") if $OSname eq "IRIX" ; if (! $Errors) { if ($Verbosity>2) { print "Linking: $Linker @Options\n"; } elsif ($Verbosity>0) { print "Linking: @O_files @Ld_params\n"; } system($Linker, @Options) && $Errors++; } } # Run () # --- # Run the compiled and linked program. sub Run { local(@Command) = ("./$Sim_prog"); push(@Command, "-d") if $Debug ; print "Executing: @Command \n\n" if $Verbosity > 0; system(@Command); } # Check_system_prog () # ----------------- # Check if the user has chosen a program name that is also a UNIX program. sub Check_system_prog { local($Fullname); foreach $F (split(':',$ENV{"PATH"})) { $Fullname = "$F" ? "$F/$Sim_prog" : "$Sim_prog"; print "$Prog: Checking $Fullname...\n" if $Verbosity>=3; if (-x "$Fullname") { return if "$F" eq "" || "$F" eq "."; print "$Prog: Warning: Your program name `$Sim_prog' is also the name of a UNIX program;\n"; print " To run it, write `./$Sim_prog'.\n"; return; } } } # Done () # ---- # Delete all temporary files and exit with status value. sub Done { if (@Temp_files) { print "\nRemoving: @Temp_files\n" if $Verbosity > 0; unlink(@Temp_files); } exit $Errors; }