#!/usr/local/perl # $HopeName: MMQA_harness!script:compile(trunk.20) $ # # provides subroutines to compile or compile and link # tests and test libraries. # # it should work at least on SunOS, Solaris and NT # 1; sub debug { local ($text) = @_; if ($DEBUG_INFO eq "on") { print $text."\n"; } } sub compiler_settings { if ($PLATFORM =~ "^nt_") { &settings_nt(); if ($PLATFORM =~ "^nt_x86_cap") { &settings_nt_cap(); } elsif ($PLATFORM =~ "^nt_x86_coff") { &settings_nt_coff(); } } elsif ($PLATFORM =~ "^so|^linux") { &settings_unix(); if ($PLATFORM =~ "^sos8gp") { &settings_gprof(); } } elsif ($PLATFORM =~ "::unix") { &logcomment("I don't know anything specific about $PLATFORM --"); &logcomment("using generic unix/gcc settings."); &settings_unix(); } else { die "Sorry: I don't know how to use ".$PLATFORM."\n"; } } sub settings_nt { $dirsep = "\\"; $cc_command = "cl"; $cc_opts = "/nologo /DWIN32 /D_WINDOWS /W3 /Zi /Oy- /DMMQA_VERS_$INTERFACE_VERSION"; $cc_link = "$obj_dir/platform.obj"; $cc_link_opts = "/link /NODEFAULTLIB:LIBCMT /debugtype:both /pdb:none /debug:full"; $cc_include = "/I$testlib_dir /I$MPS_INCLUDE_DIR"; $cc_conly = "/c"; $cc_obj = "/Fo"; $cc_exe = "/Fe"; $cc_objandexe = 1; $obj_suffix = ".obj"; $try_command = ""; $catcommand = "cat"; $comwrap = "\""; $comwrapend = "\""; $stdout_red = ">"; $err_red = "2>"; $stdout_dup = "| $script_dir/ntx86bin/tee.exe"; } sub settings_nt_cap { $cc_opts = "$cc_opts /Gh"; $cc_link = "$cc_link CAP.lib"; $cc_link_opts = "/link /NODEFAULTLIB:LIBCMT /debugtype:coff /debug:mapped,partial"; } sub settings_nt_coff { $cc_link_opts = "/link /NODEFAULTLIB:LIBCMT /debugtype:coff /debug:full"; } sub settings_unix { $dirsep = "/"; $cc_link = "$obj_dir/platform.o -lm"; $cc_link_opts = "-z muldefs"; $cc_command = "gcc"; $cc_opts = "-ansi -pedantic -Wall -Wstrict-prototypes ". "-Winline -Waggregate-return -Wnested-externs -Wcast-qual ". "-Wshadow -Wmissing-prototypes -Wcast-align ". "-O -g -ggdb3 -DMMQA_VERS_$INTERFACE_VERSION"; $cc_include = "-I$testlib_dir -I$MPS_INCLUDE_DIR"; $cc_conly = "-c"; $cc_obj = "-o "; $cc_exe = "-o "; $cc_objandexe = 0; $obj_suffix = ".o"; $try_command = "sh -c "; $catcommand = "cat"; $comwrap = "sh -c \"ulimit -c 0; "; $comwrapend = "\""; $stdout_red = ">"; $err_red = "2>"; $stdout_dup = "| tee"; } sub settings_gprof { $cc_opts = "-pg ".$cc_opts; } sub mysystem { local ($command) = @_; $command =~ s/(\S)\//$1$dirsep/g; &debug("SYSTEM >>$command<<"); system($command); } sub log_system { local ($command, $output, $logfile, $time0, $time1) = @_; $std_log = "$obj_dir/std_log.log"; $err_log = "$obj_dir/err_log.log"; &debug("LOG SYSTEM:\n c>$command\n o>$output\n l>$logfile"); $time0 = time; if ($logfile ne "no") { if ($output eq "no") { &mysystem("$comwrap$command$comwrapend $stdout_red $std_log $err_red $err_log"); } else { &mysystem("$comwrap$command$comwrapend $err_red $err_log $stdout_dup $std_log"); # there's no way to duplicate std_err as far as I know. &mysystem("$catcommand $err_log"); } &mysystem("$catcommand $std_log $err_log $stdout_red $logfile"); } else { if ($output eq "no") { die "Silly attempt to run test and ignore results.\n"; } else { &mysystem("$comwrap$command$comwrapend"); } } $time1 = time; $testtotaltime = $time1-$time0; } sub compile { local($srcfile, $objfile) = @_; &compiler_settings; $command = "$cc_command $cc_conly $cc_opts $cc_obj$objfile ". "$srcfile $cc_include"; if (&mysystem($command)) { return 0; } else { return 1; } } sub compile_and_link { local($srcfile, $exefile, $linkfiles, $objfile) = @_; &compiler_settings; unless ($linkfiles) {$linkfiles =""}; $linkfiles = " ".$linkfiles; $linkfiles =~ s/ +(\S)/ $obj_dir\/$1/g; $linkfiles = $linkfiles." "; $linkfiles =~ s/\.o /$obj_suffix /g; $objfile = "$obj_dir/tmp_obj$obj_suffix"; if ($cc_objandexe) { $comobjfspec = "$cc_obj$objfile " } else { $comobjfspec = "" } $command = "$cc_command $cc_opts $comobjfspec$cc_exe$exefile ". "$srcfile $linkfiles $MPS_LINK_OBJ $cc_link $cc_include $cc_link_opts"; if (&mysystem($command)) { return 0; } else { return 1; } }