-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcfg_wmake.lua
More file actions
executable file
·278 lines (250 loc) · 11.6 KB
/
Copy pathcfg_wmake.lua
File metadata and controls
executable file
·278 lines (250 loc) · 11.6 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/lua
--
-- Creates Open Watcom WMake file for Windows NT target. This script uses
-- an approach similar to ninja build system: doesn't try to use wildcards
-- in rules, advanced wmake options etc.
--
-- Open Watcom C can compile only for 16- and 32-bit platforms and its support
-- of x86 is limited by Pentium Pro subset. The next issues should be taken
-- into account:
--
-- 1. Different calling conventions and name mangling may be used by
-- the Open Watcom compiler. We use '-6s' flag to use cdecl instead of
-- default watcall / WATCOM_C.
-- 2. Some combinations of keys for wcl386 may cause incorrect linking
-- of DLLs with PRNGs (they would crash).
-- 3. Some PRNGs, especially some 64-bit PRNGs and most CSPRNGs may be
-- very slow in comparison to modern x86-64 compilers.
-- 4. Too many threads (more than 2) may cause program crashes, probably due
-- to memory limitations.
--
-- This script will create makefile that will compile SmokeRand for two
-- platforms: Windows NT (32-bit only) and DOS (both 16-bit and 32-bit).
--
-- 1. For Windows NT executables are compiled as usual. But DLLs are compiled
-- as freestanding. It required some hacks with compiler and linker keys;
-- also $(%WATCOM)/lib386/dos/clib3s.lib C runtime library is used instead
-- of runtime for Windows NT: we need some functions for 64-bit integers
-- but not DLL stubs, runtime library etc.
-- 2. 16-bit DOS version is compiled from `sr_tiny.c` and `specfuncs.c`. It
-- provides the `express` battery for 16-bit computers.
-- 3. 32-bit DOS version is compiled for DOS extenders such as DOS/32, PMODEW
-- or CauseWay. It DOES SUPPORT loading of Win32 DLLs without exports:
-- it is made by a custom `pe32loader.c`. It also supports DOS LFN API
-- by means of the `lib386/dos/doslfn3s.lib` Open Watcom C static library.
-- It may be autolinked by means of definiton of the `__WATCOM_LFN__`.
-- macro. But an explicit linking is more reliable and clear.
--
-- An alternative way to build it under DOS is to use Windows NT build and
-- software like HX DOS Extender, WDOSX or DOSWIN32 together with DOSLFN to
-- obtain 32-bit implementation for DOS. But it may require proprietary DLLs
-- such as MSVCRT.DLL.
--
-- Compilation and linking of SmokeRand for 32-bit DOS with DLL support is
-- definetly possible even without HX DOS Extender but may be a little bit
-- tricky and require makefiles customization. Enjoy!
--
-- (c) 2025-2026 Alexey L. Voskov, Lomonosov Moscow State University
-- alvoskov@gmail.com
--
-- This software is licensed under the MIT license.
--
cfg = require('cfg_data')
-- About DOS extenders: %WATCOM%\BINW should be added to the path:
-- it will help to automatically stubify the resulting EXE.
--
local dosextender = "dos32a"
local lib_sources = cfg.get_lib_sources()
local bat_sources = cfg.get_bat_sources()
local lib_headers = cfg.get_lib_headers()
local gen_sources_raw = cfg.get_gen_sources()
local gen_asm_sources = {'dandelion64_nt32', 'kiss03_nt32', 'mwc64x_nt32',
'mwc3232x_nt32', 'rwc32_nt32', 'tf0duper32_nt32', 'xkiss16_awc_nt32',
'xkiss32_awc_nt32', 'xkiss32_sh_awc_nt32', 'xoshiro128pp_nt32'}
local exefiles = {'smokerand', 'sr_speed', 'find_xorshift_params',
'test_funcs', 'test_lfsr_period', 'test_rdseed', 'test_syscrypto'}
-- Filter out the floating point based generator: in WATCOM C
-- it requires a runtime library.
local gen_sources = {}
for i=1,#gen_sources_raw do
local gen = gen_sources_raw[i]
if gen ~= "lfib_ranmar" then
table.insert(gen_sources, gen)
end
end
local file = io.open("Makefile.wat", "w")
io.output(file)
-- Generic rules
-- Add -DNO_CPU_EXTENSIONS to cflags if RDTSC is not desired
io.write([[# NOTE: THIS FILE IS AUTOGENERATED BY cfg_wmake.lua!
# DON'T EDIT IT MANUALLY!
cflags_generic = -s -q -otexanh -oe -d0 -6s -za99 -bm -Iinclude
cflags = $(cflags_generic) -bt=nt -DUSE_WINTHREADS
cflags_dos32 = $(cflags_generic) -bt=DOS -DNOTHREADS -DNO_POSIX
cc = wcc386
lnk = wcl386
appsrcdir = apps
srcdir = src
objdir = obj
objdir_dos32 = dos32
bindir = bin
libdir = lib
dll_runtime = $(%WATCOM)/lib386/dos/clib3s.lib
dos32_runtime = $(%WATCOM)/lib386/dos/doslfn3s.lib
includedir = include/smokerand
gen_bindir = $(bindir)\\generators
gen_srcdir = generators
]])
-- Prepare list of library core headers
local lib_headers_str = "include/smokerand_core.h "
for _, v in pairs(lib_headers) do
lib_headers_str = lib_headers_str .. " $(includedir)/" .. v
end
io.write("lib_headers = " .. lib_headers_str .. "\n")
-- Make "all" section
local all_section = "all: $(bindir)/sr_dos32.exe $(bindir)/srtiny16.exe $(bindir)/setvesa.com "
for _, fname in pairs(exefiles) do
all_section = all_section .. "$(bindir)/" .. fname .. ".exe "
end
io.write(all_section .. "\n")
--[[
io.write("all: $(bindir)/smokerand.exe $(bindir)/sr_speed.exe $(bindir)/sr_dos32.exe " ..
"$(bindir)/test_funcs.exe $(bindir)/test_syscrypto.exe $(bindir)/srtiny16.exe " ..
"$(bindir)/find_xorshift_params.exe " ..
"$(bindir)/setvesa.com &\n")
--]]
local gen_all_sources = {}
for _, e in pairs(gen_sources) do table.insert(gen_all_sources, e) end
for _, e in pairs(gen_asm_sources) do table.insert(gen_all_sources, e) end
for i = 1, #gen_all_sources do
local dllfile = "$(gen_bindir)/" .. gen_all_sources[i] .. ".dll "
io.write(dllfile)
if i % 3 == 0 and i ~= #gen_all_sources then
io.write(" &\n ")
end
end
io.write("\n")
io.write("dos: $(bindir)/sr_dos32.exe $(bindir)/srtiny16.exe\n")
-- Make the program executable
-- a) Line with dependencies
local sources = {}
for _, v in pairs(lib_sources) do
table.insert(sources, v)
end
for _, v in pairs(bat_sources) do
table.insert(sources, v)
end
table.insert(sources, "smokerand.c")
local objstr, objstr_dos32, objstr_genexec = "", "", ""
for _, v in pairs(sources) do
objstr = objstr .. " $(objdir)/" .. v:gsub("%.c", ".obj")
objstr_dos32 = objstr_dos32 .. " $(objdir_dos32)/" .. v:gsub("%.c", ".obj")
if v ~= "smokerand.c" then
objstr_genexec = objstr_genexec .. " $(objdir)/" .. v:gsub("%.c", ".obj")
end
end
objstr_dos32 = objstr_dos32 .. " $(objdir_dos32)/pe32loader.obj"
-- b) Line with commands
for _, fname in pairs(exefiles) do
local objstr_fname = "$(objdir)/" .. fname .. ".obj " .. objstr_genexec;
io.write("$(bindir)/" .. fname .. ".exe: " .. objstr_fname .. "\n")
io.write("\twcl386 -4s -fe=$(bindir)/" .. fname .. ".exe " .. objstr_fname .. "\n")
end
-- b1) Special cases
io.write("$(bindir)/sr_dos32.exe:" .. objstr_dos32 .. "\n")
io.write("\twcl386 -4s -fe=$(bindir)/sr_dos32.exe -bcl=" .. dosextender ..
" $(dos32_runtime) " .. objstr_dos32 .. "\n")
---------- Object file with the main() function ----------
for _, fname in pairs(exefiles) do
io.write("$(objdir)/" .. fname .. ".obj: $(appsrcdir)/" .. fname .. ".c $(lib_headers)\n")
io.write("\twcc386 $(cflags) -fo=$(objdir)/" .. fname .. ".obj $(appsrcdir)/" .. fname .. ".c\n")
end
-- Some special cases
io.write("$(objdir_dos32)/smokerand.obj: $(appsrcdir)/smokerand.c $(lib_headers)\n")
io.write("\twcc386 $(cflags_dos32) -fo=$(objdir_dos32)/smokerand.obj $(appsrcdir)/smokerand.c\n")
io.write("$(objdir_dos32)/pe32loader.obj: $(srcdir)/pe32loader.c $(lib_headers)\n")
io.write("\twcc386 $(cflags_dos32) -fo=$(objdir_dos32)/pe32loader.obj $(srcdir)/pe32loader.c\n")
---------- Compile the 16-bit version ----------
io.write("$(bindir)/srtiny16.exe: $(objdir_dos32)/srtiny16.obj $(objdir_dos32)/spfunc16.obj\n")
io.write("\twcl -s -q -mc -otexanh $(objdir_dos32)/srtiny16.obj $(objdir_dos32)/spfunc16.obj " ..
"-fe=$(bindir)/srtiny16.exe\n")
io.write("$(objdir_dos32)/srtiny16.obj: $(appsrcdir)/sr_tiny.c\n")
io.write("\twcc -s -q -mc -otexanhi $(appsrcdir)/sr_tiny.c -fo=$(objdir_dos32)/srtiny16.obj -Iinclude\n")
io.write("$(objdir_dos32)/spfunc16.obj: $(srcdir)/specfuncs.c\n")
io.write("\twcc -s -q -mc -otexanhi $(srcdir)/specfuncs.c -fo=$(objdir_dos32)/spfunc16.obj -Iinclude\n")
---------- Object files for Windows NT ----------
-- Compile the library core sources
for _, v in pairs(lib_sources) do
local cfile, objfile = "$(srcdir)/" .. v, "$(objdir)/" .. v:gsub("%.c", ".obj")
io.write(objfile .. ": " .. cfile .. " $(lib_headers)\n")
io.write("\twcc386 $(cflags) -fo=" .. objfile .. " " .. cfile .. "\n")
end
-- Compile the batteries sources
for _, v in pairs(bat_sources) do
local cfile = "$(srcdir)/" .. v
local objfile = "$(objdir)/" .. v:gsub("%.c", ".obj")
local hfile = "$(includedir)/" .. v:gsub("%.c", ".h")
io.write(objfile .. ": " .. cfile .. " " .. hfile .. " $(lib_headers)\n")
io.write("\twcc386 $(cflags) -fo=" .. objfile .. " " .. cfile .. "\n")
end
---------- Object files for DOS32 ----------
for _, v in pairs(lib_sources) do
local cfile, objfile = "$(srcdir)/" .. v, "$(objdir_dos32)/" .. v:gsub("%.c", ".obj")
io.write(objfile .. ": " .. cfile .. " $(lib_headers)\n")
io.write("\twcc386 $(cflags_dos32) -fo=" .. objfile .. " " .. cfile .. "\n")
end
-- Compile the batteries sources
for _, v in pairs(bat_sources) do
local cfile = "$(srcdir)/" .. v
local objfile = "$(objdir_dos32)/" .. v:gsub("%.c", ".obj")
local hfile = "$(includedir)/" .. v:gsub("%.c", ".h")
io.write(objfile .. ": " .. cfile .. " " .. hfile .. " $(lib_headers) \n")
io.write("\twcc386 $(cflags_dos32) -fo=" .. objfile .. " " .. cfile .. "\n")
end
---------- Compile the generators ----------
-- A simple hack for compiling without RUNTIME.
-- wcc386 -s -d0 -bm -bt=nt -6s -za99 generators/lcg69069.c -Iinclude -fo=lcg69069.obj
-- wcl386 lcg69069.obj d:/watcom/lib386/dos/clib3s.lib -fe=lcg69069.dll -q -6s -bd -bcl=nt_dll
for _, g in pairs(gen_sources) do
local cfile = "$(gen_srcdir)/" .. g .. ".c"
local objfile = "$(gen_bindir)/obj/" .. g .. ".obj"
local dllfile = "$(gen_bindir)/" .. g .. ".dll"
--dllstr = dllstr .. dllfile
io.write(objfile .. ": " .. cfile .. " $(lib_headers)\n")
io.write("\twcc386 $(cflags) " .. cfile .. " -Iinclude -fo=" .. objfile .. "\n")
io.write(dllfile .. ": " .. objfile .. "\n")
io.write("\twcl386 " .. objfile .. " $(dll_runtime) -fe=" .. dllfile ..
" -q -bd -bcl=nt_dll -\"OPTION NODEFAULTLIBS\"\n")
end
---------- Compile the generators written in x86 assembly language ----------
for _, g in pairs(gen_asm_sources) do
local dllfile = "$(gen_bindir)/" .. g .. ".dll"
local objfile = "$(gen_bindir)/obj/" .. g .. ".obj"
local asmfile = "$(gen_srcdir)/asm/" .. g .. ".asm"
io.write(dllfile .. ": " .. objfile .. "\n")
io.write("\twcl386 " .. objfile .. " -bcl=nt_dll -fe=" .. dllfile .. "\n")
io.write(objfile .. ": " .. asmfile .. " $(gen_srcdir)/asm/consts.inc\n")
io.write("\twasm " .. asmfile .. " -fo=" .. objfile .."\n")
end
---------- Compile some utilities written in x86 assembly language ----------
io.write("$(bindir)/setvesa.com: $(objdir)/setvesa.obj\n")
io.write("\twcl -q $(objdir)/setvesa.obj -fe=$(bindir)/setvesa.exe\n")
io.write("\texe2bin -q $(bindir)/setvesa.exe $(bindir)/setvesa.com\n")
io.write("\tdel $(bindir)\\setvesa.exe\n")
io.write("$(objdir)/setvesa.obj: $(appsrcdir)/setvesa.asm\n")
io.write("\twasm -q $(appsrcdir)/setvesa.asm -fo=$(objdir)/setvesa.obj\n")
-- Make "clean" section
io.write("clean: .SYMBOLIC\n")
io.write("\tdel $(bindir)\\smokerand.exe\n")
io.write("\tdel $(bindir)\\sr_dos32.exe\n")
io.write("\tdel $(bindir)\\sr_speed.exe\n")
io.write("\tdel $(bindir)\\srtiny16.exe\n")
io.write("\tdel $(bindir)\\test_crypto.exe\n")
io.write("\tdel $(bindir)\\test_funcs.exe\n")
io.write("\tdel $(objdir)\\*.obj\n")
io.write("\tdel $(gen_bindir)\\obj\\*.obj\n")
io.write("\tdel $(gen_bindir)\\*.dll\n")
-- Finish the work
io.close(file)
io.output(io.stdout)
print("Success")