1$ ! vms/vmsbuild.com -- compile and link NetHack 3.6.* [pr] 2$ version_number = "3.6.6" 3$ ! $NHDT-Date: 1557701518 2019/05/12 22:51:58 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.23 $ 4$ ! Copyright (c) 2018 by Robert Patrick Rankin 5$ ! NetHack may be freely redistributed. See license for details. 6$ ! 7$ ! usage: 8$ ! $ set default [.src] !or [-.-.src] if starting from [.sys.vms] 9$ ! $ @[-.sys.vms]vmsbuild [compiler-option] [link-option] [cc-switches] - 10$ ! [linker-switches] [interface] 11$ ! options: 12$ ! compiler-option : either "VAXC", "DECC" or "GNUC" or "" !default VAXC 13$ ! link-option : either "SHARE[able]" or "LIB[rary]" !default SHARE 14$ ! cc-switches : optional qualifiers for CC (such as "/noOpt/Debug") 15$ ! linker-switches : optional qualifers for LINK (/Debug or /noTraceback) 16$ ! interface : "TTY" or "CURSES" or "TTY+CURSES" or "CURSES+TTY" 17$ ! notes: 18$ ! If the symbol "CC" is defined, compiler-option is not used (unless it 19$ ! is "LINK"). 20$ ! The link-option refers to VAXCRTL (C Run-Time Library) handling; 21$ ! to specify it while letting compiler-option default, use "" as 22$ ! the compiler-option. 23$ ! To re-link without compiling, use "LINK" as special 'compiler-option'; 24$ ! to re-link with GNUC library, 'CC' must begin with "G" (or "g"). 25$ ! All options are positional; to specify a later one without an earlier 26$ ! one, use "" in the earlier one's position, such as 27$ ! $ @[-.sys.vms]vmsbuild "" "" "" "" "TTY+CURSES" 28$ 29$ decc_dflt = f$trnlnm("DECC$CC_DEFAULT") 30$ j = (decc_dflt.nes."") .and. 1 31$ vaxc_ = "CC" + f$element(j,"#","#/VAXC") + "/NOLIST/OPTIMIZE=NOINLINE" 32$ decc_ = "CC" + f$element(j,"#","#/DECC") + "/PREFIX=ALL/NOLIST" 33$ gnuc_ = "GCC" 34$ if f$type(gcc).eqs."STRING" then gnuc_ = gcc 35$ gnulib = "gnu_cc:[000000]gcclib/Library" !(not used w/ vaxc) 36$ ! common CC options (/obj=file doesn't work for GCC 1.36, use rename instead) 37$ c_c_ = "/INCLUDE=[-.INCLUDE]" 38$ veryold_vms = f$extract(1,1,f$getsyi("VERSION")).eqs."4" - 39 .and. f$extract(3,3,f$getsyi("VERSION")).lts."6" 40$ if veryold_vms then c_c_ = c_c_ + "/DEFINE=(""VERYOLD_VMS"")" 41$ axp = (f$getsyi("CPU").ge.128) !f$getsyi("ARCH_NAME").eqs."Alpha" 42$ ! miscellaneous setup 43$ ivqual = %x00038240 !DCL-W-IVQUAL (used to check for ancient vaxc) 44$ abort := exit %x1000002A 45$ cur_dir = f$environment("DEFAULT") 46$ vmsbuild = f$environment("PROCEDURE") 47$ ! validate first parameter 48$ p1 := 'p1' 49$ if p1.eqs."" .and. (axp .or. decc_dflt.eqs."/DECC") then p1 = "DECC" 50$ o_VAXC = 0 !(c_opt substring positions) 51$ o_DECC = 5 52$ o_GNUC = 10 53$ o_LINK = 15 54$ o_SPCL = 20 55$ c_opt = f$locate("|"+p1, "|VAXC|DECC|GNUC|LINK|SPECIAL|") !5 56$ if (c_opt/5)*5 .eq. c_opt then goto p1_ok 57$ copy sys$input: sys$error: !p1 usage 58%first arg is compiler option; it must be one of 59 "VAXC" -- use VAX C to compile everything 60 or "DECC" -- use DEC C to compile everything 61 or "GNUC" -- use GNU C to compile everything 62 or "LINK" -- skip compilation, just relink nethack.exe 63 or "SPEC[IAL]" -- just compile and link lev_comp.exe 64 or "" -- default operation (VAXC unless 'CC' is defined) 65 66Note: if a DCL symbol for CC is defined, "VAXC" and "GNUC" are no-ops. 67 If the symbol value begins with "G" (or "g"), then the GNU C 68 library will be included in all link operations. Do not rebuild 69 lev_comp with "SPECIAL" unless you have a CC symbol setup with 70 the proper options. 71$ abort 72$p1_ok: 73$ ! validate second parameter 74$ p2 := 'p2' 75$ l_opt = f$locate("|"+p2, "|SHAREABLE|LIBRARY__|NONE_____|") !10 76$ if (l_opt/10)*10 .eq. l_opt then goto p2_ok 77$ copy sys$input: sys$error: !p2 usage 78%second arg is C run-time library handling; it must be one of 79 "SHAREABLE" -- link with SYS$SHARE:VAXCRTL.EXE/SHAREABLE 80 or "LIBRARY" -- link with SYS$LIBRARY:VAXCRTL.OLB/LIBRARY 81 or "NONE" -- explicitly indicate DECC$SHR 82 or "" -- default operation (use shareable image) 83 84Note: for MicroVMS 4.x, "SHAREABLE" (which is the default) is required. 85 Specify "NONE" if using DEC C with a CC symbol overriding 1st arg. 86$ abort 87$p2_ok: 88$ ! start from a known location -- [.sys.vms], then move to [-.-.src] 89$ set default 'f$parse(vmsbuild,,,"DEVICE")''f$parse(vmsbuild,,,"DIRECTORY")' 90$ set default [-.-.src] !move to source directory 91$ ! compiler setup; if a symbol for "CC" is already defined it will be used 92$ if f$type(cc).eqs."STRING" then goto got_cc 93$ cc = vaxc_ !assume "VAXC" requested or defaulted 94$ if c_opt.eq.o_GNUC then goto chk_gcc !explicitly invoked w/ "GNUC" option 95$ if c_opt.eq.o_DECC then cc = decc_ 96$ if c_opt.ne.o_VAXC then goto got_cc !"SPEC" or "LINK", skip compiler check 97$ ! we want to prevent function inlining with vaxc v3.x (/opt=noinline) 98$ ! but we can't use noInline with v2.x, so need to determine version 99$ set noOn 100$ msgenv = f$environment("MESSAGE") 101$ set message/noFacil/noSever/noIdent/noText 102$ cc/noObject _NLA0:/Include=[] !strip 'noinline' if error 103$ sts = $status 104$ if sts then goto reset_msg !3.0 or later will check out OK 105$ ! must be dealing with vaxc 2.x; ancient version (2.2 or earlier) 106$ ! can't handle /include='dir', needs c$include instead 107$ cc = cc - "=NOINLINE" - ",NOINLINE" - "NOINLINE," 108$ if sts.ne.IVQUAL then goto reset_msg 109$ define/noLog c$include [-.INCLUDE] 110$ c_c_ = "/DEFINE=(""ANCIENT_VAXC"")" 111$ if veryold_vms then c_c_ = c_c_ - ")" + ",""VERYOLD_VMS"")" 112$reset_msg: 113$ set message 'msgenv' 114$ set On 115$ goto got_cc 116$ ! 117$chk_gcc: 118$ cc = gnuc_ 119$ ! old versions of gcc-vms don't have <varargs.h> or <stdarg.h> available 120$ c_c_ = "/DEFINE=(""USE_OLDARGS"")" 121$ if veryold_vms then c_c_ = c_c_ - ")" + ",""VERYOLD_VMS"")" 122$ if veryold_vms then goto chk_gas !avoid varargs & stdarg 123$ if f$search("gnu_cc_include:[000000]varargs.h").nes."" then - 124 c_c_ = "/DEFINE=(""USE_VARARGS"")" 125$ if f$search("gnu_cc_include:[000000]stdarg.h").nes."" then - 126 c_c_ = "/DEFINE=(""USE_STDARG"")" 127$chk_gas: 128$ ! test whether this version of gas handles the 'const' construct correctly 129$ gas_chk_tmp = "sys$scratch:gcc-gas-chk.tmp" 130$ if f$search(gas_chk_tmp).nes."" then delete/noconfirm/nolog 'gas_chk_tmp';* 131$ gas_ok = 0 !assume bad 132$ on warning then goto skip_gas 133$ define/user/nolog sys$error 'gas_chk_tmp' 134$ mcr gnu_cc:[000000]gcc-as sys$input: -o _NLA0: 135$DECK 136.const 137.comm dummy,0 138.const 139.comm dummy,0 140$EOD 141$ gas_ok = 1 !assume good 142$ if f$search(gas_chk_tmp).eqs."" then goto skip_gas 143$ ! if the error file is empty, gas can deal properly with const 144$ gas_ok = f$file_attrib(gas_chk_tmp,"EOF") .eq. 0 145$ delete/noconfirm/nolog 'gas_chk_tmp';* 146$skip_gas: 147$ on warning then continue 148$ if .not.gas_ok then c_c_ = c_c_ - ")" + ",""const="")" 149$ c_c_ = "/INCLUDE=[-.INCLUDE]" + c_c_ 150$ ! 151$got_cc: 152$ cc = cc + c_c_ !append common qualifiers 153$ if p3.nes."" then cc = cc + p3 !append optional user preferences 154$ g := 'f$extract(0,1,cc)' 155$ if g.eqs."$" then g := 'f$extract(1,1,cc)' !"foreign" gcc 156$ if f$edit(f$extract(1,1,cc),"UPCASE").eqs."E" then g := X !GEMC 157$ if g.nes."G" .and. c_opt.ne.o_GNUC then gnulib = "" 158$ ! linker setup; if a symbol for "LINK" is defined, we'll use it 159$ if f$type(link).nes."STRING" then link = "LINK/NOMAP" 160$ if p4.nes."" then link = link + p4 !append optional user preferences 161$ if f$trnlnm("F").nes."" then close/noLog f 162$ create crtl.opt !empty 163$ open/Append f crtl.opt 164$ write f "! crtl.opt" 165$ if c_opt.eq.o_DECC .or. l_opt.eq.20 166$ then $! l_opt=="none", leave crtl.opt empty (shs$share:decc$shr.exe/Share) 167$ else 168$ ! gnulib order: vaxcrtl.exe+gcclib.olb vs gcclib.olb+vaxcrtl.olb 169$ if l_opt.eq.0 then write f "sys$share:vaxcrtl.exe/Shareable" 170$ if gnulib.nes."" then write f gnulib 171$ if l_opt.ne.0 then write f "sys$library:vaxcrtl.olb/Library" 172$ endif 173$ close f 174$ if f$search("crtl.opt;-2").nes."" then purge/Keep=2/noLog crtl.opt 175$ ! version ID info for linker to record in .EXE files 176$ create ident.opt 177$ open/Append f ident.opt 178$ write f "! ident.opt" 179$ write f "identification=""",version_number,""" !version" 180$ close f 181$ if f$search("ident.opt;-1").nes."" then purge/noLog ident.opt 182$ ! final setup 183$ nethacklib = "[-.src]nethack.olb" 184$ create nethack.opt 185! nethack.opt 186nethack.olb/Include=(vmsmain)/Library 187! lib$initialize is used to call a routine (before main()) in vmsunix.c that 188! tries to check whether debugger support has been linked in, for PANICTRACE 189sys$library:starlet.olb/Include=(lib$initialize) 190! psect_attr=lib$initialize, Con,Usr,noPic,Rel,Gbl,noShr,noExe,Rd,noWrt,Long 191! IA64 linker doesn't support Usr or Pic and complains that Long is too small 192psect_attr=lib$initialize, Con,Rel,Gbl,noShr,noExe,Rd,noWrt 193! increase memory available to RMS (the default iosegment is probably adequate) 194iosegment=128 195$ if f$search("nethack.opt;-2").nes."" then purge/Keep=2/noLog nethack.opt 196$ milestone = "write sys$output f$fao("" !5%T "",0)," 197$ if c_opt.eq.o_LINK then goto link !"LINK" requested, skip compilation 198$ rename := rename/New_Vers 199$ touch := set file/Truncate 200$ makedefs := $sys$disk:[-.util]makedefs 201$ show symbol cc 202$ goto begin !skip subroutines 203$! 204$compile_file: !input via 'c_file' 205$ no_lib = ( f$extract(0,1,c_file) .eqs. "#" ) 206$ if no_lib then c_file = f$extract(1,255,c_file) 207$ c_name = f$edit(f$parse(c_file,,,"NAME"),"LOWERCASE") 208$ f_opts = "" !options for this file 209$ if f$type('c_name'_options).nes."" then f_opts = 'c_name'_options 210$ milestone " (",c_name,")" 211$ if f$search("''c_name'.obj").nes."" then delete 'c_name'.obj;* 212$ cc 'f_opts' 'c_file' 213$ if .not.no_lib then nh_obj_list == nh_obj_list + ",''c_name'.obj;0" 214$ return 215$! 216$compile_list: !input via 'c_list' 217$ nh_obj_list == "" 218$ j = -1 219$ c_loop: 220$ j = j + 1 221$ c_file = f$element(j,",",c_list) !get next file 222$ if c_file.eqs."," then goto c_done 223$ c_file = c_file + ".c" 224$ gosub compile_file 225$ goto c_loop 226$ c_done: 227$ nh_obj_list == f$extract(1,999,nh_obj_list) 228$ if nh_obj_list.nes."" then libr/Obj 'nethacklib' 'nh_obj_list'/Replace 229$ if nh_obj_list.nes."" then delete 'nh_obj_list' 230$ delete/symbol/global nh_obj_list 231$ return 232$! 233$begin: 234$! 235$! miscellaneous special source file setup 236$! 237$ if f$search("pmatchregex.c").eqs."" then copy [-.sys.share]pmatchregex.c []*.* 238$ if f$search("random.c").eqs."" then copy [-.sys.share]random.c []*.* 239$ if f$search("tclib.c") .eqs."" then copy [-.sys.share]tclib.c []*.* 240$ if f$search("[-.util]lev_yacc.c").eqs."" then @[-.sys.vms]spec_lev.com 241$! 242$ p5 := 'p5' 243$ ttysrc = "[-.win.tty]getline,[-.win.tty]termcap" - 244 + ",[-.win.tty]topl,[-.win.tty]wintty" 245$ cursessrc = "[-.win.curses]cursdial,[-.win/curses]cursmesg" - 246 + ",[-.win.curses]cursinit,[-.win.curses]cursmisc" - 247 + ",[-.win.curses]cursinvt,[-.win.curses]cursstat" - 248 + ",[-.win.curses]cursmain,[-.win.curses]curswins" 249$ interface = ttysrc !default 250$ if p5.eqs."CURSES" then interface = cursessrc 251$ if p5.eqs."TTY+CURSES" then interface = ttysrc + "," + cursessrc 252$ if p5.eqs."CURSES+TTY" then interface = cursessrc + "," + ttysrc 253$! 254$! create object library 255$! 256$ if c_opt.ne.o_SPCL .or. f$search(nethacklib).eqs."" then - 257 libr/Obj 'nethacklib'/Create=(Block=3000,Hist=0) 258$ if f$search("''nethacklib';-1").nes."" then purge 'nethacklib' 259$! 260$! compile and link makedefs, then nethack, lev_comp+dgn_comp, dlb+recover. 261$! 262$ milestone "<compiling...>" 263$ c_list = "[-.sys.vms]vmsmisc,[-.sys.vms]vmsfiles,[]alloc,dlb,monst,objects" 264$ if c_opt.eq.o_SPCL then c_list = c_list + ",decl,drawing" 265$ gosub compile_list 266$ if c_opt.eq.o_SPCL then goto special !"SPECIAL" requested, skip main build 267$ set default [-.util] 268$ c_list = "#makedefs" 269$ gosub compile_list 270$ link makedefs.obj,'nethacklib'/Lib,[-.src]ident.opt/Opt,[-.src]crtl/Opt 271$ milestone "makedefs" 272$! create some build-time files 273$ makedefs -p !pm.h 274$ makedefs -o !onames.h 275$ makedefs -v !date.h 276$ milestone " (*.h)" 277$ makedefs -z !../src/vis_tab.c, ../include/vis_tab.h 278$ milestone " (*.c)" 279$ set default [-.src] 280$! compile most of the source files: 281$ c_list = "decl,version,[-.sys.vms]vmsmain,[-.sys.vms]vmsunix" - 282 + ",[-.sys.vms]vmstty,[-.sys.vms]vmsmail" - 283 + ",[]isaac64" - !already in [.src] 284 + ",[]random,[]tclib,[]pmatchregex" !copied from [-.sys.share] 285$ gosub compile_list 286$ c_list = interface !ttysrc or cursessrc or both 287$ gosub compile_list 288$ c_list = "allmain,apply,artifact,attrib,ball,bones,botl,cmd,dbridge,detect" - 289 + ",dig,display,do,do_name,do_wear,dog,dogmove,dokick,dothrow,drawing" - 290 + ",dungeon,eat,end,engrave,exper,explode,extralev,files,fountain" 291$ gosub compile_list 292$ c_list = "hack,hacklib,invent,light,lock,mail,makemon,mapglyph,mcastu" - 293 + ",mhitm,mhitu,minion,mklev,mkmap,mkmaze,mkobj,mkroom,mon,mondata" - 294 + ",monmove,mplayer,mthrowu,muse,music,o_init,objnam,options" - 295 + ",pager,pickup" 296$ gosub compile_list 297$ c_list = "pline,polyself,potion,pray,priest,quest,questpgr,read" - 298 + ",rect,region,restore,rip,rnd,role,rumors,save,shk,shknam,sit" - 299 + ",sounds,sp_lev,spell,steal,steed,sys,teleport,timeout,topten" - 300 + ",track,trap,u_init" 301$ gosub compile_list 302$ c_list = "uhitm,vault,vision,vis_tab,weapon,were,wield,windows" - 303 + ",wizard,worm,worn,write,zap" 304$ gosub compile_list 305$! 306$link: 307$ milestone "<linking...>" 308$ link/Exe=nethack.exe nethack.opt/Options,ident.opt/Options,crtl.opt/Options 309$ milestone "NetHack" 310$ if c_opt.eq.o_LINK then goto done !"LINK" only 311$special: 312$! 313$! build special level and dungeon compilers 314$! 315$ set default [-.util] 316$ c_list = "#panic,#lev_main,#lev_yacc,#dgn_main,#dgn_yacc" 317$ if c_opt.eq.o_SPCL then c_list = "[-.sys.vms]vmsfiles," + c_list 318$ gosub compile_list 319$ c_list = "#lev_lex,#dgn_lex" 320$ copy [-.sys.vms]lev_lex.h stdio.*/Prot=(s:rwd,o:rwd) 321$ gosub compile_list 322$ rename stdio.h lev_lex.* 323$ link/exe=lev_comp.exe lev_main.obj,lev_yacc.obj,lev_lex.obj,- 324 panic.obj,'nethacklib'/Lib,[-.src]ident.opt/Opt,[-.src]crtl.opt/Opt 325$ milestone "lev_comp" 326$ link/exe=dgn_comp.exe dgn_main.obj,dgn_yacc.obj,dgn_lex.obj,- 327 panic.obj,'nethacklib'/Lib,[-.src]ident.opt/Opt,[-.src]crtl.opt/Opt 328$ milestone "dgn_comp" 329$! 330$ c_list = "#dlb_main,#recover" 331$ gosub compile_list 332$ link/exe=dlb.exe dlb_main.obj,- 333 panic.obj,'nethacklib'/Lib,[-.src]ident.opt/Opt,[-.src]crtl.opt/Opt 334$ milestone "dlb" 335$ link/exe=recover.exe recover.obj,- 336 'nethacklib'/Lib,[-.src]ident.opt/Opt,[-.src]crtl.opt/Opt 337$ milestone "recover" 338$! 339$done: 340$ set default 'cur_dir' 341$ exit 342