removed trailing whitespace
[platform/upstream/curl.git] / packages / vms / build_vms.com
1 $! $Id$
2 $! BUILD_VMS.COM
3 $!
4 $! I've taken the original build_vms.com, supplied by Nico Baggus, if
5 $! memory serves me correctly, and made some modifications.
6 $!
7 $! SSL support is controlled by logical names.  If SSL$INCLUDE is
8 $! defined, then it is assumed that HP's SSL product has been installed.
9 $! If OPENSSL is defined, but SSL$INCLUDE is not, then OpenSSL will be
10 $! used.  If neither logical name is defined, then SSL support will not
11 $! be compiled/linked in.  Command-line options NOHPSSL and NOSSL can be
12 $! specified to override the automatic SSL selection.
13 $!
14 $! Command-line Options:
15 $!
16 $!    CLEAN     Delete product files for this host architecture.  (No
17 $!              build done.)
18 $!    CLEAN_ALL Delete product files for all host architectures.  (No
19 $!              build done.)
20 $!
21 $!    64        Compile with 64-bit pointers.
22 $!    CCQUAL=x  Add "x" to the C compiler qualifiers.
23 $!    DEBUG     Compile and link with debug.
24 $!    IEEE      Use IEEE floating point.  (Alpha.)
25 $!    LARGE     Enable large-file support.  (Non-VAX, VMS >= V7.2.)
26 $!    LDAP      Enable LDAP support.
27 $!    LIST      Create C compiler listings and linker maps.
28 $!    NOHPSSL   Don't use HP SSL, even if available.
29 $!    NOSSL     Don't use any SSL, even if available.
30 $!    OSSLOLB   Use OpenSSL object libraries (.OLB), even if shared
31 $!              images (.EXE) are available.
32 $!
33 $! DCL Symbols:
34 $!
35 $!    CURL_CCDEFS="c_macro_1=value1 [, c_macro_2=value2 [...]]"
36 $!              Compile with these additional C macros defined.
37 $!
38 $! Revisions:
39 $!
40 $!  2-DEC-2003, MSK, the "original" version.
41 $!                   It works for me.  Your mileage may vary.
42 $! 13-JAN-2004, MSK, moved this procedure to the [.packages.vms] directory
43 $!                   and updated it to do hardware dependent builds.
44 $! 29-JAN-2004, MSK, moved logical defines into defines.com
45 $!  6-FEB-2004, MSK, put in various SSL support bits
46 $!  9-MAR-2004, MSK, the config-vms.h* files are now copied to the lib and
47 $!                   src directories as curl_config.h.
48 $! 15-MAR-2004, MSK, All of the curlmsg*.* files have also been moved to
49 $!                   this build directory.  They will be copied to the src
50 $!                   directory before build.  The .msg file will be compiled
51 $!                   to get the .obj for messages, but the .h and .sdl files
52 $!                   are not automatically created since they partly rely on
53 $!                   the freeware SDL tool.
54 $!  8-FEB-2005, MSK, merged the two config-vms.h* files into one that uses
55 $!                   USE_SSLEAY to define if the target has SSL support built
56 $!                   in.  Changed the cc/define parameter accordingly.
57 $! 11-FEB-2005, MSK, If [--.LIB]AMIGAOS.C and NWLIB.C are there, rename them
58 $! 23-MAR-2005, MSK, relocated cc_qual define so that DEBUG option would work
59 $! 25-APR-2007, STL, allow compilation in 64-bit mode.
60 $! 13-DEC-2009. SMS, Changed to skip unwanted source files without
61 $!                   renaming the original files.
62 $!                   Eliminated needless, persistent logical names.
63 $!                   Added CURL_CCDEFS DCL symbol for user-specified C
64 $!                   macro definitions.
65 $!                   Added CLEAN and CLEAN_ALL options.
66 $!                   Added CCQUAL option for user-specified C compiler
67 $!                   qualifiers.
68 $!                   Added IEEE option for IEEE floating point (Alpha).
69 $!                   Added LARGE option for large-file support.
70 $!                   Added OSSLOLB option, and support for OpenSSL
71 $!                   shared images.
72 $!                   Changed to put listing and map files into lisdir:.
73 $!                   Changed to avoid case confusion on ODS5 disks.
74 $!                   Added more default dev:[dir] save+restore.
75 $!                   Moved remaining "defines.com" code (back) into
76 $!                   here, eliminating the hard-coded OpenSSL nonsense.
77 $!                   Changed to use F$GETSYI( "ARCH_NAME") (or
78 $!                   equivalent) to name architecture-specific product
79 $!                   file destination directory, and to create the
80 $!                   directory if needed (obviating inclusion of these
81 $!                   directories and dummy files in the distribution
82 $!                   kit).
83 $!                   Changed the "compile" subroutine to break the CC
84 $!                   command across multiple lines to avoid DCL
85 $!                   line-too-long problems.
86 $!                   Changed "vo_c" messages to show the CC qualifiers
87 $!                   once, not with every compile command.
88 $!
89 $!
90 $! Save the original default dev:[dir], and arrange for its restoration
91 $! at exit.
92 $!
93 $ curl = ""
94 $ orig_def = f$environment( "DEFAULT")
95 $ on error then goto Common_Exit
96 $ on control_y then goto Common_Exit
97 $!
98 $ ctrl_y  = 1556
99 $ proc = f$environment( "PROCEDURE")
100 $ proc_dev_dir = -
101    f$parse( proc, , , "DEVICE")+ f$parse( proc, , , "DIRECTORY")
102 $!
103 $! Verbose output message stuff.  Define symbol to "write sys$output" or "!".
104 $! vo_c - verbose output for compile
105 $! vo_l - link
106 $! vo_o - object check
107 $!
108 $ vo_c = "write sys$output"
109 $ vo_l = "write sys$output"
110 $ vo_o = "!"
111 $!
112 $! Determine the main distribution directory ("[--]") in an
113 $! ODS5-tolerant (case-insensitive) way.  (We do assume that the only
114 $! "]" is the one at the end.)
115 $!
116 $ set default 'proc_dev_dir'
117 $ set default [--]
118 $ top_dev_dir = f$environment( "DEFAULT")- "]"
119 $!
120 $! Define the architecture-specific product file destination directory
121 $! name(s).
122 $!
123 $ if (f$getsyi( "HW_MODEL") .lt. 1024)
124 $ then
125 $    arch_name = "VAX"
126 $ else
127 $    arch_name = ""
128 $    arch_name = arch_name+ f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
129 $    if (arch_name .eqs. "") then arch_name = "UNK"
130 $ endif
131 $!
132 $ exedir = proc_dev_dir- "]"+ ".''arch_name']"
133 $ lisdir = exedir
134 $ objdir = exedir
135 $!
136 $! Interpret command-line options.
137 $!
138 $ hpssl = 0
139 $ ldap = 0
140 $ list = 0
141 $ nohpssl = 0
142 $ nossl = 0
143 $ openssl = 0
144 $ osslolb = 0
145 $ cc_qual1 = ""
146 $ cc_qual2 = ""
147 $ cc_defs = "HAVE_CONFIG_H=1"
148 $ if (f$type( CURL_CCDEFS) .nes. "")
149 $ then
150 $    CURL_CCDEFS = f$edit( CURL_CCDEFS, "TRIM")
151 $    cc_defs = cc_defs+ ", "+ CURL_CCDEFS
152 $ endif
153 $ link_qual = ""
154 $ msg_qual = "/object = ''objdir'"
155 $ ssl_opt = ""
156 $!
157 $ arg = 1
158 $arg_loop:
159 $    p = "p''arg'"
160 $    arg_val = 'p'
161 $    if (arg_val .eqs. "") then goto arg_loop_out
162 $    arg_val = f$edit( arg_val, "upcase")
163 $!
164 $    if (arg_val .eqs. "CLEAN")
165 $    then
166 $       prods = "''exedir'*.*;*"
167 $       if (f$search( prods) .nes. "") then delete /log 'prods'
168 $       prods = proc_dev_dir+ arch_name+ ".DIR;1"
169 $       if (f$search( prods) .nes. "") then delete /log 'prods'
170 $       goto Common_Exit
171 $    endif
172 $!
173 $    if (arg_val .eqs. "CLEAN_ALL")
174 $    then
175 $       prods = proc_dev_dir- "]"+ ".ALPHA]*.*;*"
176 $       if (f$search( prods) .nes. "") then delete /log 'prods'
177 $       prods = proc_dev_dir+ "ALPHA"+ ".DIR;1"
178 $       if (f$search( prods) .nes. "") then delete /log 'prods'
179 $       prods = proc_dev_dir- "]"+ ".IA64]*.*;*"
180 $       if (f$search( prods) .nes. "") then delete /log 'prods'
181 $       prods = proc_dev_dir+ "IA64"+ ".DIR;1"
182 $       if (f$search( prods) .nes. "") then delete /log 'prods'
183 $       prods = proc_dev_dir- "]"+ ".VAX]*.*;*"
184 $       if (f$search( prods) .nes. "") then delete /log 'prods'
185 $       prods = proc_dev_dir+ "VAX"+ ".DIR;1"
186 $       if (f$search( prods) .nes. "") then delete /log 'prods'
187 $       goto Common_Exit
188 $    endif
189 $!
190 $    if (arg_val .eqs. "64")
191 $    then
192 $       cc_qual1 = cc_qual1+ " /POINTER = 64"
193 $       goto arg_loop_end
194 $    endif
195 $!
196 $    if (f$extract( 0, 6, arg_val) .eqs. "CCQUAL")
197 $    then
198 $       opts = f$edit( arg_val, "COLLAPSE")
199 $       eq = f$locate( "=", opts)
200 $       cc_qual2 = f$extract( (eq+ 1), 1000, opts)
201 $       goto arg_loop_end
202 $    endif
203 $!
204 $    if (arg_val .eqs. "DEBUG")
205 $    then
206 $       cc_qual1 = cc_qual1+ " /debug /nooptimize"
207 $       link_qual = link_qual+ " /debug"
208 $       goto arg_loop_end
209 $    endif
210 $!
211 $    if (arg_val .eqs. "IEEE")
212 $    then
213 $       cc_qual1 = cc_qual1+ " /FLOAT = IEEE_FLOAT"
214 $       goto arg_loop_end
215 $    endif
216 $!
217 $    if (arg_val .eqs. "LARGE")
218 $    then
219 $       if (arch_name .eqs. "VAX")
220 $       then
221 $          write sys$output """LARGE"" is ignored on VAX."
222 $       else
223 $          cc_defs = cc_defs+ ", _LARGEFILE=1"
224 $       endif
225 $       goto arg_loop_end
226 $    endif
227 $!
228 $    if (arg_val .eqs. "LDAP")
229 $    then
230 $       ldap = 1
231 $       goto arg_loop_end
232 $    endif
233 $!
234 $    if (f$extract( 0, 4, arg_val) .eqs. "LIST")
235 $    then
236 $       list = 1
237 $       cc_qual1 = cc_qual1+ " /list = ''lisdir' /show = (all, nomessages)"
238 $       link_qual = link_qual+ " /map = ''lisdir'"
239 $       msg_qual = msg_qual+ " /list = ''lisdir'"
240 $       goto arg_loop_end
241 $    endif
242 $!
243 $    if (arg_val .eqs. "NOHPSSL")
244 $    then
245 $       nohpssl = 1
246 $       goto arg_loop_end
247 $    endif
248 $!
249 $    if (arg_val .eqs. "NOSSL")
250 $    then
251 $       nossl = 1
252 $       goto arg_loop_end
253 $    endif
254 $!
255 $    if (arg_val .eqs. "OSSLOLB")
256 $    then
257 $       osslolb = 1
258 $       goto arg_loop_end
259 $    endif
260 $!
261 $    write sys$output "Unrecognized command-line option: ''arg_val'"
262 $    goto Common_Exit
263 $!
264 $arg_loop_end:
265 $ arg = arg+ 1
266 $ goto arg_loop
267 $arg_loop_out:
268 $!
269 $! CC /LIST, LINK /MAP, and MESSAGE /LIST are defaults in batch mode,
270 $! so be explicit when they're not desired.
271 $!
272 $ if (list .eq. 0)
273 $ then
274 $    cc_qual1 = cc_qual1+ " /nolist"
275 $    link_qual = link_qual+ " /nomap"
276 $    msg_qual = msg_qual+ " /nolist"
277 $ endif
278 $!
279 $! Create product directory, if needed.
280 $!
281 $ if (f$search( proc_dev_dir+ arch_name+ ".DIR;1") .eqs. "")
282 $ then
283 $    create /directory 'exedir'
284 $ endif
285 $!
286 $! Detect available (but not prohibited) SSL software.
287 $!
288 $ if (.not. nossl)
289 $ then
290 $    if (f$trnlnm( "OPENSSL") .nes. "")
291 $    then
292 $       cc_defs = cc_defs+ ", USE_SSLEAY=1"
293 $       if ((f$trnlnm( "SSL$INCLUDE") .nes. "") .and. (.not. nohpssl))
294 $       then
295 $!         Use HP SSL.
296 $          hpssl = 1
297 $          ssl_opt = ", ''proc_dev_dir'hpssl_"+ -
298             f$getsyi("ARCH_NAME")+ ".opt /options"
299 $       else
300 $!         Use OpenSSL.  Assume object libraries, unless shared images
301 $!         are found (and not prohibited).
302 $          openssl = 1
303 $          ssl_opt = ", ssllib:libssl.olb /library"+ -
304             ", ssllib:libcrypto.olb /library"
305 $          if (osslolb .eq. 0)
306 $          then
307               if ((f$search( "ssllib:ssl_libcrypto.exe") .nes. "") .and. -
308                (f$search( "ssllib:ssl_libssl.exe") .nes. ""))
309 $             then
310 $!               OpenSSL shared images with "SSL_xxx.EXE names.
311 $                openssl = 2
312 $                ssl_opt = ", ''proc_dev_dir'openssl_ssl_"+ -
313                   f$getsyi("ARCH_NAME")+ ".opt /options"
314 $             else
315 $                if ((f$search( "ssllib:libcrypto.exe") .nes. "") .and. -
316                   (f$search( "ssllib:libssl.exe") .nes. ""))
317 $                then
318 $!                  OpenSSL shared images with "xxx.EXE names.
319 $                   openssl = 3
320 $                   ssl_opt = ", ''proc_dev_dir'openssl_"+ -
321                      f$getsyi("ARCH_NAME")+ ".opt /options"
322 $                endif
323 $             endif
324 $          endif
325 $       endif
326 $    endif
327 $ endif
328 $!
329 $! LDAP.
330 $!
331 $ if (ldap .eq. 0)
332 $ then
333 $    cc_defs = cc_defs+ ", CURL_DISABLE_LDAP=1"
334 $ endif
335 $!
336 $! Form CC qualifiers.
337 $!
338 $ cc_defs = "/define = (''cc_defs')"
339 $ cc_qual2 = cc_qual2+ " /object = ''objdir'"+ -
340    " /include = ([-.lib], [-.src],"+ -
341    " [-.packages.vms], [-.packages.vms.''arch_name'])"
342 $!
343 $ 'vo_c' "CC opts:", -
344   " ''cc_defs'", -
345   " ''cc_qual1'", -
346   " ''cc_qual2'"
347 $!
348 $! Inform the victim of our plans.
349 $!
350 $ if (hpssl)
351 $ then
352 $    'vo_c' "%CURL-I-BLDHPSSL, building with HP SSL support"
353 $ else
354 $    if (openssl .ne. 0)
355 $    then
356 $       if (openssl .eq. 1)
357 $       then
358 $          'vo_c' -
359  "%CURL-I-BLDOSSL_OLB, building with OpenSSL (object library) support"
360 $       else
361 $          'vo_c' -
362  "%CURL-I-BLDOSSL_EXE, building with OpenSSL (shared image) support"
363 $       endif
364 $    else
365 $       'vo_c' "%CURL-I-BLDNOSSL, building with NO SSL support"
366 $    endif
367 $ endif
368 $!
369 $! Announce destination and SSL directories.
370 $!
371 $ 'vo_c' "   OBJDIR = ''objdir'"
372 $ 'vo_c' "   EXEDIR = ''exedir'"
373 $!
374 $ if (openssl .ne. 0)
375 $ then
376 $    ssllib = f$trnlnm( "ssllib")
377 $    if (ssllib .eqs. "")
378 $    then
379 $        ssllib = "(undefined)"
380 $    endif
381 $    'vo_c' "   SSLLIB = ''ssllib'"
382 $!
383 $    if (openssl .eq. 1)
384 $    then
385 $       ossl_lib1 = f$trnlnm( "ssllib")+ "LIBSSL.OLB"
386 $       ossl_lib2 = f$trnlnm( "ssllib")+ "LIBCRYPTO.OLB"
387 $       msg = "object libraries"
388 $    else
389 $       if (openssl .eq. 2)
390 $       then
391 $          ossl_lib1 = f$trnlnm( "ssllib")+ "SSL_LIBSSL.EXE"
392 $          ossl_lib2 = f$trnlnm( "ssllib")+ "SSL_LIBCRYPTO.EXE"
393 $       else
394 $          ossl_lib1 = f$trnlnm( "ssllib")+ "LIBSSL.EXE"
395 $          ossl_lib2 = f$trnlnm( "ssllib")+ "LIBCRYPTO.EXE"
396 $       endif
397 $       msg = "shared images"
398 $    endif
399 $    if ((f$search( ossl_lib1) .eqs. "") .or. -
400       (f$search( ossl_lib2) .eqs. ""))
401 $    then
402 $       write sys$output "Can't find OpenSSL ''msg':"
403 $       write sys$output "   ''ossl_lib1'"
404 $       write sys$output "   ''ossl_lib2'"
405 $       goto Common_Exit
406 $    endif
407 $ endif
408 $!
409 $! Define the "curl" (process) logical name for "#include <curl/xxx.h>".
410 $!
411 $ curl = f$trnlnm( "curl", "LNM$PROCESS")
412 $ if (curl .nes. "")
413 $ then
414 $    write sys$output ""
415 $    write sys$output -
416  "Process logical name ""curl"" is already defined, but this procedure"
417 $    write sys$output -
418  "would override that definition.  Use a command like"
419 $    write sys$output -
420  "      deassign /process curl"
421 $    write sys$output -
422  "to cancel that logical name definition, and then and re-run this procedure."
423 $    write sys$output ""
424 $    goto Common_Exit
425 $ endif
426 $ define curl 'top_dev_dir'.include.curl]
427 $!
428 $! Copy the VMS-specific config file into the product directory.
429 $!
430 $ call MoveIfDiff 'proc_dev_dir'config-vms.h 'objdir'curl_config.h
431 $!
432 $ on control_y then goto Common_Exit
433 $!
434 $ set default 'proc_dev_dir'
435 $ call build "[--.lib]" "*.c" "''objdir'CURLLIB.OLB" "amigaos, nwlib, nwos"
436 $ if ($status .eq. ctrl_y) then goto Common_Exit
437 $ call build "[--.src]" "*.c" "''objdir'CURLSRC.OLB"
438 $ if ($status .eq. ctrl_y) then goto Common_Exit
439 $ call build "[]" "*.msg" "''objdir'CURLSRC.OLB"
440 $ if ($status .eq. ctrl_y) then goto Common_Exit
441 $!
442 $ ldap_opt = ""
443 $ if (ldap .ne. 0) then ldap_opt = ", ''proc_dev_dir'ldap.opt /options"
444 $!
445 $ if (openssl .ne. 0)
446 $ then
447 $    if (openssl .eq. 1)
448 $    then
449 $       'vo_l' "%CURL-I-LINK_OSSL, linking with OpenSSL (object library)"
450 $    else
451 $       'vo_l' "%CURL-I-LINK_HPSSL, linking with OpenSSL (shared image)"
452 $    endif
453 $ else
454 $    if (hpssl)
455 $    then
456 $       'vo_l' "%CURL-I-LINK_HPSSL, linking with HP SSL"
457 $    else
458 $       'vo_l' "%CURL-I-LINK_NOSSL, linking with NO SSL support"
459 $    endif
460 $ endif
461 $!
462 $ link 'link_qual' /executable = 'exedir'CURL.EXE -
463    'objdir'curlsrc.olb /library /include = (main, curlmsg), -
464    'objdir'curllib.olb /library -
465    'ssl_opt' -
466    'ldap_opt'
467 $!
468 $ goto Common_Exit
469 $!
470 $! Subroutine to build everything with a filetype passed in via P2 in
471 $! the directory passed in via P1 and put it in the object library named
472 $! via P3.  Exclude items in P4.
473 $!
474 $build:   subroutine
475 $    build_def = f$environment( "default")
476 $    on control_y then goto EndLoop ! SS$_CONTROLY
477 $    sts = 1 ! SS$_NORMAL.
478 $!    set noon
479 $    set default 'p1'
480 $    search = p2
481 $    reset = f$search("reset")
482 $    if f$search( p3) .eqs. ""
483 $    then
484 $       librarian /create /object 'p3'
485 $    endif
486 $    reject_list__ = ","+ f$edit( p4, "COLLAPSE, UPCASE")+ ","
487 $    reject_list___len = f$length( reject_list__)
488 $    reset = f$search( "reset", 1)
489 $Loop:
490 $    file = f$search( search, 1)
491 $    if file .eqs. "" then goto EndLoop
492 $!      Skip a name if it's in the P4 exclusion list.
493 $       if (p4 .nes. "")
494 $       then
495 $          name__ = ","+ -
496             f$edit( f$parse( file, , , "NAME", "SYNTAX_ONLY"), "UPCASE")+ -
497             ","
498 $          if (f$locate( name__, reject_list__) .lt. reject_list___len)
499 $          then
500 $             goto Loop
501 $          endif
502 $       endif
503 $       objfile = f$parse( "''objdir'.OBJ;", file)
504 $       obj = f$search( objfile, 2)
505 $       if (obj .nes. "")
506 $       then
507 $          if (f$cvtime(f$file(file,"rdt")) .gts. f$cvtime(f$file(obj,"rdt")))
508 $          then
509 $             call compile 'file'
510 $             sts = $status
511 $             if .not. sts
512 $             then
513 $                goto EndLoop
514 $             endif
515 $             librarian /object 'p3' 'objfile'
516 $          else
517 $             'vo_o' "%CURL-I-OBJUTD, ", objfile, " is up to date"
518 $          endif
519 $       else
520 $          'vo_o' "%CURL-I-OBJDNE, ", file, " does not exist"
521 $          call compile 'file'
522 $          sts = $status
523 $          if .not. sts
524 $          then
525 $             goto EndLoop
526 $          endif
527 $          librarian /object 'p3' 'objfile'
528 $       endif
529 $    goto Loop
530 $EndLoop:
531 $!!!    purge
532 $    set default 'build_def'
533 $    exit 'sts'
534 $ endsubroutine   ! Build
535 $!
536 $! Based on the file TYPE, do the right compile command.
537 $! Only C and MSG supported.
538 $!
539 $compile:   subroutine
540 $    on control_y then return ctrl_y ! SS$_CONTROLY
541 $!    set noon
542 $    file = p1
543 $    qual = p2+ p3+ p4+ p5+ p6+ p7+ p8
544 $    typ = f$edit( f$parse( file, , , "TYPE"), "UPCASE") - "."
545 $    if (typ .eqs. "C")
546 $    then
547 $       'vo_c' "CC (opts) ", file
548 $       CC 'cc_defs' -
549          'cc_qual1' -
550          'cc_qual2' -
551          'file'
552 $    else
553 $       cmd_msg = "MESSAGE "+ msg_qual
554 $       x = cmd_'typ'
555 $       'vo_c' x," ",file
556 $       'x' 'file'
557 $    endif
558 $ ENDSUBROUTINE   ! Compile
559 $!
560 $! Do a diff of the file specified in P1 with that in P2.  If different
561 $! copy P1 to P2.  This also covers if P2 doesn't exist, but not if P2
562 $! is an invalid filespec.
563 $!
564 $MoveIfDiff:  subroutine
565 $    set NoOn
566 $    define /user_mode sys$error nl:
567 $    define /user_mode sys$output nl:
568 $    differences 'p1' 'p2'
569 $    status = $status
570 $    if ( status .ne. %X006C8009) ! if status is not "no diff"
571 $    then
572 $       copy 'p1' 'p2'
573 $       purge /nolog 'p2'
574 $    endif
575 $    on control_y then return ctrl_y ! SS$_CONTROLY
576 $ ENDSUBROUTINE   ! MoveIfDiff
577 $!
578 $Common_Exit:
579 $ set default 'orig_def'
580 $ if ((curl .eqs. "") .and. (f$trnlnm( "curl", "LNM$PROCESS") .nes. ""))
581 $ then
582 $    deassign curl
583 $ endif
584 $ exit