2015-12-11 18:49:14 -06:00
# 16 october 2015
2016-01-19 15:40:00 -06:00
# IMPORTANT
# Do NOT use / for command-line options here!
# This breaks on GNU makes that come with some versions of
# MinGW because they mangle things that start with /, thinking that
# those arguments are Unix paths that need to be converted to
# Windows paths. This cannot be turned off. -_-'
# MSDN says cl, rc, and link all accept - instead of /, so we're good.
# See also:
# - https://github.com/andlabs/libui/issues/16
# - http://www.mingw.org/wiki/Posix_path_conversion
# - http://www.mingw.org/wiki/FAQ
# - http://stackoverflow.com/questions/7250130/how-to-stop-mingw-and-msys-from-mangling-path-names-given-at-the-command-line
# - http://stackoverflow.com/questions/28533664/how-to-prevent-msys-to-convert-the-file-path-for-an-external-program
2015-12-11 18:49:14 -06:00
# TODO subsystem version
# TODO silence compiler non-diagnostics (/nologo is not enough)
# Global flags.
# TODO /Wall does too much
# TODO -Wno-switch equivalent
# TODO /sdl turns C4996 into an ERROR
# TODO loads of warnings in the system header files
# TODO /analyze requires us to write annotations everywhere
# TODO undecided flags from qo?
2016-05-13 14:13:41 -05:00
# -RTCc is not supplied because it's discouraged as of VS2015; see https://www.reddit.com/r/cpp/comments/46mhne/rtcc_rejects_conformant_code_with_visual_c_2015/d06auq5
2015-12-11 18:49:14 -06:00
CFLAGS += \
2016-01-19 15:40:00 -06:00
-W4 \
-wd4100 \
-TC \
-bigobj -nologo \
2016-05-13 14:13:41 -05:00
-RTC1 -RTCs -RTCu
2015-12-11 18:49:14 -06:00
2016-04-23 16:31:59 -05:00
# TODO prune these
# -EHsc is to shut the compiler up in some cases
2015-12-11 18:49:14 -06:00
CXXFLAGS += \
2016-01-19 15:40:00 -06:00
-W4 \
-wd4100 \
-TP \
-bigobj -nologo \
2016-05-13 14:13:41 -05:00
-RTC1 -RTCs -RTCu \
2016-04-23 16:31:59 -05:00
-EHsc
2015-12-11 18:49:14 -06:00
# TODO warnings on undefined symbols
LDFLAGS += \
2016-01-19 15:40:00 -06:00
-largeaddressaware -nologo -incremental:no
2015-12-11 18:49:14 -06:00
i f n e q ( $( NODEBUG ) , 1 )
2016-01-19 15:40:00 -06:00
CFLAGS += -Zi
CXXFLAGS += -Zi
LDFLAGS += -debug
2015-12-11 18:49:14 -06:00
e n d i f
# Build rules.
OFILES = \
$( subst /,_,$( CFILES) ) \
$( subst /,_,$( CXXFILES) ) \
$( subst /,_,$( MFILES) ) \
$( subst /,_,$( RCFILES) )
OFILES := $( OFILES:%= $( OBJDIR) /%.o)
OUT = $( OUTDIR) /$( NAME) $( SUFFIX)
2016-01-19 15:40:00 -06:00
# TODO use $(CC), $(CXX), $(LD), and s$(RC)
2015-12-11 18:49:14 -06:00
$(OUT) : $( OFILES ) | $( OUTDIR )
2016-01-19 15:40:00 -06:00
@link -out:$( OUT) $( OFILES) $( LDFLAGS)
2015-12-11 18:49:14 -06:00
@echo = = = = = = Linked $( OUT)
.SECONDEXPANSION :
# TODO can we put /Fd$@.pdb in a variable?
$(OBJDIR)/%.c.o : $$( subst _ ,/,%) .c $( HFILES ) | $( OBJDIR )
i f e q ( $( NODEBUG ) , 1 )
2016-01-19 15:40:00 -06:00
@cl -Fo:$@ -c $< $( CFLAGS)
2015-12-11 18:49:14 -06:00
e l s e
2016-01-19 15:40:00 -06:00
@cl -Fo:$@ -c $< $( CFLAGS) -Fd$@ .pdb
2015-12-11 18:49:14 -06:00
e n d i f
@echo = = = = = = Compiled $<
2015-12-22 19:01:53 -06:00
$(OBJDIR)/%.cpp.o : $$( subst _ ,/,%) .cpp $( HFILES ) | $( OBJDIR )
2015-12-11 18:49:14 -06:00
i f e q ( $( NODEBUG ) , 1 )
2016-01-19 15:40:00 -06:00
@cl -Fo:$@ -c $< $( CXXFLAGS)
2015-12-11 18:49:14 -06:00
e l s e
2016-01-19 15:40:00 -06:00
@cl -Fo:$@ -c $< $( CXXFLAGS) -Fd$@ .pdb
2015-12-11 18:49:14 -06:00
e n d i f
@echo = = = = = = Compiled $<
2016-01-19 15:40:00 -06:00
# note: don't run cvtres directly; the linker does that for us
2015-12-11 18:49:14 -06:00
$(OBJDIR)/%.rc.o : $$( subst _ ,/,%) .rc $( HFILES ) | $( OBJDIR )
2016-01-19 15:40:00 -06:00
@rc -nologo -v -fo $@ $<
2015-12-11 18:49:14 -06:00
@echo = = = = = = Compiled $<
$(OBJDIR) $(OUTDIR) :
@mkdir $@