DSCF

.co.uk

PC32

A ColorForth compiler and editor for x86-64
git clone https://dscf.co.uk/clone/PC32.git
Back | Log | Files | Refs | Issues

makefile.win (2805B)


      1 # Windows build of PC32 - cross-compiled from Linux with MinGW-w64 (no cmake, no Windows needed).
      2 # Produces ./PC32.exe: one static 32-bit executable for Windows 7+ (runs on 32/64-bit Windows).
      3 # Only system DLLs are needed at run time (opengl32, glu32, gdi32, user32, kernel32, msvcrt...).
      4 #
      5 #   make win         (from the main makefile)  or:  make -f makefile.win
      6 #   make winclean    remove objects + PC32.exe
      7 #
      8 # The toolchain (gcc, binutils, headers, nasm) is fetched into ./mingw by tools/mkmingw.py.
      9 # The Linux build (makefile) is untouched by this file.
     10 # After `make winslim` an up-to-date PC32.exe does not trigger a re-download; only compiling does.
     11 
     12 MINGW  ?= $(CURDIR)/mingw
     13 # Fetch the toolchain only when a recipe that needs it actually runs (not an order-only prerequisite:
     14 # make builds those whenever they are missing, which would re-download after `make winslim`).
     15 NEEDTC  = @test -f $(MINGW)/.done || python3 -I tools/mkmingw.py $(MINGW)
     16 BIN     = $(MINGW)/usr/bin
     17 # the Debian-packaged cross compiler needs its math libs, which live in the unpacked tree
     18 ENVSET  = PATH=$(BIN):$$PATH LD_LIBRARY_PATH=$(MINGW)/usr/lib/x86_64-linux-gnu
     19 WCC     = $(ENVSET) i686-w64-mingw32-gcc-win32
     20 WAR     = $(ENVSET) i686-w64-mingw32-ar
     21 NASM    = $(ENVSET) nasm
     22 
     23 TARGETOS = -D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -DNTDDI_VERSION=0x06010000
     24 GLFWDIR  = third_party/glfw
     25 GLFWSRC  = context init input monitor vulkan window win32_init win32_joystick win32_monitor \
     26            win32_thread win32_time win32_window wgl_context egl_context osmesa_context
     27 GLFWOBJ  = $(addprefix build/win/glfw/,$(addsuffix .o,$(GLFWSRC)))
     28 
     29 GLFWFLAGS = -m32 -O2 -w -D_GLFW_WIN32 $(TARGETOS) -I$(GLFWDIR)/include
     30 CFLAGS    = -m32 -w -g -O0 -Wno-format $(TARGETOS) -I$(GLFWDIR)/include
     31 
     32 # -static: no MinGW runtime DLLs.  binutils 2.31 leaves ASLR (dynamicbase) and NX (nxcompat) off by default,
     33 # which is what the VM needs (fixed addresses, executable data); newer binutils would need --disable-dynamicbase etc.
     34 LDFLAGS = -m32 -static
     35 LIBS    = build/win/libglfw.a -lopengl32 -lglu32 -lgdi32 -luser32 -lkernel32 -lshell32 -lwinmm
     36 
     37 DATA = data/sine.bin data/fnt.bin
     38 
     39 PC32.exe: build/win/cf.o build/win/main.o build/win/libglfw.a
     40 	$(WCC) $(LDFLAGS) -o $@ build/win/main.o build/win/cf.o $(LIBS)
     41 	python3 -I tools/pepatch.py $@
     42 
     43 build/win/cf.o: cf.s $(DATA)
     44 	$(NEEDTC)
     45 	@mkdir -p build/win
     46 	$(NASM) -f win32 --prefix _ -DWIN32 cf.s -o $@
     47 
     48 build/win/main.o: main.c win32_compat.h debuglog.h
     49 	$(NEEDTC)
     50 	@mkdir -p build/win
     51 	$(WCC) $(CFLAGS) -c main.c -o $@
     52 
     53 build/win/libglfw.a: $(GLFWOBJ)
     54 	$(WAR) rcs $@ $^
     55 
     56 build/win/glfw/%.o: $(GLFWDIR)/src/%.c
     57 	$(NEEDTC)
     58 	@mkdir -p build/win/glfw
     59 	$(WCC) $(GLFWFLAGS) -c $< -o $@
     60 
     61 $(MINGW)/.done:
     62 	python3 -I tools/mkmingw.py $(MINGW)
     63 
     64 winclean:
     65 	rm -rf build/win PC32.exe
     66 
     67 .PHONY: winclean