Newer
Older
dub_jkp / build.sh
  1. #!/usr/bin/env bash
  2. set -e
  3.  
  4. if [ "$DMD" = "" ]; then
  5. if [ ! "$DC" = "" ]; then # backwards compatibility with DC
  6. DMD=$DC
  7. else
  8. command -v gdmd >/dev/null 2>&1 && DMD=gdmd || true
  9. command -v ldmd2 >/dev/null 2>&1 && DMD=ldmd2 || true
  10. command -v dmd >/dev/null 2>&1 && DMD=dmd || true
  11. fi
  12. fi
  13.  
  14. if [ "$DMD" = "" ]; then
  15. echo >&2 "Failed to detect D compiler. Use DMD=... to set a dmd compatible binary manually."
  16. exit 1
  17. fi
  18.  
  19. VERSION=$($DMD --version 2>/dev/null | sed -n 's|DMD.* v||p')
  20. if [[ $VERSION < 2.069.0 ]]; then
  21. # link against libcurl
  22. LIBS=`pkg-config --libs libcurl 2>/dev/null || echo "-lcurl"`
  23. fi
  24.  
  25. # fix for modern GCC versions with --as-needed by default
  26. if [[ `$DMD --help | head -n1 | grep 'DMD\(32\|64\)'` ]]; then
  27. if [ `uname` = "Linux" ]; then
  28. LIBS="-l:libphobos2.a $LIBS"
  29. else
  30. LIBS="-lphobos2 $LIBS"
  31. fi
  32. elif [[ `$DMD --help | head -n1 | grep '^LDC '` ]]; then
  33. LIBS="-lphobos2-ldc $LIBS"
  34. fi
  35.  
  36. # adjust linker flags for dmd command line
  37. LIBS=`echo "$LIBS" | sed 's/^-L/-L-L/; s/ -L/ -L-L/g; s/^-l/-L-l/; s/ -l/ -L-l/g'`
  38.  
  39. echo Generating version file...
  40. GITVER=$(git describe) || GITVER=unknown
  41. echo "module dub.version_;" > source/dub/version_.d
  42. echo "enum dubVersion = \"$GITVER\";" >> source/dub/version_.d
  43.  
  44. # For OSX compatibility >= 10.7
  45. MACOSX_DEPLOYMENT_TARGET=10.7
  46.  
  47. echo Running $DMD...
  48. $DMD -ofbin/dub -w -version=DubUseCurl -Isource $* $LIBS @build-files.txt
  49. echo DUB has been built as bin/dub.
  50. echo
  51. echo You may want to run
  52. echo sudo ln -s $(pwd)/bin/dub /usr/local/bin
  53. echo now.