aboutsummaryrefslogtreecommitdiff
path: root/Makefile.win
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile.win')
-rw-r--r--Makefile.win51
1 files changed, 51 insertions, 0 deletions
diff --git a/Makefile.win b/Makefile.win
new file mode 100644
index 0000000..fffe03f
--- /dev/null
+++ b/Makefile.win
@@ -0,0 +1,51 @@
+# Makefile.win - cross-compile the Windows build with mingw-w64.
+#
+# Links the Win32 backend instead of the Wayland one (no protocols, no
+# wayland-scanner, no pkg-config). Produces a single static mouseboard.exe.
+#
+# make -f Makefile.win # x86_64
+# make -f Makefile.win CC=i686-w64-mingw32-gcc # 32-bit
+#
+# Needs a mingw-w64 cross toolchain on the build host:
+# Debian / Ubuntu : sudo apt install gcc-mingw-w64-x86-64
+# Arch : sudo pacman -S mingw-w64-gcc
+# Fedora : sudo dnf install mingw64-gcc
+#
+# Built for the GUI subsystem (-mwindows) so launching it - e.g. from a hotkey -
+# creates no console window. The backend still calls AttachConsole() at startup,
+# so --help / --dry-run / --selftest output appears when run from a terminal.
+
+VERSION = 0-dev
+
+# Unconditional: make predefines CC=cc, which ?= would keep, silently
+# building with the host compiler. `make -f Makefile.win CC=...` still wins.
+CC = x86_64-w64-mingw32-gcc
+CFLAGS ?= -std=c11 -Wall -Wextra -O2
+override CPPFLAGS += -DMOUSEBOARD_VERSION='"$(VERSION)"'
+# -s strips at link: no symbols in the shipped exe.
+MB_LDFLAGS = -static -mwindows -s
+MB_LDLIBS = -lgdi32 -luser32
+
+# Distinct object names: the Linux Makefile compiles main.o etc. with the
+# host cc, and sharing names would link objects from the wrong compiler when
+# switching builds without a clean.
+OBJ = main.win.o core.win.o config.win.o draw.win.o font.win.o \
+ backend-windows.win.o
+
+# font8x8_basic.h is vendored verbatim; its 0xFF rows overflow signed char.
+font.win.o: override CFLAGS += -Wno-overflow
+
+mouseboard.exe: $(OBJ)
+ $(CC) $(CFLAGS) $(LDFLAGS) $(MB_LDFLAGS) -o $@ $(OBJ) \
+ $(LDLIBS) $(MB_LDLIBS)
+
+# Every object depends on every header: over-rebuilds a little, never stale.
+$(OBJ): config.h core.h draw.h font.h platform.h font8x8_basic.h
+
+%.win.o: %.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+
+clean:
+ rm -f mouseboard.exe $(OBJ)
+
+.PHONY: clean