installed pty
[VSoRC/.git] / node_modules / node-pty / deps / winpty / configure
1 #!/bin/bash
2 #
3 # Copyright (c) 2011-2015 Ryan Prichard
4 #
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:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
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
21 # IN THE SOFTWARE.
22
23 #
24 # findTool(desc, commandList)
25 #
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.
28 #
29 FINDTOOL_OUT=""
30 function findTool {
31     DESC=$1
32     OPTIONS=$2
33     for CMD in ${OPTIONS}; do
34         if (which $CMD &>/dev/null) then
35             echo "Found $DESC: $CMD"
36             FINDTOOL_OUT="$CMD"
37             return
38         fi
39     done
40     echo "Error: could not find $DESC.  One of these should be in your PATH:"
41     for CMD in ${OPTIONS}; do
42         echo " * $CMD"
43     done
44     exit 1
45 }
46
47 IS_CYGWIN=0
48 IS_MSYS1=0
49 IS_MSYS2=0
50
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
55 # Windows C++ ABI.
56 UNIX_LDFLAGS_STATIC='-static -static-libgcc -static-libstdc++'
57
58 # Detect the environment -- Cygwin or MSYS.
59 case $(uname -s) in
60     CYGWIN*)
61         echo 'uname -s identifies a Cygwin environment.'
62         IS_CYGWIN=1
63             case $(uname -m) in
64             i686)
65                 echo 'uname -m identifies an i686 environment.'
66                 UNIX_CXX=i686-pc-cygwin-g++
67                 MINGW_CXX=i686-w64-mingw32-g++
68                 ;;
69             x86_64)
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++
73                 ;;
74             *)
75                 echo 'Error: uname -m did not match either i686 or x86_64.'
76                 exit 1
77                 ;;
78             esac
79         ;;
80     MSYS*|MINGW*)
81         # MSYS2 notes:
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.
89         # MSYS notes:
90         #  - `uname -s` is always MINGW32_NT-6.1 on Win7.
91         echo 'uname -s identifies an MSYS/MSYS2 environment.'
92         case $(uname -m) in
93             i686)
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.
101                     #
102                     # Distinguish between the two using the major version
103                     # number of `uname -r`:
104                     #
105                     #   MSYS uname -r:  1.0.18(0.48/3/2)
106                     #   MSYS2 uname -r: 2.0.0(0.284/5/3)
107                     #
108                     # This is suboptimal because MSYS2 is not actually the
109                     # second version of MSYS--it's a brand-new fork of Cygwin.
110                     #
111                     IS_MSYS1=1
112                     UNIX_LDFLAGS_STATIC=
113                     MINGW_CXX=mingw32-g++
114                 else
115                     IS_MSYS2=1
116                     MINGW_CXX=i686-w64-mingw32-g++.exe
117                 fi
118                 ;;
119             x86_64)
120                 echo 'uname -m identifies an x86_64 environment.'
121                 IS_MSYS2=1
122                 UNIX_CXX=x86_64-pc-msys-g++
123                 MINGW_CXX=x86_64-w64-mingw32-g++
124                 ;;
125             *)
126                 echo 'Error: uname -m did not match either i686 or x86_64.'
127                 exit 1
128                 ;;
129         esac
130         ;;
131     *)
132         echo 'Error: uname -s did not match either CYGWIN* or MINGW*.'
133         exit 1
134         ;;
135 esac
136
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
142
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
148
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
157 fi
158
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
163 else
164     echo "Commit info: none"
165     echo 'COMMIT_HASH := none' >> config.mk
166     echo 'COMMIT_HASH_DEP := config.mk' >> config.mk
167 fi