Skip to content

Commit dc392ad

Browse files
committed
Fix use of mktemp on Mac, fixes #87
1 parent 9e2a792 commit dc392ad

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

stc/code/bin/swift-t

+26-11
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,41 @@ verbose()
151151
message "Swift/T"
152152

153153
# Handle temp file creation across platforms
154-
# Always has .SUFFIX somewhere
154+
# Always has .SUFFIX somewhere, preferably at the end
155155
make_temp()
156156
{
157157
local SUFFIX=$1
158158
local PROGRAM_DIR=$2
159159
local NAME=$3
160-
# Linux:
161-
MKTEMP_VERSION=$( mktemp -V | awk '{print $NF;exit}' )
162-
if (( ${MKTEMP_VERSION} > 2 ))
160+
local MKTEMP_TYPE=""
161+
local SUFFIX_ARG=""
162+
163+
# Attempt to determine mktemp version
164+
# Mac mktemp does not support -V
165+
if mktemp -V >& /dev/null
166+
then
167+
# Linux:
168+
MKTEMP_VERSION=$( mktemp -V | awk '{print $NF;exit}' )
169+
if (( ${MKTEMP_VERSION} > 2 ))
170+
then
171+
MKTEMP_TYPE="Linux"
172+
else
173+
MKTEMP_TYPE="BSD"
174+
fi
175+
else
176+
MKTEMP_TYPE="Mac"
177+
fi
178+
179+
if [[ ${MKTEMP_TYPE} == "Linux" ]]
163180
then
164-
# Modern mktemp. .tic at the end.
165-
local SUFFIX_ARG
166-
SUFFIX_ARG=( --suffix .${SUFFIX} )
181+
# Modern mktemp. .tic at the end.
182+
SUFFIX_ARG=( --suffix .${SUFFIX} )
167183
else
168-
# Old (BSD?) mktemp. .SUFFIX. will be in the middle of the name
169-
local SUFFIX_ARG=""
170-
NAME=${NAME}.${SUFFIX}
184+
# Old (BSD?) mktemp. .SUFFIX. will be in the middle of the name
185+
NAME=${NAME}.${SUFFIX}
171186
fi
187+
172188
mktemp ${SUFFIX_ARG} ${PROGRAM_DIR}/swift-t-${NAME}.XXX
173-
# TODO: Mac?
174189
}
175190

176191
DELETE_PROGRAM_SWIFT=0

0 commit comments

Comments
 (0)