OS/2 tests and more
[p5sagit/p5-mst-13.2.git] / hints / os2.sh
1 #! /bin/sh
2 # hints/os2.sh
3 # This file reflects the tireless work of
4 # Ilya Zakharevich <ilya@math.ohio-state.edu>
5 #
6 # Trimmed and comments added by 
7 #     Andy Dougherty  <doughera@lafcol.lafayette.edu>
8 #     Exactly what is required beyond a standard OS/2 installation?
9 #     (see in README.os2)
10
11 # Note that symbol extraction code gives wrong answers (sometimes?) on
12 # gethostent and setsid.
13
14 # Optimization (GNU make 3.74 cannot be loaded :-():
15 emxload -m 30 sh.exe ls.exe tr.exe id.exe sed.exe # make.exe 
16 emxload -m 30 grep.exe egrep.exe fgrep.exe cat.exe rm.exe mv.exe cp.exe
17 emxload -m 30 uniq.exe basename.exe sort.exe awk.exe echo.exe
18
19 path_sep=\;
20
21 if test -f $sh.exe; then sh=$sh.exe; fi
22
23 startsh="#!$sh"
24 cc='gcc'
25
26 # Make denser object files and DLL
27 case "X$optimize" in
28   X)
29         optimize="-O2 -fomit-frame-pointer -malign-loops=2 -malign-jumps=2 -malign-functions=2 -s"
30         ld_dll_optimize="-s"
31         ;;
32 esac
33
34 # Get some standard things (indented to avoid putting in config.sh):
35  oifs="$IFS"
36  IFS=" ;"
37  set $MANPATH
38  tryman="$@"
39  set $LIBRARY_PATH
40  libemx="$@"
41  set $C_INCLUDE_PATH
42  usrinc="$@"
43  IFS="$oifs"
44  tryman="`./UU/loc . /man $tryman`"
45  tryman="`echo $tryman | tr '\\\' '/'`"
46  
47  # indented to avoid having it *two* times at start
48  libemx="`./UU/loc os2.a /emx/lib $libemx`"
49
50 usrinc="`./UU/loc stdlib.h /emx/include $usrinc`"
51 usrinc="`dirname $usrinc | tr '\\\' '/'`"
52 libemx="`dirname $libemx | tr '\\\' '/'`"
53
54 if test -d $tryman/man1; then
55   sysman="$tryman/man1"
56 else
57   sysman="`./UU/loc . /man/man1 c:/man/man1 c:/usr/man/man1 d:/man/man1 d:/usr/man/man1 e:/man/man1 e:/usr/man/man1 f:/man/man1 f:/usr/man/man1 g:/man/man1 g:/usr/man/man1 /usr/man/man1`"
58 fi
59
60 emxpath="`dirname $libemx`"
61 if test ! -d "$emxpath"; then 
62   emxpath="`./UU/loc . /emx c:/emx d:/emx e:/emx f:/emx g:/emx h:/emx /emx`"
63 fi
64
65 if test ! -d "$libemx"; then 
66   libemx="$emxpath/lib"
67 fi
68 if test ! -d "$libemx"; then 
69   if test -d "$LIBRARY_PATH"; then
70     libemx="$LIBRARY_PATH"
71   else
72     libemx="`./UU/loc . X c:/emx/lib d:/emx/lib e:/emx/lib f:/emx/lib g:/emx/lib h:/emx/lib /emx/lib`"
73   fi
74 fi
75
76 if test ! -d "$usrinc"; then 
77   if test -d "$emxpath/include"; then 
78     usrinc="$emxpath/include"
79   else
80     if test -d "$C_INCLUDE_PATH"; then
81       usrinc="$C_INCLUDE_PATH"
82     else
83       usrinc="`./UU/loc . X c:/emx/include d:/emx/include e:/emx/include f:/emx/include g:/emx/include h:/emx/include /emx/include`"
84     fi
85   fi
86 fi
87
88 rsx="`./UU/loc rsx.exe undef $pth`"
89
90 if test "$libemx" = "X"; then echo "Cannot find C library!" >&2; fi
91
92 # Acute backslashitis:
93 libpth="`echo \"$LIBRARY_PATH\" | tr ';\\\' ' /'`"
94 libpth="$libpth $libemx/mt $libemx"
95
96 set `cmd /c emxrev -f emxlibcm`
97 emxcrtrev=$5
98 # indented to not put it into config.sh
99   _defemxcrtrev=-D_EMX_CRT_REV_=$emxcrtrev
100
101 so='dll'
102
103 # Additional definitions:
104
105 firstmakefile='GNUmakefile'
106 exe_ext='.exe'
107
108 # We provide it
109 i_dlfcn='define'
110
111 # The default one uses exponential notation between 0.0001 and 0.1
112 d_Gconvert='gcvt_os2((x),(n),(b))'
113
114 # -Zomf build has a problem with _exit() *flushing*, so the test
115 # gets confused:
116 fflushNULL="define"
117
118 aout_d_shrplib='undef'
119 aout_useshrplib='false'
120 aout_obj_ext='.o'
121 aout_lib_ext='.a'
122 aout_ar='ar'
123 aout_plibext='.a'
124 aout_lddlflags="-Zdll $ld_dll_optimize"
125 # Cannot have 32000K stack: get SYS0170  ?!
126 if [ $emxcrtrev -ge 50 ]; then 
127     aout_ldflags='-Zexe -Zsmall-conv -Zstack 16000'
128 else
129     aout_ldflags='-Zexe -Zstack 16000'
130 fi
131
132 # To get into config.sh:
133 aout_ldflags="$aout_ldflags"
134
135 aout_d_fork='define'
136 aout_ccflags="-DDOSISH -DPERL_IS_AOUT -DOS2=2 -DEMBED -I. $_defemxcrtrev"
137 aout_cppflags="-DDOSISH -DPERL_IS_AOUT -DOS2=2 -DEMBED -I. $_defemxcrtrev"
138 aout_use_clib='c'
139 aout_usedl='undef'
140 aout_archobjs="os2.o dl_os2.o"
141 # Not listed in dynamic_ext, but needed for AOUT static_ext nevertheless
142 aout_extra_static_ext="OS2::DLL"
143
144 # variable which have different values for aout compile
145 used_aout='d_shrplib useshrplib plibext lib_ext obj_ext ar plibext d_fork lddlflags ldflags ccflags use_clib usedl archobjs cppflags'
146
147 if [ "$emxaout" != "" ]; then
148     d_shrplib="$aout_d_shrplib"
149     useshrplib="$aout_useshrplib"
150     obj_ext="$aout_obj_ext"
151     lib_ext="$aout_lib_ext"
152     ar="$aout_ar"
153     plibext="$aout_plibext"
154     if [ $emxcrtrev -lt 50 ]; then 
155         d_fork="$aout_d_fork"
156     fi
157     lddlflags="$aout_lddlflags"
158     ldflags="$aout_ldflags"
159     ccflags="$aout_ccflags"
160     cppflags="$aout_cppflags"
161     use_clib="$aout_use_clib"
162     usedl="$aout_usedl"
163 else
164     d_shrplib='define'
165     useshrplib='true'
166     obj_ext='.obj'
167     lib_ext='.lib'
168     ar='emxomfar'
169     plibext='.lib'
170     if [ $emxcrtrev -ge 50 ]; then 
171         d_fork='define'
172     else
173         d_fork='undef'
174     fi
175     lddlflags="-Zdll -Zomf -Zmt -Zcrtdll -Zlinker /e:2"
176     # Recursive regmatch may eat 2.5M of stack alone.
177     ldflags='-Zexe -Zomf -Zmt -Zcrtdll -Zstack 32000 -Zlinker /e:2'
178     if [ $emxcrtrev -ge 50 ]; then 
179         ccflags="-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. $_defemxcrtrev"
180     else
181         ccflags="-Zomf -Zmt -DDOSISH -DOS2=2 -DEMBED -I. -DEMX_BAD_SBRK $_defemxcrtrev"
182     fi
183     use_clib='c_import'
184     usedl='define'
185 fi
186
187 # indented to miss config.sh
188   _ar="$ar"
189
190 # To get into config.sh (should start at the beginning of line)
191 # or you can put it into config.over.
192 plibext="$plibext"
193 # plibext is not needed anymore.  Just directly set $libperl.
194 libperl="libperl${plibext}"
195
196 #libc="/emx/lib/st/c_import$lib_ext"
197 libc="$libemx/mt/$use_clib$lib_ext"
198
199 if test -r "$libemx/c_alias$lib_ext"; then 
200     libnames="$libemx/c_alias$lib_ext"
201 fi
202 # otherwise puts -lc ???
203
204 # [Maybe we should just remove c from $libswanted ?]
205
206 # Test would pick up wrong rand, so we hardwire the value for random()
207 libs='-lsocket -lm -lbsd'
208 randbits=31
209 archobjs="os2$obj_ext dl_os2$obj_ext"
210
211 # Run files without extension with sh:
212 EXECSHELL=sh
213
214 cccdlflags='-Zdll'
215 dlsrc='dl_dlopen.xs'
216 ld='gcc'
217
218 #cppflags='-DDOSISH -DOS2=2 -DEMBED -I.'
219
220 # for speedup: (some patches to ungetc are also needed):
221 # Note that without this guy tests 8 and 10 of io/tell.t fail, with it 11 fails
222
223 stdstdunder=`echo "#include <stdio.h>" | cpp | egrep -c "char +\* +_ptr"`
224 d_stdstdio='define'
225 d_stdiobase='define'
226 d_stdio_ptr_lval='define'
227 d_stdio_cnt_lval='define'
228
229 if test "$stdstdunder" = 0; then
230   stdio_ptr='((fp)->ptr)'
231   stdio_cnt='((fp)->rcount)'
232   stdio_base='((fp)->buffer)'
233   stdio_bufsiz='((fp)->rcount + (fp)->ptr - (fp)->buffer)'
234   ccflags="$ccflags -DMYTTYNAME"
235   myttyname='define'
236 else
237   stdio_ptr='((fp)->_ptr)'
238   stdio_cnt='((fp)->_rcount)'
239   stdio_base='((fp)->_buffer)'
240   stdio_bufsiz='((fp)->_rcount + (fp)->_ptr - (fp)->_buffer)'
241 fi
242
243 # to put into config.sh
244 myttyname="$myttyname"
245
246 # To have manpages installed
247 nroff='nroff.cmd'
248 # above will be overwritten otherwise, indented to avoid config.sh
249   _nroff='nroff.cmd'
250
251 # should be handled automatically by Configure now.
252 ln='cp'
253 # Will be rewritten otherwise, indented to not put in config.sh
254   _ln='cp'
255 lns='cp'
256
257 nm_opt='-p'
258
259 ####### We define these functions ourselves
260
261 d_strtoll='define'
262 d_strtoull='define'
263 d_getprior='define'
264 d_setprior='define'
265
266 # The next two are commented. pdksh handles #!, extproc gives no path part.
267 # sharpbang='extproc '
268 # shsharp='false'
269
270 # Commented:
271 #startsh='extproc ksh\\n#! sh'
272
273 # Find patch:
274 gnupatch='patch'
275 if (gnupatch -v || gnupatch --version)   2>&1 >/dev/null; then
276     gnupatch=gnupatch
277 else
278     if (gpatch -v || gpatch --version)   2>&1 >/dev/null; then
279         gnupatch=gpatch
280     else
281         # They may have a special PATH during configuring
282         if (patch -v || patch --version) 2>&1 >/dev/null; then
283             gnupatch="`./UU/loc patch.exe undef $pth`"
284         fi
285     fi
286 fi
287
288 for f in less.exe less.sh less.ksh less.cmd more.exe more.sh more.ksh more.cmd ; do
289   if test -z "$pager"; then
290     pager="`./UU/loc $f '' $pth`"
291   fi
292 done
293 if test -z "$pager"; then
294   pager='cmd /c more'
295 fi
296
297 # Apply patches if needed
298 case "$0$running_c_cmd" in
299   *[/\\]Configure|*[/\\]Configure.|Configure|Configure.) # Skip Configure.cmd
300     if test "Xyes" = "X$configure_cmd_loop"; then
301         cat <<EOC >&2
302 !!!
303 !!! PANIC: Loop of self-invocations detected, aborting!
304 !!!
305 EOC
306         exit 20
307     fi
308     configure_cmd_loop=yes
309     export configure_cmd_loop
310
311     configure_needs_patch=''
312     if test -s ./os2/diff.configure; then
313         if ! grep "^#OS2-PATCH-APPLIED" ./Configure > /dev/null; then
314             configure_needs_patch=yes       
315         fi
316     fi
317     if test -n "$configure_needs_patch"; then
318         # Not patched!
319         # Restore the initial command line arguments
320         if test -f ./Configure.cmd ; then
321             cat <<EOC >&2
322 !!!
323 !!! I see that what is running is ./Configure.
324 !!! ./Configure is not patched, but ./Configure.cmd exists.
325 !!!
326 !!! You are supposed to run Configure.cmd, not Configure
327 !!!  after an automagic patching.
328 !!!
329 !!! If you insist on running Configure, you may
330 !!!  patch it manually from ./os2/diff.configure.
331 !!!
332 !!! However, I went through incredible hoolahoops, and I expect I can
333 !!!  auto-restart Configure.cmd myself.  I will start it with arguments:
334 !!!
335 !!!    Configure.cmd $args_exp
336 !!!
337 EOC
338             rp='Do you want to auto-restart Configure.cmd?'
339             dflt='y'
340             . UU/myread
341             case "$ans" in
342                 [yY]) echo >&4 "Okay, continuing." ;;
343                 *) echo >&4 "Okay, bye."
344                    exit 2
345                    ;;
346             esac
347             eval "set X $args_exp";
348             shift;
349             # Restore the output
350             exec Configure.cmd "$@" 1>&2
351             exit 2
352         fi
353         cat <<EOC >&2
354 !!!
355 !!! You did not patch ./Configure!
356 !!! I can create Configure.cmd and patch it from ./os2/diff.configure with the command
357 !!!
358 !!!   $gnupatch -b -p1 --output=Configure.cmd <./os2/diff.configure 2>&1 | tee 00_auto_patch
359 EOC
360         rp='Do you want to auto-patch Configure to Configure.cmd?'
361         dflt='y'
362         . UU/myread
363         case "$ans" in
364                 [yY]) echo >&4 "Okay, continuing." ;;
365                 *) echo >&4 "Okay, bye."
366                    exit 2
367                    ;;
368         esac
369         ($gnupatch -b -p1 --output=Configure.cmd <./os2/diff.configure 2>&1 | tee 00_auto_patch) >&2
370         cat <<EOC >&2
371 !!!
372 !!! The report of patching is copied to 00_auto_patch.
373 !!! Now we need to restart Configure.cmd with all the options.
374 !!!
375 EOC
376         echo "extproc sh" > Configure.ctm
377         ( cat Configure.cmd >> Configure.ctm && mv -f Configure.ctm Configure.cmd ) || (echo "!!! Failure to add extproc-line to Configure.cmd." >&2 ; exit 21)
378         cat <<EOC >&2
379 !!! I went through incredible hoolahoops, and I expect I can
380 !!!  auto-restart Configure.cmd myself.  I will start it with arguments:
381 !!!
382 !!!    Configure.cmd $args_exp
383 !!!
384 EOC
385         rp='Do you want to auto-restart Configure.cmd?'
386         dflt='y'
387         . UU/myread
388         case "$ans" in
389                 [yY]) echo >&4 "Okay, continuing." ;;
390                 *) echo >&4 "Okay, bye."
391                    exit 2
392                    ;;
393         esac
394         eval "set X $args_exp";
395         shift;
396         exec Configure.cmd "$@" 1>&2
397         exit 2
398     else
399         if test -s ./os2/diff.configure; then
400             echo "!!! Apparently we are running a patched Configure." >&2
401         else
402             echo "!!! Apparently there is no need to patch Configure." >&2
403         fi
404     fi 
405     ;;
406   *) echo "!!! Apparently we are running a renamed Configure: '$0'." >&2
407 esac
408
409 # This script UU/usethreads.cbu will get 'called-back' by Configure 
410 # after it has prompted the user for whether to use threads.
411 cat > UU/usethreads.cbu <<'EOCBU'
412 case "$usethreads" in
413 $define|true|[yY]*)
414         ccflags="-Zmt $ccflags"
415         cppflags="-Zmt $cppflags"  # Do we really need to set this?
416         aout_ccflags="-DUSE_THREADS $aout_ccflags"
417         aout_cppflags="-DUSE_THREADS $aout_cppflags"
418         aout_lddlflags="-Zmt $aout_lddlflags"
419         aout_ldflags="-Zmt $aout_ldflags"
420         ;;
421 esac
422 EOCBU
423
424 if test -z "$cryptlib"; then
425         cryptlib=`UU/loc crypt$lib_ext "" $libpth`
426         if $test -n "$cryptlib"; then
427                 cryptlib=-lcrypt
428         else
429                 cryptlib=`UU/loc ufc$lib_ext "" $libpth`
430                 if $test -n "$cryptlib"; then
431                         cryptlib=-lufc
432                 fi
433         fi
434 fi
435 if test -n "$cryptlib"; then
436         libs="$libs $cryptlib"
437         # d_crypt=define
438 fi
439
440 # Now install the external modules. We are in the ./hints directory.
441
442 cd ./os2/OS2
443
444 if ! test -d ../../ext/OS2 ; then
445    mkdir ../../ext/OS2
446 fi
447
448 cp -rfu * ../../ext/OS2/
449
450 # Install tests:
451
452 cp -uf ../*.t ../../t/lib
453 for xxx in * ; do
454         if $test -d $xxx/t; then
455                 cp -uf $xxx/t/*.t ../../t/lib
456         else
457                 if $test -d $xxx; then
458                         cd $xxx
459                         for yyy in * ; do
460                                 if $test -d $yyy/t; then
461                                     cp -uf $yyy/t/*.t ../../t/lib
462                                 fi
463                         done
464                         cd ..
465                 fi
466         fi
467 done
468
469 case "$ldlibpthname" in
470 '') ldlibpthname=none ;;
471 esac
472
473 # Now go back
474 cd ../..
475 cp os2/*.t t/lib