1$! vmsbuild.com -- DCL procedure to build unixODBC on OpenVMS
2$!
3$ say := "write sys$OUTPUT"
4$ whoami = f$parse(f$environment("PROCEDURE"),,,,"NO_CONCEAL")
5$ cwd = f$parse(whoami,,,"DEVICE") + f$parse(whoami,,,"DIRECTORY") - ".][000000]" - "][" - ".]" - "]" + "]"
6$ set default 'cwd'
7$!
8$ basedir = cwd - "]"
9$ define/translation=concealed ODBCSRC "''basedir'.]"
10$!
11$ if p1 .eqs. "" then $goto ERR_NOPARAMS
12$!
13$ includes = "ODBCSRC:[include],ODBCSRC:[extras],""/ODBCSRC/libltdl"""
14$! /first_include requires CC 6.4 or later but avoids impossibly long /define qualifier
15$ CFLAGS="/names=as_is/prefix=all/include=(" + includes + ")/first_include=(ODBCSRC:[include]vmsconfig.h)
16$ LFLAGS="/nodebug/notrace"
17$!
18$ if p2 .eqs. "DEBUG"
19$ then
20$     CFLAGS = CFLAGS + "/noopt/debug"
21$     LFLAGS = LFLAGS + "/debug/trace"
22$ endif
23$!
24$ if p1 .eqs. "CLEAN"
25$ then
26$   set default 'cwd'
27$   d = f$parse(whoami,,,"DEVICE") + f$parse(whoami,,,"DIRECTORY") - ".][000000]" - "][" - ".]" - "]" + "]"
28$   say "Removing all object files and listings"
29$   delete/noconfirm [...]*.obj;*, *.lis;*
30$   say "Removing all object libraries and linker maps"
31$   delete/noconfirm [...]*.olb;*, *.map;*
32$   goto all_done
33$ endif
34$!
35$ if p1 .eqs. "COMPILE" .or. p1 .eqs. "ALL"
36$ then
37$   say "Compiling unixODBC"
38$   if f$search("ODBCSRC:[vms]libodbcinst.olb") .eqs. "" then library/create ODBCSRC:[vms]libodbcinst.olb
39$   if f$search("ODBCSRC:[vms]libodbc.olb") .eqs. "" then library/create ODBCSRC:[vms]libodbc.olb
40$   if f$search("ODBCSRC:[vms]libodbcpsql.olb") .eqs. "" then library/create ODBCSRC:[vms]libodbcpsql.olb
41$   call create_vmsconfig_h
42$   call compile "ODBCSRC:[extras]" "*.c" "ODBCSRC:[vms]libodbcinst.olb" "ODBCSRC:[vms]libodbc.olb"
43$   call compile "ODBCSRC:[ini]" "*.c" "ODBCSRC:[vms]libodbcinst.olb" "ODBCSRC:[vms]libodbc.olb"
44$   call compile "ODBCSRC:[log]" "*.c" "ODBCSRC:[vms]libodbcinst.olb"
45$   call compile "ODBCSRC:[lst]" "*.c" "ODBCSRC:[vms]libodbcinst.olb" "ODBCSRC:[vms]libodbc.olb"
46$   call compile "ODBCSRC:[odbcinst]" "*.c" "ODBCSRC:[vms]libodbcinst.olb"
47$   call compile "ODBCSRC:[drivermanager]" "*.c" "ODBCSRC:[vms]libodbc.olb"
48$   call compile "ODBCSRC:[exe]" "*.c"
49$   if f$getdvi("ODBCSRC:", "ACPTYPE") .eqs. "F11V5"
50$   then
51$       set process/parse=extended
52$       call compile "ODBCSRC:[Drivers.Postgre7^.1]" "*.c" "ODBCSRC:[vms]libodbcpsql.olb"
53$   else
54$       call compile "ODBCSRC:[Drivers.Postgre7_1]" "*.c" "ODBCSRC:[vms]libodbcpsql.olb"
55$   endif
56$   set default 'cwd'
57$!
58$ endif
59$!
60$ if f$trnlnm("ODBC_LIBDIR").eqs.""
61$ then
62$     if f$search("ODBCSRC:[000000]odbclib.dir") .eqs. ""
63$     then
64$       create/directory/log ODBCSRC:[odbclib]
65$     endif
66$     libdir = f$parse("ODBCSRC:[odbclib]",,,,"NO_CONCEAL")  -".][000000"-"]["-"].;"+"]"
67$     define/process ODBC_LIBDIR 'libdir'
68$     say "Defining ODBC_LIBDIR as """ + f$trnlnm("ODBC_LIBDIR") + """
69$ else
70$     if f$search("ODBC_LIBDIR") .eqs. ""
71$     then
72$       create/directory/log ODBC_LIBDIR
73$     endif
74$ endif
75$!
76$! Build Shared objects
77$!
78$ if p1 .eqs. "LINK" .or. p1 .eqs. "ALL"
79$ then
80$   set default ODBCSRC:[vms]
81$!
82$   say "Linking libodbcinst.exe"
83$   link 'LFLAGS' libodbcinst.olb/library,odbcinst_axp.opt/opt/share=libodbcinst.exe
84$!
85$   say "Linking libodbc.exe"
86$   link 'LFLAGS' libodbc.olb/library,odbc_axp.opt/opt/share=libodbc.exe
87$!
88$!  The following kludge brought to you by the fact that on ODS-5 disks the C compiler
89$!  may create module names in upper or mixed case depending on how the archive was
90$!  unpacked.  Try lower case and if it's not there, assume uppper case.
91$!
92$   module = "psqlodbc"
93$   module_exists == 0
94$   call check_module "''module'" "libodbcpsql.olb"
95$   if .not. module_exists then module = f$edit(module,"UPCASE")
96$!
97$   say "Linking libodbcpsql.exe"
98$   link 'LFLAGS' libodbcpsql.olb/library/include="''module'",odbc2_axp.opt/opt/share=libodbcpsql.exe
99$!
100$   set default ODBCSRC:[exe]
101$   say "Linking isql.exe, dltest.exe and odbc-config.exe"
102$   link 'LFLAGS' isql.OBJ,SYS$INPUT/OPT
103ODBCSRC:[vms]libodbc.exe/SHARE
104$ eod
105$!
106$   link 'LFLAGS' dltest.OBJ,ODBCSRC:[vms]libodbcinst.olb/library
107$   link 'LFLAGS' odbc-config.OBJ
108$ endif
109$!
110$ if p1 .eqs. "INSTALL" .or. p1 .eqs. "ALL"
111$ then
112$!
113$   copy/log ODBCSRC:[vms]libodbc*.exe ODBC_LIBDIR:
114$   copy/log ODBCSRC:[vms]odbc_setup.com ODBC_LIBDIR:
115$   copy/log ODBCSRC:[exe]isql.exe ODBC_LIBDIR:
116$   copy/log ODBCSRC:[exe]dltest.exe ODBC_LIBDIR:
117$   copy/log ODBCSRC:[exe]odbc-config.exe ODBC_LIBDIR:
118$!
119$! check for odbc.ini and odbcinst.ini in ODBC_LIBDIR
120$!
121$   file = f$search ("ODBC_LIBDIR:odbc.ini")
122$   if file .eqs. ""
123$   then
124$     say "Creating ODBC_LIBDIR:odbc.ini"
125$     create ODBC_LIBDIR:odbc.ini
126
127$   endif
128$!
129$   file = f$search ("ODBC_LIBDIR:odbcinst.ini")
130$   if file .eqs. ""
131$   then
132$     say "Creating ODBC_LIBDIR:odbcinst.ini"
133$     create ODBC_LIBDIR:odbcinst.ini
134
135$   endif
136$!
137$   set file ODBC_LIBDIR:*.*/protection=(w:re)
138$ endif
139$!
140$ all_done:
141$ set default 'cwd'
142$ exit (1)
143$!
144$ ERR_NOPARAMS:
145$ say " "
146$ say "The correct calling sequence is: "
147$ say " "
148$ say "$ @vmsbuild p1 [p2]
149$ say " "
150$ say "Where p1 is : "
151$ say " "
152$ say "    ALL      : COMPILE LINK, and INSTALL steps."
153$ say "    CLEAN    : Remove all objects and object libraries."
154$ say "    COMPILE  : Compile all source and produce object libraries"
155$ say "    LINK     : Create shareable images"
156$ say "    INSTALL  : Copy shareable images to ODBC_LIBDIR:"
157$ say " "
158$ say "and DEBUG may optionally be specified for p2 when p1 is COMPILE, LINK, or ALL"
159$ say " "
160$ exit 44
161$!
162$! compile subroutine will compile all p2 source files
163$! and place the resulting object files in libraries
164$! specified as p3 and/or p4
165$!
166$ compile : subroutine
167$ set default 'p1'
168$ loop:
169$   file = f$search ("''p2'",1)
170$   if file .eqs. "" then goto complete
171$   filename = f$parse (file,,,"name")
172$   if f$edit(filename,"UPCASE") .eqs. "INIOS2PROFILE" then goto loop
173$   object = F$SEARCH ("''filename'.OBJ;*",2)
174$   if object .eqs. ""
175$   then
176$      say "cc" + CFLAGS + " ''filename'.c"
177$      on warning then continue
178$      cc 'CFLAGS' 'filename'
179$!     keep module names upper case to avoid insanity on ODS-5 volumes
180$      if p3 .nes. "" then library/replace/log 'p3' 'f$edit(filename,"UPCASE")'
181$      if p4 .nes. "" then library/replace/log 'p4' 'f$edit(filename,"UPCASE")'
182$   endif
183$   goto loop
184$ complete:
185$ set default 'cwd'
186$ exit
187$ endsubroutine ! compile
188$
189$!
190$ create_vmsconfig_h : subroutine
191$!
192$ SEARCH/KEY=(POS:2,SIZE:8) ODBCSRC:[000000]CONFIGURE. "VERSION="/EXACT/OUTPUT=version.tmp
193$ open/read version version.tmp
194$ read version versionline
195$ close version
196$ delete/noconfirm/nolog version.tmp;*
197$ versionstring = f$element(1, "=", f$edit(versionline, "COLLAPSE"))
198$!
199$ if f$search("ODBCSRC:[include]vmsconfig.h") .nes. "" then delete/noconfirm/nolog ODBCSRC:[include]vmsconfig.h;*
200$ open/write vmsconfig ODBCSRC:[include]vmsconfig.h
201$ write vmsconfig "/* auto-generated definitions for VMS port */
202$ write vmsconfig "#define UNIXODBC"
203$ write vmsconfig "#define HAVE_PWD_H 1"
204$ write vmsconfig "#if __VMS_VER >= 70000000"
205$ write vmsconfig "#define HAVE_STRCASECMP"
206$ write vmsconfig "#define HAVE_STRNCASECMP"
207$ write vmsconfig "#define HAVE_STDARG_H"
208$ write vmsconfig "#define HAVE_STDLIB_H"
209$ write vmsconfig "#define HAVE_STRING_H"
210$ write vmsconfig "#define HAVE_STRINGS_H"
211$ write vmsconfig "#define HAVE_DTIME"
212$ write vmsconfig "#define HAVE_SYS_TIME_H"
213$ write vmsconfig "#define HAVE_GETTIMEOFDAY"
214$ write vmsconfig "#define HAVE_UNISTD_H"
215$ write vmsconfig "#endif"
216$ write vmsconfig "#define SIZEOF_LONG_INT 4"
217$ write vmsconfig "#define UNIXODBC_SOURCE"
218$ write vmsconfig "#define readonly __readonly"
219$ write vmsconfig "#define DEFLIB_PATH ""ODBC_LIBDIR:[LIB]"""
220$ write vmsconfig "#define SYSTEM_LIB_PATH ""ODBC_LIBDIR:[LIB]"""
221$ write vmsconfig "#define SHLIBEXT "".exe"""
222$ write vmsconfig "#define VERSION ""''versionstring'"""
223$ write vmsconfig "#define PREFIX ""ODBC_LIBDIR:"""
224$ write vmsconfig "#define EXEC_PREFIX ""ODBC_LIBDIR:[BIN]"""
225$ write vmsconfig "#define BIN_PREFIX ""ODBC_LIBDIR:[BIN]"""
226$ write vmsconfig "#define INCLUDE_PREFIX ""ODBC_LIBDIR:[INCLUDE]"""
227$ write vmsconfig "#define LIB_PREFIX ""ODBC_LIBDIR:[ETC]"""
228$ write vmsconfig "#define SYSTEM_FILE_PATH ""ODBC_LIBDIR:[ETC]"""
229$ write vmsconfig "char* getvmsenv (char* symbol);"
230$ close vmsconfig
231$!
232$ if f$search("ODBCSRC:[include]unixodbc_conf.h") .nes. "" then delete/noconfirm/nolog ODBCSRC:[include]unixodbc_conf.h;*
233$ open/write unixodbcconfig ODBCSRC:[include]unixodbc_conf.h
234$ write unixodbcconfig "/* auto-generated definitions for VMS port */
235$ write unixodbcconfig "#ifndef HAVE_PWD_H"
236$ write unixodbcconfig " #define HAVE_PWD_H"
237$ write unixodbcconfig "#endif"
238$ write unixodbcconfig "#ifndef SIZEOF_LONG_INT"
239$ write unixodbcconfig " #define SIZEOF_LONG_INT 8"
240$ write unixodbcconfig "#endif"
241$ close unixodbcconfig
242$ if f$search("ODBCSRC:[include]config.h") .nes. "" then delete/noconfirm/nolog ODBCSRC:[include]config.h;*
243$ open/write config_h ODBCSRC:[include]config.h
244$ write config_h "/* The real stuff is in vmsconfig.h */
245$ close config_h
246$ exit
247$ endsubroutine ! create_vmsconfig_h
248$!
249$ check_module : subroutine
250$!  Check for presence of a particular module in an object library.
251$!  p1: module name, p2: object library
252$ set noon
253$ define/user_mode sys$output nl:
254$ define/user_mode sys$error nl:
255$ library/list/only="''p1'" 'p2'
256$ if .not. $status
257$ then
258$!    probably LBR$_KEYNOTFND; defer other errors until link time
259$     module_exists == 0
260$ else
261$     module_exists == 1
262$ endif
263$ set on
264$ exit
265$ endsubroutine ! check_module
266