1$! File: build_libcurl_pc.com
2$!
3$! $Id:$
4$!
5$! Build the curl-config file from the config_curl.in file
6$!
7$! Copyright 2013, John Malmberg
8$!
9$! Permission to use, copy, modify, and/or distribute this software for any
10$! purpose with or without fee is hereby granted, provided that the above
11$! copyright notice and this permission notice appear in all copies.
12$!
13$! THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14$! WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15$! MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16$! ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17$! WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18$! ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19$! OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20$!
21$!
22$! 15-Jun-2013  J. Malmberg
23$!
24$!===========================================================================
25$!
26$! Skip this if the curl-config. already exists.
27$ if f$search("[--]curl-config.") .nes. "" then goto all_exit
28$!
29$! Need to know the kit type.
30$ kit_name = f$trnlnm("GNV_PCSI_KITNAME")
31$ if kit_name .eqs. ""
32$ then
33$   write sys$output "@MAKE_PCSI_CURL_KIT_NAME.COM has not been run."
34$   goto all_exit
35$ endif
36$!
37$!
38$! Parse the kit name into components.
39$!---------------------------------------
40$ producer = f$element(0, "-", kit_name)
41$ base = f$element(1, "-", kit_name)
42$ product = f$element(2, "-", kit_name)
43$ mmversion = f$element(3, "-", kit_name)
44$ majorver = f$extract(0, 3, mmversion)
45$ minorver = f$extract(3, 2, mmversion)
46$ updatepatch = f$element(4, "-", kit_name)
47$ if updatepatch .eqs. "-" then updatepatch = ""
48$!
49$! kit type of "D" means a daily build
50$ kit_type = f$edit(f$extract(0, 1, majorver), "upcase")
51$!
52$ cfg_file_in = "[--]curl-config.in"
53$!
54$ if f$search(cfg_file_in) .eqs. ""
55$ then
56$    write sys$output "Can not find curl-config.in."
57$    goto all_exit
58$ endif
59$!
60$ if (f$getsyi("HW_MODEL") .lt. 1024)
61$ then
62$    arch_name = "VAX"
63$ else
64$    arch_name = ""
65$    arch_name = arch_name + f$edit(f$getsyi("ARCH_NAME"), "UPCASE")
66$    if (arch_name .eqs. "") then arch_name = "UNK"
67$ endif
68$!
69$!
70$ curl_version = "0.0.0"
71$ open/read vf [--.include.curl]curlver.h
72$version_loop:
73$   read vf/end=version_loop_end line_in
74$   if line_in .eqs. "" then goto version_loop
75$   key = f$element(0, " ", line_in)
76$   if key .nes. "#define" then goto version_loop
77$   name = f$element(1, " ", line_in)
78$   if name .eqs. "LIBCURL_VERSION"
79$   then
80$       curl_version = f$element(2, " ", line_in) - """" - """"
81$       goto version_loop
82$   endif
83$   if name .eqs. "LIBCURL_VERSION_NUM"
84$   then
85$       version_num_hex = f$element(2, " ", line_in)
86$       version_num = version_num_hex - "0x"
87$       goto version_loop
88$   endif
89$version_loop_end:
90$ close vf
91$!
92$!
93$ create [--]curl-config.
94$ open/append pco [--]curl-config.
95$ open/read pci 'cfg_file_in'
96$cfg_file_loop:
97$ read pci/end=cfg_file_loop_end line_in
98$!
99$! blank lines
100$ if line_in .eqs. ""
101$ then
102$   write pco ""
103$   goto cfg_file_loop
104$ endif
105$!
106$! comment lines
107$ key = f$extract(0, 1, line_in)
108$ if key .eqs. "#"
109$ then
110$   write pco line_in
111$   goto cfg_file_loop
112$ endif
113$!
114$! No substitution line
115$ line_in_len = f$length(line_in)
116$ if f$locate("@", line_in) .ge. line_in_len
117$ then
118$   write pco line_in
119$   goto cfg_file_loop
120$ endif
121$!
122$ if f$locate("@prefix@", line_in) .lt line_in_len
123$ then
124$    if kit_type .nes. "D"
125$    then
126$        write pco "prefix=/usr"
127$    else
128$        write pco "prefix=/beta"
129$    endif
130$    goto cfg_file_loop
131$ endif
132$ if f$locate("@exec_prefix@", line_in) .lt line_in_len
133$ then
134$    if kit_type .nes. "D"
135$    then
136$        write pco "exec_prefix=/usr"
137$    else
138$        write pco "exec_prefix=/beta"
139$    endif
140$    goto cfg_file_loop
141$ endif
142$ if f$locate("=@includedir@", line_in) .lt line_in_len
143$ then
144$    write pco "includedir=$(prefix}/include"
145$    goto cfg_file_loop
146$ endif
147$ if f$locate("X@includedir@", line_in) .lt line_in_len
148$ then
149$    write pco "        if test ""X$(prefix}/include""; then"
150$    goto cfg_file_loop
151$ endif
152$ if f$locate("I@includedir@", line_in) .lt line_in_len
153$ then
154$    write pco "          echo "${CPPFLAG_CURL_STATICLIB}-I$(prefix}/include"
155$    goto cfg_file_loop
156$ endif
157$ if f$locate("@CPPFLAG_CURL_STATICLIB@", line_in) .lt line_in_len
158$ then
159$    write pco "cppflag_curl_staticlib=-DCURL_STATICLIB"
160$    goto cfg_file_loop
161$ endif
162$ if f$locate("@ENABLE_SHARED@", line_in) .lt line_in_len
163$ then
164$    write pco "        echo no"
165$    goto cfg_file_loop
166$ endif
167$ if f$locate("@CURL_CA_BUNDLE@", line_in) .lt line_in_len
168$ then
169$    write pco "        echo """""
170$    goto cfg_file_loop
171$ endif
172$ if f$locate("@CC@", line_in) .lt line_in_len
173$ then
174$    write pco "        echo ""cc"""
175$    goto cfg_file_loop
176$ endif
177$ if f$locate("@SUPPORT_FEATURES@", line_in) .lt line_in_len
178$ then
179$    if arch_name .eqs. "VAX"
180$    then
181$        write pco "        for feature in SSL libz NTLM ""; do"
182$    else
183$        write pco "        for feature in SSL IPv6 libz NTLM ""; do"
184$    endif
185$    goto cfg_file_loop
186$ endif
187$ if f$locate("@SUPPORT_PROTOCOLS@", line_in) .lt line_in_len
188$ then
189$    proto1 = "DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS"
190$    proto2 = " LDAP LDAPS POP3 POP3S RTSP SMTP SMTPS TELNET TFTP"
191$    proto = proto1 + proto2
192$    write pco "        for protocol in " + proto + "; do"
193$    goto cfg_file_loop
194$ endif
195$ if f$locate("libcurl @CURLVERSION@", line_in) .lt line_in_len
196$ then
197$    write pco "        echo libcurl ''curl_version'"
198$    goto cfg_file_loop
199$ endif
200$ if f$locate("existing @CURLVERSION@", line_in) .lt line_in_len
201$ then
202$    line_start = -
203  "          echo ""requested version $checkfor is newer than existing"
204$    write pco "''line_start' ''curl_version'"""
205$    goto cfg_file_loop
206$ endif
207$ if f$locate("`echo @versionnum@", line_in) .lt line_in_len
208$ then
209$    write pco "        numuppercase=`echo ''version_num' | tr 'a-f' 'A-F'`"
210$    goto cfg_file_loop
211$ endif
212$ if f$locate(" echo @versionnum@", line_in) .lt line_in_len
213$ then
214$    write pco "        echo ''version_num'"
215$    goto cfg_file_loop
216$ endif
217$ if f$locate("X@libdir@", line_in) .lt line_in_len
218$ then
219$    part1 = "        if test ""$(exec_prefix}/lib"" != ""X/usr/lib"""
220$    part2 = "-a ""X$(exec_prefix}/lib"" != ""X/usr/lib64""; then"
221$    write pco part1,part2
222$    goto cfg_file_loop
223$ endif
224$ if f$locate("L@libdir@", line_in) .lt line_in_len
225$ then
226$    write pco "           CURLLIBDIR=""$(exec_prefix}/lib """
227$    goto cfg_file_loop
228$ endif
229$ if f$locate("@REQUIRE_LIB_DEPS@", line_in) .lt line_in_len
230$ then
231$    write pco "        if test "Xyes" = "Xyes"; then"
232$    goto cfg_file_loop
233$ endif
234$ if f$locate("@LIBCURL_LIBS@", line_in) .lt line_in_len
235$ then
236$    if arch_name .eqs. "VAX"
237$    then
238$        write pco "          echo ${CURLLIBDIR}-lssl -lcrypto -lz"
239$    else
240$        write pco "          echo ${CURLLIBDIR}-lssl -lcrypto -lgssapi -lz"
241$    endif
242$    goto cfg_file_loop
243$ endif
244$ if f$locate("@ENABLE_STATIC@", line_in) .lt line_in_len
245$ then
246$    write pco "        if test "Xyes" != "Xno" ; then"
247$    goto cfg_file_loop
248$ endif
249$ if f$locate("@LIBCURL_LIBS@", line_in) .lt line_in_len
250$ then
251$    part1 = "          echo ${exec_prefix}/lib/libcurl.a"
252$    part2 = "-L/usr/lib -L/SSL_LIB"
253$    if arch_name .eqs. "VAX"
254$    then
255$        write pco "''part1' ''part2' -lssl -lcrypto -lz"
256$    else
257$        write pco "''part1' ''part2' -lssl -lcrypto -lgssapi -lz"
258$    endif
259$    goto cfg_file_loop
260$ endif
261$ if f$locate("@CONFIGURE_OPTIONS@", line_in) .lt line_in_len
262$ then
263$    if kit_type .nes. "D"
264$    then
265$        part1 = "        echo "" '--prefix=/usr' '--exec-prefix=/usr' "
266$    else
267$        part1 = "        echo "" '--prefix=/beta' '--exec_prefix=/beta' "
268$    endif
269$    if arch_name .eqs. "VAX"
270$    then
271$        part3 = ""
272$    else
273$        part3 = "'--with-gssapi' "
274$    endif
275$    part2 = "'--disable-dependency-tracking' '--disable-libtool-lock' "
276$    part4 = "'--disable-ntlm-wb' '--with-ca-path=gnv$curl_ca_path'"""
277$!
278$    write pco part1,part2,part3,part4
279$!
280$    goto cfg_file_loop
281$ endif
282$!
283$pc_file_loop_end:
284$ close pco
285$ close pci
286$!
287$all_exit:
288$ exit
289