From: nhmall Date: Fri, 17 Feb 2023 15:23:40 +0000 (-0500) Subject: allow setting the standard X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24dab181678a40a1839780ef36b92d4c149ce537;p=nethack allow setting the standard CSTD can be manually set near the top of src/Makefile, util/Makefile or by including c99=1 or C99=1 on the build make command line if using the linux.370 or macOS.370 hints files. --- diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src index df88008d1..6c9bddc0a 100644 --- a/sys/unix/Makefile.src +++ b/sys/unix/Makefile.src @@ -44,7 +44,7 @@ SHELL=/bin/sh #LINK=$(CC) # If we're cross-compiling, a hints file will override this -# to a uniq target directory, but otherwise it just goes in +# to a unique target directory, but otherwise it just goes in # ../src TARGETPFX= @@ -68,6 +68,11 @@ SYSOBJ = $(TARGETPFX)ioctl.o $(TARGETPFX)unixmain.o $(TARGETPFX)unixtty.o \ #SYSOBJ = $(TARGETPFX)bemain.o $(TARGETPFX)unixtty.o $(TARGETPFX)ioctl.o +# NetHack 3.7 began introducing C99 code. +# +# If your compiler needs an appropriate switch to accept C99 code. +# CSTD = -std=c99 + # if you are using gcc as your compiler: # uncomment the CC definition below if it's not in your environment # if you get setcgtty() warnings during execution, you are feeding gcc @@ -90,6 +95,11 @@ SYSOBJ = $(TARGETPFX)ioctl.o $(TARGETPFX)unixmain.o $(TARGETPFX)unixtty.o \ # CC = arm-linux-gcc # # +# The gcc compiler switch for accepting C99 code. Because gcc had extensions in +# earlier versions, a number of C99 features were already compiling cleanly, but +# not all (e.g., 'for' loop initial declarations). +# CSTD = -std=c99 + # if you're debugging and want gcc to check as much as possible, use: # CC = gcc -W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings @@ -189,7 +199,7 @@ MOCPATH ?= $(QTDIR)/bin/$(MOC) # If we're cross-compiling these will get overridden elsewhere, likely via # a hints file. TARGETPFX was set above earlier. TARGET_CC = $(CC) -TARGET_CFLAGS = $(CFLAGS) +TARGET_CFLAGS = $(CFLAGS) $(CSTD) TARGET_LINK = $(LINK) TARGET_LFLAGS = $(LFLAGS) TARGET_CXX = $(CXX) @@ -674,11 +684,11 @@ $(LUALIB) ../include/nhlua.h: # special rules, to force update of makedefs, real dependencies should be # below in the 'make depend' output. monst.o: - $(CC) $(CFLAGS) -c -o $@ monst.c + $(CC) $(CFLAGS) $(CSTD) -c -o $@ monst.c @rm -f $(MAKEDEFS) objects.o: - $(CC) $(CFLAGS) -c -o $@ objects.c + $(CC) $(CFLAGS) $(CSTD) -c -o $@ objects.c @rm -f $(MAKEDEFS) # outdated Qt 3 windowport meta-object-compiler output diff --git a/sys/unix/Makefile.utl b/sys/unix/Makefile.utl index f9a0c5af1..b97f59b55 100644 --- a/sys/unix/Makefile.utl +++ b/sys/unix/Makefile.utl @@ -23,6 +23,11 @@ NHSROOT=.. # execute things like 'foo.o') # MAKE = make +# NetHack 3.7 began introducing C99 code. +# +# If your compiler needs an appropriate switch to accept C99 code. +# CSTD = -std=c99 + # if you are using gcc as your compiler, # uncomment the CC definition below if it's not in your environment # CC = gcc @@ -203,7 +208,7 @@ DLBOBJS = dlb_main.o $(OBJDIR)/dlb.o $(OALLOC) TARGETPFX= TARGET_CC = $(CC) -TARGET_CFLAGS = $(CFLAGS) +TARGET_CFLAGS = $(CFLAGS) $(CSTD) TARGET_CLINK = $(CLINK) TARGET_LFLAGS = $(LFLAGS) TARGET_CXX = $(CXX) @@ -226,7 +231,7 @@ makedefs.o: makedefs.c ../src/mdlib.c $(CONFIG_H) \ ../include/monst.h ../include/monsters.h ../include/objects.h \ ../include/you.h ../include/context.h ../include/flag.h \ ../include/dlb.h ../include/patchlevel.h mdgrep.h - $(CC) $(CFLAGS) -c makedefs.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c makedefs.c -o $@ # Don't require perl to build; that is why mdgrep.h is spelled wrong below. mdgreph: mdgrep.pl @@ -249,7 +254,7 @@ lintdefs: # support code used by several of the utility programs (but not makedefs) panic.o: panic.c $(CONFIG_H) - $(CC) $(CFLAGS) -c panic.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c panic.c -o $@ # with all of extern.h's functions to complain about, we drown in @@ -274,7 +279,7 @@ dlb: $(DLBOBJS) $(CLINK) $(LFLAGS) -o dlb $(DLBOBJS) $(LIBS) dlb_main.o: dlb_main.c $(CONFIG_H) ../include/dlb.h - $(CC) $(CFLAGS) -c dlb_main.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c dlb_main.c -o $@ # dependencies for tile utilities @@ -318,34 +323,34 @@ tilemap: tilemap.o $(OBJDIR)/objects.o $(OBJDIR)/monst.o $(OBJDIR)/drawing.o ./tilemap tiletext.o: ../win/share/tiletext.c $(CONFIG_H) ../win/share/tile.h - $(CC) $(CFLAGS) -I../win/share -c ../win/share/tiletext.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -I../win/share -c ../win/share/tiletext.c -o $@ tiletxt.o: ../win/share/tiletxt.c ../win/share/tilemap.c $(HACK_H) - $(CC) $(CFLAGS) -I../win/share -c ../win/share/tiletxt.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -I../win/share -c ../win/share/tiletxt.c -o $@ tilemap.o: ../win/share/tilemap.c $(HACK_H) - $(CC) $(CFLAGS) -c ../win/share/tilemap.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../win/share/tilemap.c -o $@ gifread.o: ../win/share/gifread.c $(CONFIG_H) ../win/share/tile.h - $(CC) $(CFLAGS) -I../win/share -c ../win/share/gifread.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -I../win/share -c ../win/share/gifread.c -o $@ ppmwrite.o: ../win/share/ppmwrite.c $(CONFIG_H) ../win/share/tile.h - $(CC) $(CFLAGS) -I../win/share -c ../win/share/ppmwrite.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -I../win/share -c ../win/share/ppmwrite.c -o $@ tile2bmp.o: ../win/share/tile2bmp.c $(HACK_H) ../win/share/tile.h - $(CC) $(CFLAGS) -I../win/share -c ../win/share/tile2bmp.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -I../win/share -c ../win/share/tile2bmp.c -o $@ tile2x11.o: ../win/X11/tile2x11.c $(HACK_H) ../win/share/tile.h \ ../include/tile2x11.h - $(CC) $(CFLAGS) -I../win/share -c ../win/X11/tile2x11.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -I../win/share -c ../win/X11/tile2x11.c -o $@ tile2img.o: ../win/gem/tile2img.c $(HACK_H) ../win/share/tile.h \ ../include/bitmfile.h - $(CC) $(CFLAGS) -I../win/share -c ../win/gem/tile2img.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -I../win/share -c ../win/gem/tile2img.c -o $@ xpm2img.o: ../win/gem/xpm2img.c $(HACK_H) ../include/bitmfile.h - $(CC) $(CFLAGS) -c ../win/gem/xpm2img.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../win/gem/xpm2img.c -o $@ bitmfile.o: ../win/gem/bitmfile.c ../include/bitmfile.h - $(CC) $(CFLAGS) -c ../win/gem/bitmfile.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../win/gem/bitmfile.c -o $@ tile2beos.o: ../win/BeOS/tile2beos.cpp $(HACK_H) ../win/share/tile.h - $(CXX) $(CFLAGS) -I../win/share -c ../win/BeOS/tile2beos.cpp -o $@ + $(CXX) $(CFLAGS) $(CSTD) -I../win/share -c ../win/BeOS/tile2beos.cpp -o $@ # note: tileedit.cpp was developed for Qt2 and will not compile using Qt5 tileedit.o: ../win/Qt/tileedit.cpp @@ -357,7 +362,7 @@ tileedit: tileedit.o $(TEXT_IO) uudecode: uudecode.o $(CLINK) $(LFLAGS) -o uudecode uudecode.o $(LIBS) uudecode.o: ../sys/share/uudecode.c - $(CC) $(CFLAGS) -c -o uudecode.o ../sys/share/uudecode.c + $(CC) $(CFLAGS) $(CSTD) -c -o uudecode.o ../sys/share/uudecode.c # using dependencies like # ../src/foo:: @@ -374,27 +379,27 @@ uudecode.o: ../sys/share/uudecode.c # (note: these dependencies have been copied from Makefile.src so only come # indirectly from 'make depend', hence are subject to bit rot as src changes) $(OBJDIR)/alloc.o: ../src/alloc.c $(CONFIG_H) - $(CC) $(CFLAGS) -c ../src/alloc.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../src/alloc.c -o $@ $(OBJDIR)/drawing.o: ../src/drawing.c $(CONFIG_H) ../include/color.h \ ../include/rm.h ../include/objclass.h ../include/defsym.h \ ../include/objects.h ../include/sym.h - $(CC) $(CFLAGS) -c ../src/drawing.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../src/drawing.c -o $@ $(OBJDIR)/decl.o: ../src/decl.c $(HACK_H) - $(CC) $(CFLAGS) -c ../src/decl.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../src/decl.c -o $@ $(OBJDIR)/monst.o: ../src/monst.c $(CONFIG_H) ../include/permonst.h \ ../include/align.h ../include/monattk.h ../include/monflag.h \ ../include/monsters.h ../include/sym.h ../include/defsym.h \ ../include/color.h - $(CC) $(CFLAGS) -c ../src/monst.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../src/monst.c -o $@ $(OBJDIR)/objects.o: ../src/objects.c $(CONFIG_H) ../include/obj.h \ ../include/prop.h ../include/skills.h ../include/color.h \ ../include/objclass.h ../include/defsym.h ../include/objects.h - $(CC) $(CFLAGS) -c ../src/objects.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../src/objects.c -o $@ $(OBJDIR)/dlb.o: ../src/dlb.c $(CONFIG_H) ../include/dlb.h - $(CC) $(CFLAGS) -c ../src/dlb.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../src/dlb.c -o $@ # this differs substantially from what Makefile.src specifies $(OBJDIR)/date.o: ../src/date.c $(CONFIG_H) - $(CC) $(CFLAGS) -c ../src/date.c -o $@ + $(CC) $(CFLAGS) $(CSTD) -c ../src/date.c -o $@ # make sure hack.h dependencies get transitive information $(HACK_H): $(CONFIG_H) diff --git a/sys/unix/hints/include/compiler.370 b/sys/unix/hints/include/compiler.370 index 7615f84e4..0c1233bcc 100755 --- a/sys/unix/hints/include/compiler.370 +++ b/sys/unix/hints/include/compiler.370 @@ -149,8 +149,18 @@ endif # CPLUSPLUS_NEED17 endif # end of clang++-specific section CXX=$(CCXX) endif # CPLUSPLUS_NEEDED - endif # MAKEFILE_SRC +ifeq "$(c99)" "1" +WANT_C99=1 +endif +ifeq "$(C99)" "1" +WANT_C99=1 +endif + +ifeq "$(WANT_C99)" "1" +CSTD = -std=c99 +endif + #end of compiler.370 #------------------------------------------------------------------------------