| 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 |
require 5.004; |
|---|
| 54 |
|
|---|
| 55 |
use strict 'vars'; |
|---|
| 56 |
use vars qw($dir_prfx $exp_file $gmake $sub_objdir); |
|---|
| 57 |
use vars qw(@basic_libs @extra_libs @includes); |
|---|
| 58 |
use vars qw(%VARS); |
|---|
| 59 |
|
|---|
| 60 |
use File::Basename; |
|---|
| 61 |
use File::Copy; |
|---|
| 62 |
use Getopt::Long; |
|---|
| 63 |
use Text::Wrap qw(wrap $columns); |
|---|
| 64 |
|
|---|
| 65 |
$columns = 76; |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
my $path; |
|---|
| 69 |
|
|---|
| 70 |
BEGIN { |
|---|
| 71 |
$path = (fileparse("$0"))[1]; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
use lib($path); |
|---|
| 75 |
use InstallOps; |
|---|
| 76 |
use SourceList; |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
sub printHelp(); |
|---|
| 80 |
sub findSources($$); |
|---|
| 81 |
sub readSources($); |
|---|
| 82 |
sub printObjMakefile($$@); |
|---|
| 83 |
sub printAppMakefile($$$); |
|---|
| 84 |
sub printMultiAppMakefile($$$); |
|---|
| 85 |
sub printAppMakefileStart_in($$); |
|---|
| 86 |
sub printAppObjs_in($$$); |
|---|
| 87 |
sub printAppSuffixRules_in($$); |
|---|
| 88 |
sub printAppMakefileEnd_in($;@); |
|---|
| 89 |
sub expandAll($); |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
my $app = ''; |
|---|
| 93 |
my %apps = (); |
|---|
| 94 |
my $dotin = 1; |
|---|
| 95 |
my $gmake = 0; |
|---|
| 96 |
my $heading = ''; |
|---|
| 97 |
my $help = 0; |
|---|
| 98 |
my @srcdirs = (); |
|---|
| 99 |
my @subdirs = (); |
|---|
| 100 |
my @nosrcs = (); |
|---|
| 101 |
|
|---|
| 102 |
$dir_prfx = ''; |
|---|
| 103 |
$sub_objdir = ''; |
|---|
| 104 |
@basic_libs = (); |
|---|
| 105 |
@extra_libs = (); |
|---|
| 106 |
@includes = (); |
|---|
| 107 |
|
|---|
| 108 |
my @saved_ARGV = @ARGV; |
|---|
| 109 |
|
|---|
| 110 |
GetOptions('app=s' => \$app, 'apps=s' => \%apps, 'basiclibs=s' => \@basic_libs, |
|---|
| 111 |
'dirprefix=s' => \$dir_prfx, 'dotin!' => \$dotin, |
|---|
| 112 |
'expfile=s' => \$exp_file, 'extralibs=s' => \@extra_libs, |
|---|
| 113 |
'gmake' => \$gmake, 'heading=s' => \$heading, 'help' => \$help, |
|---|
| 114 |
'includes=s' => \@includes, 'nosrcs=s' => \@nosrcs, |
|---|
| 115 |
'srcdir=s' => \@srcdirs, 'subdirs=s' => \@subdirs, |
|---|
| 116 |
'subobjdir=s' => \$sub_objdir) |
|---|
| 117 |
or printHelp() && exit(1); |
|---|
| 118 |
|
|---|
| 119 |
printHelp() && exit(0) if $help; |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
@basic_libs = split(/,/, join(',', @basic_libs)); |
|---|
| 124 |
@extra_libs = split(/,/, join(',', @extra_libs)); |
|---|
| 125 |
@includes = split(/,/, join(',', @includes)); |
|---|
| 126 |
@nosrcs = split(/,/, join(',', @nosrcs)); |
|---|
| 127 |
@srcdirs = split(/,/, join(',', @srcdirs)); |
|---|
| 128 |
@subdirs = split(/,/, join(',', @subdirs)); |
|---|
| 129 |
|
|---|
| 130 |
my $all_src = findSources(\@srcdirs, \@nosrcs); |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
my $makefile_name = 'Makefile'; |
|---|
| 135 |
$makefile_name .= ".in" if $dotin; |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
open(MAKEFILE, "> $makefile_name") |
|---|
| 139 |
or die "ERROR: Could not create $makefile_name: $!\n"; |
|---|
| 140 |
|
|---|
| 141 |
if ( $heading ) |
|---|
| 142 |
{ |
|---|
| 143 |
if ( open(HEADING, "$heading") ) |
|---|
| 144 |
{ |
|---|
| 145 |
print MAKEFILE while <HEADING>; |
|---|
| 146 |
close(HEADING); |
|---|
| 147 |
} |
|---|
| 148 |
else |
|---|
| 149 |
{ |
|---|
| 150 |
warn "WARNING: Could not read from heading file $heading: $!\n"; |
|---|
| 151 |
} |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
print MAKEFILE "# Generated by mkmakefile.pl using the following options:\n"; |
|---|
| 156 |
print MAKEFILE wrap("# ", "# ", @saved_ARGV), "\n\n"; |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
if ( $app ) |
|---|
| 160 |
{ |
|---|
| 161 |
printAppMakefile(MAKEFILE, $all_src, "$app"); |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
elsif ( keys(%apps) ) |
|---|
| 165 |
{ |
|---|
| 166 |
printMultiAppMakefile(MAKEFILE, $all_src, \%apps); |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
else |
|---|
| 170 |
{ |
|---|
| 171 |
printObjMakefile(MAKEFILE, $all_src, @subdirs); |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
close(MAKEFILE) or warn "WARNING: Could not close $makefile_name: $!\n"; |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
expandAll($makefile_name) unless $dotin; |
|---|
| 178 |
|
|---|
| 179 |
exit(0); |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
sub printHelp() |
|---|
| 189 |
{ |
|---|
| 190 |
print <<EOF; |
|---|
| 191 |
Usage: |
|---|
| 192 |
$0 |
|---|
| 193 |
[ --app=<name> | --apps <name1>=<srcs1> [ --apps <name2>=<srcs2> ... ]] |
|---|
| 194 |
[ --basiclibs=<lib1> [...] ] [ --dirprefix=<prefix> ] |
|---|
| 195 |
[ --dotin | --nodotin --expfile=<file> ] [ --extralibs=<lib1> [...] ] |
|---|
| 196 |
[ --gmake ] [ --heading=<file> ] [ --includes=<option> [...] ] |
|---|
| 197 |
[ --nosrcs=<file1> [...] ] [ --srcdir=<dirs> [...] ] |
|---|
| 198 |
[ --subdirs=<dirs> [...] ] [ --subobjdir=<dir> ] |
|---|
| 199 |
|
|---|
| 200 |
For application makefiles: |
|---|
| 201 |
|
|---|
| 202 |
--app=<name> |
|---|
| 203 |
Specify the name of the application to be compiled. |
|---|
| 204 |
|
|---|
| 205 |
or |
|---|
| 206 |
|
|---|
| 207 |
--apps <name1>=<srcs1> --apps <name2>=<srcs2> ... --apps <nameN>=<srcsN> |
|---|
| 208 |
Specify the names of multiple applications and the lists of source |
|---|
| 209 |
files that will be compiled for each application. |
|---|
| 210 |
|
|---|
| 211 |
--basiclibs=<lib1> --basliclibs=<lib2> ... --basiclibs=<libN> |
|---|
| 212 |
Provide additional basic libraries that should be linked. These |
|---|
| 213 |
are in addition to the default basic libraries linked. Typically, |
|---|
| 214 |
these are optional libraries built as part of the system being |
|---|
| 215 |
compiled needed for a specific application. |
|---|
| 216 |
|
|---|
| 217 |
--extralibs=<lib1> --basliclibs=<lib2> ... --extralibs=<libN> |
|---|
| 218 |
Provide additional extra libraries that should be linked. These |
|---|
| 219 |
are in addition to the default extra libraries linked. Typically, |
|---|
| 220 |
these are optional system libraries needed for a specific application. |
|---|
| 221 |
|
|---|
| 222 |
--gmake |
|---|
| 223 |
Use GNU make features. |
|---|
| 224 |
|
|---|
| 225 |
--srcdir=<dirs1> --srcdir=<dirs2> ... --srcdir=<dirsN> |
|---|
| 226 |
Give a list of directories besides the current directory where |
|---|
| 227 |
source files will be found. Each directory can be given as an |
|---|
| 228 |
argument to a separate --srcdir option, or they can all be passed |
|---|
| 229 |
to a single --srcdir option as a comma-separated list (no spaces). |
|---|
| 230 |
|
|---|
| 231 |
For object makefiles: |
|---|
| 232 |
|
|---|
| 233 |
--dirprefix=<prefix> |
|---|
| 234 |
Name a prefix for the directory containing the source files. |
|---|
| 235 |
|
|---|
| 236 |
--subdirs=<dirs1> --subdirs=<dirs2> ... --subdirs=<dirsN> |
|---|
| 237 |
Give a list of subdirectories of the current directory where the |
|---|
| 238 |
build must recurse. Each subdirectory can be given as an argument |
|---|
| 239 |
to a separate --subdirs option, or they can all be passed to a |
|---|
| 240 |
single --subdirs option as a comma-separated list (no spaces). |
|---|
| 241 |
|
|---|
| 242 |
--subobjdir=<dir> |
|---|
| 243 |
Name the subdirectory of \$(OBJDIR) where the object files will go. |
|---|
| 244 |
|
|---|
| 245 |
For all types of makefiles: |
|---|
| 246 |
|
|---|
| 247 |
--dotin (default) |
|---|
| 248 |
Generate Makefile.in |
|---|
| 249 |
|
|---|
| 250 |
or |
|---|
| 251 |
|
|---|
| 252 |
--nodotin --expfile=<Perl file> |
|---|
| 253 |
Generate a fully expanded Makefile using the \%VARS hash in the |
|---|
| 254 |
file named as the argument to --expfile. |
|---|
| 255 |
|
|---|
| 256 |
--heading=<file> |
|---|
| 257 |
Print the contents of the given file at the top of the generated |
|---|
| 258 |
makefile before anything else is written. |
|---|
| 259 |
|
|---|
| 260 |
--includes=-I<path1> --includes=-I<path2> ... --includes=-I<pathN> |
|---|
| 261 |
Extend the include path to use the specified additional options. |
|---|
| 262 |
The options must be specified using the compiler option that |
|---|
| 263 |
extends the include path. Each option can be given as an argument |
|---|
| 264 |
to a separate --includes option, or they can all be passed to a |
|---|
| 265 |
single --includes option as a comma-separated list (no spaces). |
|---|
| 266 |
|
|---|
| 267 |
--nosrcs=<file1> --nosrcs=<file2> ... --nosrcs=<fileN> |
|---|
| 268 |
List files that should be excluded when preparing the source list. |
|---|
| 269 |
Each file can be given as an argument to a separate --nosrcs option, |
|---|
| 270 |
or they can all be passed to a single --nosrcs option as a |
|---|
| 271 |
comma-separated list (no spaces). Any paths used must be the same |
|---|
| 272 |
as used for --srcdir. |
|---|
| 273 |
EOF |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
sub findSources($$) |
|---|
| 280 |
{ |
|---|
| 281 |
my @dirs = @{$_[0]}; |
|---|
| 282 |
my @nosrcs = @{$_[1]}; |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
my $found_dot = 0; |
|---|
| 287 |
|
|---|
| 288 |
foreach ( @dirs ) |
|---|
| 289 |
{ |
|---|
| 290 |
if ( "$_" eq "." ) |
|---|
| 291 |
{ |
|---|
| 292 |
$found_dot = 1; |
|---|
| 293 |
last; |
|---|
| 294 |
} |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|
| 297 |
push(@dirs, ".") unless $found_dot; |
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
my $srcs = new SourceList(); |
|---|
| 302 |
my $dir; |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
foreach $dir ( @dirs ) |
|---|
| 306 |
{ |
|---|
| 307 |
next if $srcs->hasDirectory("$dir"); |
|---|
| 308 |
$srcs->readSources("$dir", @nosrcs) |
|---|
| 309 |
or warn "Failed to read sources in $dir\n"; |
|---|
| 310 |
} |
|---|
| 311 |
|
|---|
| 312 |
return $srcs; |
|---|
| 313 |
} |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
sub printObjMakefile($$@) |
|---|
| 320 |
{ |
|---|
| 321 |
my $handle = shift; |
|---|
| 322 |
my $srcs = shift; |
|---|
| 323 |
my @subdirs = @_; |
|---|
| 324 |
|
|---|
| 325 |
my $include_dir = '@includedir@'; |
|---|
| 326 |
$include_dir .= "/$dir_prfx" if $dir_prfx; |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
print $handle <<MK_START; |
|---|
| 331 |
default: all |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
includedir = $include_dir |
|---|
| 337 |
srcdir = \@srcdir\@ |
|---|
| 338 |
top_srcdir = \@top_srcdir\@ |
|---|
| 339 |
INSTALL = \@INSTALL\@ |
|---|
| 340 |
MK_START |
|---|
| 341 |
|
|---|
| 342 |
print $handle "EXTRA_INCLUDES\t+= @includes" if @includes; |
|---|
| 343 |
|
|---|
| 344 |
my($has_objs, $has_subdirs) = (0, 0); |
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
my @src_files = $srcs->getAllFiles(); |
|---|
| 348 |
$has_objs = 1 if $#src_files > -1; |
|---|
| 349 |
|
|---|
| 350 |
print $handle "SUBOBJDIR\t= $sub_objdir\n" if $sub_objdir && $has_objs; |
|---|
| 351 |
|
|---|
| 352 |
print $handle "\n"; |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
if ( $#subdirs > -1 ) |
|---|
| 356 |
{ |
|---|
| 357 |
$has_subdirs = 1; |
|---|
| 358 |
print $handle "DIRPRFX\t= $dir_prfx/\n\n" if $dir_prfx; |
|---|
| 359 |
|
|---|
| 360 |
print $handle "# Subdirectories to compile.\n"; |
|---|
| 361 |
print $handle "SUBDIR\t="; |
|---|
| 362 |
|
|---|
| 363 |
foreach ( @subdirs ) |
|---|
| 364 |
{ |
|---|
| 365 |
print $handle " $_" unless "$_" eq "." ; |
|---|
| 366 |
} |
|---|
| 367 |
|
|---|
| 368 |
print $handle "\n\n"; |
|---|
| 369 |
} |
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
if ( $has_objs ) |
|---|
| 373 |
{ |
|---|
| 374 |
print $handle "SRCS\t= ", join(' ', sort(@src_files)), "\n"; |
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
my @other_dirs = $srcs->getDirectories(); |
|---|
| 380 |
if ( $#other_dirs > 0 ) |
|---|
| 381 |
{ |
|---|
| 382 |
print $handle "EXTRA_SRCS_PATH\t= ", join(' ', sort(@other_dirs)), |
|---|
| 383 |
"\n"; |
|---|
| 384 |
} |
|---|
| 385 |
|
|---|
| 386 |
print $handle "\n"; |
|---|
| 387 |
} |
|---|
| 388 |
|
|---|
| 389 |
warn "No object files found, no subdirectories listed!\n" |
|---|
| 390 |
unless $has_objs || $has_subdirs; |
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
if ( $has_objs && $has_subdirs ) |
|---|
| 395 |
{ |
|---|
| 396 |
print $handle "include \$(MKPATH)/dpp.obj-subdir.mk\n\n"; |
|---|
| 397 |
} |
|---|
| 398 |
|
|---|
| 399 |
elsif ( $has_objs ) |
|---|
| 400 |
{ |
|---|
| 401 |
print $handle "include \$(MKPATH)/dpp.obj.mk\n\n"; |
|---|
| 402 |
} |
|---|
| 403 |
|
|---|
| 404 |
elsif ( $has_subdirs ) |
|---|
| 405 |
{ |
|---|
| 406 |
print $handle "\$(RECTARGET): recursive\n\n"; |
|---|
| 407 |
print $handle "include \$(MKPATH)/dpp.subdir.mk\n\n"; |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
if ( $has_objs ) |
|---|
| 413 |
{ |
|---|
| 414 |
print $handle <<MK_END; |
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
ifndef DO_CLEANDEPEND |
|---|
| 419 |
-include \$(DEPEND_FILES) |
|---|
| 420 |
endif |
|---|
| 421 |
MK_END |
|---|
| 422 |
} |
|---|
| 423 |
} |
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
sub printAppMakefile($$$) |
|---|
| 430 |
{ |
|---|
| 431 |
my $handle = shift; |
|---|
| 432 |
my $srcs = shift; |
|---|
| 433 |
my $app = shift; |
|---|
| 434 |
|
|---|
| 435 |
print $handle "default: $app\@EXEEXT\@\n\n"; |
|---|
| 436 |
|
|---|
| 437 |
printAppMakefileStart_in($handle, $srcs); |
|---|
| 438 |
printAppObjs_in($handle, 'OBJS', $srcs); |
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
print $handle <<MK_END; |
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
$app\@EXEEXT\@: \$(OBJS) |
|---|
| 446 |
\$(LINK) \@EXE_NAME_FLAG\@ \$(OBJS) \$(BASIC_LIBS) \$(EXTRA_LIBS) |
|---|
| 447 |
|
|---|
| 448 |
MK_END |
|---|
| 449 |
|
|---|
| 450 |
printAppSuffixRules_in($handle, $srcs); |
|---|
| 451 |
printAppMakefileEnd_in($handle, "$app"); |
|---|
| 452 |
} |
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
sub printMultiAppMakefile($$$) |
|---|
| 460 |
{ |
|---|
| 461 |
my $handle = shift; |
|---|
| 462 |
my $srcs = shift; |
|---|
| 463 |
my %apps = %{$_[0]}; |
|---|
| 464 |
|
|---|
| 465 |
print $handle "default: all\n\n"; |
|---|
| 466 |
|
|---|
| 467 |
printAppMakefileStart_in($handle, $srcs); |
|---|
| 468 |
|
|---|
| 469 |
my @cur_srcs = (); |
|---|
| 470 |
my @all_apps = sort(keys(%apps)); |
|---|
| 471 |
my $app; |
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
foreach $app ( @all_apps ) |
|---|
| 476 |
{ |
|---|
| 477 |
@cur_srcs = split(/,/, "$apps{$app}"); |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
my $cur_app_src = new SourceList(@cur_srcs); |
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
my $file; |
|---|
| 484 |
foreach $file ( @cur_srcs ) |
|---|
| 485 |
{ |
|---|
| 486 |
|
|---|
| 487 |
my $dir = $srcs->findFile("$file"); |
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
if ( $dir ) |
|---|
| 492 |
{ |
|---|
| 493 |
$cur_app_src->insertFile("$file", "$dir"); |
|---|
| 494 |
} |
|---|
| 495 |
|
|---|
| 496 |
else |
|---|
| 497 |
{ |
|---|
| 498 |
warn "WARING: Could not find file $file!\n"; |
|---|
| 499 |
} |
|---|
| 500 |
} |
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
printAppObjs_in($handle, "${app}_OBJS", $cur_app_src); |
|---|
| 504 |
} |
|---|
| 505 |
|
|---|
| 506 |
print $handle <<EOF; |
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
EOF |
|---|
| 511 |
|
|---|
| 512 |
print $handle "all:"; |
|---|
| 513 |
|
|---|
| 514 |
foreach ( @all_apps ) |
|---|
| 515 |
{ |
|---|
| 516 |
print $handle " $_\@EXEEXT\@"; |
|---|
| 517 |
} |
|---|
| 518 |
|
|---|
| 519 |
print $handle "\n\n"; |
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
foreach ( @all_apps ) |
|---|
| 524 |
{ |
|---|
| 525 |
print $handle <<MK_END; |
|---|
| 526 |
$_\@EXEEXT\@: \$(${_}_OBJS) |
|---|
| 527 |
\$(LINK) \@EXE_NAME_FLAG\@ \$(${_}_OBJS) \$(BASIC_LIBS) \$(EXTRA_LIBS) |
|---|
| 528 |
|
|---|
| 529 |
MK_END |
|---|
| 530 |
} |
|---|
| 531 |
|
|---|
| 532 |
printAppSuffixRules_in($handle, $srcs); |
|---|
| 533 |
printAppMakefileEnd_in($handle, @all_apps); |
|---|
| 534 |
} |
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
sub printAppMakefileStart_in($$) |
|---|
| 541 |
{ |
|---|
| 542 |
my $handle = shift; |
|---|
| 543 |
my $srcs = shift; |
|---|
| 544 |
|
|---|
| 545 |
my @dirs = sort($srcs->getDirectories()); |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
my $inc_line = '@APP_INCLUDES@'; |
|---|
| 549 |
$inc_line .= " @includes" if @includes; |
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
foreach ( @dirs ) |
|---|
| 553 |
{ |
|---|
| 554 |
if ( "$_" eq "." ) |
|---|
| 555 |
{ |
|---|
| 556 |
$inc_line .= ' -I$(srcdir)'; |
|---|
| 557 |
} |
|---|
| 558 |
else |
|---|
| 559 |
{ |
|---|
| 560 |
$inc_line .= " -I\$(srcdir)/$_"; |
|---|
| 561 |
} |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
print $handle <<MK_START; |
|---|
| 565 |
|
|---|
| 566 |
srcdir = \@srcdir\@ |
|---|
| 567 |
CFLAGS = \@APP_CFLAGS\@ \$(EXTRA_CFLAGS) \$(INCLUDES) \$(DEFS) |
|---|
| 568 |
CXXFLAGS = \@APP_CXXFLAGS\@ \$(EXTRA_CFLAGS) \$(INCLUDES) \$(DEFS) |
|---|
| 569 |
DEFS = \@APP_DEFS\@ |
|---|
| 570 |
EXTRA_CFLAGS = \@APP_EXTRA_CFLAGS\@ \$(DEBUG_CFLAGS) |
|---|
| 571 |
DEBUG_CFLAGS = \@APP_DEBUG_CFLAGS\@ |
|---|
| 572 |
OPTIM_CFLAGS = \@APP_OPTIM_CFLAGS\@ |
|---|
| 573 |
INCLUDES = $inc_line |
|---|
| 574 |
|
|---|
| 575 |
EXTRA_LFLAGS = \@APP_EXTRA_LFLAGS\@ \$(DEBUG_LFLAGS) |
|---|
| 576 |
DEBUG_LFLAGS = \@APP_DEBUG_LFLAGS\@ |
|---|
| 577 |
OPTIM_LFLAGS = \@APP_OPTIM_LFLAGS\@ |
|---|
| 578 |
LINK_FLAGS = \@APP_LINK_FLAGS\@ \$(EXTRA_LFLAGS) |
|---|
| 579 |
LINKALL_ON = \@APP_LINKALL_ON\@ |
|---|
| 580 |
LINKALL_OFF = \@APP_LINKALL_OFF\@ |
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
BASIC_LIBS = \@APP_BASIC_LIBS_BEGIN\@ \@APP_BASIC_LIBS\@ @basic_libs \@APP_BASIC_EXT_LIBS\@ \@APP_BASIC_LIBS_END\@ |
|---|
| 584 |
EXTRA_LIBS = \@APP_EXTRA_LIBS_BEGIN\@ \@APP_EXTRA_LIBS\@ @extra_libs \@APP_EXTRA_LIBS_END\@ |
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
C_COMPILE = \@APP_CC\@ \$(CFLAGS) |
|---|
| 588 |
CXX_COMPILE = \@APP_CXX\@ \$(CXXFLAGS) |
|---|
| 589 |
LINK = \@APP_LINK\@ \$(LINK_FLAGS) |
|---|
| 590 |
|
|---|
| 591 |
MK_START |
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
if ( $gmake ) |
|---|
| 596 |
{ |
|---|
| 597 |
my($suffix, $dir); |
|---|
| 598 |
foreach $suffix ( $srcs->getSuffixes() ) |
|---|
| 599 |
{ |
|---|
| 600 |
print $handle 'vpath %', "$suffix "; |
|---|
| 601 |
|
|---|
| 602 |
foreach $dir ( @dirs ) |
|---|
| 603 |
{ |
|---|
| 604 |
if ( $srcs->hasSuffix("$dir", "$suffix") ) |
|---|
| 605 |
{ |
|---|
| 606 |
if ( "$dir" eq "." ) |
|---|
| 607 |
{ |
|---|
| 608 |
print $handle '$(srcdir) '; |
|---|
| 609 |
} |
|---|
| 610 |
else |
|---|
| 611 |
{ |
|---|
| 612 |
print $handle "\$(srcdir)/$dir "; |
|---|
| 613 |
} |
|---|
| 614 |
} |
|---|
| 615 |
} |
|---|
| 616 |
|
|---|
| 617 |
print $handle "\n"; |
|---|
| 618 |
} |
|---|
| 619 |
} |
|---|
| 620 |
else |
|---|
| 621 |
{ |
|---|
| 622 |
print $handle "VPATH\t= \@srcdir\@"; |
|---|
| 623 |
|
|---|
| 624 |
foreach ( @dirs ) |
|---|
| 625 |
{ |
|---|
| 626 |
print $handle ":\@srcdir\@/$_" if "$_" ne "."; |
|---|
| 627 |
} |
|---|
| 628 |
} |
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 |
print $handle "\n\n"; |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
sub printAppObjs_in($$$) |
|---|
| 640 |
{ |
|---|
| 641 |
my($handle, $obj_var, $srcs) = @_; |
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
my $files = join(' ', sort($srcs->getAllFiles())); |
|---|
| 645 |
$files =~ s/\.(cpp|cxx|c\+\+|cc|c)/.\@OBJEXT\@/gi; |
|---|
| 646 |
|
|---|
| 647 |
|
|---|
| 648 |
print $handle "$obj_var\t= $files\n\n"; |
|---|
| 649 |
} |
|---|
| 650 |
|
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
sub printAppSuffixRules_in($$) |
|---|
| 656 |
{ |
|---|
| 657 |
my($handle, $srcs) = @_; |
|---|
| 658 |
|
|---|
| 659 |
my @suffixes = sort($srcs->getSuffixes()); |
|---|
| 660 |
|
|---|
| 661 |
print $handle "# Suffix rules for building object files.\n"; |
|---|
| 662 |
print $handle ".SUFFIXES: ", join(' ', @suffixes), " .\@OBJEXT\@\n\n"; |
|---|
| 663 |
|
|---|
| 664 |
|
|---|
| 665 |
foreach ( @suffixes ) |
|---|
| 666 |
{ |
|---|
| 667 |
print $handle "$_.\@OBJEXT\@:\n"; |
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
if ( "$_" eq ".c" ) |
|---|
| 671 |
{ |
|---|
| 672 |
print $handle "\t\$(C_COMPILE) \@OBJ_NAME_FLAG\@ \@OBJ_BUILD_FLAG\@ \$<\n\n"; |
|---|
| 673 |
} |
|---|
| 674 |
|
|---|
| 675 |
else |
|---|
| 676 |
{ |
|---|
| 677 |
print $handle "\t\$(CXX_COMPILE) \@OBJ_NAME_FLAG\@ \@OBJ_BUILD_FLAG\@ \$<\n\n"; |
|---|
| 678 |
} |
|---|
| 679 |
} |
|---|
| 680 |
} |
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 |
sub printAppMakefileEnd_in($;@) |
|---|
| 686 |
{ |
|---|
| 687 |
my $handle = shift; |
|---|
| 688 |
my @apps = @_; |
|---|
| 689 |
|
|---|
| 690 |
my($dirt, $cruft) = ('', ''); |
|---|
| 691 |
foreach ( @_ ) |
|---|
| 692 |
{ |
|---|
| 693 |
$dirt .= "$_\@EXEEXT\@ "; |
|---|
| 694 |
$cruft .= "$_.ilk "; |
|---|
| 695 |
} |
|---|
| 696 |
|
|---|
| 697 |
print $handle <<MK_END; |
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
clean: |
|---|
| 702 |
rm -f Makedepend *.\@OBJEXT\@ $cruft so_locations *.?db core* |
|---|
| 703 |
rm -rf ii_files |
|---|
| 704 |
|
|---|
| 705 |
clobber: |
|---|
| 706 |
\@\$(MAKE) clean |
|---|
| 707 |
rm -f $dirt |
|---|
| 708 |
MK_END |
|---|
| 709 |
} |
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 |
|
|---|
| 713 |
|
|---|
| 714 |
sub expandAll($) |
|---|
| 715 |
{ |
|---|
| 716 |
my $filename = shift; |
|---|
| 717 |
|
|---|
| 718 |
|
|---|
| 719 |
require "$exp_file" if $exp_file; |
|---|
| 720 |
|
|---|
| 721 |
warn "WARNING: No expansion values!\n" unless keys(%VARS) && $exp_file; |
|---|
| 722 |
|
|---|
| 723 |
replaceTags("$filename", %VARS); |
|---|
| 724 |
} |
|---|