From 3169331e84d4cc13192403a7f218899b5e98cfba Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 5 Jun 2024 10:54:31 +0200 Subject: CMake: Generate the install.hpp and version.hpp files The values of defines in these files should be the same as those set from version.mk / Makefile.in. --- src/conf/install.hpp.in | 29 +++++++++++++++++++++++++++++ src/conf/version.hpp.in | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/conf/install.hpp.in create mode 100644 src/conf/version.hpp.in (limited to 'src') diff --git a/src/conf/install.hpp.in b/src/conf/install.hpp.in new file mode 100644 index 0000000..c44f026 --- /dev/null +++ b/src/conf/install.hpp.in @@ -0,0 +1,29 @@ +#pragma once +// conf/install.hpp - Import configuration variables related to install. +// +// Copyright © 2014 Ben Longbons +// +// This file is part of The Mana World (Athena server) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// just mention "fwd.hpp" to make formatter happy + +#define PACKAGESYSCONFDIR "@PACKAGESYSCONFDIR@"_s +#define PACKAGELOCALSTATEDIR "@PACKAGELOCALSTATEDIR@"_s +#define PACKAGEDATADIR "@PACKAGEDATADIR@"_s + +namespace tmwa +{ +} // namespace tmwa diff --git a/src/conf/version.hpp.in b/src/conf/version.hpp.in new file mode 100644 index 0000000..126fae2 --- /dev/null +++ b/src/conf/version.hpp.in @@ -0,0 +1,39 @@ +#pragma once +// conf/version.hpp - Import configuration variables related to version. +// +// Copyright © 2013-2014 Ben Longbons +// +// This file is part of The Mana World (Athena server) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// just mention "fwd.hpp" to make formatter happy + +#define VERSION_FULL "@VERSION_FULL@"_s +#define VERSION_HASH "@VERSION_HASH@"_s + +#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define VERSION_PATCH @PROJECT_VERSION_PATCH@ +#define VERSION_DEVEL @PROJECT_VERSION_TWEAK@ + +#define VENDOR_NAME "@VENDOR_NAME@"_s +#define VENDOR_POINT @VENDOR_POINT@ +#define VENDOR_SOURCE "@VENDOR_SOURCE@"_s + +#define VERSION_STRING "@VERSION_STRING@"_s + +namespace tmwa +{ +} // namespace tmwa -- cgit v1.2.3-70-g09d2 From 69a603e87496dcc05cf93d1359686c23a0c43e28 Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Wed, 5 Jun 2024 10:59:41 +0000 Subject: cmake: Fix out of tree build Also remove {install,version}.hpp from source control, so they're actually generated. There may be a better way to handle this, but I'll just leave a note as a TODO for now. --- CMakeLists.txt | 8 ++++++-- src/conf/install.hpp | 30 ------------------------------ src/conf/version.hpp | 40 ---------------------------------------- 3 files changed, 6 insertions(+), 72 deletions(-) delete mode 100644 src/conf/install.hpp delete mode 100644 src/conf/version.hpp (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 11c58d0..a0587b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,8 +101,12 @@ set(PACKAGEDATADIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/tmwa") set(PACKAGELOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/tmwa") set(PACKAGESYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/tmwa") -configure_file(src/conf/install.hpp.in src/conf/install.hpp @ONLY) -configure_file(src/conf/version.hpp.in src/conf/version.hpp @ONLY) +# Generate the install.hpp and version.hpp files in the source directory. +# TODO: Is there a nicer way to handle this so we're still able to make fully +# out-of-tree builds, generating the files in the build directory, but still +# having them found by includes? +configure_file(src/conf/install.hpp.in ${CMAKE_SOURCE_DIR}/src/conf/install.hpp @ONLY) +configure_file(src/conf/version.hpp.in ${CMAKE_SOURCE_DIR}/src/conf/version.hpp @ONLY) set(conf_SOURCES ${conf_SOURCES} src/conf/install.hpp src/conf/version.hpp) # Add a shared library: libtmwa-shared.so.0 diff --git a/src/conf/install.hpp b/src/conf/install.hpp deleted file mode 100644 index 42fd125..0000000 --- a/src/conf/install.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -// conf/install.hpp - Import configuration variables related to install. -// -// Copyright © 2014 Ben Longbons -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// just mention "fwd.hpp" to make formatter happy - -#include "conf-raw/str-PACKAGESYSCONFDIR.h" -#include "conf-raw/str-PACKAGELOCALSTATEDIR.h" -#include "conf-raw/str-PACKAGEDATADIR.h" - - -namespace tmwa -{ -} // namespace tmwa diff --git a/src/conf/version.hpp b/src/conf/version.hpp deleted file mode 100644 index df8a8b6..0000000 --- a/src/conf/version.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -// conf/version.hpp - Import configuration variables related to version. -// -// Copyright © 2013-2014 Ben Longbons -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// just mention "fwd.hpp" to make formatter happy - -#include "conf-raw/str-VERSION_FULL.h" -#include "conf-raw/str-VERSION_HASH.h" - -#include "conf-raw/int-VERSION_MAJOR.h" -#include "conf-raw/int-VERSION_MINOR.h" -#include "conf-raw/int-VERSION_PATCH.h" -#include "conf-raw/int-VERSION_DEVEL.h" - -#include "conf-raw/str-VENDOR_NAME.h" -#include "conf-raw/int-VENDOR_POINT.h" -#include "conf-raw/str-VENDOR_SOURCE.h" - -#include "conf-raw/str-VERSION_STRING.h" - - -namespace tmwa -{ -} // namespace tmwa -- cgit v1.2.3-70-g09d2 From 2ff7077ab900cca73e6dc3a256a67caff5d447f8 Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Wed, 5 Jun 2024 13:27:51 +0000 Subject: Generate {install,version}.hpp through attoconf Or more specifically, in the attoconf buildchain. attoconf itself directly generates src/conf/install.hpp alongside Makefile, but version inforation is only available later. To generate version.hpp, I extended version.mk slightly to provide the recipe. It's not anywhere near as generic as real.make tends to be, but with any luck we'll soon be doing all builds through cmake going forward. The template for install.hpp has been changed to use variables actually provided by attoconf. PACKAGE{SYSCONF,LOCALSTATE}DIR are actually only defined in real.make, and then only in terms of SYSCONFDIR and LOCALSTATEDIR, adding `/tmwa`. It's simpler to just use the attoconf variable and adjust the template, which conveniently also simplifies the construction in CMakeLists.txt, too. --- CMakeLists.txt | 4 ++-- Makefile.in | 1 + configure | 4 +++- src/conf/install.hpp.in | 4 ++-- version.mk | 23 +++++++++++++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index dd99bf2..5981636 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,8 +98,8 @@ set(VERSION_DOTS "${PROJECT_VERSION}.${VENDOR_POINT}") include(GNUInstallDirs) set(PACKAGEDATADIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/tmwa") -set(PACKAGELOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/tmwa") -set(PACKAGESYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/tmwa") +set(LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}") +set(SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}") # Generate the install.hpp and version.hpp files in the source directory. # TODO: Is there a nicer way to handle this so we're still able to make fully diff --git a/Makefile.in b/Makefile.in index 75f91f7..df8a2df 100644 --- a/Makefile.in +++ b/Makefile.in @@ -386,6 +386,7 @@ vpath include/%.hpp ${SRC_DIR} vpath src/%.tcc ${SRC_DIR} vpath tools/% ${SRC_DIR} vpath src/%.py ${SRC_DIR} +vpath src/%.in ${SRC_DIR} .DELETE_ON_ERROR: .DEFAULT_GOAL := all diff --git a/configure b/configure index 275a9c4..7a7a9ef 100755 --- a/configure +++ b/configure @@ -112,7 +112,9 @@ def main(): srcdir = os.path.dirname(sys.argv[0]) proj = Configuration( srcdir=srcdir, - template_files=['Makefile'], + # Note that src/conf/version.hpp is made later, by Makefile. + # See version.mk (included by Makefile). + template_files=['Makefile', 'src/conf/install.hpp'], ) proj.set_package('tmwa', 'The Mana World (Athena server)'); proj.jiggle() diff --git a/src/conf/install.hpp.in b/src/conf/install.hpp.in index c44f026..e63164a 100644 --- a/src/conf/install.hpp.in +++ b/src/conf/install.hpp.in @@ -20,8 +20,8 @@ // just mention "fwd.hpp" to make formatter happy -#define PACKAGESYSCONFDIR "@PACKAGESYSCONFDIR@"_s -#define PACKAGELOCALSTATEDIR "@PACKAGELOCALSTATEDIR@"_s +#define PACKAGESYSCONFDIR "@SYSCONFDIR@/tmwa"_s +#define PACKAGELOCALSTATEDIR "@LOCALSTATEDIR@/tmwa"_s #define PACKAGEDATADIR "@PACKAGEDATADIR@"_s namespace tmwa diff --git a/version.mk b/version.mk index a5137ad..39cf181 100644 --- a/version.mk +++ b/version.mk @@ -50,6 +50,29 @@ SO_SHORT := so.${ABI_VERSION} SO_LONG := ${SO_SHORT}.${VERSION_DOTS} # and thanks for all the fish +# Fully generate version.hpp here, where we have all the relevant information. +# version.mk is included by the top level Makefile, so simply explaning how to +# make it here will let it be built later, when needed. +# Note that some variable substitutions are slightly different here to use the +# name used by standard CMake macros, such as PROJECT_VERSION_TWEAK instead of +# VERSION_DEVEL. +src/conf/version.hpp: src/conf/version.hpp.in + sed -e 's/@VERSION_FULL@/${VERSION_FULL}/g' \ + -e 's/@VERSION_HASH@/${VERSION_HASH}/g' \ + -e 's/@VERSION_STRING@/${VERSION_STRING}/g' \ + -e 's/@PROJECT_VERSION_MAJOR@/${VERSION_MAJOR}/g' \ + -e 's/@PROJECT_VERSION_MINOR@/${VERSION_MINOR}/g' \ + -e 's/@PROJECT_VERSION_PATCH@/${VERSION_PATCH}/g' \ + -e 's/@PROJECT_VERSION_TWEAK@/${VERSION_DEVEL}/g' \ + -e 's/@VENDOR_NAME@/${VENDOR_NAME}/g' \ + -e 's/@VENDOR_POINT@/${VENDOR_POINT}/g' \ + -e 's|@VENDOR_SOURCE@|${VENDOR_SOURCE}|g' \ + -e 's/@ABI_VERSION@/${ABI_VERSION}/g' \ + -e 's/@SO_SHORT@/${SO_SHORT}/g' \ + -e 's/@SO_LONG@/${SO_LONG}/g' \ + $< > $@ + + version: @echo version '${VERSION_STRING}' @echo based on commit ${VERSION_FULL} aka ${VERSION_HASH} -- cgit v1.2.3-70-g09d2 From 9903d45c343fe51309075674c96b4411b6e1a002 Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Wed, 5 Jun 2024 20:09:57 +0000 Subject: python3: Add explicit list()s for python3.6 This should be reverted once we drop support for Ubuntu 18.04, and therefore python3.6, as it does clutter up the code a bit. Sourced from specing's work on the porting process. See https://git.themanaworld.org/legacy/tmwa/-/merge_requests/256 --- src/main-gdb-head.py | 2 +- src/map/script-parse.py | 2 +- tools/config.py | 6 +++--- tools/protocol.py | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main-gdb-head.py b/src/main-gdb-head.py index a465c97..09e22fe 100644 --- a/src/main-gdb-head.py +++ b/src/main-gdb-head.py @@ -5,7 +5,7 @@ # gdb sticks everything in one scope. # This lets us enumerate what *we* added. -initial_globals = {id(v):v for v in globals().values()} +initial_globals = {id(v):v for v in list(globals().values())} import re diff --git a/src/map/script-parse.py b/src/map/script-parse.py index 199e348..3346b92 100644 --- a/src/map/script-parse.py +++ b/src/map/script-parse.py @@ -106,7 +106,7 @@ class ScriptBuffer(object): code_begin = code['_M_impl']['_M_start'] code_end = code['_M_impl']['_M_finish'] code_size = int(code_end - code_begin) - r = iter(range(code_size)) + r = iter(list(range(code_size))) for i in r: buf = [] for label in labels_dict.get(i, []): diff --git a/tools/config.py b/tools/config.py index ce61440..22ece0b 100755 --- a/tools/config.py +++ b/tools/config.py @@ -257,7 +257,7 @@ class Group(object): short_cpp_name = '%s.cpp' % var_name cpp_name = os.path.join(path, short_cpp_name) - values = sorted(self.options.values(), key=lambda o: o.name) + values = sorted(list(self.options.values()), key=lambda o: o.name) desc = 'Config for %s::%s' % (namespace_name, self.name) with OpenWrite(hpp_name) as hpp, \ @@ -382,7 +382,7 @@ class Realm(object): return rv def dump(self): - for g in self.groups.values(): + for g in list(self.groups.values()): g.dump_in(self.path, self.path.split('/')[-1]) class Everything(object): @@ -399,7 +399,7 @@ class Everything(object): def dump(self): for g in glob.glob('src/*/*_conf.[ch]pp'): os.rename(g, g + '.old') - for v in self.realms.values(): + for v in list(self.realms.values()): v.dump() for g in glob.glob('src/*/*_conf.[ch]pp.old'): print('Obsolete: %s' % g) diff --git a/tools/protocol.py b/tools/protocol.py index 8059c59..b0d46a4 100755 --- a/tools/protocol.py +++ b/tools/protocol.py @@ -7084,7 +7084,7 @@ def partition(d): changed = True while changed: changed = False - for k, vlist in d.items(): + for k, vlist in list(d.items()): if vlist: m = min(leaders[v] for v in vlist) if m < leaders[k]: @@ -7100,9 +7100,9 @@ def partition(d): leaders[v] = m followers = {} - for k, v in leaders.items(): + for k, v in list(leaders.items()): followers.setdefault(v, []).append(k) - return [set(v) for v in followers.values()] + return [set(v) for v in list(followers.values())] def ids_only(vpost): rv = [e for e in vpost if not isinstance(e, SpecialEventOrigin)] @@ -7125,7 +7125,7 @@ def make_dots(ctx): for g in glob.glob('doc-gen/Packet-*.md'): os.rename(g, g + '.old') - for (id, p) in d.items(): + for (id, p) in list(d.items()): md = 'doc-gen/Packet-0x%04x.md' % id dot = 'doc-gen/packets-around-0x%04x.gv' % id with OpenWrite(md) as f: -- cgit v1.2.3-70-g09d2 From dd024fdf9ca01c02b79371512672f6798468020d Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Wed, 5 Jun 2024 22:06:13 +0000 Subject: Create generated files in the build directory Also, just require the use of full paths when #including a generated file. This fixes fresh out-of-tree builds using attoconf, and gets rid of a lot of annoying terminal output when attoconf is tracing dependencies. --- CMakeLists.txt | 13 +++++++------ Makefile.in | 10 +++------- src/mmo/version.cpp | 2 +- src/shared/lib.cpp | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d5e9d1..d997b98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,13 +101,14 @@ set(PACKAGEDATADIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/tmwa") set(LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}") set(SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}") -# Generate the install.hpp and version.hpp files in the source directory. -# TODO: Is there a nicer way to handle this so we're still able to make fully -# out-of-tree builds, generating the files in the build directory, but still -# having them found by includes? -configure_file(src/conf/install.hpp.in ${CMAKE_SOURCE_DIR}/src/conf/install.hpp @ONLY) -configure_file(src/conf/version.hpp.in ${CMAKE_SOURCE_DIR}/src/conf/version.hpp @ONLY) +# Generate the install.hpp and version.hpp files. +configure_file(src/conf/install.hpp.in src/conf/install.hpp @ONLY) +configure_file(src/conf/version.hpp.in src/conf/version.hpp @ONLY) set(conf_SOURCES ${conf_SOURCES} src/conf/install.hpp src/conf/version.hpp) +# And have the build search for files in the build directory. +# Note that #includes with generated files should use a path relative to the +# top level source or build directory. +include_directories(${CMAKE_CURRENT_BINARY_DIR}) # Add a shared library: libtmwa-shared.so.0 # When we add_executable later, we need to link against this library. diff --git a/Makefile.in b/Makefile.in index d4334eb..2f62baf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -488,12 +488,8 @@ obj/%.d: src/%.cpp | stamp/generated.stamp -MF $@ $< # -MG takes the include parameter as-is without prepending the path whenever # it's not found, and presumed to be a not-yet generated file. -# This is troublesome, since real.make tends not to be in the same directory. -# We work around this by checking to see if a file doesn't exist, and if it -# doesn't, we prepend the path. - for f in $$(sed -e '1s@$(patsubst obj/%.d,%,$@) := \(.*\)@\1@' $@ | tr ' ' \\n | grep -vFx -e : -e \\); do \ - test -f "$${f}" || sed -i "s|\($${f}\)|src/$(dir $*)\1|" $@; \ - done +# #include statements for generated files should always be relative to the +# source (or build) directory. endif # the above SRC_DIR replacement is not really safe, but it works okayish. obj/%.ii: src/%.cpp @@ -742,7 +738,7 @@ conf-raw/str-%.h: FORCE FORCE:: ; .PHONY: FORCE -override CPPFLAGS += -I . -I ${SRC_DIR}/include +override CPPFLAGS += -I. -I${SRC_DIR}/include # distribution tarballs # this only works from within a git checkout diff --git a/src/mmo/version.cpp b/src/mmo/version.cpp index f91b748..c75c25c 100644 --- a/src/mmo/version.cpp +++ b/src/mmo/version.cpp @@ -20,7 +20,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "../conf/version.hpp" +#include "src/conf/version.hpp" #include "../strings/xstring.hpp" diff --git a/src/shared/lib.cpp b/src/shared/lib.cpp index 0eebf17..563bff4 100644 --- a/src/shared/lib.cpp +++ b/src/shared/lib.cpp @@ -18,7 +18,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "../conf/install.hpp" +#include "src/conf/install.hpp" #include "../strings/literal.hpp" #include "../strings/astring.hpp" -- cgit v1.2.3-70-g09d2