+foreach (@ARGV) {
+ ($key,$val) = split('=',$_,2);
+ if ($key eq 'cc') { # Figure out which C compiler we're using
+ my($cc,$ccflags) = split('/',$val,2);
+ my($d_attr);
+ $ccflags = "/$ccflags";
+ if ($ccflags =~s!/DECC!!ig) {
+ $cc .= '/DECC';
+ $cctype = 'decc';
+ $d_attr = 'undef';
+ }
+ elsif ($ccflags =~s!/VAXC!!ig) {
+ $cc .= '/VAXC';
+ $cctype = 'vaxc';
+ $d_attr = 'undef';
+ }
+ elsif (`$val/NoObject/NoList _nla0:/Version` =~ /GNU C version (\S+)/) {
+ $cctype = 'gcc';
+ $d_attr = 'define';
+ print OUT "gccversion='$1'\n";
+ }
+ elsif ($archsufx eq 'VAX' &&
+ # Check exit status too, in case message is turned off
+ ( `$val/NoObject/NoList /prefix=all _nla0:` =~ /IVQUAL/ ||
+ $? == 0x38240 )) {
+ $cctype = 'vaxc';
+ $d_attr = 'undef';
+ }
+ else {
+ $cctype = 'decc';
+ $d_attr = 'undef';
+ }
+ print OUT "vms_cc_type='$cctype'\n";
+ print OUT "d_attribut='$d_attr'\n";
+ print OUT "cc='$cc'\n";
+ if ( ($cctype eq 'decc' and $archsufx eq 'VAX') || $cctype eq 'gcc') {
+ # gcc and DECC for VAX requires filename in /object qualifier, so we
+ # have to remove it here. Alas, this means we lose the user's
+ # object file suffix if it's not .obj.
+ $ccflags =~ s#/obj(?:ect)?=[^/\s]+##i;
+ }
+ $debug = $optimize = '';
+ while ( ($qual) = $ccflags =~ m|(/(No)?Deb[^/]*)|i ) {
+ $debug = $qual;
+ $ccflags =~ s/$qual//;
+ }
+ while ( ($qual) = $ccflags =~ m|(/(No)?Opt[^/]*)|i ) {
+ $optimize = $qual;
+ $ccflags =~ s/$qual//;
+ }
+ $usethreads = ($ccflags =~ m!/DEF[^/]+USE_5005THREADS!i and
+ $ccflags !~ m!/UND[^/]+USE_5005THREADS!i);
+ print OUT "usethreads='",($usethreads ? 'define' : 'undef'),"'\n";;
+ $optimize = "$debug$optimize";
+ print OUT "ccflags='$ccflags'\n";
+ print OUT "optimize='$optimize'\n";
+ $dosock = ($ccflags =~ m!/DEF[^/]+VMS_DO_SOCKETS!i and
+ $ccflags !~ m!/UND[^/]+VMS_DO_SOCKETS!i);
+ print OUT "d_vms_do_sockets=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_socket=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_sockpair=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_gethent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_sethent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_select=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "i_netdb=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "i_niin=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "i_neterrno=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_gethbyname=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_gethbyaddr=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getpbyname=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getpbynumber=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getsbyname=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getsbyport=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_endhent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getpent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_setpent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_endpent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getsent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_setsent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_endsent=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "netdb_name_type=",$dosock ? "'char *'\n" : "'undef'\n";
+ print OUT "netdb_host_type=",$dosock ? "'char *'\n" : "'undef'\n";
+ print OUT "netdb_hlen_type=",$dosock ? "'int'\n" : "'undef'\n";
+ print OUT "d_gethostprotos=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getnetprotos=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getservprotos=",$dosock ? "'define'\n" : "'undef'\n";
+ print OUT "d_getprotoprotos=",$dosock ? "'define'\n" : "'undef'\n";
+
+ if ($dosock and $cctype eq 'decc' and $ccflags =~ /DECCRTL_SOCKETS/) {
+ print OUT "selecttype='fd_set'\n";
+ print OUT "d_getnbyaddr='define'\n";
+ print OUT "d_getnbyname='define'\n";
+ print OUT "d_getnent='define'\n";
+ print OUT "d_setnent='define'\n";
+ print OUT "d_endnent='define'\n";
+ print OUT "netdb_net_type='long'\n";
+ }
+ else {
+ print OUT "selecttype='int'\n";
+ print OUT "d_getnybname='undef'\n";
+ print OUT "d_getnybaddr='undef'\n";
+ print OUT "d_getnent='undef'\n";
+ print OUT "d_setnent='undef'\n";
+ print OUT "d_endnent='undef'\n";
+ print OUT "netdb_net_type='undef'\n";
+ }
+
+ if ($cctype eq 'decc') {
+ $rtlhas = 'define';
+ print OUT "useposix='true'\n";
+ ($ccver,$vmsver) = `$cc/VERSION` =~ /V(\S+) on .*V(\S+)$/;
+ # Best guess; the may be wrong on systems which have separately
+ # installed the new CRTL.
+ if ($ccver >= 5.2 and $vmsver >= 7) { $rtlnew = 'define'; }
+ else { $rtlnew = 'undef'; }
+ }
+ else { $rtlhas = $rtlnew = 'undef'; print OUT "useposix='false'\n"; }
+ foreach (qw[ d_stdstdio d_stdio_ptr_lval d_stdio_cnt_lval d_stdiobase
+ d_locconv d_setlocale i_locale d_mbstowcs d_mbtowc
+ d_wcstombs d_wctomb d_mblen d_mktime d_strcoll d_strxfrm ]) {
+ print OUT "$_='$rtlhas'\n";
+ }
+ print OUT "d_stdio_ptr_lval_sets_cnt='undef'\n";
+ print OUT "d_stdio_ptr_lval_nochange_cnt='undef'\n";
+ foreach (qw[ d_gettimeod d_uname d_truncate d_wait4 d_index
+ d_pathconf d_fpathconf d_sysconf d_sigsetjmp ]) {
+ print OUT "$_='$rtlnew'\n";
+ }
+ next;
+ }
+ elsif ($key eq 'exe_ext') {
+ my($nodot) = $val;
+ $nodot =~ s!\.!!;
+ print OUT "so='$nodot'\ndlext='$nodot'\n";
+ }
+ elsif ($key eq 'obj_ext') { print OUT "dlobj='dl_vms$val'\n"; }
+ print OUT "$key='$val'\n";
+}
+
+# Are there any other logicals which TCP/IP stacks use for the host name?
+$myname = $ENV{'ARPANET_HOST_NAME'} || $ENV{'INTERNET_HOST_NAME'} ||
+ $ENV{'MULTINET_HOST_NAME'} || $ENV{'UCX$INET_HOST'} ||
+ $ENV{'TCPWARE_DOMAINNAME'} || $ENV{'NEWS_ADDRESS'};
+if (!$myname) {
+ ($myname) = `hostname` =~ /^(\S+)/;
+ if ($myname =~ /IVVERB/) {
+ warn "Can't determine TCP/IP hostname" if $dosock;
+ $myname = '';
+ }
+}
+$myname = $ENV{'SYS$NODE'} unless $myname;
+($myhostname,$mydomain) = split(/\./,$myname,2);
+print OUT "myhostname='$myhostname'\n" if $myhostname;
+if ($mydomain) {
+ print OUT "mydomain='.$mydomain'\n";
+ print OUT "perladmin='$cf_by\@$myhostname.$mydomain'\n";
+ print OUT "cf_email='$cf_by\@$myhostname.$mydomain'\n";
+}
+else {
+ print OUT "perladmin='$cf_by'\n";
+ print OUT "cf_email='$cf_by'\n";
+}
+chomp($hwname = `Write Sys\$Output F\$GetSyi("HW_NAME")`);
+$hwname = $archsufx if $hwname =~ /IVKEYW/; # *really* old VMS version
+print OUT "myuname='VMS $myname $osvers $hwname'\n";
+
+# Before we read the C header file, find out what config.sh constants are
+# equivalent to the C preprocessor macros
+if (open(SH,"${outdir}config_h.SH")) {
+ while (<SH>) {
+ next unless m%^#(?!if).*\$%;
+ s/^#//; s!(.*?)\s*/\*.*!$1!;
+ my(@words) = split;
+ $words[1] =~ s/\(.*//; # Clip off args from macro
+ # Did we use a shell variable for the preprocessor directive?
+ if ($words[0] =~ m!^\$(\w+)!) { $pp_vars{$words[1]} = $1; }
+ if (@words > 2) { # We may also have a shell var in the value
+ shift @words; # Discard preprocessor directive
+ my($token) = shift @words; # and keep constant name
+ my($word);
+ foreach $word (@words) {
+ next unless $word =~ m!\$(\w+)!;
+ $val_vars{$token} = $1;
+ last;
+ }
+ }
+ }
+ close SH;
+}
+else { warn "Couldn't read ${outdir}config_h.SH: $!\n"; }
+$pp_vars{UNLINK_ALL_VERSIONS} = 'd_unlink_all_versions'; # VMS_specific
+
+# OK, now read the C header file, and retcon statements into config.sh