Skip to content

Instantly share code, notes, and snippets.

@MichaelMackus
Created April 20, 2025 04:54
Show Gist options
  • Save MichaelMackus/38c57ad25f678cbc923da10c62f4332e to your computer and use it in GitHub Desktop.
Save MichaelMackus/38c57ad25f678cbc923da10c62f4332e to your computer and use it in GitHub Desktop.
PDCurses windows console cross compilation with clang-cl
# Visual C++ Makefile for PDCurses - Windows console
#
# Usage: nmake -f [path/]Makefile.vc [DEBUG=Y] [DLL=Y] [WIDE=Y] [UTF8=Y]
# [INFOEX=N] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
O = obj
E = .exe
RM = rm
ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
endif
include $(PDCURSES_SRCDIR)/common/libobjs.mif
osdir = $(PDCURSES_SRCDIR)/wincon
common = $(PDCURSES_SRCDIR)/common
PDCURSES_WIN_H = $(osdir)/pdcwin.h
XWIN_DIR=$(HOME)/windows-sdk/.xwin-cache/splat
CC = clang-cl -nologo --target=x86_64-pc-windows-msvc \
-vctoolsdir $(XWIN_DIR)/crt/lib/x86_64/ \
-winsdkdir $(XWIN_DIR)/sdk/ \
/I $(XWIN_DIR)/crt/include/
ifdef DEBUG
CFLAGS = -Z7 -DPDCDEBUG
LDFLAGS = -debug -pdb:none
else
CFLAGS = -O1
LDFLAGS =
endif
ifdef WIDE
WIDEOPT = -DPDC_WIDE
endif
ifdef UTF8
UTF8OPT = -DPDC_FORCE_UTF8
endif
ifdef INFOEX
INFOPT = -DHAVE_NO_INFOEX
endif
SHL_LD = lld-link $(LDFLAGS) -nologo -dll -out:pdcurses.dll /libpath:$(XWIN_DIR)/crt/lib/x86_64/ \
/libpath:$(XWIN_DIR)/sdk/lib/ucrt/x86_64/ \
/libpath:$(XWIN_DIR)/sdk/lib/um/x86_64/ \
/libpath:$(PDCURSES_SRCDIR)/wincon/
LINK = lld-link $(LDFLAGS) -nologo /libpath:$(XWIN_DIR)/crt/lib/x86_64/ \
/libpath:$(XWIN_DIR)/sdk/lib/ucrt/x86_64/ \
/libpath:$(XWIN_DIR)/sdk/lib/um/x86_64/ \
/libpath:$(PDCURSES_SRCDIR)/wincon/
CCLIBS = user32.lib advapi32.lib
# may need to add msvcrt for older compilers
#CCLIBS = msvcrt.lib user32.lib advapi32.lib
LIBEXE = lld-link /lib -nologo /libpath:$(XWIN_DIR)/crt/lib/x86_64/ \
/libpath:$(XWIN_DIR)/sdk/lib/ucrt/x86_64/ \
/libpath:$(XWIN_DIR)/sdk/lib/um/x86_64/ \
/libpath:$(PDCURSES_SRCDIR)/wincon/
# needed for building DLL
WINDRES = x86_64-w64-mingw32-windres
LIBCURSES = pdcurses.lib
CURSESDLL = pdcurses.dll
ifdef DLL
DLLOPT = -DPDC_DLL_BUILD
PDCLIBS = $(CURSESDLL)
else
PDCLIBS = $(LIBCURSES)
endif
BUILD = $(CC) -I$(PDCURSES_SRCDIR) -c $(CFLAGS) $(DLLOPT) \
$(WIDEOPT) $(UTF8OPT) $(INFOPT)
all: $(PDCLIBS)
clean:
-$(RM) *.obj
-$(RM) *.lib
-$(RM) *.exe
-$(RM) *.dll
-$(RM) *.exp
-$(RM) *.res
demos: $(PDCLIBS) $(DEMOS)
DEMOOBJS = $(DEMOS:.exe=.obj) tui.obj
$(LIBOBJS) $(PDCOBJS) : $(PDCURSES_HEADERS)
$(PDCOBJS) : $(PDCURSES_WIN_H)
$(DEMOOBJS) : $(PDCURSES_CURSES_H)
$(DEMOS) : $(LIBCURSES)
panel.obj : $(PANEL_HEADER)
ifndef DLL
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
$(LIBEXE) -out:$@ $(LIBOBJS) $(PDCOBJS)
endif
# $(CURSESDLL) : $(LIBOBJS) $(PDCOBJS) pdcurses.obj
# $(SHL_LD) $(LIBOBJS) $(PDCOBJS) pdcurses.obj $(CCLIBS)
# the following seems to work instead of using windows utilities (needs windres from mingw):
$(CURSESDLL) : $(LIBOBJS) $(PDCOBJS) pdcurses.o
$(SHL_LD) $(LIBOBJS) $(PDCOBJS) pdcurses.o $(CCLIBS)
pdcurses.res pdcurses.obj: $(common)/pdcurses.rc
rc -r -fopdcurses.res $(common)/pdcurses.rc
cvtres -machine:$(PLATFORM) -nologo -out:pdcurses.obj pdcurses.res
pdcurses.o: $(common)/pdcurses.rc
$(WINDRES) -i $(common)/pdcurses.rc pdcurses.o
$(LIBOBJS) : %.obj: $(srcdir)/%.c
$(BUILD) $<
$(PDCOBJS) : %.obj: $(osdir)/%.c
$(BUILD) $<
$(DEMOS) : %.exe: %.obj
$(LINK) $(LDFLAGS) $< $(LIBCURSES) $(CCLIBS)
$(DEMOOBJS) : %.obj: $(demodir)/%.c
$(BUILD) -I$(demodir) $<
tuidemo.exe: tuidemo.obj tui.obj
$(LINK) $(LDFLAGS) tuidemo.obj tui.obj $(LIBCURSES) $(CCLIBS)
@MichaelMackus
Copy link
Author

public domain

@MichaelMackus
Copy link
Author

You need to use xwin to download the windows libraries (via xwin splat).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment