summaryrefslogtreecommitdiff
path: root/third_party/mcpc/mk
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/mcpc/mk')
-rw-r--r--third_party/mcpc/mk/ccdefs-cygwin.mk34
-rw-r--r--third_party/mcpc/mk/ccdefs-linux.mk79
-rw-r--r--third_party/mcpc/mk/ccdefs-macos.mk53
-rw-r--r--third_party/mcpc/mk/ccdefs-mingw.mk89
-rw-r--r--third_party/mcpc/mk/ccdefs-win.mk60
-rw-r--r--third_party/mcpc/mk/dbgrel.mk92
-rw-r--r--third_party/mcpc/mk/step0.mk31
7 files changed, 438 insertions, 0 deletions
diff --git a/third_party/mcpc/mk/ccdefs-cygwin.mk b/third_party/mcpc/mk/ccdefs-cygwin.mk
new file mode 100644
index 0000000..d41e814
--- /dev/null
+++ b/third_party/mcpc/mk/ccdefs-cygwin.mk
@@ -0,0 +1,34 @@
+ifneq (,$(and $(isnot_done_ccdefs),$(is_cygwin)))
+ is_unix = xxx
+ is_unixar = xxx
+ is_winld = xxx
+
+ # currently we enforce gcc on cygwin
+ CC = gcc
+ CFLAGS += -Dis_unix
+ CFLAGS += -Dis_cygwin
+ is_gcc = xxx
+ is_gcclike = xxx
+ gcc_ver = $(shell $(CC) --version)
+ is_gcc12 = $(findstring 12.,$(gcc_ver))
+ is_gcc13 = $(findstring 13.,$(gcc_ver))
+ is_gcc14 = $(findstring 14.,$(gcc_ver))
+
+ ifeq (1,2)
+ else ifneq (,$(and $(is_gcc12)))
+ # deb12
+ CFLAGS += -std=c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc14)))
+ # fc41
+ CFLAGS += -std=c23
+ CFLAGS += -DMCPC_C23PTCH_UCHAR2
+ isnot_done_ccdefs =
+ endif
+
+
+
+endif
diff --git a/third_party/mcpc/mk/ccdefs-linux.mk b/third_party/mcpc/mk/ccdefs-linux.mk
new file mode 100644
index 0000000..b59540a
--- /dev/null
+++ b/third_party/mcpc/mk/ccdefs-linux.mk
@@ -0,0 +1,79 @@
+ifneq (,$(and $(isnot_done_ccdefs),$(is_linux)))
+ is_unix = xxx
+ is_unixar = xxx
+ CFLAGS += -Dis_unix
+
+ cc_ver = $(shell $(CC) --version)
+ ifneq (,$(findstring Free Software Foundation,$(cc_ver)))
+ found_gcc = xxx
+ endif
+ ifneq (,$(findstring clang,$(cc_ver)))
+ found_clang = xxx
+ endif
+
+ ifneq (,$(found_gcc))
+ is_gcc = xxx
+ is_gcclike = xxx
+ gcc_ver = $(shell $(CC) --version)
+ is_gcc10 = $(findstring 10.,$(gcc_ver))
+ is_gcc12 = $(findstring 12.,$(gcc_ver))
+ is_gcc13 = $(findstring 13.,$(gcc_ver))
+ is_gcc14 = $(findstring 14.,$(gcc_ver))
+ else ifneq (,$(found_clang))
+ is_clang = xxx
+ is_gcclike = xxx
+ clang_ver = $(shell $(CC) --version)
+ is_clang18 = $(findstring 18.,$(clang_ver))
+ is_clang19 = $(findstring 19.,$(clang_ver))
+ endif
+
+ ldd_ver = $(shell ldd --version)
+ is_glibc231 = $(and $(findstring Free Software Foundation,$(ldd_ver)),$(findstring 2.31,$(ldd_ver)))
+ is_glibc236 = $(and $(findstring Free Software Foundation,$(ldd_ver)),$(findstring 2.36,$(ldd_ver)))
+ is_glibc240 = $(and $(findstring Free Software Foundation,$(ldd_ver)),$(findstring 2.40,$(ldd_ver)))
+ is_cygwin = $(and $(findstring cygwin,$(ldd_ver)))
+
+ ifeq (1,2)
+ else ifneq (,$(and $(is_gcc10),$(is_glibc231)))
+ # deb11
+ CFLAGS += -std=c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ CFLAGS += -DMCPC_C23GIVUP_FIXENUM
+ is_manual_pthread = xxx
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc12),$(is_glibc236)))
+ # deb12
+ CFLAGS += -std=c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ CFLAGS += -DMCPC_C23GIVUP_FIXENUM
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc14),$(is_cygwin)))
+ # fc41
+ CFLAGS += -std=c23
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc14),$(is_mingw)))
+ # fc41
+ CFLAGS += -std=c233
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc14),$(is_glibc240)))
+ # fc41
+ CFLAGS += -std=c23
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_clang18),$(is_glibc240)))
+ # fc41
+ CFLAGS += -std=c23
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_clang19),$(is_glibc240)))
+ # fc41
+ CFLAGS += -std=c23
+ isnot_done_ccdefs =
+ endif
+
+
+
+endif
diff --git a/third_party/mcpc/mk/ccdefs-macos.mk b/third_party/mcpc/mk/ccdefs-macos.mk
new file mode 100644
index 0000000..8e38be5
--- /dev/null
+++ b/third_party/mcpc/mk/ccdefs-macos.mk
@@ -0,0 +1,53 @@
+ifneq (,$(and $(isnot_done_ccdefs),$(is_macos)))
+ is_unix = xxx
+ is_unixar = xxx
+ CFLAGS += -Dis_unix
+ cc_ver = $(shell $(CC) --version)
+ ifneq (,$(findstring Free Software Foundation,$(cc_ver)))
+ found_gcc = xxx
+ endif
+ ifneq (,$(findstring clang,$(cc_ver)))
+ found_clang = xxx
+ endif
+
+ ifneq (,$(found_gcc))
+ is_gcc = xxx
+ is_gcclike = xxx
+ gcc_ver = $(shell $(CC) --version)
+ is_gcc12 = $(findstring 12.,$(gcc_ver))
+ is_gcc13 = $(findstring 13.,$(gcc_ver))
+ is_gcc14 = $(findstring 14.,$(gcc_ver))
+ else ifneq (,$(found_clang))
+ is_clang = xxx
+ is_gcclike = xxx
+ clang_ver = $(shell $(CC) --version)
+ is_clang14 = $(findstring 14.,$(clang_ver))
+ is_clang15 = $(findstring 15.,$(clang_ver))
+ is_clang16 = $(findstring 16.,$(clang_ver))
+ endif
+
+ ifeq (1,2)
+ else ifneq (,$(and $(is_clang14)))
+ CFLAGS += -std=c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ CFLAGS += -Dno_c23_n2508
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_clang15)))
+ CFLAGS += -std=c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ CFLAGS += -Dno_c23_n2508
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_clang16)))
+ CFLAGS += -std=c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ CFLAGS += -Dno_c23_n2508
+ isnot_done_ccdefs =
+ endif
+
+endif
diff --git a/third_party/mcpc/mk/ccdefs-mingw.mk b/third_party/mcpc/mk/ccdefs-mingw.mk
new file mode 100644
index 0000000..4b36d0b
--- /dev/null
+++ b/third_party/mcpc/mk/ccdefs-mingw.mk
@@ -0,0 +1,89 @@
+ifneq (,$(and $(isnot_done_ccdefs),$(is_mingw)))
+ is_unix = xxx
+ CFLAGS += -Dis_mingw
+ CFLAGS += -Dis_win # winapi?
+
+ wherecl = $(shell where cl)
+ ifneq (,$(wherecl))
+ found_cl = xxx
+ endif
+
+ # Use cl whenever possible
+ ifneq (,$(and $(found_cl),$(is_indirsh)))
+ CC = cl
+ is_cllike = xxx
+ is_winlib = xxx
+ else
+ # To find any other cc
+
+ # gh win2019 patch, intentionally to use gcc
+ ifneq (,$(is_win2019))
+ CC = gcc
+ endif
+ # GH win2022 patch, intentionally to use gcc
+ ifneq (,$(is_win2022))
+ CC = gcc
+ endif
+
+ cc_ver = $(shell $(CC) --version)
+ ifneq (,$(findstring Free Software Foundation,$(cc_ver)))
+ found_gcc = xxx
+ endif
+ ifneq (,$(found_gcc))
+ is_gcc = xxx
+ is_gcclike = xxx
+ is_unixar = xxx
+ is_winld = xxx
+ gcc_ver = $(shell $(CC) --version)
+ is_gcc8 = $(findstring 8.,$(gcc_ver))
+ is_gcc12 = $(findstring 12.,$(gcc_ver))
+ is_gcc13 = $(findstring 13.,$(gcc_ver))
+ is_gcc14 = $(findstring 14.,$(gcc_ver))
+ endif
+ ifneq (,$(found_clang))
+ is_clang = xxx
+ is_gcclike = xxx
+ is_unixar = xxx
+ is_winld = xxx
+ clang_ver = $(shell $(CC) --version)
+ is_clang18 = $(findstring 18.,$(clang_ver))
+ is_clang19 = $(findstring 19.,$(clang_ver))
+ endif
+ endif
+
+ ifeq (1,2)
+ else ifneq (,$(is_cllike))
+ CFLAGS += /Dis_win
+ CFLAGS += /Dis_wincl
+ CFLAGS += /nologo
+ CFLAGS += /std:c17
+ CFLAGS += /DMCPC_C23PTCH_KW1
+ CFLAGS += /DMCPC_C23PTCH_CKD1
+ CFLAGS += /DMCPC_C23PTCH_UCHAR1
+ CFLAGS += /DMCPC_C23GIVUP_FIXENUM
+ LDFLAGS += /nologo
+ is_cllike = xxx
+ is_winlib = xxx
+ is_cl = xxx
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc8)))
+ CFLAGS += -std=c11
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ CFLAGS += -DMCPC_C23GIVUP_FIXENUM
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc12)))
+ CFLAGS += -std=c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ CFLAGS += -DMCPC_C23GIVUP_FIXENUM
+ isnot_done_ccdefs =
+ else ifneq (,$(and $(is_gcc14)))
+ # fc41
+ CFLAGS += -std=c23
+ CFLAGS += -DMCPC_C23PTCH_UCHAR2
+ isnot_done_ccdefs =
+ endif
+endif
diff --git a/third_party/mcpc/mk/ccdefs-win.mk b/third_party/mcpc/mk/ccdefs-win.mk
new file mode 100644
index 0000000..76e9246
--- /dev/null
+++ b/third_party/mcpc/mk/ccdefs-win.mk
@@ -0,0 +1,60 @@
+ifneq (,$(and $(isnot_done_ccdefs),$(is_win)))
+
+ ifdef USE_WINCLANG
+ CC = clang-cl
+ CFLAGS += /Dis_win
+ is_cllike = xxx
+ is_clang = xxx
+ is_winclang = xxx
+ clang_ver = $(shell $(CC) --version)
+ is_clang14 = $(findstring 14.,$(clang_ver))
+ is_clang16 = $(findstring 16.,$(clang_ver))
+ is_clang19 = $(findstring 19.,$(clang_ver))
+
+ ifeq (1,2)
+ else ifneq (,$(and $(is_clang14)))
+ CFLAGS += /std:c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ else ifneq (,$(and $(is_clang16)))
+ CFLAGS += /std:c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ else ifneq (,$(and $(is_clang19)))
+ CFLAGS += /std:c17
+ CFLAGS += -DMCPC_C23PTCH_KW1
+ CFLAGS += -DMCPC_C23PTCH_CKD1
+ CFLAGS += -DMCPC_C23PTCH_UCHAR1
+ endif
+
+ else
+
+ ifneq (,$(found_cl))
+ CC = cl
+ CFLAGS += /Dis_win
+ CFLAGS += /Dis_wincl
+ CFLAGS += /nologo
+ CFLAGS += /std:c17
+ CFLAGS += /DMCPC_C23PTCH_KW1
+ CFLAGS += /DMCPC_C23PTCH_CKD1
+ CFLAGS += /DMCPC_C23PTCH_UCHAR1
+ CFLAGS += /DMCPC_C23GIVUP_FIXENUM
+ LDFLAGS += /nologo
+ is_cllike = xxx
+ is_winlib = xxx
+ is_cl = xxx
+ isnot_done_ccdefs =
+ else
+ cc_ver = $(shell $(CC) --version)
+ ifneq (,$(findstring Free Software Foundation,$(ccver)))
+ is_gcc = xxx
+ is_gcclike = xxx
+ is_unixar = xxx
+ is_winld = xxx
+ endif
+ endif
+ endif
+
+endif
diff --git a/third_party/mcpc/mk/dbgrel.mk b/third_party/mcpc/mk/dbgrel.mk
new file mode 100644
index 0000000..a32e0bd
--- /dev/null
+++ b/third_party/mcpc/mk/dbgrel.mk
@@ -0,0 +1,92 @@
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# dbgrel
+
+ifdef DBG
+ ifeq (1,2)
+ else ifneq (,$(is_gcclike))
+ CFLAGS += -g -O0
+ CFLAGS += -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter -Wno-unused-label
+ CFLAGS += -DMCPC_DBG
+ CFLAGS += -I..
+ else ifneq (,$(is_cllike))
+ CFLAGS += /Zi /Od /Ob0
+ CFLAGS += /RTC1
+ # CFLAGS += /Wall
+ CFLAGS += /DMCPC_DBG
+ CFLAGS += /I..
+ endif
+else
+ ifeq (1,2)
+ else ifneq (,$(is_gcclike))
+ CFLAGS += -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter -Wno-unused-label -Wno-error=unused-variable -Wno-error=unused-but-set-variable
+ CFLAGS += -O2 -Os
+ CFLAGS += -I..
+ else ifneq (,$(is_cllike))
+ CFLAGS += /MD
+ CFLAGS += /Wall
+ CFLAGS += /wd4152 # okay with: nonstandard extension, function/data pointer conversion in expression
+ CFLAGS += /wd4310 # okay with cast causing truncate
+ CFLAGS += /wd4127 # window is wrong about sizeof(long) being constant
+ CFLAGS += /wd4102 # okay to have unref label
+ CFLAGS += /wd4189 # local variable is initialized but not referenced
+ CFLAGS += /wd4100 # its okay not ref to param
+ CFLAGS += /wd5045 # why call spectre rather than boundcheck?
+ CFLAGS += /wd4005 # alloca macro redef is ok
+ CFLAGS += /wd4996 # use strerror sprintf anyway
+ CFLAGS += /wd4456 # no need to warn shadow decl
+ CFLAGS += /wd4255 # ok for C23
+ CFLAGS += /wd4668 # disb #if macro
+ CFLAGS += /wd4710 # disable inline warn
+ CFLAGS += /wd4820 # we know there is padding
+ CFLAGS += /O2 /Ob1
+ CFLAGS += /I..
+ endif
+endif
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# strip
+
+ifndef DBG
+ # LDFLAGS += --strip-all ld not recoginizing?
+ ifneq (,$(is_linux))
+ LDFLAGS += -s
+ endif
+ ifneq (,$(is_macos))
+ LDFLAGS += -dead_strip
+ endif
+endif
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# sanitizer
+
+ifdef VALG
+ which_valg = $(shell which valgrind)
+ ifneq (,$(which_valg))
+ is_valg = xxx
+ endif
+endif
+
+
+# NOTE asan triggered only if ASAN=1, we use valgrind by default
+ifdef ASAN
+ is_asan = xxx
+ is_valg =
+ ifneq (,$(is_linux))
+ CFLAGS += -fsanitize=address
+ LDFLAGS += -lasan
+ endif
+ ifneq (,$(is_macos))
+ CFLAGS += -fsanitize=address
+ LDFLAGS += -fsanitize=address
+ endif
+ ifneq (,$(is_cllike))
+ CFLAGS += /fsanitize=address
+ LDFLAGS += /DEBUG
+# LDFLAGS += "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\Llvm\\lib\\clang\\19\\lib\\windows\\clang_rt.asan-i386.lib"
+ LDFLAGS += /NODEFAULTLIB:libcmt.lib
+ LDFLAGS += msvcrt.lib
+ endif
+endif
+
+
diff --git a/third_party/mcpc/mk/step0.mk b/third_party/mcpc/mk/step0.mk
new file mode 100644
index 0000000..8ec5d72
--- /dev/null
+++ b/third_party/mcpc/mk/step0.mk
@@ -0,0 +1,31 @@
+ifeq ($(SHELL),/bin/sh)
+ is_sh = xxx
+ is_dirsh = xxx
+ unameall = $(shell uname -a)
+ is_linux = $(findstring Linux,$(unameall))
+ is_cygwin = $(findstring Cygwin,$(unameall))
+ is_mingw = $(findstring MINGW64_NT,$(unameall))
+ is_macos = $(findstring Darwin,$(unameall))
+else ifneq (,$(findstring /sh.exe,$(SHELL)))
+ # indirectly enter bash (but the only way we enter GH win)
+ is_sh = xxx
+ is_indirsh = xxx
+ is_win = xxx
+ unameall = $(shell uname -a)
+ is_msys = $(findstring MSYS_NT,$(unameall))
+ is_mingw = $(findstring MINGW64_NT,$(unameall))
+ sysinfo = $(shell systeminfo)
+ ifneq (,$(findstring Windows Server 2019,$(sysinfo)))
+ is_win2019 = xxx
+ endif
+ ifneq (,$(findstring Windows Server 2022,$(sysinfo)))
+ is_win2022 = xxx
+ endif
+ ifneq (,$(findstring Windows Server 2025,$(sysinfo)))
+ is_win2025 = xxx
+ endif
+else ifneq (,$(findstring sh.exe,$(SHELL)))
+ is_win = xxx
+ is_cmd = xxx
+endif
+isnot_done_ccdefs = xxx