blob: 7f93f168dfd8d73f2aebc9b895b01f91f065876a [file] [log] [blame]
Reid Spencerb195d9d2006-03-23 23:21:29 +00001#!@PERL@
Chris Lattner584073a2006-06-02 18:58:21 +00002##===- tools/llvm-config ---------------------------------------*- perl -*-===##
3#
4# The LLVM Compiler Infrastructure
Reid Spencerf2722ca2006-03-22 15:59:55 +00005#
Chris Lattner234d5292007-12-29 22:59:10 +00006# This file is distributed under the University of Illinois Open Source
7# License. See LICENSE.TXT for details.
Chris Lattner584073a2006-06-02 18:58:21 +00008#
9##===----------------------------------------------------------------------===##
Reid Spencerf2722ca2006-03-22 15:59:55 +000010#
11# Synopsis: Prints out compiler options needed to build against an installed
12# copy of LLVM.
13#
Chris Lattner7f71e212006-04-13 04:21:31 +000014# Syntax: llvm-config OPTIONS... [COMPONENTS...]
Chris Lattner584073a2006-06-02 18:58:21 +000015#
16##===----------------------------------------------------------------------===##
Reid Spencerf2722ca2006-03-22 15:59:55 +000017
Reid Spencerb195d9d2006-03-23 23:21:29 +000018use 5.006;
Reid Spencerf2722ca2006-03-22 15:59:55 +000019use strict;
20use warnings;
21
22#---- begin autoconf values ----
Reid Spencer2d2c2f22006-06-02 18:31:41 +000023my $PACKAGE_NAME = q{@PACKAGE_NAME@};
Reid Spencerf2722ca2006-03-22 15:59:55 +000024my $VERSION = q{@PACKAGE_VERSION@};
25my $PREFIX = q{@LLVM_PREFIX@};
Reid Spencer2d2c2f22006-06-02 18:31:41 +000026my $LLVM_CONFIGTIME = q{@LLVM_CONFIGTIME@};
27my $LLVM_SRC_ROOT = q{@abs_top_srcdir@};
28my $LLVM_OBJ_ROOT = q{@abs_top_builddir@};
Reid Spencerf2722ca2006-03-22 15:59:55 +000029my $ARCH = lc(q{@ARCH@});
Reid Spencer2d2c2f22006-06-02 18:31:41 +000030my $TARGET_TRIPLE = q{@target@};
31my $TARGETS_TO_BUILD = q{@TARGETS_TO_BUILD@};
Reid Spencerb195d9d2006-03-23 23:21:29 +000032my $TARGET_HAS_JIT = q{@TARGET_HAS_JIT@};
Reid Spencerf2722ca2006-03-22 15:59:55 +000033my @TARGETS_BUILT = map { lc($_) } qw{@TARGETS_TO_BUILD@};
34#---- end autoconf values ----
35
Jeff Cohen02c91ef2007-03-28 04:45:02 +000036# Must pretend x86_64 architecture is really x86, otherwise the native backend
37# won't get linked in.
38$ARCH = "x86" if $ARCH eq "x86_64";
39
Reid Spencerf2722ca2006-03-22 15:59:55 +000040#---- begin Makefile values ----
David Greenea696d242007-06-28 19:36:08 +000041my $CPPFLAGS = q{@LLVM_CPPFLAGS@};
Reid Spencerf72538e2007-01-06 02:48:03 +000042my $CFLAGS = q{@LLVM_CFLAGS@};
Reid Spencerf2722ca2006-03-22 15:59:55 +000043my $CXXFLAGS = q{@LLVM_CXXFLAGS@};
44my $LDFLAGS = q{@LLVM_LDFLAGS@};
Reid Spencer1bc68642006-07-27 23:00:30 +000045my $SYSTEM_LIBS = q{@LIBS@};
Chris Lattnerabdbae72006-06-02 19:13:29 +000046my $LLVM_BUILDMODE = q{@LLVM_BUILDMODE@};
Reid Spencerf2722ca2006-03-22 15:59:55 +000047#---- end Makefile values ----
48
Chris Lattner16ad6182006-06-02 21:48:10 +000049# Figure out where llvm-config is being run from. Primarily, we care if it has
50# been installed, or is running from the build directory, which changes the
51# locations of some files.
52
Chris Lattnere02b97b2006-06-02 01:23:18 +000053# Convert the current executable name into its directory (e.g. ".").
Chris Lattner16ad6182006-06-02 21:48:10 +000054my ($RUN_DIR) = ($0 =~ /^(.*)\/.*$/);
55
Tanya Lattnere32d58f2008-11-04 21:06:11 +000056# Find the unix pwd program: we don't want to use the bash builtin, as it does
57# not look through symlinks etc.
58my $PWD = `which pwd`;
59chomp($PWD);
60$PWD = "pwd" if (!-e $PWD);
61
Chris Lattner16ad6182006-06-02 21:48:10 +000062# Turn the directory into an absolute directory on the file system, also pop up
63# from "bin" into the build or prefix dir.
Tanya Lattnere32d58f2008-11-04 21:06:11 +000064my $ABS_RUN_DIR = `cd $RUN_DIR/..; $PWD`;
65chomp($ABS_RUN_DIR);
Chris Lattner16ad6182006-06-02 21:48:10 +000066
67# Compute the absolute object directory build, e.g. "foo/llvm/Debug".
Chris Lattner3e347f22006-06-06 23:54:15 +000068my $ABS_OBJ_ROOT = "$LLVM_OBJ_ROOT/$LLVM_BUILDMODE";
Tanya Lattnere32d58f2008-11-04 21:06:11 +000069$ABS_OBJ_ROOT = `cd $ABS_OBJ_ROOT; $PWD` if (-d $ABS_OBJ_ROOT);
70chomp($ABS_OBJ_ROOT);
Chris Lattner16ad6182006-06-02 21:48:10 +000071
Chris Lattner0cd059e2006-06-02 22:03:50 +000072my $INCLUDEDIR = "$ABS_RUN_DIR/include";
Jeffrey Yasskin9a3b13f2009-07-07 22:15:37 +000073my $INCLUDEOPTION = "-I$INCLUDEDIR";
Chris Lattner0cd059e2006-06-02 22:03:50 +000074my $LIBDIR = "$ABS_RUN_DIR/lib";
75my $BINDIR = "$ABS_RUN_DIR/bin";
Chris Lattner16ad6182006-06-02 21:48:10 +000076if ($ABS_RUN_DIR eq $ABS_OBJ_ROOT) {
77 # If we are running out of the build directory, the include dir is in the
78 # srcdir.
79 $INCLUDEDIR = "$LLVM_SRC_ROOT/include";
Jeffrey Yasskin9a3b13f2009-07-07 22:15:37 +000080 # We need include files from both the srcdir and objdir.
81 $INCLUDEOPTION = "-I$INCLUDEDIR -I$LLVM_OBJ_ROOT/include"
Chris Lattner16ad6182006-06-02 21:48:10 +000082} else {
Chris Lattner0cd059e2006-06-02 22:03:50 +000083 # If installed, ignore the prefix the tree was configured with, use the
84 # current prefix.
85 $PREFIX = $ABS_RUN_DIR;
Chris Lattner16ad6182006-06-02 21:48:10 +000086}
Chris Lattnere02b97b2006-06-02 01:23:18 +000087
Reid Spencerf2722ca2006-03-22 15:59:55 +000088sub usage;
89sub fix_library_names (@);
Chris Lattnerd179de52006-06-06 22:38:29 +000090sub fix_library_files (@);
Reid Spencerd8c20a92006-08-03 21:45:35 +000091sub expand_dependencies (@);
Reid Spencerf2722ca2006-03-22 15:59:55 +000092sub name_map_entries;
93
94# Parse our command-line arguments.
95usage if @ARGV == 0;
96my @components;
97my $has_opt = 0;
98my $want_libs = 0;
99my $want_libnames = 0;
Chris Lattnerd179de52006-06-06 22:38:29 +0000100my $want_libfiles = 0;
Reid Spencerf2722ca2006-03-22 15:59:55 +0000101my $want_components = 0;
102foreach my $arg (@ARGV) {
103 if ($arg =~ /^-/) {
104 if ($arg eq "--version") {
105 $has_opt = 1; print "$VERSION\n";
106 } elsif ($arg eq "--prefix") {
107 $has_opt = 1; print "$PREFIX\n";
108 } elsif ($arg eq "--bindir") {
Chris Lattner16ad6182006-06-02 21:48:10 +0000109 $has_opt = 1; print "$BINDIR\n";
Reid Spencerf2722ca2006-03-22 15:59:55 +0000110 } elsif ($arg eq "--includedir") {
Chris Lattner16ad6182006-06-02 21:48:10 +0000111 $has_opt = 1; print "$INCLUDEDIR\n";
Reid Spencerf2722ca2006-03-22 15:59:55 +0000112 } elsif ($arg eq "--libdir") {
Chris Lattner16ad6182006-06-02 21:48:10 +0000113 $has_opt = 1; print "$LIBDIR\n";
David Greenea696d242007-06-28 19:36:08 +0000114 } elsif ($arg eq "--cppflags") {
Jeffrey Yasskin9a3b13f2009-07-07 22:15:37 +0000115 $has_opt = 1; print "$INCLUDEOPTION $CPPFLAGS\n";
Reid Spencerf72538e2007-01-06 02:48:03 +0000116 } elsif ($arg eq "--cflags") {
Jeffrey Yasskin9a3b13f2009-07-07 22:15:37 +0000117 $has_opt = 1; print "$INCLUDEOPTION $CFLAGS\n";
Reid Spencerf2722ca2006-03-22 15:59:55 +0000118 } elsif ($arg eq "--cxxflags") {
Jeffrey Yasskin9a3b13f2009-07-07 22:15:37 +0000119 $has_opt = 1; print "$INCLUDEOPTION $CXXFLAGS\n";
Reid Spencerf2722ca2006-03-22 15:59:55 +0000120 } elsif ($arg eq "--ldflags") {
Reid Spencer1bc68642006-07-27 23:00:30 +0000121 $has_opt = 1; print "-L$LIBDIR $LDFLAGS $SYSTEM_LIBS\n";
Reid Spencerf2722ca2006-03-22 15:59:55 +0000122 } elsif ($arg eq "--libs") {
123 $has_opt = 1; $want_libs = 1;
124 } elsif ($arg eq "--libnames") {
125 $has_opt = 1; $want_libnames = 1;
Chris Lattnerd179de52006-06-06 22:38:29 +0000126 } elsif ($arg eq "--libfiles") {
127 $has_opt = 1; $want_libfiles = 1;
Reid Spencerf2722ca2006-03-22 15:59:55 +0000128 } elsif ($arg eq "--components") {
129 $has_opt = 1; print join(' ', name_map_entries), "\n";
130 } elsif ($arg eq "--targets-built") {
131 $has_opt = 1; print join(' ', @TARGETS_BUILT), "\n";
Reid Spencer3b87d6a2007-04-22 05:05:36 +0000132 } elsif ($arg eq "--host-target") {
133 $has_opt = 1; print "$TARGET_TRIPLE\n";
Chris Lattner0cd059e2006-06-02 22:03:50 +0000134 } elsif ($arg eq "--build-mode") {
135 $has_opt = 1; print "$LLVM_BUILDMODE\n";
136 } elsif ($arg eq "--obj-root") {
Tanya Lattnere32d58f2008-11-04 21:06:11 +0000137 $has_opt = 1; print `cd $LLVM_OBJ_ROOT/; $PWD`;
Chris Lattner0cd059e2006-06-02 22:03:50 +0000138 } elsif ($arg eq "--src-root") {
Tanya Lattnere32d58f2008-11-04 21:06:11 +0000139 $has_opt = 1; print `cd $LLVM_SRC_ROOT/; $PWD`;
Reid Spencerf2722ca2006-03-22 15:59:55 +0000140 } else {
141 usage();
142 }
143 } else {
144 push @components, $arg;
145 }
146}
147
148# If no options were specified, fail.
149usage unless $has_opt;
150
151# If no components were specified, default to 'all'.
152if (@components == 0) {
153 push @components, 'all';
154}
155
Chris Lattner54eae9e2006-09-04 05:35:23 +0000156# Force component names to lower case.
157@components = map lc, @components;
158
Reid Spencerf2722ca2006-03-22 15:59:55 +0000159# Handle any arguments which require building our dependency graph.
Chris Lattnerd179de52006-06-06 22:38:29 +0000160if ($want_libs || $want_libnames || $want_libfiles) {
Reid Spencerd8c20a92006-08-03 21:45:35 +0000161 my @libs = expand_dependencies(@components);
Chris Lattnerd179de52006-06-06 22:38:29 +0000162 print join(' ', fix_library_names(@libs)), "\n" if ($want_libs);
163 print join(' ', @libs), "\n" if ($want_libnames);
164 print join(' ', fix_library_files(@libs)), "\n" if ($want_libfiles);
Reid Spencerf2722ca2006-03-22 15:59:55 +0000165}
166
167exit 0;
168
169#==========================================================================
170# Support Routines
171#==========================================================================
172
173sub usage {
174 print STDERR <<__EOD__;
175Usage: llvm-config <OPTION>... [<COMPONENT>...]
176
177Get various configuration information needed to compile programs which use
178LLVM. Typically called from 'configure' scripts. Examples:
179 llvm-config --cxxflags
180 llvm-config --ldflags
Reid Spencerb195d9d2006-03-23 23:21:29 +0000181 llvm-config --libs engine bcreader scalaropts
Reid Spencerf2722ca2006-03-22 15:59:55 +0000182
183Options:
Reid Spencer087d90e2007-07-10 07:48:09 +0000184 --version Print LLVM version.
185 --prefix Print the installation prefix.
186 --src-root Print the source root LLVM was built from.
187 --obj-root Print the object root used to build LLVM.
188 --bindir Directory containing LLVM executables.
189 --includedir Directory containing LLVM headers.
190 --libdir Directory containing LLVM libraries.
191 --cppflags C preprocessor flags for files that include LLVM headers.
192 --cflags C compiler flags for files that include LLVM headers.
193 --cxxflags C++ compiler flags for files that include LLVM headers.
194 --ldflags Print Linker flags.
195 --libs Libraries needed to link against LLVM components.
196 --libnames Bare library names for in-tree builds.
197 --libfiles Fully qualified library filenames for makefile depends.
198 --components List of all possible components.
199 --targets-built List of all targets currently built.
200 --host-target Target triple used to configure LLVM.
201 --build-mode Print build mode of LLVM tree (e.g. Debug or Release).
Reid Spencerf2722ca2006-03-22 15:59:55 +0000202Typical components:
Reid Spencer087d90e2007-07-10 07:48:09 +0000203 all All LLVM libraries (default).
204 backend Either a native backend or the C backend.
205 engine Either a native JIT or a bytecode interpreter.
Reid Spencerf2722ca2006-03-22 15:59:55 +0000206__EOD__
207 exit(1);
208}
209
210# Use -lfoo instead of libfoo.a whenever possible, and add directories to
211# files which can't be found using -L.
212sub fix_library_names (@) {
213 my @libs = @_;
214 my @result;
215 foreach my $lib (@libs) {
216 # Transform the bare library name appropriately.
217 my ($basename) = ($lib =~ /^lib([^.]*)\.a/);
218 if (defined $basename) {
219 push @result, "-l$basename";
220 } else {
Chris Lattner16ad6182006-06-02 21:48:10 +0000221 push @result, "$LIBDIR/$lib";
Reid Spencerf2722ca2006-03-22 15:59:55 +0000222 }
223 }
224 return @result;
225}
226
Chris Lattnerd179de52006-06-06 22:38:29 +0000227# Turn the list of libraries into a list of files.
228sub fix_library_files(@) {
229 my @libs = @_;
230 my @result;
231 foreach my $lib (@libs) {
232 # Transform the bare library name into a filename.
233 push @result, "$LIBDIR/$lib";
234 }
235 return @result;
236}
Reid Spencerf2722ca2006-03-22 15:59:55 +0000237
238#==========================================================================
239# Library Dependency Analysis
240#==========================================================================
241# Given a few human-readable library names, find all their dependencies
242# and sort them into an order which the linker will like. If we packed
243# our libraries into fewer archives, we could make the linker do much
244# of this work for us.
245#
246# Libraries have two different types of names in this code: Human-friendly
247# "component" names entered on the command-line, and the raw file names
248# we use internally (and ultimately pass to the linker).
249#
250# To understand this code, you'll need a working knowledge of Perl 5,
251# and possibly some quality time with 'man perlref'.
252
253sub load_dependencies;
254sub build_name_map;
Reid Spencerb195d9d2006-03-23 23:21:29 +0000255sub have_native_backend;
256sub find_best_engine;
Reid Spencerf2722ca2006-03-22 15:59:55 +0000257sub expand_names (@);
258sub find_all_required_sets (@);
259sub find_all_required_sets_helper ($$@);
Reid Spencerf2722ca2006-03-22 15:59:55 +0000260
261# Each "set" contains one or more libraries which must be included as a
262# group (due to cyclic dependencies). Sets are represented as a Perl array
263# reference pointing to a list of internal library names.
264my @SETS;
265
266# Various mapping tables.
267my %LIB_TO_SET_MAP; # Maps internal library names to their sets.
268my %SET_DEPS; # Maps sets to a list of libraries they depend on.
269my %NAME_MAP; # Maps human-entered names to internal names.
270
271# Have our dependencies been loaded yet?
272my $DEPENDENCIES_LOADED = 0;
273
274# Given a list of human-friendly component names, translate them into a
275# complete set of linker arguments.
Reid Spencerd8c20a92006-08-03 21:45:35 +0000276sub expand_dependencies (@) {
Reid Spencerf2722ca2006-03-22 15:59:55 +0000277 my @libs = @_;
278 load_dependencies;
279 my @required_sets = find_all_required_sets(expand_names(@libs));
280 my @sorted_sets = topologically_sort_sets(@required_sets);
281
Chris Lattner06e752e2006-06-02 00:56:15 +0000282 # Expand the library sets into libraries.
Reid Spencerf2722ca2006-03-22 15:59:55 +0000283 my @result;
284 foreach my $set (@sorted_sets) { push @result, @{$set}; }
Chris Lattner06e752e2006-06-02 00:56:15 +0000285 return @result;
Reid Spencerf2722ca2006-03-22 15:59:55 +0000286}
287
288# Load in the raw dependency data stored at the end of this file.
289sub load_dependencies {
290 return if $DEPENDENCIES_LOADED;
291 $DEPENDENCIES_LOADED = 1;
292 while (<DATA>) {
293 # Parse our line.
Anton Korobeynikovde9c02b2006-08-04 21:52:23 +0000294 my ($libs, $deps) = /^\s*([^:]+):\s*(.*)\s*$/;
Reid Spencerf2722ca2006-03-22 15:59:55 +0000295 die "Malformed dependency data" unless defined $deps;
296 my @libs = split(' ', $libs);
297 my @deps = split(' ', $deps);
298
299 # Record our dependency data.
300 my $set = \@libs;
301 push @SETS, $set;
302 foreach my $lib (@libs) { $LIB_TO_SET_MAP{$lib} = $set; }
303 $SET_DEPS{$set} = \@deps;
304 }
305 build_name_map;
306}
307
308# Build a map converting human-friendly component names into internal
309# library names.
310sub build_name_map {
311 # Add entries for all the actual libraries.
312 foreach my $set (@SETS) {
313 foreach my $lib (sort @$set) {
314 my $short_name = $lib;
315 $short_name =~ s/^(lib)?LLVM([^.]*)\..*$/$2/;
316 $short_name =~ tr/A-Z/a-z/;
317 $NAME_MAP{$short_name} = [$lib];
318 }
319 }
320
Anton Korobeynikov3c3bc482008-08-17 13:53:59 +0000321 # Add target-specific entries
322 foreach my $target (@TARGETS_BUILT) {
323 # FIXME: Temporary, until we don't switch all targets
324 if (defined $NAME_MAP{$target.'asmprinter'}) {
Daniel Dunbar8cca8f92009-07-15 07:43:34 +0000325 $NAME_MAP{$target} = [$target.'info',
326 $target.'asmprinter',
327 $target.'codegen']
328 } else {
329 $NAME_MAP{$target} = [$target.'info',
330 $NAME_MAP{$target}[0]]
Anton Korobeynikov3c3bc482008-08-17 13:53:59 +0000331 }
Daniel Dunbarf8bd8442009-07-17 21:26:27 +0000332
333 if (defined $NAME_MAP{$target.'asmparser'}) {
334 push @{$NAME_MAP{$target}},$target.'asmparser'
335 }
Anton Korobeynikov3c3bc482008-08-17 13:53:59 +0000336 }
337
Reid Spencerf2722ca2006-03-22 15:59:55 +0000338 # Add virtual entries.
Reid Spencerb195d9d2006-03-23 23:21:29 +0000339 $NAME_MAP{'native'} = have_native_backend() ? [$ARCH] : [];
Anton Korobeynikov3c3bc482008-08-17 13:53:59 +0000340 $NAME_MAP{'nativecodegen'} = have_native_backend() ? [$ARCH.'codegen'] : [];
Reid Spencerb195d9d2006-03-23 23:21:29 +0000341 $NAME_MAP{'backend'} = have_native_backend() ? ['native'] : ['cbackend'];
342 $NAME_MAP{'engine'} = find_best_engine;
343 $NAME_MAP{'all'} = [name_map_entries]; # Must be last.
Reid Spencerf2722ca2006-03-22 15:59:55 +0000344}
345
Reid Spencerb195d9d2006-03-23 23:21:29 +0000346# Return true if we have a native backend to use.
347sub have_native_backend {
Reid Spencerf2722ca2006-03-22 15:59:55 +0000348 my %BUILT;
349 foreach my $target (@TARGETS_BUILT) { $BUILT{$target} = 1; }
Reid Spencerb195d9d2006-03-23 23:21:29 +0000350 return defined $NAME_MAP{$ARCH} && defined $BUILT{$ARCH};
351}
352
353# Find a working subclass of ExecutionEngine for this platform.
354sub find_best_engine {
355 if (have_native_backend && $TARGET_HAS_JIT) {
Reid Spencer1c070fc2006-03-24 01:10:39 +0000356 return ['jit', 'native'];
Reid Spencerf2722ca2006-03-22 15:59:55 +0000357 } else {
Reid Spencerb195d9d2006-03-23 23:21:29 +0000358 return ['interpreter'];
Reid Spencerf2722ca2006-03-22 15:59:55 +0000359 }
360}
361
362# Get all the human-friendly component names.
363sub name_map_entries {
364 load_dependencies;
365 return sort keys %NAME_MAP;
366}
367
368# Map human-readable names to internal library names.
369sub expand_names (@) {
370 my @names = @_;
371 my @result;
372 foreach my $name (@names) {
373 if (defined $LIB_TO_SET_MAP{$name}) {
374 # We've hit bottom: An actual library name.
375 push @result, $name;
376 } elsif (defined $NAME_MAP{$name}) {
377 # We've found a short name to expand.
378 push @result, expand_names(@{$NAME_MAP{$name}});
379 } else {
380 print STDERR "llvm-config: unknown component name: $name\n";
381 exit(1);
382 }
383 }
384 return @result;
385}
386
387# Given a list of internal library names, return all sets of libraries which
388# will need to be included by the linker (in no particular order).
389sub find_all_required_sets (@) {
390 my @libs = @_;
391 my %sets_added;
392 my @result;
393 find_all_required_sets_helper(\%sets_added, \@result, @libs);
394 return @result;
395}
396
397# Recursive closures are pretty broken in Perl, so we're going to separate
398# this function from find_all_required_sets and pass in the state we need
399# manually, as references. Yes, this is fairly unpleasant.
400sub find_all_required_sets_helper ($$@) {
401 my ($sets_added, $result, @libs) = @_;
402 foreach my $lib (@libs) {
403 my $set = $LIB_TO_SET_MAP{$lib};
404 next if defined $$sets_added{$set};
405 $$sets_added{$set} = 1;
406 push @$result, $set;
407 find_all_required_sets_helper($sets_added, $result, @{$SET_DEPS{$set}});
408 }
409}
410
411# Print a list of sets, with a label. Used for debugging.
412sub print_sets ($@) {
413 my ($label, @sets) = @_;
414 my @output;
415 foreach my $set (@sets) { push @output, join(',', @$set); }
416 print "$label: ", join(';', @output), "\n";
417}
418
419# Returns true if $lib is a key in $added.
420sub has_lib_been_added ($$) {
421 my ($added, $lib) = @_;
422 return defined $$added{$LIB_TO_SET_MAP{$lib}};
423}
424
425# Returns true if all the dependencies of $set appear in $added.
426sub have_all_deps_been_added ($$) {
427 my ($added, $set) = @_;
428 #print_sets(" Checking", $set);
429 #print_sets(" Wants", $SET_DEPS{$set});
430 foreach my $lib (@{$SET_DEPS{$set}}) {
431 return 0 unless has_lib_been_added($added, $lib);
432 }
433 return 1;
434}
435
436# Given a list of sets, topologically sort them using dependencies.
437sub topologically_sort_sets (@) {
438 my @sets = @_;
439 my %added;
440 my @result;
441 SCAN: while (@sets) { # We'll delete items from @sets as we go.
442 #print_sets("So far", reverse(@result));
443 #print_sets("Remaining", @sets);
444 for (my $i = 0; $i < @sets; ++$i) {
445 my $set = $sets[$i];
446 if (have_all_deps_been_added(\%added, $set)) {
447 push @result, $set;
448 $added{$set} = 1;
449 #print "Removing $i.\n";
450 splice(@sets, $i, 1);
451 next SCAN; # Restart our scan.
452 }
453 }
454 die "Can't find a library with no dependencies";
455 }
456 return reverse(@result);
457}
458
Reid Spencerf2722ca2006-03-22 15:59:55 +0000459# Our library dependency data will be added after the '__END__' token, and will
460# be read through the magic <DATA> filehandle.
461__END__