1: \ lib.fs shared library support package 11may97py
2:
3: \ Copyright (C) 1995,1996,1997,1998,2000,2003,2005,2006,2007,2008 Free Software Foundation, Inc.
4:
5: \ This file is part of Gforth.
6:
7: \ Gforth is free software; you can redistribute it and/or
8: \ modify it under the terms of the GNU General Public License
9: \ as published by the Free Software Foundation, either version 3
10: \ of the License, or (at your option) any later version.
11:
12: \ This program is distributed in the hope that it will be useful,
13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: \ GNU General Public License for more details.
16:
17: \ You should have received a copy of the GNU General Public License
18: \ along with this program. If not, see http://www.gnu.org/licenses/.
19:
20: s" os-type" environment? [IF]
21: 2dup s" linux-gnu" str= [IF] 2drop
22: cell 8 = [IF] s" /usr/lib64/libffi.so" [ELSE] s" libffi.so" [THEN]
23: [ELSE] 2dup s" bsd" search nip nip [IF] 2drop s" libffi.so"
24: [ELSE] 2dup s" cygwin" str= [IF] 2drop s" libffi.dll"
25: [ELSE] 2dup s" darwin" string-prefix? [IF] 2drop s" libffi.dylib"
26: [ELSE] 2drop s" libffi" [THEN] [THEN] [THEN] [THEN] [THEN]
27: open-lib [if]
28: \ warnings @ [IF] .( including libffi.fs ) [THEN]
29: include libffi.fs
30: [ELSE]
31: s" libavcall.so" open-lib 0<>
32: s" libcallback.so" open-lib 0<> and [if]
33: \ warnings @ [IF] .( including fflib.fs [ffcall] ) [THEN]
34: include fflib.fs
35: [ELSE]
36: .( Neither libffi nor ffcall are available ) cr
37: abort
38: .( Using oldlib.fs; incompatible with fflib.fs and libffi.fs) cr
39: include oldlib.fs
40: [THEN]
41: [THEN]
42:
43: \ testing stuff
44:
45: [IFUNDEF] libc
46: s" os-type" environment? [IF]
47: 2dup s" linux-gnu" str= [IF] 2drop
48: cell 8 = [IF]
49: library libc /lib64/libc.so.6
50: [ELSE]
51: library libc /lib/libc.so.6
52: [THEN]
53: [ELSE] 2dup s" cygwin" str= [IF] 2drop
54: library libc cygwin1.dll
55: [ELSE] 2dup s" bsd" search nip nip [IF] 2drop
56: library libc libc.so
57: [ELSE] 2dup s" darwin" string-prefix? [IF] 2drop
58: library libc libc.dylib
59: [ELSE] 2drop \ or add your stuff here
60: [THEN]
61: [THEN]
62: [THEN]
63: [THEN]
64: [THEN]
65: [THEN]
66:
67: [ifdef] testing
68:
69: library libc libc.so.6
70:
71: libc sleep int (int) sleep
72: libc open ptr int int (int) open
73: libc lseek int llong int (llong) lseek64
74: libc read int ptr int (int) read
75: libc close int (int) close
76:
77: library libm libm.so.6
78:
79: libm fmodf sf sf (sf) fmodf
80: libm fmod df df (fp) fmod
81:
82: \ example for a windows callback
83:
84: callback wincall (int) int int int int callback;
85:
86: :noname ( a b c d -- e ) 2drop 2drop 0 ; wincall do_timer
87:
88: \ test a callback
89:
90: callback 2:1 (int) int int callback;
91:
92: : cb-test ( a b -- c )
93: cr ." Testing callback"
94: cr ." arguments: " .s
95: cr ." result " + .s cr ;
96: ' cb-test 2:1 c_plus
97:
98: fptr 2:1call int int (int)
99:
100: : test c_plus 2:1call ;
101:
102: \ 3 4 test
103:
104: \ bigFORTH legacy library test
105:
106: library libX11 libX11.so.6
107:
108: legacy on
109:
110: 1 libX11 XOpenDisplay XOpenDisplay ( name -- dpy )
111: 5 libX11 XInternAtoms XInternAtoms ( atoms flag count names dpy -- status )
112:
113: legacy off
114:
115: [then]
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>