From 11837e6f10ff58f249cbfe75b92e9c50e7348132 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 21 Dec 2024 20:47:18 +0000 Subject: [PATCH 1/2] Codefix: Explicitly cast size_t result to uint32_t. --- src/sample.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sample.cpp b/src/sample.cpp index 3231e5a..65e70da 100644 --- a/src/sample.cpp +++ b/src/sample.cpp @@ -228,13 +228,15 @@ void Sample::SetOffset(uint32_t offset) uint32_t Sample::GetNextOffset() const { - return this->offset + + return static_cast( + this->offset + 1 + // length of the name (this->name.length() + 1) + // the name + '\0' this->size + // size of the data 1 + // the delimiter 1 + // length of the filename - (this->filename.length() + 1); // the filename + '\0' + (this->filename.length() + 1) // the filename + '\0' + ); } uint32_t Sample::GetOffset() const From 3372b8afbd27097679e3be5de6ce0f4e20b9bb71 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 18 Dec 2024 23:00:41 +0000 Subject: [PATCH 2/2] Change: Switch to CMake. Workflows are borrowed from grfcodec. --- .github/workflows/ci-build.yml | 128 ++++++++++++++++++++++++--- .github/workflows/commit-checker.yml | 36 +------- .github/workflows/release.yml | 117 ++++++++++++++++++++++++ CMakeLists.txt | 115 ++++++++++++++++++++++++ CPackProperties.cmake.in | 5 ++ Makefile | 68 -------------- Makefile.bundle | 121 ------------------------- Makefile.msvc | 38 -------- docs/CMakeLists.txt | 11 +++ findversion.sh | 60 ------------- generate_version.cmake | 40 +++++++++ make.bat | 8 -- src/CMakeLists.txt | 11 +++ src/catcodec.cpp | 2 +- src/rev.cpp.in | 29 ------ src/rev.hpp | 28 ------ src/version.h.in | 3 + 17 files changed, 422 insertions(+), 398 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 CMakeLists.txt create mode 100644 CPackProperties.cmake.in delete mode 100644 Makefile delete mode 100644 Makefile.bundle delete mode 100644 Makefile.msvc create mode 100644 docs/CMakeLists.txt delete mode 100755 findversion.sh create mode 100644 generate_version.cmake delete mode 100644 make.bat create mode 100644 src/CMakeLists.txt delete mode 100644 src/rev.cpp.in delete mode 100644 src/rev.hpp create mode 100644 src/version.h.in diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 9437f07..6360322 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -7,27 +7,131 @@ on: - master jobs: - build: - name: Build + linux: + name: Linux - runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: include: - - os: windows-latest - makefile: Makefile.msvc - - os: ubuntu-latest - makefile: Makefile + - compiler: clang + cxxcompiler: clang++ + - compiler: gcc + cxxcompiler: g++ + + runs-on: ubuntu-latest + env: + CC: ${{ matrix.compiler }} + CXX: ${{ matrix.cxxcompiler }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install GCC problem matcher + uses: ammaraskar/gcc-problem-matcher@master + + - name: Build + run: | + mkdir build + cd build + + echo "::group::CMake" + cmake .. + echo "::endgroup::" + + echo "::group::Build" + echo "Running on $(nproc) cores" + cmake --build . -j $(nproc) + echo "::endgroup::" + + macos: + name: Mac OS + + strategy: + fail-fast: false + matrix: + include: + - arch: arm64 + full_arch: arm64 + + runs-on: macos-latest + env: + MACOSX_DEPLOYMENT_TARGET: 10.13 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install GCC problem matcher + uses: ammaraskar/gcc-problem-matcher@master + + - name: Build + run: | + mkdir build + cd build + + echo "::group::CMake" + cmake ${GITHUB_WORKSPACE} \ + -DCMAKE_OSX_ARCHITECTURES=${{ matrix.full_arch }} \ + # EOF + echo "::endgroup::" + + echo "::group::Build" + echo "Running on $(sysctl -n hw.logicalcpu) cores" + cmake --build . -j $(sysctl -n hw.logicalcpu) + echo "::endgroup::" + + windows: + name: Windows + + strategy: + fail-fast: false + matrix: + os: [windows-latest] + arch: [x86, x64] + + runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v1 - - name: Set build environment - if: matrix.os == 'windows-latest' + uses: actions/checkout@v4 + + - name: Install MSVC problem matcher + uses: ammaraskar/msvc-problem-matcher@master + + - name: Configure developer command prompt for ${{ matrix.arch }} uses: ilammy/msvc-dev-cmd@v1 with: - arch: x86 + arch: ${{ matrix.arch }} + - name: Build - run: make -f ${{ matrix.makefile }} shell: bash + run: | + mkdir build + cd build + + echo "::group::CMake" + cmake .. \ + -GNinja \ + # EOF + echo "::endgroup::" + + echo "::group::Build" + cmake --build . + echo "::endgroup::" + + check_annotations: + name: Check Annotations + needs: + - linux + - macos + - windows + + if: always() && github.event_name == 'pull_request' + + runs-on: ubuntu-latest + + steps: + - name: Check annotations + uses: OpenTTD/actions/annotation-check@v5 diff --git a/.github/workflows/commit-checker.yml b/.github/workflows/commit-checker.yml index d83183a..511e6f3 100644 --- a/.github/workflows/commit-checker.yml +++ b/.github/workflows/commit-checker.yml @@ -10,42 +10,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 4 - name: Get pull-request commits - run: | - set -x - # actions/checkout did a merge checkout of the pull-request. As such, the first - # commit is the merge commit. This means that on HEAD^ is the base branch, and - # on HEAD^2 are the commits from the pull-request. We now check if those trees - # have a common parent. If not, we fetch a few more commits till we do. In result, - # the log between HEAD^ and HEAD^2 will be the commits in the pull-request. - DEPTH=4 - while [ -z "$(git merge-base HEAD^ HEAD^2)" ]; do - # Prevent infinite recursion - if [ ${DEPTH} -gt 256 ]; then - echo "No common parent between '${GITHUB_HEAD_REF}' and '${GITHUB_BASE_REF}'." >&2 - exit 1 - fi - - git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --deepen=${DEPTH} origin HEAD - DEPTH=$(( ${DEPTH} * 4 )) - done - - # Just to show which commits we are going to evaluate. - git log --oneline HEAD^..HEAD^2 - - - name: Checkout commit-checker - uses: actions/checkout@v2 - with: - repository: OpenTTD/OpenTTD-git-hooks - path: git-hooks - ref: master + uses: OpenTTD/actions/checkout-pull-request@v5 - name: Check commits - run: | - set -x - HOOKS_DIR=./git-hooks/hooks GIT_DIR=.git ./git-hooks/hooks/check-commits.sh HEAD^..HEAD^2 - echo "Commit checks passed" + uses: OpenTTD/OpenTTD-git-hooks@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c233fa4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,117 @@ +name: Release + +on: + release: + types: + - published + +jobs: + source: + name: Source + + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Generate .version + run: | + cmake -DWRITE_VERSION=1 -P generate_version.cmake + + - name: Create bundles + run: | + FOLDER_NAME=catcodec-${{ github.event.release.tag_name }} + + # Rename the folder to catcodec-NNN + mkdir ${FOLDER_NAME} + find . -maxdepth 1 -not -name . -not -name .git -not -name ${FOLDER_NAME} -exec mv {} ${FOLDER_NAME}/ \; + + mkdir -p build/bundles + + echo "::group::Create tarball (xz) bundle" + tar --xz -cvf build/bundles/${FOLDER_NAME}-source.tar.xz ${FOLDER_NAME} + echo "::endgroup::" + + echo "::group::Create zip bundle" + zip -9 -r build/bundles/${FOLDER_NAME}-source.zip ${FOLDER_NAME} + echo "::endgroup::" + + - name: Store bundles + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ github.event.release.tag_name }} build/bundles/* + + windows: + needs: source + + strategy: + fail-fast: false + matrix: + arch: [x86, x64] + + name: Windows (${{ matrix.arch }}) + + runs-on: windows-latest + + steps: + - name: Prepare build dir for gh usage + shell: bash + run: | + git init build + cd build + git remote add origin ${{ github.event.repository.html_url }} + + - name: Download source + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + cd build + gh release download ${{ github.event.release.tag_name }} -p "*.xz" -D .. + + - name: Unpack source + shell: bash + run: | + tar --xz -xf *-source.tar.xz --strip-components=1 + + - name: Install MSVC problem matcher + uses: ammaraskar/msvc-problem-matcher@master + + - name: Configure developer command prompt for ${{ matrix.arch }} + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + + - name: Build + shell: bash + run: | + cd build + + echo "::group::CMake" + cmake .. \ + -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + # EOF + echo "::endgroup::" + + echo "::group::Build" + cmake --build . + echo "::endgroup::" + + - name: Create bundles + shell: bash + run: | + cd build + echo "::group::Run CPack" + cpack + echo "::endgroup::" + + - name: Store bundles + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + cd build + gh release upload ${{ github.event.release.tag_name }} bundles/* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a2a3c41 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,115 @@ +cmake_minimum_required(VERSION 3.16) + +project(catcodec) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED) +set(CMAKE_CXX_EXTENSIONS NO) + +if(MINGW) + # Force searching static libs, so the executables can run outside MinGW environment + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + + # Force static linking, so the executables can run outside MinGW environment + link_libraries(-static -static-libgcc -static-libstdc++) +endif() + +if(MSVC) + # Switch to MT (static) instead of MD (dynamic) binary + + # For MSVC two generators are available + # - a command line generator (Ninja) using CMAKE_BUILD_TYPE to specify the + # configuration of the build tree + # - an IDE generator (Visual Studio) using CMAKE_CONFIGURATION_TYPES to + # specify all configurations that will be available in the generated solution + list(APPEND MSVC_CONFIGS "${CMAKE_BUILD_TYPE}" "${CMAKE_CONFIGURATION_TYPES}") + + # Set usage of static runtime for all configurations + foreach(MSVC_CONFIG ${MSVC_CONFIGS}) + string(TOUPPER "CMAKE_CXX_FLAGS_${MSVC_CONFIG}" MSVC_FLAGS) + string(REPLACE "/MD" "/MT" ${MSVC_FLAGS} "${${MSVC_FLAGS}}") + endforeach() + + add_compile_options( + /wd4996 # Disable deprecation warnings + /W3 + ) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + add_compile_options( + -Wall + -Wextra + -Wno-format-nonliteral + -Wno-multichar + ) +endif() + + +# Add some -D flags for Debug builds. We cannot use add_definitions(), because +# it does not appear to support the $<> tags. +add_compile_options( + "$<$:-D_DEBUG>" + "$<$>:-D_FORTIFY_SOURCE=2>" # FORTIFY_SOURCE should only be used in non-debug builds (requires -O1+) +) +if(MINGW) + add_link_options( + "$<$>:-fstack-protector>" # Prevent undefined references when _FORTIFY_SOURCE > 0 + ) +endif() + +# Prepare generated dir +set(GENERATED_BINARY_DIR "${CMAKE_BINARY_DIR}/generated") +include_directories("${GENERATED_BINARY_DIR}") + +# Target to generate version.h +add_custom_target(version_header + COMMAND ${CMAKE_COMMAND} + -DGENERATED_BINARY_DIR=${GENERATED_BINARY_DIR} + -DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR} + -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_version.cmake" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + BYPRODUCTS "${GENERATED_BINARY_DIR}/version.h" +) + + +# Create catcodec +add_executable(catcodec) +add_dependencies(catcodec version_header) + +# Add source files +add_subdirectory(src) + + +# Install files +include(GNUInstallDirs) + +install(TARGETS + catcodec + DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/changelog.txt + ${CMAKE_CURRENT_SOURCE_DIR}/COPYING + DESTINATION ${CMAKE_INSTALL_DOCDIR} +) + +add_subdirectory(docs) + + +# CPack +if(WIN32) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ARCHITECTURE "win64") + else() + set(ARCHITECTURE "win32") + endif() + + set(CPACK_SYSTEM_NAME "${ARCHITECTURE}") + set(CPACK_STRIP_FILES YES) + set(CPACK_OUTPUT_FILE_PREFIX "bundles") + set(CPACK_PACKAGE_FILE_NAME "catcodec-#CPACK_PACKAGE_VERSION#-windows-${CPACK_SYSTEM_NAME}") + + set(CPACK_GENERATOR "ZIP") + + include(CPack) +endif() diff --git a/CPackProperties.cmake.in b/CPackProperties.cmake.in new file mode 100644 index 0000000..55c0626 --- /dev/null +++ b/CPackProperties.cmake.in @@ -0,0 +1,5 @@ +# Make the current version available to CPack +set(CPACK_PACKAGE_VERSION "@GIT_VERSION@") + +# Name the output file with the correct version +string(REPLACE "#CPACK_PACKAGE_VERSION#" "${CPACK_PACKAGE_VERSION}" CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}") diff --git a/Makefile b/Makefile deleted file mode 100644 index 552e882..0000000 --- a/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -# $Id$ - -# ========================================================= -# Makefile for the catcodec program -# -# Don't put any local configuration in here -# Change Makefile.local instead, it'll be -# preserved when updating the sources -# ========================================================= -# -# catcodec 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, version 2. -# catcodec 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 catcodec. If not, see . - -ifdef VERBOSE - Q = -else - Q = @ -endif - - -ROOT_DIR := $(shell pwd) -PACKAGE_NAME = catcodec - --include Makefile.local - -AWK ?= "awk" -BUNDLE_DIR ?= "$(ROOT_DIR)/bundle" -BUNDLES_DIR ?= "$(ROOT_DIR)/bundles" -CATCODEC ?= catcodec$(EXTENSION) -CXXFLAGS ?= -Wall -Wcast-qual -Wwrite-strings -OS ?= unknown - - -OBJS = catcodec.o io.o sample.o rev.o - -# Regardless of the warning settings, we really do not want these errors. -CXXFLAGS += -Wno-multichar -ifdef DEBUG - CXXFLAGS += -g -ggdb -endif - -all: $(CATCODEC) - -objs/%.o: src/%.cpp - $(Q)mkdir -p objs - @echo '[CPP] $@' - $(Q)$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< - -$(CATCODEC): $(OBJS:%=objs/%) - @echo '[LINK] $@' - $(Q)$(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $^ - -VERSION := $(shell ./findversion.sh | cut -f 1 -d' ') -RES := $(shell if [ "`cat version.cache 2>/dev/null`" != "$(VERSION)" ]; then echo "$(VERSION)" > version.cache; fi ) - -src/rev.cpp: version.cache src/rev.cpp.in - $(Q)cat src/rev.cpp.in | sed "s@\!\!VERSION\!\!@$(VERSION)@g" > src/rev.cpp - -clean: - @echo '[CLEAN]' - $(Q)rm -f $(CATCODEC) src/rev.cpp version.cache - $(Q)rm -rf objs - -mrproper: clean - $(Q)rm -rf $(BUNDLE_DIR) $(BUNDLES_DIR) - -include Makefile.bundle diff --git a/Makefile.bundle b/Makefile.bundle deleted file mode 100644 index 5f4960d..0000000 --- a/Makefile.bundle +++ /dev/null @@ -1,121 +0,0 @@ -# $Id$ - -# This file is part of catcodec. -# catcodec 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, version 2. -# catcodec 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 catcodec. If not, see . - -# -# Creation of bundles -# - -# Standard make convention variables/locations -prefix ?= /usr/local -exec_prefix ?= $(prefix) -datarootdir ?= $(prefix)/share -datadir ?= $(datarootdir) - -bindir ?= $(exec_prefix)/bin -mandir ?= $(datarootdir)/man -man1dir ?= $(mandir)/man1 -docdir ?= $(datarootdir)/doc/$(PACKAGE_NAME) - -openttddir ?= $(datarootdir}/openttd -openttdgmdir ?= $(openttddir)/gm/$(PACKAGE_NAME) -openttddatadir ?= $(openttddir)/data/$(PACKAGE_NAME) - -# The revision is needed for the bundle name and creating an OSX application bundle. -ifdef REVISION -REV := $(REVISION) -else -# Detect the revision -VERSIONS := $(shell AWK="$(AWK)" "./findversion.sh") -REV := $(shell echo "$(VERSIONS)" | cut -f 1 -d' ') -endif - -# Make sure we have something in REV -ifeq ($(REV),) -REV := norev000 -endif - -ifndef BUNDLE_NAME -BUNDLE_NAME = catcodec-custom-$(REV)-$(OS) -endif - -bundle: all - @echo '[BUNDLE] Constructing bundle' - $(Q)rm -rf "$(BUNDLE_DIR)" - $(Q)mkdir -p "$(BUNDLE_DIR)" - $(Q)mkdir -p "$(BUNDLE_DIR)/docs" - $(Q)mkdir -p "$(BUNDLE_DIR)/man" - $(Q)cp "$(CATCODEC)" "$(BUNDLE_DIR)/" - $(Q)cp "$(ROOT_DIR)/COPYING" "$(BUNDLE_DIR)/" - $(Q)cp "$(ROOT_DIR)/changelog.txt" "$(BUNDLE_DIR)/" - $(Q)cp "$(ROOT_DIR)/docs/readme.txt" "$(BUNDLE_DIR)/docs/" - $(Q)cp "$(ROOT_DIR)/docs/catcodec.1" "$(BUNDLE_DIR)/man/" - $(Q)gzip -9 "$(BUNDLE_DIR)/man/catcodec.1" -ifeq ($(CATCODEC), catcodec.exe) - $(Q)unix2dos "$(BUNDLE_DIR)/COPYING" - $(Q)unix2dos "$(BUNDLE_DIR)/"*.txt -endif - -install: bundle - @echo '[INSTALL] Installing catcodec' - $(Q)install -d "$(DESTDIR)$(bindir)" - $(Q)install -m 755 "$(BUNDLE_DIR)/$(CATCODEC)" "$(DESTDIR)$(bindir)/" -ifndef DO_NOT_INSTALL_DOCS - $(_C)install -d "$(DESTDIR)$(docdir)" - $(_C)install -m 644 "$(BUNDLE_DIR)/docs/"* "$(DESTDIR)$(docdir)" -endif -ifndef DO_NOT_INSTALL_CHANGELOG - $(_C)install -d "$(DESTDIR)$(docdir)" - $(_C)install -m 644 "$(BUNDLE_DIR)/changelog.txt" "$(DESTDIR)$(docdir)" -endif -ifndef DO_NOT_INSTALL_LICENSE - $(_C)install -d "$(DESTDIR)$(docdir)" - $(_C)install -m 644 "$(BUNDLE_DIR)/COPYING" "$(DESTDIR)$(docdir)" -endif -ifndef DO_NOT_INSTALL_MAN - $(_C)install -d "$(DESTDIR)$(man1dir)" - $(_C)install -m 644 "$(BUNDLE_DIR)/man/"*.1.gz "$(DESTDIR)$(man1dir)/" -endif - -### Packing the current bundle into several compressed file formats ### -# -# Zips & dmgs do not contain a root folder, i.e. they have files in the root of the zip/dmg. -# gzip, bzip2 and lha archives have a root folder, with the same name as the bundle. -# -# One can supply a custom name by adding BUNDLE_NAME:= to the make command. -# -bundle_zip: bundle - @echo '[BUNDLE] Creating $(BUNDLE_NAME).zip' - $(Q)mkdir -p "$(BUNDLES_DIR)" - $(Q)cd "$(BUNDLE_DIR)" && zip -r $(shell if test -z "$(VERBOSE)"; then echo '-q'; fi) "$(BUNDLES_DIR)/$(BUNDLE_NAME).zip" . - -bundle_gzip: bundle - @echo '[BUNDLE] Creating $(BUNDLE_NAME).tar.gz' - $(Q)mkdir -p "$(BUNDLES_DIR)/.gzip/$(BUNDLE_NAME)" - $(Q)cp -R "$(BUNDLE_DIR)/"* "$(BUNDLES_DIR)/.gzip/$(BUNDLE_NAME)/" - $(Q)cd "$(BUNDLES_DIR)/.gzip" && tar -zc$(shell if test -n "$(VERBOSE)"; then echo 'v'; fi)f "$(BUNDLES_DIR)/$(BUNDLE_NAME).tar.gz" "$(BUNDLE_NAME)" - $(Q)rm -rf "$(BUNDLES_DIR)/.gzip" - -bundle_bzip2: bundle - @echo '[BUNDLE] Creating $(BUNDLE_NAME).tar.bz2' - $(Q)mkdir -p "$(BUNDLES_DIR)/.bzip2/$(BUNDLE_NAME)" - $(Q)cp -R "$(BUNDLE_DIR)/"* "$(BUNDLES_DIR)/.bzip2/$(BUNDLE_NAME)/" - $(Q)cd "$(BUNDLES_DIR)/.bzip2" && tar -jc$(shell if test -n "$(VERBOSE)"; then echo 'v'; fi)f "$(BUNDLES_DIR)/$(BUNDLE_NAME).tar.bz2" "$(BUNDLE_NAME)" - $(Q)rm -rf "$(BUNDLES_DIR)/.bzip2" - -bundle_lha: bundle - @echo '[BUNDLE] Creating $(BUNDLE_NAME).lha' - $(Q)mkdir -p "$(BUNDLES_DIR)/.lha/$(BUNDLE_NAME)" - $(Q)cp -R "$(BUNDLE_DIR)/"* "$(BUNDLES_DIR)/.lha/$(BUNDLE_NAME)/" - $(Q)cd "$(BUNDLES_DIR)/.lha" && lha ao6 "$(BUNDLES_DIR)/$(BUNDLE_NAME).lha" "$(BUNDLE_NAME)" - $(Q)rm -rf "$(BUNDLES_DIR)/.lha" - -bundle_dmg: bundle - @echo '[BUNDLE] Creating $(BUNDLE_NAME).dmg' - $(Q)mkdir -p "$(BUNDLES_DIR)/catcodec $(REV)" - $(Q)cp -R "$(BUNDLE_DIR)/" "$(BUNDLES_DIR)/catcodec $(REV)" - $(Q)hdiutil create -ov -format UDZO -srcfolder "$(BUNDLES_DIR)/catcodec $(REV)" "$(BUNDLES_DIR)/$(BUNDLE_NAME).dmg" - $(Q)rm -fr "$(BUNDLES_DIR)/catcodec $(REV)" diff --git a/Makefile.msvc b/Makefile.msvc deleted file mode 100644 index c25b824..0000000 --- a/Makefile.msvc +++ /dev/null @@ -1,38 +0,0 @@ -# $Id$ -# This file is part of catcodec. -# catcodec 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, version 2. -# catcodec 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 catcodec. If not, see . - -# -# Makefile for creating bundles of MSVC's binaries in the same way as we make -# the zip bundles for ALL other OSes. -# -# Usage: make -f Makefile.msvc PLATFORM=[Win32|x64] BUNDLE_NAME=openttd--win[32|64] -# or make -f Makefile.msvc PLATFORM=[Win32|x64] BUNDLE_NAME=OTTD-win[32|64]-nightly- -# - -# Check if we want to show what we are doing -ifdef VERBOSE - Q = -else - Q = @ -endif - -AWK = "awk" -ROOT_DIR := $(shell pwd) -BUNDLE_DIR = "$(ROOT_DIR)/bundle" -BUNDLES_DIR = "$(ROOT_DIR)/bundles" -CATCODEC = "catcodec.exe" -OS = "windows" - -all: src/catcodec.cpp src/io.cpp src/sample.cpp src/rev.cpp - cmd /c make.bat - -VERSION := $(shell ./findversion.sh | cut -f 1 -d' ') -RES := $(shell if [ "`cat version.cache 2>/dev/null`" != "$(VERSION)" ]; then echo "$(VERSION)" > version.cache; fi ) - -src/rev.cpp: version.cache src/rev.cpp.in - $(Q)cat src/rev.cpp.in | sed "s@\!\!VERSION\!\!@$(VERSION)@g" > src/rev.cpp - -include Makefile.bundle diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 0000000..2bc14b5 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/catcodec.1 + DESTINATION ${CMAKE_INSTALL_MANDIR} +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/readme.txt + DESTINATION ${CMAKE_INSTALL_DOCDIR} +) diff --git a/findversion.sh b/findversion.sh deleted file mode 100755 index 9d4b82d..0000000 --- a/findversion.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -# $Id$ - -# This file is part of catcodec. -# catcodec 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, version 2. -# catcodec 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 catcodec. If not, see . - -# Arguments given? Show help text. -if [ "$#" != "0" ]; then - cat <\t\t\t -REV - a string describing what version of the code the current checkout is - based on. The exact format of this string depends on the version - control system in use, but it tries to identify the revision used as - close as possible (using the svn revision number or hg/git hash). - This also includes an indication of whether the checkout was - modified and which branch was checked out. This value is not - guaranteed to be sortable, but is mainly meant for identifying the - revision and user display. - - If no revision identifier could be found, this is left empty. -REV_NR - the revision number of the svn revision this checkout is based on. - This can be used to determine which functionality is present in this - checkout. For trunk svn checkouts and hg/git branches based upon it, - this number should be accurate. For svn branch checkouts, this - number is mostly meaningless, at least when comparing with the - REV_NR from other branches or trunk. - - This number should be sortable. Within a given branch or trunk, a - higher number means a newer version. However, when using git or hg, - this number will not increase on new commits. - - If no revision number could be found, this is left empty. -MODIFIED - Whether (the src directory of) this checkout is modified or not. A - value of 0 means not modified, a value of 2 means it was modified. - Modification is determined in relation to the commit identified by - REV, so not in relation to the svn revision identified by REV_NR. - - A value of 1 means that the modified status is unknown, because this - is not an svn/git/hg checkout for example. - -CLEAN_REV - the same as REV but without branch name - -By setting the AWK environment variable, a caller can determine which -version of "awk" is used. If nothing is set, this script defaults to -"awk". -EOF -exit 1; -fi - -VERSION="1.0.5" -echo "$VERSION $VERSION 0 $VERSION" diff --git a/generate_version.cmake b/generate_version.cmake new file mode 100644 index 0000000..d392048 --- /dev/null +++ b/generate_version.cmake @@ -0,0 +1,40 @@ +find_package(Git QUIET) + +# .git may be a directory or a regular file +if(GIT_FOUND AND EXISTS ".git") + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty=M + OUTPUT_VARIABLE GIT_VERSION + RESULT_VARIABLE GIT_DESCRIBE_RESULT + ERROR_VARIABLE GIT_DESCRIBE_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + execute_process( + COMMAND ${GIT_EXECUTABLE} show -s --pretty=%cd --date=short HEAD + OUTPUT_VARIABLE GIT_DATE + RESULT_VARIABLE GIT_SHOW_RESULT + ERROR_VARIABLE GIT_SHOW_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +elseif(EXISTS ".version") + file(READ ".version" GIT_VERSION) + string(REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}") + string(REPLACE "\t" ";" GIT_VERSION "${GIT_VERSION}") + list(GET GIT_VERSION 1 GIT_DATE) + list(GET GIT_VERSION 0 GIT_VERSION) +else() + message(WARNING "No version detected") + set(GIT_VERSION "unknown") + set(GIT_DATE "unknown") +endif() + +if(WRITE_VERSION) + file(WRITE .version "${GIT_VERSION}\t${GIT_DATE}\n") +else() + message(STATUS "Generating version.h") + configure_file("src/version.h.in" "${GENERATED_BINARY_DIR}/version.h") + + message(STATUS "Generating CPackProperties.cmake") + configure_file("CPackProperties.cmake.in" "${CPACK_BINARY_DIR}/CPackProperties.cmake" @ONLY) +endif() diff --git a/make.bat b/make.bat deleted file mode 100644 index 4aed6d8..0000000 --- a/make.bat +++ /dev/null @@ -1,8 +0,0 @@ -@rem $Id$ - -@rem This file is part of catcodec. -@rem catcodec 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, version 2. -@rem catcodec 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. -@rem See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with catcodec. If not, see . - -cl /MT /Ot /W2 /RTC1 /EHsc /DWIN32 src/catcodec.cpp src/io.cpp src/sample.cpp src/rev.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..8cb5862 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +# Add files for catcodec +target_sources(catcodec PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/catcodec.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/io.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/io.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sample.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sample.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/stdafx.h +) diff --git a/src/catcodec.cpp b/src/catcodec.cpp index e50df00..5adb3b3 100644 --- a/src/catcodec.cpp +++ b/src/catcodec.cpp @@ -23,7 +23,7 @@ #include "stdafx.h" #include "io.hpp" #include "sample.hpp" -#include "rev.hpp" +#include "version.h" /** Are we run interactively, i.e. from the console, or from a script? */ static bool _interactive; diff --git a/src/rev.cpp.in b/src/rev.cpp.in deleted file mode 100644 index cc9cb92..0000000 --- a/src/rev.cpp.in +++ /dev/null @@ -1,29 +0,0 @@ -/* $Id$ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file rev.cpp Autogenerated file with the revision and such of OpenTTD. */ - -#include "stdafx.h" -#include "rev.hpp" - -/** - * The text version of catcodec's revision. - */ -const char _catcodec_version[] = "!!VERSION!!"; diff --git a/src/rev.hpp b/src/rev.hpp deleted file mode 100644 index 1e7890c..0000000 --- a/src/rev.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* $Id$ */ - -/* - * catcodec is a tool to decode/encode the sample catalogue for OpenTTD. - * Copyright (C) 2009 Remko Bijker - * - * 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, version 2. - * - * 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, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** @file rev.h declaration of catcodec revision dependant variables */ - -#ifndef REV_HPP -#define REV_HPP - -extern const char _catcodec_version[]; - -#endif /* REV_HPP */ diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..96f0266 --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,3 @@ + +static const char _catcodec_version[] = "${GIT_VERSION}"; +static const char _catcodec_date[] = "${GIT_DATE}";