tomato/other/make_single_file
Green Sky b2ae9530a4 Squashed 'external/toxcore/c-toxcore/' changes from e29e185c03..f1df709b87
f1df709b87 feat: add ngc events
1b6c907235 refactor: Make event dispatch ordered by receive time.
b7f9367f6f test: Upgrade cppcheck, fix some warnings.
766e62bc89 chore: Use `pkg_search_module` directly in cmake.
00ff078f91 cleanup: Use target_link_libraries directly in cmake.
c58928cc89 chore: Add `IMPORTED_TARGET` to pkg-config packages.
895a6af122 cleanup: Remove NaCl support.
41dfb1c1c0 fix: unpack enum function names in event impl generator
447666d1a1 chore: Disable targets for cross-compilation.
572924e924 chore: Build a docker image with coverage info in it.
415cb78f5e cleanup: Some portability/warning fixes for Windows builds.
425216d9ec fix: Correct a use-after-free and fix some memory leaks.
4b1cfa3e08 refactor: Change all enum-like `#define` sequences into enums.
d3c2704fa9 chore: Fix make_single_file to support core-only.
0ce46b644e refactor: Change the `TCP_PACKET_*` defines into an enum.
22cd38ad50 adopt event impl generation tool to #2392
f31ea1088a add the event impl generation tool
4e603bb613 refactor: Use `enum-from-int` rule from tokstyle.
19d8f180d6 chore: Update github actions `uses`.
6a895be0c7 test: Make esp32 build actually try to instantiate tox.
65d09c9bfb cleanup: Remove test net support.
REVERT: e29e185c03 feat: add ngc events

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: f1df709b8792da4c0e946d826b11df77d565064d
2023-12-27 12:37:22 +01:00

60 lines
1.5 KiB
Perl
Executable File

#!/usr/bin/env perl
#
# This script can be used to create a single .c file with all of toxcore in it
# as well as your code or test file. It does not depend on any header files
# anymore, as those are emitted directly into the .c file.
#
# Example:
#
# other/make_single_file auto_tests/toxav_basic_test.c auto_tests/auto_test_support.c testing/misc_tools.c | \
# tcc -o toxav_basic_test - $(pkg-config --cflags --libs libsodium opus vpx)
#
# other/make_single_file -core auto_tests/send_message_test.c auto_tests/auto_test_support.c testing/misc_tools.c | \
# tcc -o send_message_test - $(pkg-config --cflags --libs libsodium)
use strict;
use warnings;
use Cwd 'abs_path';
sub relative_to {
my ($rel, $fn) = @_;
my @path = split "/", $rel;
pop @path;
abs_path(join "/", @path, $fn)
}
my %seen;
sub emit {
my ($fn) = @_;
return if $seen{$fn};
$seen{$fn} = 1;
open my $fh, "<", $fn or die "$fn: $!";
my $line = 1;
print "#line $line \"$fn\"\n";
while (<$fh>) {
if (/^#include "([^"]*)"/) {
emit(relative_to($fn, $1), $1);
++$line;
print "#line $line \"$fn\"\n";
} else {
print;
++$line;
}
}
}
if (@ARGV and $ARGV[0] eq "-core") {
shift @ARGV;
for my $fn (<toxcore/*.c>, <toxcore/*/*.c>, <third_party/cmp/*.c>) {
emit(abs_path $fn);
}
} else {
for my $fn (<toxav/*.c>, <toxcore/*.c>, <toxcore/*/*.c>, <toxencryptsave/*.c>, <third_party/cmp/*.c>) {
emit(abs_path $fn);
}
}
emit(abs_path $_) for @ARGV;