/* 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 ### */
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;
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
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 ### */
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
/* 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 <regex>
#include <memory>
-
-/* nhregex interface documented in sys/share/posixregex.c */
+#include <cstring>
extern "C" { // rest of file
-#include "config.h"
+/* nhregex interface documented in sys/share/posixregex.c */
extern const char regex_id[] = "cppregex";
{
delete re;
}
-
+#undef CPPREGEX_C
} // extern "C"
/*cppregex.cpp*/
CPPFLAGS =
# file for regular expression matching
-REGEXOBJ = $(TARGETPFX)posixregex.o
+REGEXOBJ ?= $(TARGETPFX)posixregex.o
#REGEXOBJ = $(TARGETPFX)pmatchregex.o
#REGEXOBJ = $(TARGETPFX)cppregex.o
$(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)
#
#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
-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
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)
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
#------------------------------------------------------------------------------
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
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
#------------------------------------------------------------------------------
# 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
# 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
#-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"
# 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
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
+ifndef LIBXPM
+LIBXPM= -L/opt/X11/lib -lXpm
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
+
+# 4. Other
+
+#-----------------------------------------------------------------------------
+# You shouldn't need to change anything below here (in the hints file; if
+# you're reading this in Makefile augmented by hints, that may not be true).
+#
+
+#-INCLUDE multiw-2.370
+
+# compiler.370 contains compiler detection and adjustments common
+# to both linux and macOS
+
+#-INCLUDE compiler.370
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
endif # HAVE_HOMEBREW
ifndef QTDIR
ifeq "$(HAVE_MACPORTS)" "1"
+# Qt installed via macports
ifdef WANT_WIN_QT5
-# Qt5 installed via macports
QTDIR=/opt/local/libexec/qt5
endif # WANT_WIN_QT5
ifdef WANT_WIN_QT6
endif # WANT_WIN_QT6
endif # HAVE_MACPORTS
endif # QTDIR
-endif # WANT_WIN_QT
-
-ifndef LIBXPM
-LIBXPM= -L/opt/X11/lib -lXpm
-endif
-
-# 4. Other
-
-#-----------------------------------------------------------------------------
-# You shouldn't need to change anything below here (in the hints file; if
-# 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
-# to both linux and macOS
-
-#-INCLUDE compiler.370
+endif # WANT_WIN_QT
# multiw-3.370 must come after compiler.370
+# and after QTDIR is defined
#-INCLUDE multiw-3.370