Fixed the pod path in archive
[sdlgit/SDL_perl.git] / scripts / sdl_const.pl
CommitLineData
ee5feabd 1#!/usr/bin/env perl
2#
3
4open XS, "< sdl_words.txt" or die "could not open sdl_words.txt\n";
5open CPP, "| cpp `sdl-config --cflags` - > SDL.cx" or die "Could not pipe to cpp, $!\n";
6
7print 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--
20HEADER
21
22while (<XS>) {
23 chomp();
24 print CPP "#$_ $_\n";
25 $words{$_} = 0;
26}
27
28close XS;
29close CPP;
30
31#
32# ENUMS AREN'T CPPed we got to do this the hard way
33#
34
35open FP, "> sdl_const.c" or die "Could not write to sdl__const.c\n";
36
37print 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
54int
55main ( int argc, char **argv ) {
56
57HERE
58
59for ( grep { $words{$_} == 0 } keys %words ) {
60 print FP <<THERE;
61 fprintf(stdout,"sub main::$_ { \%i }\n", $_);
62THERE
63
64}
65
66print FP <<HERE;
67}
68HERE
69
70system("gcc `sdl-config --cflags --libs` -o sdl_const sdl_const.c");
71
72my $enums;
73open ENUMS, "./sdl_const |";
74{
75 local $/ = undef;
76 $enums = <ENUMS>;
77}
78close ENUMS;
79
80$goodstuff .= "\n$enums";
81
82for ( split "\n", $goodstuff ) {
83 if (/sub\s+main::([A-Za-z0-9_]+)/) {
84 $words{$1} = 1;
85 }
86}
87
88for (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
96open CONST, "> ../lib/SDL/Constants.pm";
97
98print 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
107package SDL::Constants;
108
109$goodstuff
110
1111;
112
113HERE
114
115system("rm -f SDL.cx sdl_const sdl_const.c");