Newer
Older
dub_jkp / build.sh
@Sebastian Wilzbach Sebastian Wilzbach on 6 Apr 2018 1 KB Use -flto=full for the release builds
  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 -En 's|.*DMD.* v([[:digit:]\.]+).*|\1|p')
  20. # workaround for link order issues with libcurl (phobos needs to come before curl)
  21. if [[ $VERSION < 2.069.0 ]]; then
  22. # link against libcurl
  23. LIBS=`pkg-config --libs libcurl 2>/dev/null || echo "-lcurl"`
  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. if [ `uname` = "SunOS" ]; then
  34. LIBS="-lnsl -lsocket -lphobos2-ldc $LIBS"
  35. else
  36. LIBS="-lphobos2-ldc $LIBS"
  37. fi
  38. fi
  39.  
  40. # adjust linker flags for dmd command line
  41. LIBS=`echo "$LIBS" | sed 's/^-L/-L-L/; s/ -L/ -L-L/g; s/^-l/-L-l/; s/ -l/ -L-l/g'`
  42. fi
  43.  
  44. if [ "$GITVER" = "" ]; then
  45. GITVER=$(git describe) || echo "Could not determine a version with git."
  46. fi
  47. if [ "$GITVER" != "" ]; then
  48. echo Generating version file...
  49. echo "module dub.version_;" > source/dub/version_.d
  50. echo "enum dubVersion = \"$GITVER\";" >> source/dub/version_.d
  51. else
  52. echo Using existing version file.
  53. fi
  54.  
  55. # For OSX compatibility >= 10.8
  56. MACOSX_DEPLOYMENT_TARGET=10.8
  57.  
  58. echo Running $DMD...
  59. $DMD -ofbin/dub -g -O -w -version=DubUseCurl -Isource $* $LIBS @build-files.txt
  60. bin/dub --version
  61. echo DUB has been built as bin/dub.
  62. echo
  63. echo You may want to run
  64. echo sudo ln -s $(pwd)/bin/dub /usr/local/bin
  65. echo now.