uname -s under MSYS2 never reports Windows_NT, so build.sh picked bmake.mk and gmake.mk's platform branches silently fell through to the Linux path (.so + -ldl), breaking the link. Detect MINGW/MSYS/ UCRT/CLANG uname prefixes in build.sh and route to gmake.mk; export UNAME_S once so make doesn't call uname again. gmake.mk, test/gmake.mk, and module_template/gmake.mk now derive Windows-vs-Unix from uname instead of $(OS), with the cmd.exe/batch command path reserved for environments without a POSIX shell (MSYS2 keeps mkdir -p/rm -rf).
72 lines
1.6 KiB
Makefile
72 lines
1.6 KiB
Makefile
CC := cc
|
|
CFLAGS = -Wall -Wpedantic -I../include -std=c89
|
|
LDFLAGS = -L../bin/debug -lstk
|
|
|
|
ifeq ($(UNAME_S),)
|
|
UNAME_S := $(shell uname -s)
|
|
endif
|
|
ifneq (,$(filter MINGW% MSYS% UCRT% CLANG% CYGWIN%,$(UNAME_S)))
|
|
IS_WINDOWS := 1
|
|
IS_POSIX_SHELL := 1
|
|
else ifeq ($(OS),Windows_NT)
|
|
IS_WINDOWS := 1
|
|
IS_POSIX_SHELL :=
|
|
else
|
|
IS_WINDOWS :=
|
|
IS_POSIX_SHELL := 1
|
|
endif
|
|
|
|
ifeq ($(IS_WINDOWS),1)
|
|
MODULE_EXT = .dll
|
|
EXE_EXT = .exe
|
|
else
|
|
MODULE_EXT = .so
|
|
EXE_EXT =
|
|
LDFLAGS += -Wl,-rpath,../bin/debug
|
|
endif
|
|
|
|
ifneq ($(IS_POSIX_SHELL),1)
|
|
SHELL := cmd.exe
|
|
.SHELLFLAGS := /c
|
|
endif
|
|
|
|
.PHONY: all test clean
|
|
|
|
all: test
|
|
|
|
test_program$(EXE_EXT): test.c
|
|
$(CC) $(CFLAGS) -o $@ test.c $(LDFLAGS)
|
|
|
|
test_mod$(MODULE_EXT): test_mod.c
|
|
$(CC) $(CFLAGS) -fPIC -shared -o $@ test_mod.c
|
|
|
|
test_mod_dep$(MODULE_EXT): test_mod_dep.c
|
|
$(CC) $(CFLAGS) -fPIC -shared -o $@ test_mod_dep.c
|
|
|
|
setup:
|
|
ifeq ($(IS_POSIX_SHELL),1)
|
|
@mkdir -p mods
|
|
@cp -f test_mod$(MODULE_EXT) mods/ 2>/dev/null || true
|
|
@cp -f test_mod_dep$(MODULE_EXT) mods/ 2>/dev/null || true
|
|
else
|
|
@if not exist mods mkdir mods
|
|
@if exist test_mod.dll copy /Y test_mod.dll mods\ >nul 2>&1
|
|
@if exist test_mod_dep.dll copy /Y test_mod_dep.dll mods\ >nul 2>&1
|
|
endif
|
|
|
|
test: test_program$(EXE_EXT) test_mod$(MODULE_EXT) test_mod_dep$(MODULE_EXT) setup
|
|
ifeq ($(IS_POSIX_SHELL),1)
|
|
@./test_program$(EXE_EXT)
|
|
else
|
|
@set PATH=../bin/debug;%PATH% && cmd /C "test_program.exe"
|
|
endif
|
|
|
|
clean:
|
|
ifeq ($(IS_POSIX_SHELL),1)
|
|
@rm -f test_program$(EXE_EXT) test_mod$(MODULE_EXT) test_mod_dep$(MODULE_EXT)
|
|
@rm -rf mods
|
|
else
|
|
@del /Q test_program.exe test_mod.dll test_mod_dep.dll 2>nul || true
|
|
@rmdir /S /Q mods 2>nul || true
|
|
endif
|