Skip to content

Commit

Permalink
Add MSVC_DETECT to Makefile
Browse files Browse the repository at this point in the history
Specifying make MSVC_DETECT=0 ... overrides all of the detection logic for
the Microsoft C Compiler and simply assumes that the environment is
correct. This obviously means that building both 32 and 64-bit CHAINS is
not possible.

checkenv script added which outputs a warning if the environment appears
not to include the Windows SDK, tools or the Microsoft C Runtime. The
script also attempts to determine the architecture of cl.exe and so advise
which CHAINS value can be built with MSVC_DETECT=0. No checking logic
added to Makefile, so specifying CHAINS=msvc64 with an x86 compiler and
vice versa will simply build invalid object files.

Updated CHANGES and also added execute bit to findwinsdk.
  • Loading branch information
dra27 committed Jan 1, 2016
1 parent bbcadb8 commit 05c2dbf
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* text=auto

findwinsdk text eol=lf
checkenv text eol=lf
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Next version
- Fixes for clang (patch by Roven Gabriel)
- Improve autodetection of WinSDK paths (patch by David Allsop)
- Improve autodetection of WinSDK paths (patch by David Allsopp)
- Add MSVC_DETECT Makefile variable which overrides all C Compiler detection logic when 0.
- Add checkenv script which determines if the environment is sound specifying MSVC_DETECT=0

Version 0.34
- New option -norelrelocs to check that no relative flexdll relocations are created (this ensures that the generated DLLs can be loaded at any address),
Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ Makefile.winsdk: findwinsdk
bash ./findwinsdk x86 > $@
bash ./findwinsdk x64 64 >> $@

MSVC_DETECT=1
MSVC_FLAGS=/nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-

ifeq ($(MSVC_DETECT),0)
# Assume that the environment is correctly set for a single Microsoft C Compiler; don't attempt to guess anything
MSVC_PREFIX=
MSVC64_PREFIX=
MSVCC=cl.exe $(MSVC_FLAGS)
MSVCC64=cl.exe $(MSVC_FLAGS)
else
ifeq ($(SDK),)
# Otherwise, assume the 32-bit version of VS 2008 or Win7 SDK is in the path.

Expand All @@ -50,15 +60,16 @@ MSVC_PREFIX=LIB="$(MSVC_LIB)" INCLUDE="$(MSVC_INCLUDE)"
MSVC64_LIB = $(MSVC_LIB1)/Lib/amd64;$(MSVC_LIB2)/Lib/x64
MSVC64_PREFIX=LIB="$(MSVC64_LIB)" INCLUDE="$(MSVC_INCLUDE)"

MSVCC = $(MSVCC_ROOT)/cl.exe /nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-
MSVCC64 = $(MSVCC_ROOT)/amd64/cl.exe /nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-
MSVCC = $(MSVCC_ROOT)/cl.exe $(MSVC_FLAGS)
MSVCC64 = $(MSVCC_ROOT)/amd64/cl.exe $(MSVC_FLAGS)
else
MSVCC_ROOT:=
MSVC_PREFIX=PATH="$(SDK):$(PATH)" LIB="$(SDK_LIB);$(LIB)" INCLUDE="$(SDK_INC);$(INCLUDE)"
MSVC64_PREFIX=PATH="$(SDK64):$(PATH)" LIB="$(SDK64_LIB);$(LIB)" INCLUDE="$(SDK64_INC);$(INCLUDE)"

MSVCC = cl.exe /nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-
MSVCC64 = cl.exe /nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-
MSVCC = cl.exe $(MSVC_FLAGS)
MSVCC64 = cl.exe $(MSVC_FLAGS)
endif
endif

show_root:
Expand Down
55 changes: 55 additions & 0 deletions checkenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Analyse the environment for Microsoft C Compilers

# Care needed because spaces in directory names are a given
# (if only Unix were routinely configured that way...)
# IFS chosen to be a character illegal in Windows filenames and unlikely in Unix
SAVE_IFS=$IFS

test ()
{
IFS=*
for f in $1; do find "$f" -maxdepth 1 -iname $2 -print -quit; done 2>/dev/null | grep "." -q
if [ $? -eq 1 ] ; then
echo "Cannot find $3">&2
exit 1
fi
IFS=$SAVE_IFS
}

# Check for Windows.h in INCLUDE
test "${INCLUDE//;/*}" windows.h "Windows SDK Headers (Windows.h, etc.)"

# Check for stdlib.h in INCLUDE
test "${INCLUDE//;/*}" stdlib.h "Microsoft CRT Headers (stdlib.h, etc.)"

# Check for msvcrt.lib in LIB
test "${LIB//;/*}" msvcrt.lib "Microsoft CRT Libraries (msvcrt.lib, etc.)"

# Check for kernel32.lib in LIB
test "${LIB//;/*}" kernel32.lib "Windows SDK Libraries (kernel32.lib, etc.)"

# Check for cl.exe in PATH
test "${PATH//:/*}" cl.exe "Microsoft C Compiler (cl.exe)"

# Check for rc.exe in PATH
test "${PATH//:/*}" rc.exe "Microsoft Resource Compiler (rc.exe)"

# Check for link.exe in PATH (largely academic - should hit coreutils link if nothing else)
test "${PATH//:/*}" link.exe "Microsoft Linker (link.exe)"

PROB=
# Check that link is the Microsoft Linker
if [ "`link --version | head -1 | fgrep "Microsoft (R) Incremental Linker"`" == "" ] ; then
echo "Warning - link does not appear to be the Microsoft Linker, you may need to adjust your PATH"
PROB="Probably "
fi

echo Microsoft C Compiler environment appears to be sound
if [ -z "`cl /? 2>&1 | head -1 | fgrep x86`" ] ; then
CHAINS=msvc64
else
CHAINS=msvc
fi
echo ${PROB}OK to build using MSVC_DETECT=0 CHAINS=$CHAINS
Empty file modified findwinsdk
100644 → 100755
Empty file.

0 comments on commit 05c2dbf

Please sign in to comment.