Commit | Line | Data |
ee5feabd |
1 | #!/usr/bin/env perl |
2 | # |
3 | |
4 | open XS, "< sdl_words.txt" or die "could not open sdl_words.txt\n"; |
5 | open CPP, "| cpp `sdl-config --cflags` - > SDL.cx" or die "Could not pipe to cpp, $!\n"; |
6 | |
7 | print CPP <<HEADER; |
8 | #include <SDL.h> |
9 | #define TEXT_SOLID 1 |
10 | #define TEXT_SHADED 2 |
11 | #define TEXT_BLENDED 4 |
12 | #define UTF8_SOLID 8 |
13 | #define UTF8_SHADED 16 |
14 | #define UTF8_BLENDED 32 |
15 | #define UNICODE_SOLID 64 |
16 | #define UNICODE_SHADED 128 |
17 | #define UNICODE_BLENDED 256 |
18 | |
19 | --cut-- |
20 | HEADER |
21 | |
22 | while (<XS>) { |
23 | chomp(); |
24 | print CPP "#$_ $_\n"; |
25 | $words{$_} = 0; |
26 | } |
27 | |
28 | close XS; |
29 | close CPP; |
30 | |
31 | # |
32 | # ENUMS AREN'T CPPed we got to do this the hard way |
33 | # |
34 | |
35 | open FP, "> sdl_const.c" or die "Could not write to sdl__const.c\n"; |
36 | |
37 | print FP <<HERE; |
38 | #include <SDL.h> |
39 | #include <SDL_image.h> |
40 | #include <SDL_mixer.h> |
41 | #include <SDL_ttf.h> |
42 | #include <SDL_net.h> |
43 | #include <smpeg/smpeg.h> |
44 | #define TEXT_SOLID 1 |
45 | #define TEXT_SHADED 2 |
46 | #define TEXT_BLENDED 4 |
47 | #define UTF8_SOLID 8 |
48 | #define UTF8_SHADED 16 |
49 | #define UTF8_BLENDED 32 |
50 | #define UNICODE_SOLID 64 |
51 | #define UNICODE_SHADED 128 |
52 | #define UNICODE_BLENDED 256 |
53 | |
54 | int |
55 | main ( int argc, char **argv ) { |
56 | |
57 | HERE |
58 | |
59 | for ( grep { $words{$_} == 0 } keys %words ) { |
60 | print FP <<THERE; |
61 | fprintf(stdout,"sub main::$_ { \%i }\n", $_); |
62 | THERE |
63 | |
64 | } |
65 | |
66 | print FP <<HERE; |
67 | } |
68 | HERE |
69 | |
70 | system("gcc `sdl-config --cflags --libs` -o sdl_const sdl_const.c"); |
71 | |
72 | my $enums; |
73 | open ENUMS, "./sdl_const |"; |
74 | { |
75 | local $/ = undef; |
76 | $enums = <ENUMS>; |
77 | } |
78 | close ENUMS; |
79 | |
80 | $goodstuff .= "\n$enums"; |
81 | |
82 | for ( split "\n", $goodstuff ) { |
83 | if (/sub\s+main::([A-Za-z0-9_]+)/) { |
84 | $words{$1} = 1; |
85 | } |
86 | } |
87 | |
88 | for (keys %words) { |
89 | print STDERR "Failed to find $_\n" unless $words{$_}; |
90 | } |
91 | |
92 | (@words) = grep { $words{$_} == 1 } keys %words; |
93 | |
94 | $words = join(" ",@words); |
95 | |
96 | open CONST, "> ../lib/SDL/Constants.pm"; |
97 | |
98 | print CONST <<HERE; |
99 | # SDL::Constants |
100 | # |
101 | # This is an automatically generated file, don't bother editing. |
102 | # Names are read from a list in sdl_words.txt and written by sdl_const.pl. |
103 | # |
104 | # Copyright (C) 2003 David J. Goehrig <dave\@sdlperl.org> |
105 | # |
106 | |
107 | package SDL::Constants; |
108 | |
109 | $goodstuff |
110 | |
111 | 1; |
112 | |
113 | HERE |
114 | |
115 | system("rm -f SDL.cx sdl_const sdl_const.c"); |