Skip to content

Commit fcf7ecd

Browse files
committed
mk: Add build system support for cl.exe
We have a number of support C/C++ files in Rust that we link into the standard library and other various locations, and these all need to be built with cl.exe instead of gcc.exe when targeting MSVC. This commit adds helper macros for this functionality to use different sets of programs/flags/invocations on MSVC than on GNU-like platforms.
1 parent b56d47c commit fcf7ecd

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

mk/platform.mk

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ endef
133133
$(foreach target,$(CFG_TARGET), \
134134
$(eval $(call FILTER_FLAGS,$(target))))
135135

136+
# Configure various macros to pass gcc or cl.exe style arguments
137+
define CC_MACROS
138+
CFG_CC_INCLUDE_$(1)=-I $$(1)
139+
ifeq ($$(findstring msvc,$(1)),msvc)
140+
CFG_CC_OUTPUT_$(1)=-Fo:$$(1)
141+
CFG_CREATE_ARCHIVE_$(1)=$$(AR_$(1)) -OUT:$$(1)
142+
else
143+
CFG_CC_OUTPUT_$(1)=-o $$(1)
144+
CFG_CREATE_ARCHIVE_$(1)=$$(AR_$(1)) crus $$(1)
145+
endif
146+
endef
147+
148+
$(foreach target,$(CFG_TARGET), \
149+
$(eval $(call CC_MACROS,$(target))))
150+
136151

137152
ifeq ($(CFG_CCACHE_CPP2),1)
138153
CCACHE_CPP2=1
@@ -163,7 +178,7 @@ define CFG_MAKE_TOOLCHAIN
163178
CFG_COMPILE_C_$(1) = $$(CC_$(1)) \
164179
$$(CFG_GCCISH_CFLAGS) \
165180
$$(CFG_GCCISH_CFLAGS_$(1)) \
166-
-c -o $$(1) $$(2)
181+
-c $$(call CFG_CC_OUTPUT_$(1),$$(1)) $$(2)
167182
CFG_LINK_C_$(1) = $$(CC_$(1)) \
168183
$$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
169184
$$(CFG_GCCISH_LINK_FLAGS_$(1)) \
@@ -174,7 +189,7 @@ define CFG_MAKE_TOOLCHAIN
174189
$$(CFG_GCCISH_CXXFLAGS) \
175190
$$(CFG_GCCISH_CFLAGS_$(1)) \
176191
$$(CFG_GCCISH_CXXFLAGS_$(1)) \
177-
-c -o $$(1) $$(2)
192+
-c $$(call CFG_CC_OUTPUT_$(1),$$(1)) $$(2)
178193
CFG_LINK_CXX_$(1) = $$(CXX_$(1)) \
179194
$$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
180195
$$(CFG_GCCISH_LINK_FLAGS_$(1)) \

mk/rt.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.c $$(MKFILE_DEPS)
8181
@mkdir -p $$(@D)
8282
@$$(call E, compile: $$@)
8383
$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
84-
-I $$(S)src/rt/hoedown/src \
85-
-I $$(S)src/rt \
84+
$$(call CFG_CC_INCLUDE_$(1),$$(S)src/rt/hoedown/src) \
85+
$$(call CFG_CC_INCLUDE_$(1),$$(S)src/rt) \
8686
$$(RUNTIME_CFLAGS_$(1))) $$<
8787

8888
$$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.S $$(MKFILE_DEPS) \
@@ -109,7 +109,7 @@ OBJS_$(2)_$(1) := $$(OBJS_$(2)_$(1):.S=.o)
109109
NATIVE_$(2)_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),$(2))
110110
$$(RT_OUTPUT_DIR_$(1))/$$(NATIVE_$(2)_$(1)): $$(OBJS_$(2)_$(1))
111111
@$$(call E, link: $$@)
112-
$$(Q)$$(AR_$(1)) rcs $$@ $$^
112+
$$(Q)$$(call CFG_CREATE_ARCHIVE_$(1),$$@) $$^
113113

114114
endef
115115

0 commit comments

Comments
 (0)