makellvm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/csh -f
  2. set pstatus = 0
  3. onintr cleanup
  4. alias usage 'echo "USAGE: $0:t [-h] [-n] [-obj obj-root] [gmake-flags] [VAR=...] [toolname (default: opt)]"; set pstatus = 1; goto cleanup'
  5. set EXEC = opt
  6. set GMAKE_OPTS = ""
  7. set DEBUG = 0
  8. ## Search path for automatically finding the obj-root to use.
  9. ## Note: The src root directory ${LLVMDIR} will be prepended to this path later.
  10. ##
  11. set OBJROOTDIRLIST = ( )
  12. set doit = 1
  13. unset options_done
  14. while ( !( $?options_done ) && ($#argv > 0))
  15. switch ($argv[1])
  16. case -h :
  17. usage
  18. case -f :
  19. if ($#argv < 2) usage
  20. shift argv; set MFILE = $argv[1]; shift argv; breaksw
  21. case -n :
  22. set doit = 0; shift argv; breaksw
  23. case -obj :
  24. set OBJROOT = $argv[2]; shift argv; shift argv
  25. if (! -d "$OBJROOT") then
  26. echo "FATAL: Illegal obj-root directory ${OBJROOT}"
  27. exit 1
  28. endif
  29. breaksw
  30. case -d :
  31. set doit = 0; set DEBUG = 1; shift argv; breaksw
  32. case -* :
  33. set GMAKE_OPTS = ( $GMAKE_OPTS $argv[1] ); shift argv; breaksw
  34. default :
  35. set optarg = `echo -n $argv[1] | sed 's/^[^=]*$//'`
  36. if ($#optarg) then
  37. set GMAKE_OPTS = ( $GMAKE_OPTS $optarg )
  38. shift argv
  39. else
  40. set options_done
  41. endif
  42. breaksw
  43. endsw
  44. end
  45. if ($#argv > 1) then
  46. echo 'ERROR: More than one tool is not supported by "makellvm"'
  47. usage
  48. endif
  49. if ($#argv > 0) then
  50. set EXEC = $argv[1]
  51. endif
  52. if ($DEBUG) then
  53. echo "DEBUG: EXEC = $EXEC"
  54. endif
  55. ## Compute LLVMDIR: the root of the current LLVM tree.
  56. ## It is recorded in the variable LEVEL in Makefile, to compute it
  57. ##
  58. if (! $?MFILE) then
  59. if (-f GNUmakefile) then
  60. set MFILE = GNUmakefile
  61. else if (-f makefile) then
  62. set MFILE = makefile
  63. else
  64. set MFILE = Makefile
  65. endif
  66. endif
  67. if ($DEBUG) then
  68. echo "DEBUG: MFILE = $MFILE"
  69. endif
  70. if (! -f $MFILE) then
  71. echo "Missing or invalid makefile: $MFILE"
  72. exit 1
  73. endif
  74. set LLVMDIR = `awk '/LEVEL[ ]*=/ {print $NF}' $MFILE`
  75. if ($DEBUG) then
  76. echo "DEBUG: LLVMDIR = $LLVMDIR"
  77. endif
  78. if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then
  79. echo "Unable to find LLVM src-root directory or directory is invalid."
  80. echo "Are you within a valid LLVM directory for running gmake?"
  81. exit 1
  82. endif
  83. ## Try to determine the obj-root directory automatically if not specified
  84. ##
  85. set OBJROOTDIRLIST = ( ${LLVMDIR} $OBJROOTDIRLIST ) ## add src dir
  86. if ($?OBJROOT == 0) then
  87. ## Try to determine object root directory by looking for Makefile.config
  88. foreach objdir ( $OBJROOTDIRLIST )
  89. if (-f "${objdir}/Makefile.config") then
  90. set OBJROOT = ${objdir}
  91. break
  92. endif
  93. end
  94. if ($?OBJROOT == 0) then
  95. echo "FATAL: Could not choose an obj-root directory from these choices:"
  96. echo " ${OBJROOTDIRLIST}."
  97. echo " You can specify it explicitly using '-obj obj-root'."
  98. exit 1
  99. endif
  100. echo "Using OBJ-ROOT = ${OBJROOT} (specify '-obj obj-root' to override)."
  101. endif
  102. if (${OBJROOT} == ${LLVMDIR}) then
  103. # run make in the source directory itself
  104. set BUILDROOT = .
  105. else
  106. # run make in the in the obj-root tree, in the directory for $cwd
  107. set SRCROOT = `sh -c "cd $LLVMDIR; pwd | sed 's/\//\\\//g'"`
  108. set CURSRCDIR = `echo $cwd | sed -e "s/${SRCROOT}//"`
  109. set BUILDROOT = ${OBJROOT}/${CURSRCDIR}
  110. unset SRCROOT CURSRCDIR
  111. endif
  112. if ($DEBUG) then
  113. echo "DEBUG: BUILDROOT = $BUILDROOT"
  114. endif
  115. if (! -d $BUILDROOT) then
  116. echo "FATAL: Invalid build directory: ${BUILDROOT}"
  117. exit 1
  118. endif
  119. cd $BUILDROOT
  120. set CMD = "make $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && make $GMAKE_OPTS)"
  121. if ($doit == 1) then
  122. csh -f -c "$CMD"
  123. set pstatus = $?
  124. else
  125. echo '(NOT EXECUTING) COMMAND:'
  126. echo " $CMD"
  127. endif
  128. #=========================================================
  129. # CODE TO BE EXECUTED IF INTERRUPT IS RECEIVED
  130. #=========================================================
  131. cleanup:
  132. exit($pstatus)