File: make_single_file

package info (click to toggle)
libtoxcore 0.2.20-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,124 kB
  • sloc: ansic: 75,034; cpp: 4,933; sh: 1,115; python: 651; makefile: 329; perl: 39
file content (59 lines) | stat: -rwxr-xr-x 1,544 bytes parent folder | download
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
#!/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;