Switch to clang-cl

It's less painful than mingw.
I'll next get the DLL going like this, though it'll be pretty easy.
This commit is contained in:
Lily Tsuru 2024-07-19 05:10:10 -04:00
parent d95d305734
commit cc59c0c6db
5 changed files with 70 additions and 20 deletions

30
speech2/Makefile.testprog Normal file
View file

@ -0,0 +1,30 @@
include build/arch.mk
include build/configs.mk
NAME = testprog
TYPE = exe
# Any C++ file in src/ is automatically picked up.
CXXSRCS = testprog.cpp
# Required libraries.
LIBS = kernel32.lib shell32.lib user32.lib uuid.lib ole32.lib
.PHONY: all clean matrix
include build/rules.mk
all: $(BUILD_PRODUCT)
clean:
echo -e "\e[91mCleaning... \e[0m"
rm -rf $(BINDIR)/ $(OBJS)
# A fun make trick. This allows for verbose compilation if desired.
# Set V=1 or anything, and it'll be verbose.
$V.SILENT:
# Include dependency files generated by compilation.
# `make clean` keeps them so we can reuse, however they can
# still optionally be blown away.
-include $(OBJS:.o=.d)

View file

@ -1,19 +1,26 @@
x86_Valid=yes x86_Valid=yes
x86_TRIPLET=i686-w64-mingw32 x86_TRIPLET=i686-pc-windows-msvc
#x64_Valid=yes
#x64_TRIPLET=x86_64-w64-mingw32
# Only supported arch.
ifeq ($(ARCH),) ifeq ($(ARCH),)
ARCH = x86 ARCH = x86
endif endif
ifeq ($(VCDIR),)
$(error Please set VCDIR in your environment to an appropiate path)
endif
ifneq ($($(ARCH)_Valid),yes) ifneq ($($(ARCH)_Valid),yes)
$(error Please select a valid target) $(error Please select a valid target)
endif endif
# if we really need C CC = clang -target $($(ARCH)_TRIPLET)
CC = $($(ARCH)_TRIPLET)-gcc CXX = clang -target $($(ARCH)_TRIPLET)
CXX = $($(ARCH)_TRIPLET)-g++
WINDRES = $($(ARCH)_TRIPLET)-windres LD = lld-link
# This is $(WINDRES) thanks to the fact I
# depended on the (relatively low quality)
# MinGW toolchain. Thank God For LLVM.
WINDRES = llvm-rc

View file

