#!/bin/csh -f
#
set dir=/Library/Frameworks/GHC.framework/Versions/8.4.3-x86_64/usr/lib/ghc-8.4.3
#
set file=$dir/settings
if (-e $file) then
  fgrep -q '("C compiler supports -no-pie","YES")' $file
  if ($status == 0) then
    echo -n "Do you want to fix -no-pie problem? (y or n)?"
    set yes=$<
    if ($yes == 'y') then
      if (-w $file) then
        cp $file $file.org
	rm -f $file.fix
	sed -e 's/("C compiler supports -no-pie","YES")/("C compiler supports -no-pie","NO")/' $file > $file.fix
	cp $file.fix $file
	echo "Fixed the problem of -no-pie."
      else
        echo "error: You need to execute this command with sudo to fix it."
      endif
    else
      echo "No fix of -no-pie problem."
    endif
  else
    fgrep -q '("C compiler supports -no-pie","NO")' $file
    if ($status == 0) then
      echo "You have already fixed the problem of -no-pie."
    else
      echo "error: cannot find -no-pie in the setting."
    endif
  endif
else
  echo "error: File $file does not exists."
endif

