master hovercats/oakiss / pkg / strace / gen.lua
  1local targets = {
  2	aarch64={
  3		cflags={'-D AARCH64=1'},
  4		ioctls=1,
  5	},
  6	riscv64={
  7		cflags={'-D RISCV64=1'},
  8		ioctls=0,
  9	},
 10	x86_64={
 11		cflags={'-D X86_64=1'},
 12		ioctls=2,
 13	},
 14}
 15local arch = config.target.platform:match('[^-]*')
 16local targ = targets[arch]
 17if not targ then return end
 18
 19cflags{
 20	'-D HAVE_CONFIG_H',
 21	'-D IN_STRACE',
 22	-- it is important that the arch-specific directory is searched first
 23	'-I $srcdir/src/linux/'..arch,
 24	'-I $srcdir/src/linux/generic',
 25	'-I $srcdir/src',
 26	'-I $outdir',
 27	'-isystem $builddir/pkg/linux-headers/include',
 28}
 29cflags(targ.cflags)
 30
 31build('cat', '$outdir/config.h', {
 32	'$builddir/probe/HAVE___BUILTIN_POPCOUNT',
 33	'$dir/config.h',
 34})
 35
 36build('cpp', '$outdir/ioctl_iocdef.i', '$srcdir/src/ioctl_iocdef.c')
 37build('sed', '$outdir/ioctl_iocdef.h', '$outdir/ioctl_iocdef.i', {
 38	expr=[[-n 's/^DEFINE HOST/#define /p']],
 39})
 40
 41sub('tools.ninja', function()
 42	toolchain(config.host)
 43	cflags{
 44		'-I $srcdir/src/linux/'..arch,
 45		'-I $srcdir/src/linux',
 46		'-I $outdir',
 47	}
 48	cflags(targ.cflags)
 49
 50	for i = 0, targ.ioctls do
 51		build('cat', '$outdir/ioctls_all'..i..'.h', {
 52			'$srcdir/src/linux/'..arch..'/ioctls_inc'..i..'.h',
 53			'$srcdir/src/linux/'..arch..'/ioctls_arch'..i..'.h',
 54		})
 55		build('cc', '$outdir/ioctlsort'..i..'.c.o', {
 56			'$srcdir/src/ioctlsort.c',
 57			'|', '$outdir/ioctl_iocdef.h', '$srcdir/ioctls_zfs.h', '$outdir/ioctls_all'..i..'.h',
 58		}, {cflags=string.format([[$cflags -D 'IOCTLSORT_INC="ioctls_all%d.h"']], i)})
 59		exe('ioctlsort'..i, {'ioctlsort'..i..'.c.o'})
 60		rule('ioctlsort'..i, '$outdir/ioctlsort'..i..' >$out')
 61		build('ioctlsort'..i, '$outdir/ioctlent'..i..'.h', {'|', '$outdir/ioctlsort'..i})
 62	end
 63end)
 64
 65local mpers = lines('mpers.txt')
 66for _, f in ipairs(mpers) do
 67	build('cpp', '$outdir/'..f..'.mpers.i', {'$srcdir/src/'..f, '|', '$outdir/config.h'}, {
 68		cflags='$cflags -DIN_MPERS_BOOTSTRAP',
 69	})
 70end
 71
 72local function makempers(name, script)
 73	build('awk', '$outdir/'..name, {expand{'$outdir/', mpers, '.mpers.i'}, '|', '$dir/'..script}, {
 74		expr='-f $dir/'..script,
 75	})
 76end
 77
 78makempers('printers.h', 'printers.awk')
 79makempers('native_printer_decls.h', 'printerdecls.awk')
 80makempers('native_printer_defs.h', 'printerdefs.awk')
 81
 82build('cpp', '$outdir/syscallent.i', '$srcdir/src/linux/'..arch..'/syscallent.h')
 83build('awk', '$outdir/scno-syscallent.h', {'$outdir/syscallent.i', '|', '$dir/scno.awk'}, {
 84	expr='-f $dir/scno.awk',
 85})
 86build('cat', '$outdir/scno.h', {'$srcdir/src/scno.head', '$outdir/scno-syscallent.h'})
 87
 88-- this seems to be enough syscall headers to build
 89local syscalls = expand{'$srcdir/src/linux/', {
 90	'32/syscallent.h',
 91	'64/syscallent.h',
 92	'arm/syscallent.h',
 93	'generic/subcallent.h',
 94	'generic/syscallent-common.h',
 95	'i386/syscallent.h',
 96	'riscv64/syscallent.h',
 97	'sparc/syscallent.h',
 98	'sparc64/syscallent.h',
 99	'x86_64/syscallent.h',
100}}
101build('awk', '$outdir/sen.h', {syscalls, '|', '$dir/sen.awk'}, {
102	expr='-f $dir/sen.awk',
103})
104
105local srcs = paths[[src/(
106	access.c
107	affinity.c
108	aio.c
109	alarm.c
110	alpha.c
111	basic_filters.c
112	bind.c
113	bjm.c
114	block.c
115	bpf.c
116	bpf_filter.c
117	bpf_seccomp_filter.c
118	bpf_sock_filter.c
119	btrfs.c
120	cacheflush.c
121	cachestat.c
122	capability.c
123	chdir.c
124	chmod.c
125	clone.c
126	close_range.c
127	copy_file_range.c
128	count.c
129	counter_ioctl.c
130	delay.c
131	desc.c
132	dirent.c
133	dirent64.c
134	dirent_types.c
135	dm.c
136	dup.c
137	dyxlat.c
138	epoll.c
139	epoll_ioctl.c
140	error_prints.c
141	evdev.c
142	evdev_mpers.c
143	eventfd.c
144	execve.c
145	exit.c
146	exitkill.c
147	fadvise.c
148	fallocate.c
149	fanotify.c
150	fchownat.c
151	fcntl.c
152	fetch_bpf_fprog.c
153	fetch_indirect_syscall_args.c
154	fetch_struct_flock.c
155	fetch_struct_iovec.c
156	fetch_struct_keyctl_kdf_params.c
157	fetch_struct_mmsghdr.c
158	fetch_struct_msghdr.c
159	fetch_struct_stat.c
160	fetch_struct_stat64.c
161	fetch_struct_statfs.c
162	fetch_struct_xfs_quotastat.c
163	file_attr.c
164	file_handle.c
165	filter_qualify.c
166	filter_seccomp.c
167	flock.c
168	fs_0x15_ioctl.c
169	fs_0x94_ioctl.c
170	fs_f_ioctl.c
171	fs_x_ioctl.c
172	fsconfig.c
173	fsmount.c
174	fsopen.c
175	fspick.c
176	fstatfs.c
177	fstatfs64.c
178	futex.c
179	futex2.c
180	gen/gen_hdio.c
181	get_personality.c
182	get_robust_list.c
183	getcpu.c
184	getcwd.c
185	getpagesize.c
186	getpid.c
187	getrandom.c
188	gpio_ioctl.c
189	hdio.c
190	hostname.c
191	inotify.c
192	inotify_ioctl.c
193	io.c
194	io_uring.c
195	ioctl.c
196	ioperm.c
197	iopl.c
198	ioprio.c
199	ipc.c
200	ipc_msg.c
201	ipc_msgctl.c
202	ipc_sem.c
203	ipc_semctl.c
204	ipc_shm.c
205	ipc_shmctl.c
206	kcmp.c
207	kd_ioctl.c
208	kd_mpers_ioctl.c
209	kexec.c
210	keyctl.c
211	kvm.c
212	landlock.c
213	ldt.c
214	link.c
215	lirc_ioctl.c
216	listen.c
217	listmount.c
218	listns.c
219	lookup_dcookie.c
220	loop.c
221	lseek.c
222	lsm.c
223	map_shadow_stack.c
224	mem.c
225	membarrier.c
226	memfd_create.c
227	memfd_secret.c
228	mknod.c
229	mmap_cache.c
230	mmap_notify.c
231	mmsghdr.c
232	mount.c
233	mount_setattr.c
234	move_mount.c
235	mq.c
236	msghdr.c
237	mtd.c
238	nbd_ioctl.c
239	net.c
240	netlink.c
241	netlink_crypto.c
242	netlink_generic.c
243	netlink_inet_diag.c
244	netlink_kobject_uevent.c
245	netlink_netfilter.c
246	netlink_netlink_diag.c
247	netlink_nlctrl.c
248	netlink_packet_diag.c
249	netlink_route.c
250	netlink_selinux.c
251	netlink_smc_diag.c
252	netlink_sock_diag.c
253	netlink_unix_diag.c
254	nice.c
255	nlattr.c
256	nsfs.c
257	numa.c
258	number_set.c
259	oldstat.c
260	open.c
261	or1k_atomic.c
262	pathtrace.c
263	perf.c
264	perf_ioctl.c
265	personality.c
266	pidfd_getfd.c
267	pidfd_open.c
268	pidns.c
269	pkeys.c
270	poke.c
271	poll.c
272	prctl.c
273	print_dev_t.c
274	print_group_req.c
275	print_ifindex.c
276	print_instruction_pointer.c
277	print_kernel_sigset.c
278	print_kernel_version.c
279	print_mac.c
280	print_mq_attr.c
281	print_msgbuf.c
282	print_sg_req_info.c
283	print_sigevent.c
284	print_statfs.c
285	print_struct_stat.c
286	print_syscall_number.c
287	print_time.c
288	print_timespec32.c
289	print_timespec64.c
290	print_timeval.c
291	print_timeval64.c
292	print_timex.c
293	printmode.c
294	printrusage.c
295	printsiginfo.c
296	process_vm.c
297	ptp.c
298	ptrace.c
299	ptrace_syscall_info.c
300	quota.c
301	random_ioctl.c
302	readahead.c
303	readlink.c
304	reboot.c
305	regset.c
306	renameat.c
307	resource.c
308	retval.c
309	riscv.c
310	rt_sigframe.c
311	rt_sigreturn.c
312	rtc.c
313	rtnl_addr.c
314	rtnl_addrlabel.c
315	rtnl_cachereport.c
316	rtnl_dcb.c
317	rtnl_link.c
318	rtnl_mdb.c
319	rtnl_neigh.c
320	rtnl_neightbl.c
321	rtnl_netconf.c
322	rtnl_nh.c
323	rtnl_nsid.c
324	rtnl_route.c
325	rtnl_rule.c
326	rtnl_stats.c
327	rtnl_tc.c
328	rtnl_tc_action.c
329	s390.c
330	sched.c
331	scsi.c
332	seccomp.c
333	seccomp_ioctl.c
334	sendfile.c
335	set_tid_address.c
336	sg_io_v3.c
337	sg_io_v4.c
338	shutdown.c
339	sigaltstack.c
340	signal.c
341	signalfd.c
342	sigreturn.c
343	sock.c
344	sockaddr.c
345	socketcall.c
346	socketutils.c
347	sparc.c
348	sram_alloc.c
349	stage_output.c
350	stat.c
351	stat64.c
352	statfs.c
353	statfs64.c
354	statmount.c
355	statx.c
356	strauss.c
357	string_to_uint.c
358	swapon.c
359	sync_file_range.c
360	sync_file_range2.c
361	syscall.c
362	syscall_name.c
363	sysctl.c
364	sysinfo.c
365	syslog.c
366	sysmips.c
367	tee.c
368	term.c
369	time.c
370	times.c
371	trie.c
372	truncate.c
373	ubi.c
374	ucopy.c
375	uid.c
376	uid16.c
377	umask.c
378	umount.c
379	uname.c
380	upeek.c
381	upoke.c
382	userfaultfd.c
383	ustat.c
384	util.c
385	utime.c
386	utimes.c
387	v4l2.c
388	wait.c
389	watchdog_ioctl.c
390	xattr.c
391	xgetdents.c
392	xlat.c
393	xmalloc.c
394)]]
395
396build('sed', '$outdir/sys_func.h', expand{'$srcdir/', srcs}, {
397	expr=[[-n 's/^SYS_FUNC(.*/extern &;/p']],
398})
399
400pkg.deps = {
401	'$outdir/config.h',
402	'$outdir/native_printer_decls.h',
403	'$outdir/native_printer_defs.h',
404	'$outdir/printers.h',
405	'$outdir/scno.h',
406	'$outdir/sen.h',
407	'$outdir/sys_func.h',
408	'pkg/linux-headers/headers',
409}
410
411for i = 0, targ.ioctls do
412	table.insert(pkg.deps, '$outdir/ioctlent'..i..'.h')
413end
414
415lib('libstrace.a', srcs)
416exe('strace', {'src/strace.c', 'libstrace.a'})
417file('bin/strace', '755', '$outdir/strace')
418
419build('sed', '$outdir/strace.1', '$srcdir/doc/strace.1.in', {
420	expr={
421		[[-e 's,@STRACE_MANPAGE_DATE@,2025-11-13,']],
422		[[-e 's,@VERSION@,6.19,']],
423		[[-e 's,@ENABLE_STACKTRACE_TRUE@,#,']],
424		[[-e 's,@ENABLE_STACKTRACE_FALSE@,,']],
425		[[-e 's,@ENABLE_SECONTEXT_TRUE@,#,']],
426		[[-e 's,@ENABLE_SECONTEXT_FALSE@,,']],
427	},
428})
429man{'$outdir/strace.1'}
430
431fetch 'curl'