2 ######################################################################
3 # Do not call this script directly!
5 # The generate script ensures that @INC is correct before the engine
8 # Copyright (C) 2009 Marius Storm-Olsen <mstormo@gmail.com>
9 ######################################################################
15 die "No file provided!" if !defined $file;
17 my ($cflags, $target, $type, $line);
19 open(F
, "<$file") || die "Couldn't open file $file";
23 while (my $text = shift @data) {
29 chop $text if ($text =~ /\r$/);
39 handleCompileLine
($text, $line);
41 } elsif ($text =~ / -o /) {
43 handleLinkLine
($text, $line);
45 } elsif ($text =~ /\.o / && $text =~ /\.a /) {
47 handleLibLine
($text, $line);
49 # } elsif ($text =~ /^cp /) {
52 # } elsif ($text =~ /^rm -f /) {
55 # } elsif ($text =~ /^make[ \[]/) {
58 # } elsif ($text =~ /^echo /) {
61 # } elsif ($text =~ /^if /) {
64 # } elsif ($text =~ /^tclsh /) {
67 # } elsif ($text =~ /^umask /) {
68 # # handling boilerplates
70 # } elsif ($text =~ /\$\(\:\)/) {
73 # } elsif ($text =~ /^FLAGS=/) {
74 # # flags check for dependencies
76 # } elsif ($text =~ /^'\/usr\/bin\/perl' -MError -e/) {
77 # # perl commands for copying files
79 # } elsif ($text =~ /generate-cmdlist\.sh/) {
80 # # command for generating list of commands
82 # } elsif ($text =~ /^test / && $text =~ /|| rm -f /) {
83 # # commands removing executables, if they exist
85 # } elsif ($text =~ /new locations or Tcl/) {
86 # # command for detecting Tcl/Tk changes
88 # } elsif ($text =~ /mkdir -p/) {
89 # # command creating path
91 # } elsif ($text =~ /: no custom templates yet/) {
95 # print "Unhandled (line: $line): $text\n";
101 # print "Parsed build structure:\n";
102 # print Dumper(%build_structure);
104 # -------------------------------------------------------------------
105 # Functions under here
106 # -------------------------------------------------------------------
107 my (%build_structure, @defines, @incpaths, @cflags, @sources);
119 my (%dupHash, $entry);
120 %dupHash = map { $_, 1 } @defines;
121 @defines = keys %dupHash;
123 %dupHash = map { $_, 1 } @incpaths;
124 @incpaths = keys %dupHash;
126 %dupHash = map { $_, 1 } @cflags;
127 @cflags = keys %dupHash;
129 %dupHash = map { $_, 1 } @sources;
130 @sources = keys %dupHash;
133 sub handleCompileLine
135 my ($line, $lineno) = @_;
136 my @parts = split(' ', $line);
137 shift(@parts); # ignore cmd
138 while (my $part = shift @parts) {
139 if ("$part" eq "-o") {
142 } elsif ("$part" eq "-c") {
143 # ignore compile flag
144 } elsif ("$part" eq "-c") {
145 } elsif ($part =~ /^.?-I/) {
146 push(@incpaths, $part);
147 } elsif ($part =~ /^.?-D/) {
148 push(@defines, $part);
149 } elsif ($part =~ /^-/) {
150 push(@cflags, $part);
151 } elsif ($part =~ /\.(c|cc|cpp)$/) {
152 push(@sources, $part);
154 die "Unhandled compiler option @ line $lineno: $part";
157 #print "Sources: @sources\nCFlags: @cflags\nDefine: @defines\nIncpat: @incpaths\n";
163 my ($line, $lineno) = @_;
164 my (@objfiles, @lflags, $libout, $part);
165 # kill cmd and rm 'prefix'
166 $line =~ s/^rm -f .* && .* rcs //;
167 my @parts = split(' ', $line);
168 while ($part = shift @parts) {
170 push(@lflags, $part);
171 } elsif ($part =~ /\.(o|obj)$/) {
172 push(@objfiles, $part);
173 } elsif ($part =~ /\.(a|lib)$/) {
176 die "Unhandled lib option @ line $lineno: $part";
179 #print "LibOut: '$libout'\nLFlags: @lflags\nOfiles: @objfiles\n";
182 push(@
{$build_structure{"LIBS"}}, $libout);
183 @
{$build_structure{"LIBS_${libout}"}} = ("_DEFINES", "_INCLUDES", "_CFLAGS", "_SOURCES",
185 @
{$build_structure{"LIBS_${libout}_DEFINES"}} = @defines;
186 @
{$build_structure{"LIBS_${libout}_INCLUDES"}} = @incpaths;
187 @
{$build_structure{"LIBS_${libout}_CFLAGS"}} = @cflags;
188 @
{$build_structure{"LIBS_${libout}_SOURCES"}} = @sources;
189 @
{$build_structure{"LIBS_${libout}_OBJECTS"}} = @objfiles;
195 my ($line, $lineno) = @_;
196 my (@objfiles, @lflags, @libs, $appout, $part);
197 my @parts = split(' ', $line);
198 shift(@parts); # ignore cmd
199 while ($part = shift @parts) {
200 if ($part =~ /^-[GRIDO]/) {
202 } elsif ("$part" eq "-o") {
203 $appout = shift @parts;
204 } elsif ($part =~ /^-/) {
205 push(@lflags, $part);
206 } elsif ($part =~ /\.(a|lib)$/) {
208 } elsif ($part =~ /\.(o|obj)$/) {
209 push(@objfiles, $part);
211 die "Unhandled lib option @ line $lineno: $part";
214 #print "AppOut: '$appout'\nLFlags: @lflags\nLibs : @libs\nOfiles: @objfiles\n";
217 push(@
{$build_structure{"APPS"}}, $appout);
218 @
{$build_structure{"APPS_${appout}"}} = ("_DEFINES", "_INCLUDES", "_CFLAGS", "_LFLAGS",
219 "_SOURCES", "_OBJECTS", "_LIBS");
220 @
{$build_structure{"APPS_${appout}_DEFINES"}} = @defines;
221 @
{$build_structure{"APPS_${appout}_INCLUDES"}} = @incpaths;
222 @
{$build_structure{"APPS_${appout}_CFLAGS"}} = @cflags;
223 @
{$build_structure{"APPS_${appout}_LFLAGS"}} = @lflags;
224 @
{$build_structure{"APPS_${appout}_SOURCES"}} = @sources;
225 @
{$build_structure{"APPS_${appout}_OBJECTS"}} = @objfiles;
226 @
{$build_structure{"APPS_${appout}_LIBS"}} = @libs;