1
0

condor_compile 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. #!/bin/sh
  2. ##**************************************************************
  3. ##
  4. ## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
  5. ## University of Wisconsin-Madison, WI.
  6. ##
  7. ## Licensed under the Apache License, Version 2.0 (the "License"); you
  8. ## may not use this file except in compliance with the License. You may
  9. ## obtain a copy of the License at
  10. ##
  11. ## http://www.apache.org/licenses/LICENSE-2.0
  12. ##
  13. ## Unless required by applicable law or agreed to in writing, software
  14. ## distributed under the License is distributed on an "AS IS" BASIS,
  15. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. ## See the License for the specific language governing permissions and
  17. ## limitations under the License.
  18. ##
  19. ##**************************************************************
  20. # THIS SCRIPT IS BEST VIEWED WITH TAB STOPS IN YOUR EDITOR AT 4 SPACES
  21. # Author Todd Tannenbaum, 6/97
  22. # This is an env var used to see if a condor specific ld call had
  23. # been invoked. It is set to an environment variable that if it is not
  24. # defined means that this is the "root" call of a possibly recursive
  25. # invocation of condor_compile(true via a full install). If it is defined
  26. # then it represents a file which must exist when the root invocation is
  27. # finished. If the file doesn't exist, it means that our ld didn't get called.
  28. #
  29. # This algorithm only checks to see if our ld got called AT LEAST ONCE,
  30. # not that it got called correctly in every instance of say a
  31. # "condor_compile make" or something like that.
  32. CONDOR_LD_IN_USE_FILE=$CONDOR_LD_IN_USE_FILE
  33. # if the above is not set, then we know we are the root invocation, and later
  34. # this has meaning when we create and remove this file.
  35. if [ "X$CONDOR_LD_IN_USE_FILE" = "X" ]; then
  36. CONDOR_LD_ROOT_INVOCATION=yes
  37. # if it was undefined, then set it right here.
  38. CONDOR_LD_IN_USE_FILE="/tmp/.condor_ld_in_use.$$"
  39. else
  40. # we are some child of another condor_compile.
  41. CONDOR_LD_ROOT_INVOCATION=no
  42. # we will transparently transfer the in use file name to this invocation
  43. # as well.
  44. fi
  45. # make it available to all future children of condor_compile
  46. export CONDOR_LD_IN_USE_FILE
  47. # Sometimes, a user can invoke condor_compile in such a manner as it'll never
  48. # invoke an ld, but be correct. An example of this is: condor_compile gcc
  49. # -print-prog-name=ld So, if we discover a situation like that, we'll set this
  50. # to 'no' and not die with the unable to invoke ld error message. This allows
  51. # condor_compile to be called under configure and libtool properly. The
  52. # default for this is to emit it.
  53. DIE_WITH_LD_NOT_IN_USE=yes
  54. # When we invoke a compiler/linker/whatever, make sure it eventually ends
  55. # up calling our linker. We check for that by seeing if the file we exported
  56. # into the environment is touched. This feature doesn't check all cases of
  57. # our linker being called correctly, it only checks if our linker
  58. # wasn't called AT LEAST ONCE.
  59. invoke_linker () {
  60. # trap on various signals to not leave around the in use file.
  61. trap 'echo "Signal Caught... cleaning up."; test "X$CONDOR_LD_IN_USE_FILE" != "X" && rm -f $CONDOR_LD_IN_USE_FILE; exit 1' 1 2 3 15
  62. # invoke the program specified, but don't use exec
  63. eval "$@"
  64. linker_ret_code=$?
  65. # if I am the root node, then simply invoke whatever linker I was asked to
  66. # and when it returns, check to see if the in use file was touched. If
  67. # it was, then our linker was called at least once
  68. if [ "X$CONDOR_LD_ROOT_INVOCATION" = "Xyes" ]; then
  69. # I'm the root invocation, see if the file my children made exists,
  70. # and raise an error if it doesn't. However, other invocations of
  71. # condor_compile legitimately ask information from the compiler and
  72. # don't expect to produce an executable. So, in those cases, emit
  73. # nothing and don't die with a failure.
  74. if [ ! -f "$CONDOR_LD_IN_USE_FILE" -a \
  75. "$DIE_WITH_LD_NOT_IN_USE" = "yes" ];
  76. then
  77. echo 'ERROR: Internal ld was not invoked!'
  78. echo 'ERROR: Executable may not be linked properly for Condor!'
  79. echo 'ERROR: For users of Condor on Linux, we highly recommend'
  80. echo 'ERROR: using the default compiler that came with the'
  81. echo 'ERROR: distribution. Usually placing /usr/bin first in'
  82. echo 'ERROR: your path will remedy this error.'
  83. echo 'ERROR: To learn more about this error, visit this web page:'
  84. echo 'ERROR: http://www.cs.wisc.edu/condor/manual/faq.html'
  85. echo 'ERROR: and read the FAQ entry about this problem for your'
  86. echo 'ERROR: revision of Condor.'
  87. rm -f $CONDOR_LD_IN_USE_FILE
  88. exit 1;
  89. fi
  90. # get rid of the in use file.
  91. rm -f $CONDOR_LD_IN_USE_FILE
  92. fi
  93. # if we weren't the root node, then just transparently fall backwards up
  94. # the process call chain. I'm assuming some children underneath me had
  95. # touched the file in question and the root invocation will know for sure.
  96. exit $linker_ret_code
  97. }
  98. # --------------------------------------------------
  99. # Tell our "ld" to link to with the Condor libs
  100. CONDOR_COMPILE=yes
  101. export CONDOR_COMPILE
  102. # Handle any command-line args
  103. while [ A = A ]
  104. do
  105. if [ $# = 0 ]; then
  106. break;
  107. fi
  108. if [ $1 = "-condor_syscall_lib" ]; then
  109. shift
  110. CONDOR_SPECIAL_CLIB=$1
  111. shift
  112. continue
  113. fi
  114. if [ $1 = "-condor_rt0" ]; then
  115. shift
  116. CONDOR_RT0=$1
  117. shift
  118. continue
  119. fi
  120. if [ $1 = "-condor_c++_support" ]; then
  121. shift
  122. CONDOR_CPLUS=$1
  123. shift
  124. continue
  125. fi
  126. if [ $1 = "-condor_ld_dir" ]; then
  127. shift
  128. CONDOR_LD_DIR=$1
  129. shift
  130. continue
  131. fi
  132. if [ $1 = "-condor_standalone" ]; then
  133. #
  134. # This option is ignored. Standalone checkpointing
  135. # has the same build procedure as standard jobs now.
  136. # This option is kept for compatibility.
  137. #
  138. shift
  139. continue
  140. fi
  141. if [ $1 = "-condor_lib" ]; then
  142. shift
  143. CONDOR_LIBDIR=$1
  144. shift
  145. # Reset anything based off of the libdir by default
  146. CONDOR_CLIB=$CONDOR_LIBDIR/libcondorsyscall.a
  147. CONDOR_ZCLIB=$CONDOR_LIBDIR/libcondorzsyscall.a
  148. STATIC_ZLIB=$CONDOR_LIBDIR/libcondor_z.a
  149. CONDOR_RT0=$CONDOR_LIBDIR/condor_rt0.o
  150. CONDOR_CPLUS=$CONDOR_LIBDIR/libcondorc++support.a
  151. CONDOR_LD_DIR=$CONDOR_LIBDIR
  152. continue
  153. fi
  154. # if we made it here, there are no more command-line options
  155. break
  156. done
  157. #
  158. # If the user didn't tell us which library directory to use, it's OK
  159. # to fail if we can't find one using condor_config_val.
  160. #
  161. if [ "X$CONDOR_LIBDIR" = "X" ]; then
  162. CONDOR_LIBDIR=`condor_config_val LIB 2> /dev/null`
  163. if [ $? != 0 ]; then
  164. echo "ERROR: Failed to find LIB using condor_config_val."
  165. echo "You may need to add the directory containing condor_config_val"
  166. echo "to your \$PATH, or you may need to set \$CONDOR_CONFIG in"
  167. echo "your environment."
  168. echo
  169. echo "Re-running 'condor_config_val LIB' so you can see the error..."
  170. condor_config_val LIB
  171. exit 1
  172. fi
  173. fi
  174. if [ "X$CONDOR_CLIB" = "X" ]; then
  175. CONDOR_CLIB=$CONDOR_LIBDIR/libcondorsyscall.a
  176. fi
  177. if [ "X$CONDOR_ZLIB" = "X" ]; then
  178. STATIC_ZLIB=$CONDOR_LIBDIR/libcondor_z.a
  179. fi
  180. if [ "X$CONDOR_ZCLIB" = "X" ]; then
  181. CONDOR_ZCLIB=$CONDOR_LIBDIR/libcondorzsyscall.a
  182. fi
  183. if [ "X$CONDOR_RT0" = "X" ]; then
  184. CONDOR_RT0=$CONDOR_LIBDIR/condor_rt0.o
  185. fi
  186. if [ "X$CONDOR_CPLUS" = "X" ]; then
  187. CONDOR_CPLUS=$CONDOR_LIBDIR/libcondorc++support.a
  188. fi
  189. if [ "X$CONDOR_LD_DIR" = "X" ]; then
  190. CONDOR_LD_DIR=$CONDOR_LIBDIR
  191. fi
  192. if [ "X$CONDOR_SPECIAL_CLIB" = "X" ]; then
  193. CONDOR_SPECIAL_CLIB=/not-there-bull
  194. fi
  195. #
  196. # If the compressed ckpt library is available, use it.
  197. #
  198. if [ -r $CONDOR_ZCLIB ]; then
  199. CONDOR_CLIB="$CONDOR_ZCLIB"
  200. fi
  201. #
  202. # However, we still always need the compression library for other purposes.
  203. #
  204. CONDOR_CLIB="$CONDOR_CLIB $STATIC_ZLIB"
  205. if [ -r $CONDOR_SPECIAL_CLIB ]; then
  206. CONDOR_CLIB="$CONDOR_SPECIAL_CLIB"
  207. fi
  208. # Export these so our special "ld" script can find them
  209. export CONDOR_LIBDIR
  210. export CONDOR_CLIB
  211. export CONDOR_RT0
  212. export CONDOR_CPLUS
  213. export CONDOR_LD_DIR
  214. # Since uname and awk live in different places on various
  215. # platforms, use a PATH. NOTE: we want to add these things to the END
  216. # of the PATH, to make sure people get the version of the compiler
  217. # they thought they were using.
  218. PATH=$PATH:/bin:/usr/bin:/usr/bsd
  219. # Figure out what architecture we're running on
  220. os=`uname -s`
  221. osver=`uname -r`
  222. if [ $os = "HP-UX" ]; then
  223. osmajver=`uname -r | awk -F. '{print $2}' -`
  224. else
  225. osmajver=`uname -r | awk -F. '{print $1}' -`
  226. fi
  227. osfull="$os$osmajver"
  228. abi=""
  229. # Determine if the system ld has been replaced with our ld script
  230. # or not.
  231. CONDOR_FULLINSTALL=false
  232. case $os in
  233. HP-UX )
  234. if [ $osmajver = "10" ]; then
  235. if [ -x /usr/ccs/bin/ld.real ]; then
  236. CONDOR_FULLINSTALL=true
  237. fi
  238. fi
  239. if [ $osmajver = "09" ]; then
  240. if [ -x /bin/ld.real ]; then
  241. CONDOR_FULLINSTALL=true
  242. fi
  243. fi
  244. ;;
  245. SunOS )
  246. if [ $osmajver = 5 ]; then
  247. if [ -x /usr/ccs/bin/ld.real ]; then
  248. CONDOR_FULLINSTALL=true
  249. fi
  250. fi
  251. if [ $osmajver = 4 ]; then
  252. if [ -x /bin/ld.real ]; then
  253. CONDOR_FULLINSTALL=true
  254. fi
  255. fi
  256. ;;
  257. Linux )
  258. if [ -x /usr/bin/ld.real ]; then
  259. CONDOR_FULLINSTALL=true
  260. fi
  261. ;;
  262. * )
  263. if [ -x /bin/ld.real ]; then
  264. CONDOR_FULLINSTALL=true
  265. fi
  266. ;;
  267. esac
  268. # Usage info should go here...
  269. if [ $# = 0 ]; then
  270. echo "Usage: condor_compile <command> [options/files .... ]"
  271. if [ $CONDOR_FULLINSTALL = true ]; then
  272. echo " where <commmand> is whatever you enter to compile/link your application."
  273. exit 1
  274. fi
  275. echo " where <command> is one of the following:"
  276. echo " gcc, g++, g77, gfortran, cc, acc, c89, CC, f77, fort77, ld, "
  277. echo " pgcc, pgf77, pgf90, pghpf, or icc."
  278. echo " (on some platforms, f90 is also allowed)"
  279. exit 1
  280. fi
  281. # if fully installed, then just run the command - eventually we'll
  282. # hit our special ld
  283. if [ $CONDOR_FULLINSTALL = true ]; then
  284. invoke_linker $*
  285. fi
  286. ARGS=$*
  287. # check to see if the compiler is passed things like -print-prog-name=...
  288. # If so, we don't want to die with the ld no in use error message since
  289. # the compiler produces good output in this case but no executable is expected.
  290. for i in $ARGS
  291. do
  292. case $i in
  293. -print-prog-name* | -print-file-name* | --version)
  294. DIE_WITH_LD_NOT_IN_USE=no
  295. ;;
  296. esac
  297. done
  298. # If we were passed a -c, we're not going to be used for linking, so
  299. # we don't have to do anything special to make sure our special ld is
  300. # used.
  301. #
  302. # Create warning for pthreads in Standard Universe. Pth library must be installed
  303. # with the --enable-pthread flag. Pth seems to be the best Green Threads library
  304. # that does POSIX Thread (pthread) emulation as of 01/10/2013.
  305. print_warning=0
  306. NAME=$1
  307. for j_pthread in $(seq 1 $#)
  308. do
  309. if [ $# = 0 ]; then
  310. break;
  311. fi
  312. if [ "$1" = "-c" ]; then
  313. exec $ARGS;
  314. fi
  315. if [ "$1" = "-lpthread" ]; then
  316. print_warning=1
  317. fi
  318. if [ "$1" = "-l" ] && [ "$2" = "pthread" ]; then
  319. print_warning=1
  320. fi
  321. shift
  322. done
  323. if [ $print_warning -eq 1 ]; then
  324. echo "WARNING: Using pthreads with condor_compile."
  325. echo "WARNING: condor_compile must know how to find the Pth library."
  326. echo "WARNING: Users should add /path/to/pth-library to the environment"
  327. echo "WARNING: variable LD_LIBRARY_PATH or add -L/path/to/pth-library"
  328. echo "WARNING: to the command line when invoking condor_compile."
  329. echo "WARNING: Pth must be installed with the --enable-pthread"
  330. echo "WARNING: flag. See Pth INSTALL file for more information."
  331. fi
  332. # If not fully installed, and we didn't see a -c, add options to force
  333. # the compiler to use our special ld
  334. # First of all, we need to strip off any path from our (now) first
  335. # argument, so we can compare it different names, even if the user
  336. # specified a full path to the program.
  337. myname=`echo $NAME | sed "s/.*\///"`
  338. # Handle Intel compilers
  339. if [ $myname = "icc" ]; then
  340. invoke_linker $ARGS -static -B$CONDOR_LD_DIR/
  341. fi
  342. # Handle GNU compilers
  343. if [ $myname = "gcc" ]; then
  344. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  345. fi
  346. if [ $myname = "g++" ]; then
  347. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  348. fi
  349. if [ $myname = "g77" ]; then
  350. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  351. fi
  352. if [ $myname = "gfortran" ]; then
  353. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  354. fi
  355. # Handle Portland compilers.
  356. # Notice that we explicitly do _not_ support Portland C++.
  357. # Their run-time support libraries conflict with libcondorc++support.a
  358. if [ $myname = "pgcc" ]; then
  359. invoke_linker $ARGS -Yl,$CONDOR_LD_DIR/
  360. fi
  361. if [ $myname = "pgf77" ]; then
  362. invoke_linker $ARGS -Yl,$CONDOR_LD_DIR/
  363. fi
  364. if [ $myname = "pgf90" ]; then
  365. invoke_linker $ARGS -Yl,$CONDOR_LD_DIR/
  366. fi
  367. if [ $myname = "pghpf" ]; then
  368. invoke_linker $ARGS -Yl,$CONDOR_LD_DIR/
  369. fi
  370. # Handle ld (linker). Since the user might have specified a full path
  371. # to ld, we want to shift (to get rid of the ld we were passed), and
  372. # call our ld directly with the remaining arguments.
  373. if [ $myname = "ld" ]; then
  374. shift;
  375. invoke_linker $CONDOR_LD_DIR/ld $ARGS
  376. fi
  377. # Handle all the vendor system compilers ---------------
  378. # the idea here is to simply append whatever command line
  379. # option(s) allows us to use $CONDOR_LIBDIR/ld instead
  380. # of the default path for ld.
  381. case $os in
  382. HP-UX )
  383. if [ $myname = "cc" ]; then
  384. invoke_linker $ARGS -tl,$CONDOR_LD_DIR/ld
  385. fi
  386. if [ $myname = "CC" ]; then
  387. invoke_linker $ARGS +A -tl,$CONDOR_LD_DIR/ld
  388. fi
  389. if [ $myname = "aCC" ]; then
  390. invoke_linker $ARGS +A -tl,$CONDOR_LD_DIR/ld
  391. fi
  392. if [ $myname = "c89" ]; then
  393. invoke_linker $ARGS -tl,$CONDOR_LD_DIR/ld
  394. fi
  395. if [ $myname = "f77" ]; then
  396. invoke_linker $ARGS -tl,$CONDOR_LD_DIR/ld
  397. fi
  398. if [ $myname = "fort77" ]; then
  399. invoke_linker $ARGS -tl,$CONDOR_LD_DIR/ld
  400. fi
  401. ;;
  402. SunOS )
  403. use_qpath=`cc -help -flags | grep Qpath | wc -l`
  404. if [ $myname = "cc" -a $use_qpath = 0 ]; then
  405. invoke_linker $ARGS -Yl,$CONDOR_LD_DIR
  406. fi
  407. if [ $myname = "cc" -a $use_qpath != 0 ]; then
  408. invoke_linker $ARGS -Qpath $CONDOR_LD_DIR
  409. fi
  410. if [ $myname = "acc" ]; then
  411. invoke_linker $ARGS -Qpath $CONDOR_LD_DIR
  412. fi
  413. if [ $myname = "CC" ]; then
  414. invoke_linker $ARGS -Qpath $CONDOR_LD_DIR
  415. fi
  416. if [ $myname = "f77" ]; then
  417. invoke_linker $ARGS -Qpath $CONDOR_LD_DIR
  418. fi
  419. if [ $myname = "f90" ]; then
  420. invoke_linker $ARGS -Qpath $CONDOR_LD_DIR
  421. fi
  422. ;;
  423. Linux )
  424. # Linux's system compilers are GNU
  425. if [ $myname = "cc" ]; then
  426. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  427. fi
  428. if [ $myname = "CC" ]; then
  429. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  430. fi
  431. if [ $myname = "c++" ]; then
  432. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  433. fi
  434. if [ $myname = "f77" ]; then
  435. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  436. fi
  437. if [ $myname = "gfortran" ]; then
  438. invoke_linker $ARGS -B$CONDOR_LD_DIR/
  439. fi
  440. ;;
  441. esac
  442. # If we made it here, we did not do anything, so print out usage
  443. echo "Usage: condor_compile <command> [options/files .... ]"
  444. if [ $CONDOR_FULLINSTALL = true ]; then
  445. echo " where <commmand> is whatever you enter to compile/link your application."
  446. exit 1
  447. fi
  448. echo " where <command> is one of the following:"
  449. echo " gcc, g++, g77, gfortran, cc, acc, c89, CC, f77, fort77, ld, "
  450. echo " pgcc, pgf77, pgf90, pghpf, or icc."
  451. echo " (on some platforms, f90 is also allowed)"
  452. exit 1