From c7cc152dc4a8e19710a9ff0d155fb082f25be4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Mon, 21 Feb 2022 02:41:36 +0100 Subject: [PATCH] add support for mingw64 build --- .gitignore | 1 + Makefile | 8 ++++---- build-linux.sh | 6 ++++++ build-windows.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100755 build-linux.sh create mode 100755 build-windows.sh diff --git a/.gitignore b/.gitignore index 567609b..cb812a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +mingw-w64-x86_64-xz/ diff --git a/Makefile b/Makefile index 4b2cf5a..9413db8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=gcc CXX=g++ -CFLAGS=-O3 -CXXFLAGS=-O3 +CFLAGS=$(MINGWPATHS) -O3 +CXXFLAGS=-std=c++17 $(MINGWPATHS) -O3 DEPS = src/compress.h src/stringutils.h LIBS=-llzma OBJECTS = build/compress.o build/stringutils.o @@ -17,11 +17,11 @@ build/%.o: src/%.c $(DEPS) build/%.o: src/%.cpp $(DEPS) $(MAKE_BUILD_FOLDER) - $(CXX) -c -o $@ $< $(CFLAGS) + $(CXX) -c -o $@ $< $(CXXFLAGS) build/compress_measurements: $(OBJECTS) src/compress_measurements.cpp $(MAKE_BUILD_FOLDER) - $(CXX) -o $@ $^ $(LIBS) $(CFLAGS) + $(CXX) -static -o $@ $^ $(LIBS) $(CXXFLAGS) clean: -rm -rf build diff --git a/build-linux.sh b/build-linux.sh new file mode 100755 index 0000000..2d54568 --- /dev/null +++ b/build-linux.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +make clean +make diff --git a/build-windows.sh b/build-windows.sh new file mode 100755 index 0000000..4663610 --- /dev/null +++ b/build-windows.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -e + +XZ_DIR="mingw-w64-x86_64-xz" +XZ_PACKAGE_VERSION_FILE="${XZ_DIR}/version" +XZ_PACKAGE_VERSION="mingw-w64-x86_64-xz-5.2.5-2-any.pkg.tar.zst" + +if [ -f "${XZ_DIR}/version" ]; then + XZ_PACKAGE_INSTALLED_VERSION=$(<$XZ_PACKAGE_VERSION_FILE) +else + XZ_PACKAGE_INSTALLED_VERSION="" +fi + +if [ "${XZ_PACKAGE_VERSION}" != "${XZ_PACKAGE_INSTALLED_VERSION}" ]; then + rm -rf ${XZ_DIR} + mkdir ${XZ_DIR} + (cd mingw-w64-x86_64-xz && \ + wget -qO- https://mirror.msys2.org/mingw/mingw64/${XZ_PACKAGE_VERSION} | \ + unzstd - | \ + tar -xf -) + echo ${XZ_PACKAGE_VERSION} > ${XZ_PACKAGE_VERSION_FILE} +fi + +export MINGWPATHS="-Imingw-w64-x86_64-xz/mingw64/include -Lmingw-w64-x86_64-xz/mingw64/lib" + +case "$(uname -s)" in + Linux) + export CC="x86_64-w64-mingw32-gcc" + export CXX="x86_64-w64-mingw32-g++" + ;; + + MINGW*) + export CC="gcc" + export CXX="g++" + ;; +esac + +make clean +make