#!/bin/sh

# 29.09.2006 Volker Quetschke
# Check if the directory cache can be made case insensitive
# (issue 69814)

: ${DMAKEPROG:=dmake}
file1="mfile1.mk"
file2="TeSt.target"
tmpfiles="$file1 $file2"
STARTDIR="`pwd`"; WORKDIR="$0-OUTPUT"
CLEANUP="eval (cd $STARTDIR; rm -rf $WORKDIR)"
$CLEANUP # Zap remnants of any failed run
mkdir "$WORKDIR"; cd "$WORKDIR"

trap "{ echo 'trapped signal - removing temporary files' ; $CLEANUP ; }" 1 2 3 15

echo "Something" > $file2

# Remember to quote variables in generated makefiles ( $ -> \$ ).
# Also quote line continuations ( \<nl> -> \\<nl> ).
cat > $file1 <<EOT
SHELL*:=/bin/sh 
SHELLFLAGS*:=-ce

.DIRCACHE=yes

# Only test the directory cache for case insensitivity if the FS is also 
# case insensitive.
.IF "\$(.DIRCACHERESPCASE)"!="y"
test.target :
	@echo "Building \$@"

.ELSE
TeSt.target :
	@echo "Building \$@"

.ENDIF

EOT

output=`eval ../${DMAKEPROG} -vm -r -f $file1`
result=$?

if echo "$output" | grep ".target' is up to date"  > /dev/null 2>&1
then
  # no-op, fine
  :
else
  echo "Wrong result: ${output}"
  result=1
fi 
 
test $result -eq 0 && echo "Success - Cleaning up" && $CLEANUP
test $result -ne 0 && echo "Failure!"
exit $result
