-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.cmd
executable file
·186 lines (162 loc) · 7.13 KB
/
check.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* check.cmd to test the compilation and the linkage of os2compat
* implementation
*
* Copyright (C) 2014 KO Myung-Hun <[email protected]>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
G.sNl = x2c('0d') || x2c('0a');
G.sTmpDir = value('TMPDIR',, 'OS2ENVIRONMENT');
call checkCC 'network/socklen_t.h',, 'socklen_t socklen; (void)socklen;';
call checkCC 'network/shutdown.h'
call checkCC 'network/poll.h', 'network/poll.c', 'poll( 0, 0, 0 );';
call checkCC 'network/getaddrinfo.h', 'network/getaddrinfo.c', ,
'gai_strerror( 0 );' || g.sNl ||,
'getaddrinfo( 0, 0, 0, 0 );' || g.sNl ||,
'freeaddrinfo( 0 );' || g.sNl ||,
'getnameinfo( 0, 0, 0, 0, 0, 0, 0 );';
call checkCC 'memory/mmap.h', 'memory/mmap.c', ,
'mmap( 0, 0, 0, 0, 0, 0);' || g.sNl ||,
'mprotect( 0, 0, 0);' || g.sNl ||,
'munmap( 0, 0 );' || g.sNl ||,
'mmap_anon( 0, 0, 0, 0, 0);';
call checkCC 'process.h', 'process/spawn.c', 'spawnvpe( 0, 0, 0, 0 );';
call checkCC 'stdio.h', 'io/freopen.c', 'freopen( 0, 0, 0 );';
call checkCC 'io.h fcntl.h', 'io/setmode.c', 'setmode( 0, 0 );';
call checkCC 'thread/semaphore.h', 'thread/semaphore.c', ,
'sem_init( 0, 0, 0 );' || g.sNl ||,
'sem_destroy( 0 );' || g.sNl ||,
'sem_post( 0 );' || g.sNl ||,
'sem_wait( 0 );' || g.sNl ||,
'sem_trywait( 0 );';
call checkCC 'io/scandir.h', 'io/scandir.c', 'scandir( 0, 0, 0, alphasort );';
call checkCC 'network/cmsg.h',, 'return CMSG_LEN( 0 ) + CMSG_SPACE( 0 );';
call checkCC 'network/if_nameindex.h', 'network/if_nameindex.c', ,
'struct if_nameindex *nis; (void)nis;' || g.sNL ||,
'if_nameindex();' || g.sNL ||,
'if_freenameindex( 0 );' || g.sNL ||,
'if_indextoname( 0, 0 );' || g.sNL ||,
'if_nametoindex( 0 );';
call checkCC 'stdlib.h', 'process/_response.c', '_response( 0, 0 );';
call checkCC 'sys/types.h sys/resource.h', 'process/getrusage.c', ,
'getrusage( 0, 0 );';
call checkCC 'sys/select.h', 'network/select.c', 'select( 0, 0, 0, 0, 0 );';
call checkCC 'fcntl.h', 'io/fcntl.c', 'fcntl( 0, 0, 0 );';
call checkCC 'io.h', 'io/pipe.c', 'pipe( 0 );';
call checkCC 'network/xpoll.h', 'network/xpoll.c network/poll.c', ,
'struct xpollset *xpset;' || g.sNl ||,
'xpset = xpoll_create();' || g.sNl ||,
'xpoll_add( xpset, 0, 0 );' || g.sNl ||,
'xpoll_del( xpset, 0 );' || g.sNl ||,
'xpoll_query( xpset, 0, 0 );' || g.sNl ||,
'xpoll_wait( xpset, 0, 0, 0 );';
call checkCC 'process.h', 'process/exec.c', 'execvpe( 0, 0, 0 );';
call checkCC 'thread/sched_yield.h', 'thread/sched_yield.c', ,
'sched_yield();';
call checkCC 'unistd.h', 'io/ttyname.c', 'ttyname( 0 );';
call checkCC 'network/getifaddrs.h', 'network/getifaddrs.c', ,
'struct ifaddrs *ifa;' || g.sNl ||,
'getifaddrs( &ifa );' || g.sNl ||,
'freeifaddrs( ifa );';
call checkCC 'process/spawn2.h', 'process/spawn2.c', ,
'spawn2ve( 0, 0, 0, 0, 0, 0 );' || g.sNl ||,
'spawn2vpe( 0, 0, 0, 0, 0, 0 );';
call checkCC 'process/posix_spawn/posix_spawn.h', ,
'process/posix_spawn/spawn_faction_addchdir.c',
'process/posix_spawn/spawn_faction_init.c', ,
'posix_spawn_file_actions_addchdir( 0, 0 );';
call checkCC 'process/posix_spawn/posix_spawn.h', ,
'process/posix_spawn/spawn_faction_addfchdir.c',
'process/posix_spawn/spawn_faction_init.c', ,
'posix_spawn_file_actions_addfchdir( 0, 0 );';
call checkCC 'spawn.h', ,
'process/posix_spawn/spawne.c',
'process/posix_spawn/spawni.c',
'process/spawn2.c', ,
'posix_spawn( 0, 0, 0, 0, 0, 0 );';
call checkCC 'spawn.h', ,
'process/posix_spawn/spawnpe.c',
'process/posix_spawn/spawni.c',
'process/spawn2.c', ,
'posix_spawnp( 0, 0, 0, 0, 0, 0 );';
call checkOS2CompatHeader;
say 'Check completed';
exit 0;
checkCC: procedure expose G.
parse arg sHeaders, sSources, sTests;
say 'Checking with:';
say ' headers =' sHeaders;
say ' sources =' sSources;
say ' tests =' sTests;
sTestFileBase = G.sTmpDir;
if right(sTestFileBase, 1) = '\' then
sTestFileBase = delstr(sTestFileBase, length(sTestFileBase), 1);
sTestFileBase = sTestFileBase || '\os2compat_test';
sTestFile = sTestFileBase || '.c';
sTestFileExe = sTestFileBase || '.exe';
address cmd 'del' sTestFile '>nul 2>&1';
call lineout sTestFile,, 1;
sHeaderList = sHeaders;
do while words(sHeaderList) > 0
parse var sHeaderList sHeader sHeaderList;
call lineout sTestFile, '#include "' || sHeader || '"';
end;
call lineout sTestFile, '';
call lineout sTestFile, 'int main( void )';
call lineout sTestFile, '{';
call lineout sTestFile, sTests;
call lineout sTestFile, ' return 0;';
call lineout sTestFile, '}';
call lineout sTestFile;
sCmd = 'gcc -Wall -DOS2EMX_PLAIN_CHAR -funsigned-char -o' sTestFileExe,
sTestFile sSources;
address cmd sCmd;
if rc <> 0 then
do
say 'Check failed:';
say ' headers =' sHeaders;
say ' sources =' sSources;
say ' tests =' sTests;
say ' cmd =' sCmd;
exit 1;
end;
say 'Check passed';
return;
checkOS2CompatHeader: procedure expose G.
sHeaderFiles = 'include/os2compat/dirent.h',
'include/os2compat/ifaddrs.h',
'include/os2compat/netdb.h',
'include/os2compat/poll.h',
'include/os2compat/semaphore.h',
'include/os2compat/sched.h',
'include/os2compat/spawn.h',
'include/os2compat/spawn2.h',
'include/os2compat/net/if.h',
'include/os2compat/sys/mman.h',
'include/os2compat/sys/socket.h',
'include/os2compat/sys/xpoll.h';
sPrivHeaderFiles = 'io/scandir.h',
'memory/mmap.h',
'network/cmsg.h',
'network/getaddrinfo.h',
'network/getifaddrs.h',
'network/if_nameindex.h',
'network/poll.h',
'network/shutdown.h',
'network/socklen_t.h',
'network/xpoll.h',
'process/spawn2.h',
'process/posix_spawn/posix_spawn.h',
'thread/semaphore.h',
'thread/sched_yield.h';
sDestDir = 'include/os2compat/priv';
address cmd 'ginstall -d' sDestDir;
address cmd 'cp -p --parent' sPrivHeaderFiles sDestDir;
call checkCC sHeaderFiles;
address cmd 'rm -rf' sDestDir;
return;