3 # Copyright (c) 2011-2015 Ryan Prichard
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to
7 # deal in the Software without restriction, including without limitation the
8 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 # sell copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 # findTool(desc, commandList)
26 # Searches commandLine for the first command in the PATH and returns it.
27 # Prints an error and aborts the script if no match is found.
33 for CMD in ${OPTIONS}; do
34 if (which $CMD &>/dev/null) then
35 echo "Found $DESC: $CMD"
40 echo "Error: could not find $DESC. One of these should be in your PATH:"
41 for CMD in ${OPTIONS}; do
51 # Link parts of the Cygwin binary statically to aid in redistribution? The
52 # binary still links dynamically against the main DLL. The MinGW binaries are
53 # also statically linked and therefore depend only on Windows DLLs. I started
54 # linking the Cygwin/MSYS binary statically, because G++ 4.7 changed the
56 UNIX_LDFLAGS_STATIC='-static -static-libgcc -static-libstdc++'
58 # Detect the environment -- Cygwin or MSYS.
61 echo 'uname -s identifies a Cygwin environment.'
65 echo 'uname -m identifies an i686 environment.'
66 UNIX_CXX=i686-pc-cygwin-g++
67 MINGW_CXX=i686-w64-mingw32-g++
70 echo 'uname -m identifies an x86_64 environment.'
71 UNIX_CXX=x86_64-pc-cygwin-g++
72 MINGW_CXX=x86_64-w64-mingw32-g++
75 echo 'Error: uname -m did not match either i686 or x86_64.'
82 # - MSYS2 offers two shortcuts to open an environment:
83 # - MinGW-w64 Win32 Shell. This env reports a `uname -s` of
84 # MINGW32_NT-6.1 on 32-bit Win7. The MinGW-w64 compiler
85 # (i686-w64-mingw32-g++.exe) is in the PATH.
86 # - MSYS2 Shell. `uname -s` instead reports MSYS_NT-6.1.
87 # The i686-w64-mingw32-g++ compiler is not in the PATH.
88 # - MSYS2 appears to use MinGW-w64, not the older mingw.org.
90 # - `uname -s` is always MINGW32_NT-6.1 on Win7.
91 echo 'uname -s identifies an MSYS/MSYS2 environment.'
94 echo 'uname -m identifies an i686 environment.'
95 UNIX_CXX=i686-pc-msys-g++
96 if echo "$(uname -r)" | grep '^1[.]' > /dev/null; then
97 # The MSYS-targeting compiler for the original 32-bit-only
98 # MSYS does not recognize the -static-libstdc++ flag, and
99 # it does not work with -static, because it tries to link
100 # statically with the core MSYS library and fails.
102 # Distinguish between the two using the major version
103 # number of `uname -r`:
105 # MSYS uname -r: 1.0.18(0.48/3/2)
106 # MSYS2 uname -r: 2.0.0(0.284/5/3)
108 # This is suboptimal because MSYS2 is not actually the
109 # second version of MSYS--it's a brand-new fork of Cygwin.
113 MINGW_CXX=mingw32-g++
116 MINGW_CXX=i686-w64-mingw32-g++.exe
120 echo 'uname -m identifies an x86_64 environment.'
122 UNIX_CXX=x86_64-pc-msys-g++
123 MINGW_CXX=x86_64-w64-mingw32-g++
126 echo 'Error: uname -m did not match either i686 or x86_64.'
132 echo 'Error: uname -s did not match either CYGWIN* or MINGW*.'
137 # Search the PATH and pick the first match.
138 findTool "Cygwin/MSYS G++ compiler" "$UNIX_CXX"
139 UNIX_CXX=$FINDTOOL_OUT
140 findTool "MinGW G++ compiler" "$MINGW_CXX"
141 MINGW_CXX=$FINDTOOL_OUT
143 # Write config files.
144 echo Writing config.mk
145 echo UNIX_CXX=$UNIX_CXX > config.mk
146 echo UNIX_LDFLAGS_STATIC=$UNIX_LDFLAGS_STATIC >> config.mk
147 echo MINGW_CXX=$MINGW_CXX >> config.mk
149 if test $IS_MSYS1 = 1; then
150 echo UNIX_CXXFLAGS += -DWINPTY_TARGET_MSYS1 >> config.mk
151 # The MSYS1 MinGW compiler has a bug that prevents inclusion of algorithm
152 # and math.h in normal C++11 mode. The workaround is to enable the gnu++11
153 # mode instead. The bug was fixed on 2015-07-31, but as of 2016-02-26, the
154 # fix apparently hasn't been released. See
155 # http://ehc.ac/p/mingw/bugs/2250/.
156 echo MINGW_ENABLE_CXX11_FLAG := -std=gnu++11 >> config.mk
159 if test -d .git -a -f .git/HEAD -a -f .git/index && git rev-parse HEAD >&/dev/null; then
160 echo "Commit info: git"
161 echo 'COMMIT_HASH = $(shell git rev-parse HEAD)' >> config.mk
162 echo 'COMMIT_HASH_DEP := config.mk .git/HEAD .git/index' >> config.mk
164 echo "Commit info: none"
165 echo 'COMMIT_HASH := none' >> config.mk
166 echo 'COMMIT_HASH_DEP := config.mk' >> config.mk