From 699ed0a112df7470e554f23561af1d78c784dc4f Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 14 Feb 2021 03:34:09 -0800 Subject: file: Use tool built for host to generate magic.mgc It turns out file has an undocumented define COMPILE_ONLY that enables building a tool to just generate the magic database with a minimal set of sources. Use that to build a tool for the host system to avoid version incompatibilities. Fixes #24. --- pkg/file/.gitignore | 1 + pkg/file/gen.lua | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pkg/file/.gitignore (limited to 'pkg') diff --git a/pkg/file/.gitignore b/pkg/file/.gitignore new file mode 100644 index 00000000..b38f5394 --- /dev/null +++ b/pkg/file/.gitignore @@ -0,0 +1 @@ +/host.ninja diff --git a/pkg/file/gen.lua b/pkg/file/gen.lua index 626b044d..b1cc4a28 100644 --- a/pkg/file/gen.lua +++ b/pkg/file/gen.lua @@ -38,8 +38,23 @@ exe('file', {'src/file.c', 'src/seccomp.c', 'libmagic.a', '$builddir/pkg/zlib/li file('bin/file', '755', '$outdir/file') man{'$outdir/file.1'} -rule('magic', 'cd $outdir && file -C -m magic') +sub('host.ninja', function() + toolchain(config.host) + cflags{ + '-I $outdir/include', + '-D HAVE_STDINT_H', + '-D HAVE_INTTYPES_H', + '-D HAVE_UNISTD_H', + '-D COMPILE_ONLY', + ([[-D 'VERSION="%s"']]):format(version), + } + set('outdir', '$outdir/host') + exe('magic', 'src/(magic.c apprentice.c encoding.c print.c funcs.c cdf_time.c)') +end) + +rule('magic', 'cd $outdir && ./host/magic magic') build('magic', '$outdir/magic.mgc', {'|', + '$outdir/host/magic', copy('$outdir/magic', '$srcdir/magic/Magdir', lines('magic.txt')), copy('$outdir/magic', '$srcdir/magic', {'Header', 'Localstuff'}), }) -- cgit v1.2.3