@ -1,27 +1,34 @@
# Base compiler flags. Only change if you *explicitly* know what you're doing. # Base compiler flags. Only change if you *explicitly* know what you're doing.
#ifeq ($(VCDIR),)
#$(error Please set VCDIR in your environment to )
#endif
CXXRTDIR = $(VCDIR)/crt
UCRTDIR = $(VCDIR)/ucrt
PSDKDIR = $(VCDIR)/winsdk
# _UCRT define forces mingw not to define its stupid wrappers. # TODO: Switch to debug builds
BASE_FLAGS = -MMD -fvisibility=hidden -fpermissive -fno-pic -fno-pie -fno-ident -msse -Iinclude -Isrc -Ithird_party -D_UCRT -D_WIN32_WINNT=0x0501 Release_RTLIBS = libcmt.lib libucrt.lib libvcruntime.lib libcpmt.lib
Debug_RTLIBS = libcmtd.lib libucrtd.lib libvcruntimed.lib libcpmtd.lib
# I really should rename this x_x
CLANG_FLAGS = -fms-extensions -fms-compatibility-version=19 -isystem $(CXXRTDIR)/include -isystem $(UCRTDIR)/include -isystem $(PSDKDIR)/include/shared -isystem $(PSDKDIR)/include/um
BASE_FLAGS = -MMD -g3 -fvisibility=hidden $(CLANG_FLAGS) -march=pentium3 -Iinclude -Isrc -Ithird_party -D_WIN32_WINNT=0x0501
BASE_CCFLAGS = $(BASE_FLAGS) -std=gnu17 BASE_CCFLAGS = $(BASE_FLAGS) -std=gnu17
BASE_CXXFLAGS = $(BASE_FLAGS) -std=c++20 BASE_CXXFLAGS = $(BASE_FLAGS) -std=c++20
BASE_LDFLAGS_SHARED = -Wl,--subsystem=windows -fvisibility=hidden -shared BASE_LDFLAGS_SHARED = /dll
BASE_LDFLAGS = -lkernel32 -lshell32 -luser32 -luuid -lole32
BASE_LDFLAGS = /nodefaultlib /version:5.1 /machine:i386 /subsystem:console,5.1 /libpath:$(CXXRTDIR)/lib/x86 /libpath:$(UCRTDIR)/lib /libpath:$(PSDKDIR)/lib
Release_Valid = yes Release_Valid = yes
Release_CCFLAGS = -O3 -DNDEBUG Release_CCFLAGS = -O3 -DNDEBUG
Release_CXXFLAGS = -O3 -DNDEBUG Release_CXXFLAGS = -O3 -DNDEBUG
Release_LDFLAGS = -s Release_LDFLAGS = /debug /pdb:$(BINDIR)/$(NAME).pdb
Debug_Valid = yes Debug_Valid = yes
Debug_CCFLAGS = -O0 -g -DDEBUG Debug_CCFLAGS = -O0 -g -DDEBUG
Debug_CXXFLAGS = -O0 -g -DDEBUG Debug_CXXFLAGS = -O0 -g -DDEBUG
Debug_LDFLAGS = Debug_LDFLAGS = /debug /pdb:$(BINDIR)/$(NAME).pdb
# select a default configuration or validate configuration # select a default configuration or validate configuration
ifeq ($(CONFIG),) ifeq ($(CONFIG),)

View file

@ -9,14 +9,14 @@ BUILD_PRODUCT = $(BINDIR)/$(NAME).dll
$(BINDIR)/$(NAME).dll: $(BINDIR)/ $(OBJDIR)/ $(OBJS) $(BINDIR)/$(NAME).dll: $(BINDIR)/ $(OBJDIR)/ $(OBJS)
echo -e "\e[92mLinking DLL $@\e[0m" echo -e "\e[92mLinking DLL $@\e[0m"
$(CXX) $(OBJS) $(BASE_LDFLAGS_SHARED) $(BASE_LDFLAGS) $($(CONFIG)_LDFLAGS) -o $@ $(LD) $(BASE_LDFLAGS_SHARED) $(BASE_LDFLAGS) $($(CONFIG)_LDFLAGS) $(RTLIBS) $(LIBS) $(OBJS) /out:$@
else else
ifeq ($(TYPE),exe) ifeq ($(TYPE),exe)
BUILD_PRODUCT = $(BINDIR)/$(NAME).exe BUILD_PRODUCT = $(BINDIR)/$(NAME).exe
$(BINDIR)/$(NAME).exe: $(BINDIR)/ $(OBJDIR)/ $(OBJS) $(BINDIR)/$(NAME).exe: $(BINDIR)/ $(OBJDIR)/ $(OBJS)
echo -e "\e[92mLinking EXE $@\e[0m" echo -e "\e[92mLinking EXE $@\e[0m"
$(CXX) $(OBJS) $(BASE_LDFLAGS_SHARED) $(BASE_LDFLAGS) $($(CONFIG)_LDFLAGS) -o $@ $(LD) $(BASE_LDFLAGS) $($(CONFIG)_LDFLAGS) $($(CONFIG)_RTLIBS) $(LIBS) $(OBJS) /out:$@
endif endif
endif endif

6
speech2/testprog.cpp Normal file
View file

@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello, C++20 on Windows XP~\n");
return 0;
}