Skip to content

Commit

Permalink
fix: makefile builds with mingw
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jan 8, 2024
1 parent b07eb1d commit b2c8ca4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,34 @@ jobs:
- name: CTest
shell: msys2 {0}
run: ctest --no-tests=error --test-dir out -VV --build-config Release

msys2-makefile-test:
name: msys2-makefile-${{ matrix.msystem }}
needs: makefile-analysis
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
include:
- { msystem: msys, toolchain: "gcc" }
- { msystem: mingw32, env: mingw-w64-i686- }
- { msystem: mingw64, env: mingw-w64-x86_64- }
- { msystem: ucrt64, env: mingw-w64-ucrt-x86_64- }
# - { msystem: clang32, env: mingw-w64-clang-i686- } disabled, lld does not support the "-r" option
# - { msystem: clang64, env: mingw-w64-clang-x86_64- } disabled, lld does not support the "-r" option
env:
CC: cc.exe
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup MSYS2 ${{matrix.msystem}}
uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.msystem}}
update: true
install: >-
make
${{ matrix.env }}${{ matrix.toolchain || 'toolchain' }}
- name: Run tests
shell: msys2 {0}
run: ./test/ci/test.sh
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CFLAGS += -std=c99 -O3 -Wall -Wextra -pedantic
CFLAGS += -std=c99 -O3 -Wall -Wextra -pedantic -DBASE64_STATIC_DEFINE

# Set OBJCOPY if not defined by environment:
OBJCOPY ?= objcopy
Expand Down Expand Up @@ -56,6 +56,8 @@ ifdef OPENMP
CFLAGS += -fopenmp
endif

TARGET := $(shell $(CC) -dumpmachine)


.PHONY: all analyze clean

Expand All @@ -64,9 +66,16 @@ all: bin/base64 lib/libbase64.o
bin/base64: bin/base64.o lib/libbase64.o
$(CC) $(CFLAGS) -o $@ $^

lib/libbase64.o: $(OBJS)
$(LD) -r -o $@ $^
$(OBJCOPY) --keep-global-symbols=lib/exports.txt $@
lib/exports.build.txt: lib/exports.txt
ifeq (i686-w64-mingw32, $(TARGET))
sed -e 's/^/_/' $< > $@
else
cp -f $< $@
endif

lib/libbase64.o: lib/exports.build.txt $(OBJS)
$(LD) -r -o $@ $(OBJS)
$(OBJCOPY) --keep-global-symbols=$< $@

lib/config.h:
@echo "#define HAVE_AVX512 $(HAVE_AVX512)" > $@
Expand Down Expand Up @@ -97,4 +106,4 @@ analyze: clean
scan-build --use-analyzer=`which clang` --status-bugs make

clean:
rm -f bin/base64 bin/base64.o lib/libbase64.o lib/config.h $(OBJS)
rm -f bin/base64 bin/base64.o lib/libbase64.o lib/config.h lib/exports.build.txt $(OBJS)
6 changes: 5 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
CFLAGS += -std=c99 -O3 -Wall -Wextra -pedantic
CFLAGS += -std=c99 -O3 -Wall -Wextra -pedantic -DBASE64_STATIC_DEFINE
ifdef OPENMP
CFLAGS += -fopenmp
endif

TARGET := $(shell $(CC) -dumpmachine)
ifneq (, $(findstring darwin, $(TARGET)))
BENCH_LDFLAGS=
else ifneq (, $(findstring mingw, $(TARGET)))
BENCH_LDFLAGS=
else
# default to linux, -lrt needed
BENCH_LDFLAGS=-lrt
Expand All @@ -15,7 +17,9 @@ endif

test: clean test_base64 benchmark
./test_base64
ifeq (, $(findstring mingw, $(TARGET))) # no "/dev/urandom" on Windows
./benchmark
endif

valgrind: clean test_base64
valgrind --error-exitcode=2 ./test_base64
Expand Down

0 comments on commit b2c8ca4

Please sign in to comment.