1
2#  N.B. the previous line should be blank.
3#++
4#  Name:
5#     ast_link
6
7#  Purpose:
8#     Link a program with the AST library.
9
10#  Type of Module:
11#     Shell script.
12
13#  Description:
14#     This command should be used when building programs which use the AST
15#     library, in order to generate the correct arguments to allow the compiler
16#     to link your program. The arguments generated are written to standard
17#     output but may be substituted into the compiler command line in the
18#     standard UNIX way using backward quotes (see below).
19#
20#     By default, it is assumed that you are building a stand-alone program
21#     which does not produce graphical output. However, switches are provided
22#     for linking other types of program.
23
24#  Invocation:
25#c     cc program.c -L/star/lib `ast_link [switches]` -o program
26#f     f77 program.f -L/star/lib `ast_link [switches]` -o program
27
28#  Switches:
29#     The following switches may optionally be given to this command to
30#     modify its behaviour:
31#
32#
33#     - ``-csla'': Ignored. Provided for backward compatibility only.
34#
35#     - ``-fsla'': Ignored. Provided for backward compatibility only.
36#
37#     - ``-ems'': Requests that the program be linked so that error messages
38#     produced by the AST library are delivered via the Starlink EMS (Error
39#     Message Service) library (Starlink System Note SSN/4). By default,
40#     error messages are simply written to standard error.
41#
42#     - ``-drama'': Requests that the program be linked so that error messages
43#     produced by the AST library are delivered via the DRAMA Ers (Error
44#     Reporting Service) library. By default, error messages are simply
45#     written to standard error.
46#
47#     - ``-grf'': Requests that no arguments be generated to specify which
48#     2D graphics system is used to display output from the AST library. You
49#     should use this option only if you have implemented an interface to a
50#     new graphics system yourself and wish to provide your own arguments for
51#     linking with it. This switch differs from the other ``grf'' switches in
52#     that it assumes that your graphics module implements the complete
53#     interface required by the current version of AST. If future versions of
54#     AST introduce new functions to the graphics interface, this switch will
55#     cause ``unresolved symbol'' errors to occur during linking, warning you
56#     that you need to implement new functions in your graphics module. To
57#     avoid such errors, you can use one of the other, version-specific,
58#     switches in place of the ``-grf'' switch, but these will cause run-time
59#     errors to be reported if any AST function is invoked which requires
60#     facilities not in the implemented interface.
61#
62#     - ``-grf_v2.0'': This switch is equivalent to the ``-mygrf'' switch.
63#     It indicates that you want to link with your own graphics module
64#     which implements the 2D graphics interface required by V2.0 of AST.
65#
66#     - ``-grf_v3.2'': Indicates that you want to link with your own
67#     graphics module which implements the 2D graphics interface required by
68#     V3.2 of AST.
69#
70#     - ``-grf_v5.6'': Indicates that you want to link with your own
71#     graphics module which implements the 2D graphics interface required by
72#     V5.6 of AST.
73#
74#     - ``-myerr'': Requests that no arguments be generated to specify how
75#     error messages produced by the AST library should be delivered. You
76#     should use this option only if you have implemented an interface to a
77#     new error delivery system yourself and wish to provide your own
78#     arguments for linking with it.
79#
80#     - ``-mygrf'': This switch has been superceeded by the ``-grf'' switch,
81#     but is retained in order to allow applications to be linked with a
82#     graphics module which implements the 2D interface used by AST V2.0. It
83#     is equivalent to the ``-grf_v2.0'' switch.
84#
85#     - ``-pgp'': Requests that the program be linked so that 2D
86#     graphical output from the AST library is displayed via the
87#     Starlink version of the PGPLOT graphics package (which uses GKS
88#     for its output). By default, no 2D graphics package is linked and
89#     this will result in an error at run time if AST routines are
90#     invoked that attempt to generate graphical output.
91#
92#     - ``-pgplot'': Requests that the program be linked so that 2D
93#     graphical output from the AST library is displayed via
94#     the standard (or ``native'') version of the PGPLOT graphics
95#     package. By default, no 2D graphics package is linked and this will
96#     result in an error at run time if AST routines are invoked that
97#     attempt to generate graphical output.
98#
99#     - ``-grf3d'': Requests that no arguments be generated to specify which
100#     3D graphics system is used to display output from the AST library. You
101#     should use this option only if you have implemented an interface to a
102#     new 3D graphics system yourself and wish to provide your own arguments
103#     for linking with it.
104#
105#     - ``-pgp3d'': Requests that the program be linked so that 3D
106#     graphical output from the AST library is displayed via the
107#     Starlink version of the PGPLOT graphics package (which uses GKS
108#     for its output). By default, no 3D graphics package is linked and
109#     this will result in an error at run time if AST routines are
110#     invoked that attempt to generate graphical output.
111#
112#     - ``-pgplot3d'': Requests that the program be linked so that 3D
113#     graphical output from the AST library is displayed via
114#     the standard (or ``native'') version of the PGPLOT graphics
115#     package. By default, no 3D graphics package is linked and this will
116#     result in an error at run time if AST routines are invoked that
117#     attempt to generate graphical output.
118
119#  ERFA & PAL:
120#     The AST distribution includes bundled copies of the ERFA and PAL
121#     libraries. These will be used for fundamental positional astronomy
122#     calculations unless the "--with-external_pal" option was used when
123#     AST was configured. If "--with-external_pal" is used, this script
124#     will include "-lpal" in the returned list of linking options, and
125#     the user should then ensure that external copies of the PAL and
126#     ERFA libraries are available (ERFA functions are used within PAL).
127
128#  Examples:
129#c     cc display.c -L/star/lib `ast_link -pgplot` -o display
130#c        Compiles and links a C program called ``display'' which uses
131#c        the standard version of PGPLOT for graphical output.
132#c     cc plotit.c -L. -L/star/lib `ast_link -grf` -lgrf -o plotit
133#c        Compiles and links a C program ``plotit''. The ``-grf''
134#c        switch indicates that graphical output will be delivered through
135#c        a graphical interface which you have implemented yourself, which
136#c        corresponds to the interface required by the current version of AST.
137#c        Here, this interface is supplied by means of the ``-lgrf'' library
138#c        reference.
139#c     cc plotit.c -L. -L/star/lib `ast_link -grf_v2.0` -lgrf -o plotit
140#c        Compiles and links a C program ``plotit''. The ``-grf_v2.0''
141#c        switch indicates that graphical output will be delivered through
142#c        a graphical interface which you have implemented yourself, which
143#c        corresponds to the interface required by version 2.0 of AST.
144#c        Here, this interface is supplied by means of the ``-lgrf'' library
145#c        reference.
146#f     f77 display.f -L/star/lib `ast_link -pgplot` -o display
147#f        Compiles and links a Fortran program called ``display'' which uses
148#f        the standard version of PGPLOT for graphical output.
149#f     f77 plotit.f -L. -L/star/lib `ast_link -grf` -lgrf -o plotit
150#f        Compiles and links a Fortran program ``plotit''. The ``-grf''
151#f        switch indicates that graphical output will be delivered through
152#f        a graphical interface which you have implemented yourself, which
153#f        corresponds to the interface required by the current version of AST.
154#f        Here, this interface is supplied by means of the ``-lgrf'' library
155#f        reference.
156#f     f77 plotit.f -L. -L/star/lib `ast_link -grf_v2.0` -lgrf -o plotit
157#f        Compiles and links a Fortran program ``plotit''. The ``-grf_v2.0''
158#f        switch indicates that graphical output will be delivered through
159#f        a graphical interface which you have implemented yourself, which
160#f        corresponds to the interface required by version 2.0 of AST.
161#f        Here, this interface is supplied by means of the ``-lgrf'' library
162#f        reference.
163
164#  Copyright:
165#     Copyright (C) 1997-2006 Council for the Central Laboratory of the Research Councils
166#     Copyright (C) 2007-2008 Science & Technology Facilities Council.
167#     All Rights Reserved.
168
169#  Authors:
170#     RFWS: R.F. Warren-Smith (STARLINK)
171#     DSB: David S. Berry (STARLINK)
172#     TIMJ: Tim Jenness (JAC, Hawaii)
173#     {enter_new_authors_here}
174
175#  History:
176#     11-JUN-1996 (RFWS):
177#        Original version.
178#     11-NOV-1996 (RFWS):
179#        Added switches.
180#     18-NOV-1997 (RFWS):
181#        Adapted prologue for document extraction.
182#     28-SEP-1998 (RFWS):
183#        Distinguish between -pgp and -pgplot options.
184#     12-JAN-2001 (DSB):
185#        Move terminating "}" in function "find" onto a new line to
186#        avoid error when run under bash 2.04.11(1) (redhat 7).
187#     3-MAY-2001 (DSB):
188#        Added a terminating ";" to the "done" statement at the end of
189#        the "find" function, so that ast_link can be used on Debian Linux.
190#     23-JAN-2004 (DSB):
191#        Added switches to support older grf implementations.
192#     24-AUG-2004 (DSB):
193#        Removed f77='y' from -ems case.
194#     21-APR-2005 (DSB):
195#        Added "-fsla" option.
196#     16-JUN-2006 (DSB):
197#        Ignore "-fsla" and "-clsa" options, and always use PAL.
198#     26-JUN-2007 (DSB):
199#        Added "-grf3d", "-pgplot3d" and "-pgp3d" flags.
200#     13-NOV-2008 (TIMJ):
201#        Add -drama option for DRAMA Ers support.
202#     3-MAR-2011 (DSB):
203#        Added grf 5.6 options.
204#     {enter_further_changes_here}
205
206#  Bugs:
207#     {note_any_bugs_here}
208
209#--
210
211#  This line is edited during configuration of this script to define a list
212#  of the libraries that must be linked in order to resolve Fortran 77
213#  references made from within a C main program. Typically, these will arise
214#  from libraries written in Fortran which the AST library (or the C
215#  program) calls.  The value here is worked out by the autoconf macro
216#  AC_FC_LIBRARY_LDFLAGS.
217      flibs='@FCLIBS@'
218
219#  This function searches the directory path specified in PATH, looking for
220#  an executable file which is not a directory. If found, it echos the full
221#  file name to standard output. Otherwise, it outputs nothing.
222      find() { IFS=':'; for d in $PATH; do f="${d:=.}/${1}"
223                  test -x "${f}" -a ! -d "${f}" && echo "${f}" && break
224               done;
225             }
226
227#  Initialise linking options.
228      err=''
229      grf=''
230      grf3d=''
231      sla=''
232      f77=''
233
234#  Interpret command line switches.
235#  --------------------------------
236      while :; do
237         case "${1}" in
238
239#  -csla - Previously used to request C version of SLALIB. Now ignored.
240         -csla)
241#            sla='c'
242            shift;;
243
244#  -fsla - Previously used to request Fortran version of SLALIB. Now ignored.
245         -fsla)
246#            sla='f'
247            shift;;
248
249#  -ems - Requests error reporting through EMS.
250         -ems)
251            err='ems'
252            shift;;
253
254#  -drama - Requests error reporting through DRAMA Ers.
255         -drama)
256            err='drama'
257            shift;;
258
259#  -myerr - Requests no error reporting.
260         -myerr)
261            err='my'
262            shift;;
263
264#  -grf - Requests no 2D graphics.
265         -grf)
266            grf='current'
267            shift;;
268
269#  -mygrf - Requests no 2D graphics, except for null implementations of
270#  functions aded to the grf interface after AST V2.0.
271         -mygrf)
272            grf='v2.0'
273            shift;;
274
275#  -grf_v2.0 - Requests no 2D graphics, except for null implementations of
276#  functions aded to the grf interface after AST V2.0.
277         -grf_v2.0)
278            grf='v2.0'
279            shift;;
280
281#  -grf_v3.2 - Requests no 2D graphics, except for null implementations of
282#  functions aded to the grf interface after AST V3.2.
283         -grf_v3.2)
284            grf='v3.2'
285            shift;;
286
287#  -grf_v5.6 - Requests no 2D graphics, except for null implementations of
288#  functions aded to the grf interface after AST V5.6.
289         -grf_v5.6)
290            grf='v5.6'
291            shift;;
292
293#  -pgp - Requests 2D graphical output through Starlink PGPLOT.
294         -pgp)
295            grf='pgp'
296            shift;;
297
298#  -pgplot - Requests 2D graphical output through native PGPLOT.
299         -pgplot)
300            grf='pgplot'
301            shift;;
302
303#  -grf3d - Requests no 3D graphics.
304         -grf3d)
305            grf3d='current'
306            shift;;
307
308#  -pgp3d - Requests 3D graphical output through Starlink PGPLOT.
309         -pgp3d)
310            grf3d='pgp'
311            shift;;
312
313#  -pgplot3d - Requests 3D graphical output through native PGPLOT.
314         -pgplot3d)
315            grf3d='pgplot'
316            shift;;
317
318#  Once all switches have been read, continue with the rest of the script.
319         '') break;;
320
321#  Catch unrecognised arguments and report an error.
322         *)
323            echo >&2 "ast_link: unknown argument \""${1}"\" given"
324            exit 1;;
325         esac
326      done
327
328#  Link with the main AST library.
329#  -------------------------------
330#  Start forming the list of arguments with the main AST library itself.
331      args='-last '
332
333#  Generate arguments for linking PAL.
334#  -----------------------------------
335
336      case "@EXTERNAL_PAL@" in
337
338#  If we configured --with-external_pal include a link option to pick up
339#  an external PAL library.
340      1) args="${args} -lpal";;
341
342#  Otherwise, use the internal PAL & ERFA libraries.
343      *) args="${args} -last_pal";;
344
345      esac
346
347#  Generate arguments for linking the 2D graphics system.
348#  ------------------------------------------------------
349      case "${grf}" in
350
351#  If using Starlink PGPLOT, link with the AST PGPLOT interface and
352#  the Fortran library via the PGP link script (if found).
353      pgp) args="${args} -last_pgplot `\`find pgp_link\``"
354           f77='y';;
355
356#  If using native PGPLOT, link with the AST PGPLOT interface and the
357#  Fortran library via the PGPLOT link script (if found).
358      pgplot) args="${args} -last_pgplot `\`find pgplot_link\``"
359              f77='y';;
360
361#  If using own graphics which conform to the requirements of the current
362#  version of AST, do not produce any arguments.
363      current) :;;
364
365#  If using own graphics which conform to the requirements of version 5.6
366#  of AST, produce arguments which link in dummy implementations of any
367#  functions which are required by the current version of AST but which were
368#  not required by version 5.6.
369      v5.6) :;;
370
371#  If using own graphics which conform to the requirements of version 3.2
372#  of AST, produce arguments which link in dummy implementations of any
373#  functions which are required by the current version of AST but which were
374#  not required by version 3.2.
375      v3.2) args="${args} -last_grf_5.6";;
376
377#  If using own graphics which conform to the requirements of version 2.0
378#  of AST, produce arguments which link in dummy implementations of any
379#  functions which are required by the current version of AST but which were
380#  not required by version 2.0.
381      v2.0) args="${args} -last_grf_3.2 -last_grf_5.6";;
382
383#  Default graphics (none) requires linking with all the default (null) AST
384#  "grf" modules.
385      *) args="${args} -last_grf_2.0 -last_grf_3.2 -last_grf_5.6";;
386      esac
387
388
389#  Generate arguments for linking the 3D graphics system.
390#  ------------------------------------------------------
391      case "${grf3d}" in
392
393#  If using Starlink PGPLOT, link with the AST 3D PGPLOT interface and
394#  the Fortran library via the PGP link script (if found).
395      pgp) args="${args} -last_pgplot3d `\`find pgp_link\``"
396           f77='y';;
397
398#  If using native PGPLOT, link with the AST 3D PGPLOT interface and the
399#  Fortran library via the PGPLOT link script (if found).
400      pgplot) args="${args} -last_pgplot3d `\`find pgplot_link\``"
401              f77='y';;
402
403#  If using own 3D graphics which conform to the requirements of the current
404#  version of AST, do not produce any arguments.
405      current) :;;
406
407#  Default graphics (none) requires linking with all the default (null) AST
408#  "grf3d" modules.
409      *) args="${args} -last_grf3d";;
410      esac
411
412
413
414#  Make a second pass through the AST library.
415#  -------------------------------------------
416#  This library is a link to the main AST library and results in a second
417#  pass to resolve any backward references generated by the other modules
418#  used above. A different library name must be used to avoid the two passes
419#  being merged into one (either below, or by other link scripts).
420      args="${args} -last_pass2"
421
422#  Generate arguments for linking the error reporting system.
423#  ----------------------------------------------------------
424      case "${err}" in
425
426#  If using EMS, link with the AST EMS interface and the EMS library via the
427#  link script (if found).
428      ems) args="${args} -last_ems `\`find ems_link\``";;
429
430#  If using DRAMA, link with the AST DRAMA interface and the DRAMA Ers library
431#  via the link script (if found).
432      drama) args="${args} -last_drama -lers";;
433
434#  If using own error reporting, do not produce any arguments.
435      my) :;;
436
437#  Default error reporting requires linking with the default AST "err" module.
438      *) args="${args} -last_err";;
439      esac
440
441#  Link with the maths library.
442#  ----------------------------
443      args="${args} -lm"
444
445#  Link with the starmem library, if available.
446#  --------------------------------------------
447      args="${args} `\`find starmem_link\``"
448
449#  Resolve Fortran 77 references.
450#  ------------------------------
451#  If libraries written in Fortran are being linked against, then include
452#  additional libaries needed to resolve the references these will produce
453#  (in the event that the main program is not Fortran).
454      if test "${f77}" = 'y'; then args="${args} ${flibs}"; fi
455
456#  Pass the resulting argument list through an awk script which eliminates
457#  all except the last reference to each library.
458      echo "${args}" \
459           | awk 'BEGIN{RS=" ";FS="\n"}
460                  {if($1)f[i++]=$1}
461                  END{for(;i--;)if(!w[f[i]]++)l=f[i]" "l;print l}'
462
463#  End of script.
464