diff --git a/include/extern.h b/include/extern.h index 30579cee2..979331619 100644 --- a/include/extern.h +++ b/include/extern.h @@ -14,7 +14,7 @@ extern char *fmt_ptr(const void *) NONNULL; /* This next pre-processor directive covers almost the entire file, * interrupted only occasionally to pick up specific functions as needed. */ -#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) +#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) && !defined(CPPREGEX_C) /* ### allmain.c ### */ @@ -782,9 +782,11 @@ extern void done1(int); extern int done2(void); extern void done_in_by(struct monst *, int); extern void done_object_cleanup(void); -#endif /* !MAKEDEFS_C && MDLIB_C */ +#endif /* !MAKEDEFS_C && MDLIB_C && !CPPREGEX_C */ +#if !defined(CPPREGEX_C) extern void panic(const char *, ...) PRINTF_F(1, 2) NORETURN; -#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) +#endif +#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) && !defined(CPPREGEX_C) extern void done(int); extern void container_contents(struct obj *, boolean, boolean, boolean); extern void nh_terminate(int) NORETURN; @@ -1377,7 +1379,7 @@ extern void clear_level_structures(void); extern void level_finalize_topology(void); extern void mklev(void); #ifdef SPECIALIZATION -extern void topologize(struct mkroom *, boolean)); +extern void topologize(struct mkroom *, boolean); #else extern void topologize(struct mkroom *); #endif @@ -1855,6 +1857,7 @@ extern char *stripdigits(char *); extern const char *get_lua_version(void); extern void nhl_pushhooked_open_table(lua_State *L); #endif /* !CROSSCOMPILE || CROSSCOMPILE_TARGET */ +#endif /* MAKEDEFS_C MDLIB_C CPPREGEX_C */ /* ### nhregex.c ### */ @@ -1864,6 +1867,8 @@ extern char *regex_error_desc(struct nhregex *, char *); extern boolean regex_match(const char *, struct nhregex *); extern void regex_free(struct nhregex *); +#if !defined(MAKEDEFS_C) && !defined(MDLIB_C) && !defined(CPPREGEX_C) + /* ### consoletty.c ### */ #ifdef WIN32 diff --git a/sys/share/cppregex.cpp b/sys/share/cppregex.cpp index 40ba980da..eeec30b98 100644 --- a/sys/share/cppregex.cpp +++ b/sys/share/cppregex.cpp @@ -3,14 +3,19 @@ /* Copyright (c) Sean Hunt 2015. */ /* NetHack may be freely redistributed. See license for details. */ +extern "C" { +#include "config.h" +#define CPPREGEX_C +#include "extern.h" +} // extern "C" + #include #include - -/* nhregex interface documented in sys/share/posixregex.c */ +#include extern "C" { // rest of file -#include "config.h" +/* nhregex interface documented in sys/share/posixregex.c */ extern const char regex_id[] = "cppregex"; @@ -76,7 +81,7 @@ regex_free(struct nhregex *re) { delete re; } - +#undef CPPREGEX_C } // extern "C" /*cppregex.cpp*/ diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src index a77cc9ead..423465bf2 100644 --- a/sys/unix/Makefile.src +++ b/sys/unix/Makefile.src @@ -202,7 +202,7 @@ TARGET_LIBS = $(LIBS) CPPFLAGS = # file for regular expression matching -REGEXOBJ = $(TARGETPFX)posixregex.o +REGEXOBJ ?= $(TARGETPFX)posixregex.o #REGEXOBJ = $(TARGETPFX)pmatchregex.o #REGEXOBJ = $(TARGETPFX)cppregex.o @@ -906,6 +906,7 @@ $(TARGETPFX)wintext.o: ../win/X11/wintext.c $(HACK_H) ../include/winX.h \ $(TARGETPFX)winval.o: ../win/X11/winval.c $(HACK_H) ../include/winX.h $(TARGET_CC) $(TARGET_CFLAGS) $(X11CFLAGS) -c -o $@ ../win/X11/winval.c $(TARGETPFX)tile.o: tile.c $(HACK_H) + $(TARGET_CC) $(TARGET_CFLAGS) -c -o $@ tile.c $(TARGETPFX)winshim.o: ../win/shim/winshim.c $(HACK_H) $(TARGET_CC) $(TARGET_CFLAGS) -c -o $@ ../win/shim/winshim.c $(TARGETPFX)cppregex.o: ../sys/share/cppregex.cpp $(CONFIG_H) diff --git a/sys/unix/hints/include/compiler.370 b/sys/unix/hints/include/compiler.370 index 75ac7d1ed..20c0418cb 100755 --- a/sys/unix/hints/include/compiler.370 +++ b/sys/unix/hints/include/compiler.370 @@ -22,22 +22,13 @@ CCFLAGS = -g # #CC= clang #CXX=clang++ -std=gnu++11 +# +# If these are set on entry, preparation for C++ compiles is affected. +# CPLUSPLUS_NEEDED = 1 C++ compile bits included +# CPLUSPLUS_NEED17 = 1 C++ -std=c++17 (at least) +# CPLUSPLUS_NEED_DEPSUPPRESS = 1 C++ -Wno-deprecated-copy, +# -Wno-deprecated-declarations -#detection -CCISCLANG := $(shell echo `$(CC) --version` | grep clang) -ifeq "$(CCISCLANG)" "" -ifdef WANT_WIN_QT6 -CXX=g++ -std=c++17 -else -CXX=g++ -std=gnu++11 -endif -else -ifdef WANT_WIN_QT6 -CXX=clang++ -std=c++17 -else -CXX=clang++ -std=gnu++11 -endif -endif # clang # If you want to override the compiler detection just carried out # uncomment one of the following pairs. Note, however, that @@ -55,8 +46,11 @@ CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \ -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings CFLAGS+=-pedantic CFLAGS+=-Wmissing-declarations -CFLAGS+=-Wunreachable-code + +# these are left out of the C++ flags CFLAGS+=-Wformat-nonliteral +CFLAGS+=-Wunreachable-code + # # the following are not allowed in C++ CFLAGS+=-Wimplicit @@ -66,18 +60,11 @@ CFLAGS+=-Wmissing-prototypes CFLAGS+=-Wold-style-definition CFLAGS+=-Wstrict-prototypes -CCXXFLAGS = -g -I../include -DNOTPARMDECL -CCXXFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \ - -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -CCXXFLAGS+=-pedantic -CCXXFLAGS+=-Wmissing-declarations - +#detection of clang vs gcc +CCISCLANG := $(shell echo `$(CC) --version` | grep clang) ifeq "$(CCISCLANG)" "" # gcc-specific follows -CFLAGS+=-Wmissing-parameter-type -ifdef WANT_WIN_QT -CCXXFLAGS+= -Wno-deprecated-copy -endif # WANT_WIN_QT +CXX=g++ -std=gnu++11 # get the version of gcc GCCGTEQ9 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 9) GCCGTEQ11 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 11) @@ -85,53 +72,86 @@ GCCGTEQ12 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 12) ifeq "$(GCCGTEQ9)" "1" # flags present in gcc version greater than or equal to 9 can go here CFLAGS+=-Wformat-overflow -endif #gcc version greater than or equal to 9 -#still in gcc-specific section here +CFLAGS+=-Wmissing-parameter-type +endif # GCC greater than or equal to 9 +#ifeq "$(GCCGTEQ11)" "1" +#endif +#ifeq "$(GCCGTEQ12)" "1" +#endif +# end of gcc-specific +else # gcc or clang? +CXX=clang++ -std=gnu++11 +# clang-specific follows +# none +endif # clang-specific ends here + +ifdef MAKEFILE_SRC +ifdef CPLUSPLUS_NEEDED +CCXXFLAGS = -g -I../include -DNOTPARMDECL +CCXXFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \ + -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings +CCXXFLAGS+=-pedantic +CCXXFLAGS+=-Wmissing-declarations +#detection of clang++ vs g++ +CXXISCLANG := $(shell echo `$(CXX) --version` | grep clang) +ifeq "$(CXXISCLANG)" "" +# g++-specific +CCXX=g++ -std=gnu++11 # get the version of g++ GPPGTEQ9 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 9) -GPPGTEQ11 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 11) -GPPGTEQ12 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 12) +GPPGTEQ11 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 11) +GPPGTEQ12 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 12) ifeq "$(GPPGTEQ9)" "1" CCXXFLAGS+=-Wformat-overflow -ifdef WANT_WIN_QT +ifdef CPLUSPLUS_NEED_DEPSUPPRESS CCXXFLAGS+=-Wno-deprecated-copy CCXXFLAGS+=-Wno-deprecated-declarations -endif # WANT_WIN_QT +endif # CPLUSPLUS_NEED_DEPSUPPRESS endif # g++ version greater than or equal to 9 ifeq "$(GPPGTEQ11)" "1" -#the g++ linker will have trouble linker if the following isn't included -#when compiling the C files. -ifdef WANT_WIN_QT +# the g++ linker will have trouble linking if the following isn't included +# when compiling the C files. CFLAGS+=-fPIC -endif # WANT_WIN_QT endif # g++ version greater than or equal to 11 +ifdef CPLUSPLUS_NEED17 ifeq "$(GPPGTEQ12)" "1" -ifdef WANT_WIN_QT6 -CXX=g++ -std=c++20 -endif # WANT_WIN_QT6 +CCXX=g++ -std=c++20 +else # g++ version greater than or equal to 12? (no follows) +CCXX=g++ -std=c++17 endif # g++ version greater than or equal to 12 -# end of gcc-specific +endif # CPLUSPLUS_NEED17 -else # clang-specific follows +else # g++ or clang++ ? +# clang++-specific +CCXX=clang++ -std=c++11 # get the version of clang++ CLANGPPGTEQ9 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 9) CLANGPPGTEQ14 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 14) ifeq "$(CLANGPPGTEQ9)" "1" -ifdef WANT_WIN_QT +#CCXXFLAGS+=-Wformat-overflow CCXXFLAGS+=-Wno-deprecated-copy -endif # WANT_WIN_QT -endif #clang++ greater than or equal to 9 - -ifdef WANT_WIN_QT +endif # clang++ greater than or equal to 9 ifeq "$(CLANGPPGTEQ14)" "1" -# The clang++ linker seems to have trouble linker if the following isn't +CCXXFLAGS+=-Wno-deprecated-declarations +endif # clang++ greater than or equal to 14 +# The clang++ linker seems to have trouble linking if the following isn't # included when compiling the C files by clang.. CFLAGS+=-fPIC +ifdef CPLUSPLUS_NEED17 +ifeq "$(CLANGPPGTEQ14)" "1" +$(info greaterthanorequalto14) +CCXX=clang++ -std=c++20 +else +$(info not greaterthanorequalto14) +CCXX=clang++ -std=c++17 endif # clang++ greater than or equal to 14 -CCXXFLAGS+=-Wno-deprecated-declarations -endif # WANT_WIN_QT -endif # clang-specific ends here +endif # CPLUSPLUS_NEED17 +endif # end of clang++-specific section +endif # CPLUSPLUS_NEEDED + +CXX=$(CCXX) +endif # MAKEFILE_SRC #end of compiler.370 #------------------------------------------------------------------------------ diff --git a/sys/unix/hints/include/multiw-2.370 b/sys/unix/hints/include/multiw-2.370 index 87a7fb737..b3dc021e6 100644 --- a/sys/unix/hints/include/multiw-2.370 +++ b/sys/unix/hints/include/multiw-2.370 @@ -102,12 +102,71 @@ XTRASRC += tile.c XTRAOBJ += $(TARGETPFX)tile.o endif +ifndef WANT_WIN_QT +ifdef WANT_WIN_ALL +WANT_WIN_QT=1 +endif +ifdef WANT_WIN_QT5 +ifndef WANT_WIN_QT +WANT_WIN_QT=1 +endif # not WANT_WIN_QT +endif # WANT_WIN_QT5 +ifdef WANT_WIN_QT6 +ifndef WANT_WIN_QT +WANT_WIN_QT=1 +endif # not WANT_WIN_QT +endif # WANT_WIN_QT6 +endif # not def WANT_WIN_QT + +ifdef WANT_WIN_QT +# WANT_WIN_QT5 is the default +ifndef WANT_WIN_QT5 +ifndef WANT_WIN_QT6 +WANT_WIN_QT5=1 +endif # not WANT_WIN_QT6 +endif # not WANT_WIN_QT5 +endif # WANT_WIN_QT + ifdef WANT_WIN_QT WINCFLAGS += -DQT_GRAPHICS WINSRC += $(WINQTSRC) WINOBJ0 += $(WINQTOBJ) XTRASRC += tile.c XTRAOBJ += $(TARGETPFX)tile.o +# +ifndef CPLUSPLUS_NEEDED +CPLUSPLUS_NEEDED = 1 +endif # CPLUSPLUS_NEEDED +ifdef WANT_WIN_QT6 +CPLUSPLUS_NEED17 = 1 +CPLUSPLUS_NEED_DEPSUPPRESS = 1 +endif # WANT_WIN_QT6 +endif # WANT_WIN_QT + +ifeq "$(GIT)" "1" +ifndef GITSUBMODULES +GITSUBMODULES=1 +endif +endif + +ifeq "$(git)" "1" +ifndef GITSUBMODULES +GITSUBMODULES=1 +endif +endif + +ifeq "$(CPPREGEX)" "1" +REGEXOBJ=$(TARGETPFX)cppregex.o +ifndef CPLUSPLUS_NEEDED +CPLUSPLUS_NEEDED = 1 +endif +endif + +ifeq "$(cppregex)" "1" +REGEXOBJ=$(TARGETPFX)cppregex.o +ifndef CPLUSPLUS_NEEDED +CPLUSPLUS_NEEDED = 1 +endif endif #end of hints/include/multiw-2.370 diff --git a/sys/unix/hints/include/multiw-3.370 b/sys/unix/hints/include/multiw-3.370 index 76fcf67e9..5d11441d6 100644 --- a/sys/unix/hints/include/multiw-3.370 +++ b/sys/unix/hints/include/multiw-3.370 @@ -39,6 +39,32 @@ USE_CURSESLIB=1 endif endif +ifeq "$(GIT)" "1" +ifndef GITSUBMODULES +GITSUBMODULES=1 +endif +endif + +ifeq "$(git)" "1" +ifndef GITSUBMODULES +GITSUBMODULES=1 +endif +endif + +ifeq "$(CPPREGEX)" "1" +REGEXOBJ=$(TARGETPFX)cppregex.o +ifndef CPLUSPLUS_NEEDED +CPLUSPLUS_NEEDED = 1 +endif +endif + +ifeq "$(cppregex)" "1" +REGEXOBJ=$(TARGETPFX)cppregex.o +ifndef CPLUSPLUS_NEEDED +CPLUSPLUS_NEEDED = 1 +endif +endif + #end of hints/include/multiw-3.370 #------------------------------------------------------------------------------ diff --git a/sys/unix/hints/linux.370 b/sys/unix/hints/linux.370 index 5321f6c81..d7adbf90e 100755 --- a/sys/unix/hints/linux.370 +++ b/sys/unix/hints/linux.370 @@ -20,40 +20,6 @@ # multiw-1.370 contains sections 1 to 2 #-INCLUDE multiw-1.370 -# 3. If you set WANT_WIN_QT, you need to -# A) set QTDIR either here or in the environment to point to the Qt5 -# Library installation root. -# B) set XPMLIB to point to the Xpm library -ifndef WANT_WIN_QT -ifdef WANT_WIN_ALL -WANT_WIN_QT=1 -endif -ifdef WANT_WIN_QT5 -ifndef WANT_WIN_QT -WANT_WIN_QT=1 -endif # not WANT_WIN_QT -endif # WANT_WIN_QT5 -ifdef WANT_WIN_QT6 -ifndef WANT_WIN_QT -WANT_WIN_QT=1 -endif # not WANT_WIN_QT -endif # WANT_WIN_QT6 -endif # not WANT_WIN_QT - -ifdef WANT_WIN_QT -ifndef WANT_WIN_QT5 -ifndef WANT_WIN_QT6 -WANT_WIN_QT5=1 -endif # not WANT_WIN_QT6 -endif # not WANT_WIN_QT5 -ifdef WANT_WIN_QT5 -QTDIR=/usr -endif # WANT_WIN_QT5 -ifdef WANT_WIN_QT6 -#if your Qt6 is elsewhere, change this to match -QTDIR=/usr/local/qt6 -endif # WANT_WIN_QT6 -endif # WANT_WIN_QT ifndef LIBXPM LIBXPM= -L/opt/X11/lib -lXpm @@ -68,17 +34,6 @@ GAMEGRP = games # you're reading this in Makefile augmented by hints, that may not be true). # -ifeq "$(GIT)" "1" -ifndef GITSUBMODULES -GITSUBMODULES=1 -endif -endif -ifeq "$(git)" "1" -ifndef GITSUBMODULES -GITSUBMODULES=1 -endif -endif - #-INCLUDE multiw-2.370 # compiler.370 contains compiler detection and adjustments common @@ -86,8 +41,19 @@ endif #-INCLUDE compiler.370 -# multiw-3.370 must come after compiler.370 +ifdef WANT_WIN_QT +ifdef WANT_WIN_QT5 +QTDIR=/usr +endif # WANT_WIN_QT5 +ifdef WANT_WIN_QT6 +#if your Qt6 is elsewhere, change this to match +QTDIR=/usr/local/qt6 +endif # WANT_WIN_QT6 +endif # WANT_WIN_QT +# multiw-3.370 must come after compiler.370 +# and after QTDIR is defined. +# #-INCLUDE multiw-3.370 ifeq "$(USE_CURSESLIB)" "1" diff --git a/sys/unix/hints/macOS.370 b/sys/unix/hints/macOS.370 index 713435f8a..99c0545df 100755 --- a/sys/unix/hints/macOS.370 +++ b/sys/unix/hints/macOS.370 @@ -19,7 +19,6 @@ # note: '#-INCLUDE' is not just a comment; multiw-1 contains sections 1 to 2 #-INCLUDE multiw-1.370 - ifneq "$(USEMACPORTS)" "1" HAVE_HOMEBREW := $(shell expr `which -s brew; echo $$?` = 0) endif @@ -27,55 +26,6 @@ ifneq "$(USEHOMEBREW)" "1" HAVE_MACPORTS := $(shell expr `which -s port; echo $$?` = 0) endif -# 3. If you set WANT_WIN_QT, you need to -# A) set QTDIR either here or in the environment to point to the Qt5 -# library installation root. (Qt2, Qt3, Qt4 will not work) -# B) set LIBXPM to point to the Xpm library -ifndef WANT_WIN_QT -ifdef WANT_WIN_ALL -WANT_WIN_QT=1 -endif -ifdef WANT_WIN_QT5 -ifndef WANT_WIN_QT -WANT_WIN_QT=1 -endif # not WANT_WIN_QT -endif # WANT_WIN_QT5 -ifdef WANT_WIN_QT6 -ifndef WANT_WIN_QT -WANT_WIN_QT=1 -endif # not WANT_WIN_QT -endif # WANT_WIN_QT6 -endif # not WANT_WIN_QT - -ifdef WANT_WIN_QT -ifndef WANT_WIN_QT5 -ifndef WANT_WIN_QT6 -WANT_WIN_QT5=1 -endif # not WANT_WIN_QT6 -endif # not WANT_WIN_QT5 -#QTDIR=/Developer/Qt -ifeq "$(HAVE_HOMEBREW)" "1" -ifdef WANT_WIN_QT5 -# Qt5 installed via homebrew -QTDIR :=$(shell brew --prefix)/opt/qt@5 -endif # WANT_WIN_QT5 -ifdef WANT_WIN_QT6 -QTDIR :=$(shell brew --prefix)/opt/qt@6 -endif # WANT_WIN_QT6 -endif # HAVE_HOMEBREW -ifndef QTDIR -ifeq "$(HAVE_MACPORTS)" "1" -ifdef WANT_WIN_QT5 -# Qt5 installed via macports -QTDIR=/opt/local/libexec/qt5 -endif # WANT_WIN_QT5 -ifdef WANT_WIN_QT6 -QTDIR=/opt/local/libexec/qt6 -endif # WANT_WIN_QT6 -endif # HAVE_MACPORTS -endif # QTDIR -endif # WANT_WIN_QT - ifndef LIBXPM LIBXPM= -L/opt/X11/lib -lXpm endif @@ -87,17 +37,6 @@ endif # you're reading this in Makefile augmented by hints, that may not be true). # -ifeq "$(GIT)" "1" -ifndef GITSUBMODULES -GITSUBMODULES=1 -endif -endif -ifeq "$(git)" "1" -ifndef GITSUBMODULES -GITSUBMODULES=1 -endif -endif - #-INCLUDE multiw-2.370 # compiler.370 contains compiler detection and adjustments common @@ -105,7 +44,31 @@ endif #-INCLUDE compiler.370 +ifdef WANT_WIN_QT +ifeq "$(HAVE_HOMEBREW)" "1" +ifdef WANT_WIN_QT5 +# Qt5 installed via homebrew +QTDIR :=$(shell brew --prefix)/opt/qt@5 +endif # WANT_WIN_QT5 +ifdef WANT_WIN_QT6 +QTDIR :=$(shell brew --prefix)/opt/qt@6 +endif # WANT_WIN_QT6 +endif # HAVE_HOMEBREW +ifndef QTDIR +ifeq "$(HAVE_MACPORTS)" "1" +# Qt installed via macports +ifdef WANT_WIN_QT5 +QTDIR=/opt/local/libexec/qt5 +endif # WANT_WIN_QT5 +ifdef WANT_WIN_QT6 +QTDIR=/opt/local/libexec/qt6 +endif # WANT_WIN_QT6 +endif # HAVE_MACPORTS +endif # QTDIR +endif # WANT_WIN_QT + # multiw-3.370 must come after compiler.370 +# and after QTDIR is defined #-INCLUDE multiw-3.370