]> git.tdb.fi Git - builder.git/blob - source/builder.cpp
Better encapsulation of config inside Package
[builder.git] / source / builder.cpp
1 #include <fstream>
2 #include <iostream>
3 #include <msp/progress.h>
4 #include <msp/strconv.h>
5 #include <msp/strutils.h>
6 #include <msp/core/error.h>
7 #include <msp/getopt++/getopt++.h>
8 #include <msp/parser/parser.h>
9 #include <msp/path/utils.h>
10 #include <msp/time/units.h>
11 #include <msp/time/utils.h>
12 #include "action.h"
13 #include "analyzer.h"
14 #include "builder.h"
15 #include "executable.h"
16 #include "header.h"
17 #include "install.h"
18 #include "misc.h"
19 #include "objectfile.h"
20 #include "package.h"
21 #include "pkgconfig.h"
22 #include "sharedlibrary.h"
23 #include "staticlibrary.h"
24 #include "systemlibrary.h"
25 #include "virtualtarget.h"
26
27 using namespace std;
28 using namespace Msp;
29
30 Builder::Builder(int argc, char **argv):
31         analyzer(0),
32         do_build(false),
33         verbose(1),
34         chrome(false),
35         build_file("Build"),
36         jobs(1)
37 {
38         string   analyze_mode;
39         string   work_dir;
40         bool     full_paths=false;
41         unsigned max_depth=5;
42         
43         GetOpt getopt;
44         getopt.add_option('a', "analyze",    analyze_mode, GetOpt::REQUIRED_ARG);
45         getopt.add_option('b', "build",      do_build,     GetOpt::NO_ARG);
46 //      getopt.add_option('c', "clean",      clean,        GetOpt::NO_ARG);
47         getopt.add_option('f', "file",       build_file,   GetOpt::REQUIRED_ARG);
48         getopt.add_option('h', "help",       help,         GetOpt::NO_ARG);
49         getopt.add_option('j', "jobs",       jobs,         GetOpt::REQUIRED_ARG);
50         getopt.add_option('n', "dry-run",    dry_run,      GetOpt::NO_ARG);
51         getopt.add_option('v', "verbose",    verbose,      GetOpt::NO_ARG);
52         getopt.add_option('A', "conf-all",   conf_all,     GetOpt::NO_ARG);
53         getopt.add_option('B', "build-all",  build_all,    GetOpt::NO_ARG);
54         getopt.add_option('C', "chdir",      work_dir,     GetOpt::REQUIRED_ARG);
55         getopt.add_option('W', "what-if",    what_if,      GetOpt::REQUIRED_ARG);
56         getopt.add_option(     "chrome",     chrome,       GetOpt::NO_ARG);
57         getopt.add_option(     "conf-only",  conf_only,    GetOpt::NO_ARG);
58         getopt.add_option(     "full-paths", full_paths,   GetOpt::NO_ARG);
59         getopt.add_option(     "max-depth",  max_depth,    GetOpt::REQUIRED_ARG);
60         getopt(argc, argv);
61
62         if(!analyze_mode.empty())
63         {
64                 analyzer=new Analyzer(*this);
65
66                 if(analyze_mode=="deps")
67                         analyzer->set_mode(Analyzer::DEPS);
68                 else if(analyze_mode=="alldeps")
69                         analyzer->set_mode(Analyzer::ALLDEPS);
70                 else if(analyze_mode=="rebuild")
71                         analyzer->set_mode(Analyzer::REBUILD);
72                 else if(analyze_mode=="rdeps")
73                         analyzer->set_mode(Analyzer::RDEPS);
74                 else
75                         throw UsageError("Invalid analyze mode");
76
77                 analyzer->set_max_depth(max_depth);
78                 analyzer->set_full_paths(full_paths);
79         }
80         else
81                 do_build=true;
82
83         const list<string> &args=getopt.get_args();
84         for(list<string>::const_iterator i=args.begin(); i!=args.end(); ++i)
85         {
86                 unsigned equal=i->find('=');
87                 if(equal!=string::npos)
88                         cmdline_options.insert(RawOptionMap::value_type(i->substr(0, equal), i->substr(equal+1)));
89                 else
90                         cmdline_targets.push_back(*i);
91         }
92
93         if(cmdline_targets.empty())
94                 cmdline_targets.push_back("default");
95
96         if(!work_dir.empty())
97                 chdir(work_dir.c_str());
98
99         cwd=Path::getcwd();
100
101         archs.insert(StringMap::value_type("native", ""));
102         archs.insert(StringMap::value_type("arm", "arm-linux-gnu-"));
103         archs.insert(StringMap::value_type("win32", "i586-mingw32msvc-"));
104 }
105
106 /**
107 Gets a package with the specified name, possibly creating it.
108
109 @param   n  Package name
110
111 @return  Pointer to the package, or 0 if the package could not be located
112 */
113 Package *Builder::get_package(const string &n)
114 {
115         PackageMap::iterator i=packages.find(n);
116         if(i!=packages.end())
117                 return i->second;
118
119         // Try to get source directory with pkgconfig
120         list<string> argv;
121         argv.push_back("pkg-config");
122         argv.push_back("--variable=source");
123         argv.push_back(n);
124         string srcdir=strip(run_command(argv));
125         
126         PathList dirs;
127         if(!srcdir.empty())
128                 dirs.push_back(srcdir);
129
130         // Make some other guesses about the source directory
131         string dirname=n;
132         if(!dirname.compare(0, 3, "msp"))
133                 dirname.erase(0, 3);
134         dirs.push_back(cwd/dirname);
135         dirs.push_back(cwd/".."/dirname);
136
137         // Go through the candidate directories and look for a Build file
138         for(PathList::iterator j=dirs.begin(); j!=dirs.end(); ++j)
139                 if(!load_build_file(*j/"Build"))
140                 {
141                         i=packages.find(n);
142                         if(i!=packages.end())
143                                 return i->second;
144                         break;
145                 }
146
147         // Package source not found - create a binary package
148         Package *pkg=Package::create(*this, n);
149         packages.insert(PackageMap::value_type(n, pkg));
150         if(pkg)
151                 new_pkgs.push_back(pkg);
152
153         return pkg;
154 }
155
156 /**
157 Returns the target with the given name, or 0 if no such target exists.
158 */
159 Target *Builder::get_target(const string &n)
160 {
161         TargetMap::iterator i=targets.find(n);
162         if(i!=targets.end())
163                 return i->second;
164         return 0;
165 }
166
167 /**
168 Tries to locate a header included from a given location and with a given include
169 path.  Considers known targets as well as existing files.  If a matching target
170 is not found but a file exists, a new SystemHeader target will be created and
171 returned.
172 */
173 Target *Builder::get_header(const string &include, const string &from, const list<string> &path)
174 {
175         string hash(8, 0);
176         update_hash(hash, from);
177         for(list<string>::const_iterator i=path.begin(); i!=path.end(); ++i)
178                 update_hash(hash, *i);
179
180         string id=hash+include;
181         TargetMap::iterator i=includes.find(id);
182         if(i!=includes.end())
183                 return i->second;
184
185         string fn=include.substr(1);
186         Target *tgt=0;
187         if(include[0]=='"' && (tgt=get_header(Path::Path(from)/fn)))
188                 ;
189         else if((tgt=get_header(Path::Path("/usr/include")/fn)))
190                 ;
191         //XXX Determine the C++ header location dynamically
192         else if((tgt=get_header(Path::Path("/usr/include/c++/4.1.2")/fn)))
193                 ;
194         else
195         {
196                 for(list<string>::const_iterator j=path.begin(); (j!=path.end() && !tgt); ++j)
197                         tgt=get_header(cwd/ *j/fn);
198         }
199
200         includes.insert(TargetMap::value_type(id, tgt));
201         
202         return tgt;
203 }
204
205 /**
206 Tries to locate a library with the given library path.  Considers known targets
207 as well as existing files.  If a matching target is not found but a file exists,
208 a new SystemLibrary target will be created and returned.
209
210 @param   lib   Name of the library to get (without "lib" prefix or extension)
211 @param   path  List of paths to search for the library
212 @param   mode  Shared / static mode
213
214 @return  Some kind of library target, if a match was found
215 */
216 Target *Builder::get_library(const string &lib, const list<string> &path, LibMode mode)
217 {
218         string hash(8, 0);
219         for(list<string>::const_iterator i=path.begin(); i!=path.end(); ++i)
220                 update_hash(hash, *i);
221
222         //XXX Incorporate mode into id
223         string id=hash+lib;
224         TargetMap::iterator i=libraries.find(id);
225         if(i!=libraries.end())
226                 return i->second;
227
228         Target *tgt=0;
229         if((tgt=get_library(lib, "/lib", mode)))
230                 ;
231         else if((tgt=get_library(lib, "/usr/lib", mode)))
232                 ;
233         else
234         {
235                 for(list<string>::const_iterator j=path.begin(); (j!=path.end() && !tgt); ++j)
236                         tgt=get_library(lib, cwd/ *j, mode);
237         }
238
239         libraries.insert(TargetMap::value_type(id, tgt));
240
241         return tgt;
242 }
243
244 const string &Builder::get_arch_prefix(const string &arch) const
245 {
246         StringMap::const_iterator i=archs.find(arch);
247         if(i==archs.end())
248                 throw InvalidParameterValue("Unknown architecture");
249
250         return i->second;
251 }
252
253 int Builder::main()
254 {
255         if(load_build_file(cwd/build_file))
256         {
257                 cerr<<"No build info here.\n";
258                 return 1;
259         }
260
261         default_pkg=packages.begin()->second;
262
263         while(!new_pkgs.empty())
264         {
265                 Package *pkg=new_pkgs.front();
266                 new_pkgs.erase(new_pkgs.begin());
267                 pkg->resolve_refs();
268         }
269
270         default_pkg->configure(cmdline_options, conf_all?2:1);
271
272         if(help)
273         {
274                 usage(0, "builder", false);
275                 cout<<'\n';
276                 package_help();
277                 return 0;
278         }
279
280         StringMap problems;
281         for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
282         {
283                 string prob;
284                 if(!i->second)
285                         prob="missing";
286                 else if(i->second->get_buildable() && i->second->get_arch()!=default_pkg->get_arch())
287                         prob="wrong architecture ("+i->second->get_arch()+")";
288                 if(!prob.empty())
289                         problems.insert(StringMap::value_type(i->first, prob));
290         }
291
292         if(!problems.empty())
293         {
294                 cerr<<"The following problems were detected:\n";
295                 for(StringMap::iterator i=problems.begin(); i!=problems.end(); ++i)
296                         cerr<<"  "<<i->first<<": "<<i->second<<'\n';
297                 cerr<<"Please fix them and try again.\n";
298                 return 1;
299         }
300
301         if(conf_only)
302                 return 0;
303
304         if(create_targets())
305                 return 1;
306
307         cout<<packages.size()<<" packages, "<<targets.size()<<" targets\n";
308         if(verbose>=2)
309         {
310                 for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
311                 {
312                         cout<<' '<<i->second->get_name();
313                         if(i->second->get_buildable())
314                                 cout<<'*';
315                         unsigned count=0;
316                         unsigned ood_count=0;
317                         for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
318                                 if(j->second->get_package()==i->second)
319                                 {
320                                         ++count;
321                                         if(j->second->get_rebuild())
322                                                 ++ood_count;
323                                 }
324                         if(count)
325                         {
326                                 cout<<" ("<<count<<" targets";
327                                 if(ood_count)
328                                         cout<<", "<<ood_count<<" out-of-date";
329                                 cout<<')';
330                         }
331                         cout<<'\n';
332                 }
333         }
334
335         if(analyzer)
336                 analyzer->analyze();
337
338         if(do_build)
339                 build();
340
341         return exit_code;
342 }
343
344 Builder::~Builder()
345 {
346         for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
347                 delete i->second;
348         for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
349                 delete i->second;
350         delete analyzer;
351 }
352
353 void Builder::usage(const char *reason, const char *argv0, bool brief)
354 {
355         if(reason)
356                 cerr<<reason<<'\n';
357         
358         if(brief)
359                 cerr<<"Usage: "<<argv0<<" [-a|--analyze MODE] [-b|--build] [-c|--clean] [-f|--file FILE] [-h|--help] [-j|--jobs NUM] [-n||--dry-run] [-v|--verbose] [-A|--conf-all] [-B|--build-all] [-C|--chdir DIRECTORY] [-W|--what-if FILE] [--chrome] [--conf-only] [--full-paths] [--max-depth NUM] [<target> ...]";
360         else
361         {
362                 cerr<<
363                         "Usage: "<<argv0<<" [options] [<target> ...]\n"
364                         "\n"
365                         "Options:\n"
366                         "  -a, --analyze MODE  Perform analysis.  MODE can be deps, alldeps or rebuild.\n"
367                         "  -b, --build         Perform build even if doing analysis.\n"
368                         "  -c, --clean         Clean buildable targets.\n"
369                         "  -f, --file FILE     Read info from FILE instead of Build.\n"
370                         "  -h, --help          Print this message.\n"
371                         "  -j, --jobs NUM      Run NUM commands at once, whenever possible.\n"
372                         "  -n, --dry-run       Don't actually do anything, only show what would be done.\n"
373                         "  -v, --verbose       Print more information about what's going on.\n"
374                         "  -A, --conf-all      Apply configuration to all packages.\n"
375                         "  -B, --build-all     Build all targets unconditionally.\n"
376                         "  -C, --chdir DIR     Change to DIR before doing anything else.\n"
377                         "  -W, --what-if FILE  Pretend that FILE has changed.\n"
378                         "  --chrome            Use extra chrome to print status.\n"
379                         "  --conf-only         Stop after configuring packages.\n"
380                         "  --full-paths        Output full paths in analysis.\n"
381                         "  --max-depth NUM     Maximum depth to show in analysis.\n";
382         }
383 }
384
385 /**
386 Loads the given build file.
387
388 @param   fn  Path to the file
389
390 @return  0 on success, -1 if the file could not be opened
391 */
392 int Builder::load_build_file(const Path::Path &fn)
393 {
394         ifstream in(fn.str().c_str());
395         if(!in)
396                 return -1;
397
398         Parser::Parser parser(in, fn.str());
399         Loader loader(*this, fn.subpath(0, fn.size()-1));
400         loader.load(parser);
401
402         return 0;
403 }
404
405 /**
406 Creates targets for all packages and prepares them for building.
407
408 @return  0 if everything went ok, -1 if something bad happened and a build
409          shouldn't be attempted
410 */
411 int Builder::create_targets()
412 {
413         Target *world=new VirtualTarget(*this, "world");
414         add_target(world);
415
416         Target *def_tgt=new VirtualTarget(*this, "default");
417         add_target(def_tgt);
418         world->add_depend(def_tgt);
419
420         Target *install=new VirtualTarget(*this, "install");
421         add_target(install);
422         world->add_depend(install);
423
424         for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
425         {
426                 if(!i->second)
427                         continue;
428                 if(!i->second->get_buildable())
429                         continue;
430
431                 Path::Path inst_base;
432                 if(i->second->get_buildable())
433                         inst_base=i->second->get_prefix();
434
435                 const ComponentList &components=i->second->get_components();
436                 for(ComponentList::const_iterator j=components.begin(); j!=components.end(); ++j)
437                 {
438                         // Collect all files belonging to the component
439                         PathList files;
440                         const PathList &sources=j->get_sources();
441                         for(PathList::const_iterator k=sources.begin(); k!=sources.end(); ++k)
442                         {
443                                 struct stat st;
444                                 stat(*k, st);
445                                 if(S_ISDIR(st.st_mode))
446                                 {
447                                         list<string> sfiles=list_files(*k);
448                                         for(list<string>::iterator l=sfiles.begin(); l!=sfiles.end(); ++l)
449                                                 files.push_back(*k / *l);
450                                 }
451                                 else
452                                         files.push_back(*k);
453                         }
454
455                         bool build_exe=j->get_type()!=Component::HEADERS;
456                         
457                         list<ObjectFile *> objs;
458                         for(PathList::iterator k=files.begin(); k!=files.end(); ++k)
459                         {
460                                 string basename=(*k)[-1];
461                                 string ext=Path::splitext(basename).ext;
462                                 if((ext==".cpp" || ext==".c") && build_exe)
463                                 {
464                                         SourceFile *src=new SourceFile(*this, &*j, k->str());
465                                         add_target(src);
466
467                                         // Compile sources
468                                         ObjectFile *obj=new ObjectFile(*this, *j, *src);
469                                         add_target(obj);
470                                         objs.push_back(obj);
471                                 }
472                                 else if(ext==".h")
473                                 {
474                                         Target *hdr=get_target(k->str());
475                                         if(!hdr)
476                                         {
477                                                 hdr=new Header(*this, &*j, k->str());
478                                                 add_target(hdr);
479                                         }
480
481                                         // Install headers if requested
482                                         if(!j->get_install_headers().empty())
483                                         {
484                                                 Path::Path inst_path=inst_base/"include"/j->get_install_headers()/basename;
485                                                 Install *inst=new Install(*this, *i->second, *hdr, inst_path.str());
486                                                 add_target(inst);
487                                                 install->add_depend(inst);
488                                         }
489                                 }
490                         }
491
492                         if(build_exe)
493                         {
494                                 Executable    *exe=0;
495                                 StaticLibrary *slib=0;
496                                 if(j->get_type()==Component::LIBRARY)
497                                 {
498                                         exe=new SharedLibrary(*this, *j, objs);
499                                         slib=new StaticLibrary(*this, *j, objs);
500                                         add_target(slib);
501                                 }
502                                 else
503                                         exe=new Executable(*this, *j, objs);
504                                 
505                                 add_target(exe);
506                                 if(i->second==default_pkg)
507                                 {
508                                         def_tgt->add_depend(exe);
509                                         if(slib) def_tgt->add_depend(slib);
510                                 }
511                                 else
512                                 {
513                                         world->add_depend(exe);
514                                         if(slib) world->add_depend(slib);
515                                 }
516
517                                 if(j->get_install())
518                                 {
519                                         string inst_dir;
520                                         if(j->get_type()==Component::PROGRAM)
521                                                 inst_dir="bin";
522                                         else if(j->get_type()==Component::LIBRARY)
523                                                 inst_dir="lib";
524                                         if(!inst_dir.empty())
525                                         {
526                                                 Install *inst=new Install(*this, *i->second, *exe, (inst_base/inst_dir/Path::basename(exe->get_name())).str());
527                                                 add_target(inst);
528                                                 install->add_depend(inst);
529
530                                                 if(slib)
531                                                 {
532                                                         inst=new Install(*this, *i->second, *slib, (inst_base/inst_dir/Path::basename(slib->get_name())).str());
533                                                         add_target(inst);
534                                                         install->add_depend(inst);
535                                                 }
536                                         }
537                                 }
538                         }
539                 }
540
541                 if(i->second->get_install_flags()&(Package::LIB|Package::INCLUDE))
542                 {
543                         PkgConfig *pc=new PkgConfig(*this, *i->second);
544                         add_target(pc);
545                         Install *inst=new Install(*this, *i->second, *pc, (inst_base/"lib"/"pkgconfig"/Path::basename(pc->get_name())).str());
546                         add_target(inst);
547                         install->add_depend(inst);
548                 }
549         }
550
551         // Find dependencies until no new targets are created
552         while(!new_tgts.empty())
553         {
554                 Target *tgt=new_tgts.front();
555                 new_tgts.erase(new_tgts.begin());
556                 tgt->find_depends();
557                 if(!tgt->get_depends_ready())
558                         new_tgts.push_back(tgt);
559         }
560
561         // Apply what-ifs
562         for(StringList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
563         {
564                 Target *tgt=get_target((cwd/ *i).str());
565                 if(!tgt)
566                 {
567                         cerr<<"Unknown what-if target "<<*i<<'\n';
568                         return -1;
569                 }
570                 tgt->touch();
571         }
572
573         // Make the cmdline target depend on all targets mentioned on the command line
574         Target *cmdline=new VirtualTarget(*this, "cmdline");
575         add_target(cmdline);
576         world->add_depend(cmdline);
577         for(list<string>::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
578         {
579                 Target *tgt=get_target(*i);
580                 if(!tgt)
581                         tgt=get_target((cwd/ *i).str());
582                 if(!tgt)
583                 {
584                         cerr<<"I don't know anything about "<<*i<<'\n';
585                         return -1;
586                 }
587                 cmdline->add_depend(tgt);
588         }
589
590         world->prepare();
591
592         return 0;
593 }
594
595 /**
596 Check if a header exists, either as a target or a file.  Either an existing
597 target or a new SystemHeader target will be returned.
598 */
599 Target *Builder::get_header(const Msp::Path::Path &fn)
600 {
601         Target *tgt=get_target(fn.str());
602         if(tgt) return tgt;
603
604         if(Path::exists(fn))
605         {
606                 add_target(tgt=new SystemHeader(*this, fn.str()));
607                 return tgt;
608         }
609         return 0;
610 }
611
612 Target *Builder::get_library(const string &lib, const Path::Path &path, LibMode mode)
613 {
614         string full;
615         if(mode!=DYNAMIC)
616         {
617                 full=(path/("lib"+lib+".a")).str();
618                 Target *tgt=get_target(full);
619                 // Targets can only be associated with buildable packages (or no package at all)
620                 if(tgt && (tgt->get_package() || mode==ALL_STATIC)) return tgt;
621         }
622         if(mode!=ALL_STATIC)
623         {
624                 full=(path/("lib"+lib+".so")).str();
625                 Target *tgt=get_target(full);
626                 if(tgt) return tgt;
627         }
628
629         if(Path::exists(full))
630         {
631                 Target *tgt=new SystemLibrary(*this, full);
632                 add_target(tgt);
633                 return tgt;
634         }
635
636         return 0;
637 }
638
639 /**
640 Adds a target to both the target map and the new target queue.
641 */
642 void Builder::add_target(Target *t)
643 {
644         targets.insert(TargetMap::value_type(t->get_name(), t));
645         new_tgts.push_back(t);
646 }
647
648 /**
649 Updates a hash with a string.  This is used from get_header and get_library.
650 */
651 void Builder::update_hash(string &hash, const string &value)
652 {
653         for(unsigned i=0; i<value.size(); ++i)
654                 hash[i%hash.size()]^=value[i];
655 }
656
657 /**
658 This function supervises the build process, starting new actions when slots
659 become available.
660 */
661 int Builder::build()
662 {
663         Target *cmdline=get_target("cmdline");
664
665         unsigned total=cmdline->count_rebuild();
666         if(!total)
667         {
668                 cout<<"Already up to date\n";
669                 return 0;
670         }
671         cout<<"Will build "<<total<<" target(s)\n";
672
673         vector<Action *> actions;
674
675         if(chrome)
676                 cout<<"0 targets built\n";
677         unsigned count=0;
678
679         bool fail=false;
680         bool finish=false;
681
682         while(!finish)
683         {
684                 if(actions.size()<jobs && !fail)
685                 {
686                         Target *tgt=cmdline->get_buildable_target();
687                         if(tgt)
688                         {
689                                 Action *action=tgt->build();
690                                 if(action)
691                                         actions.push_back(action);
692                         }
693                         else if(actions.empty())
694                                 finish=true;
695                 }
696                 else
697                         Time::sleep(10*Time::msec);
698
699                 for(unsigned i=0; i<actions.size();)
700                 {
701                         int status=actions[i]->check();
702                         if(status>=0)
703                         {
704                                 ++count;
705                                 if(chrome)
706                                 {
707                                         cout<<"\e["<<actions.size()+1<<'A';
708                                         cout<<count<<" targets built\n";
709                                         if(i)
710                                                 cout<<"\e["<<i<<"B";
711                                         cout<<"\e[M";
712                                         if(i<actions.size()-1)
713                                                 cout<<"\e["<<actions.size()-i-1<<"B";
714                                         cout.flush();
715                                 }
716                                 delete actions[i];
717                                 actions.erase(actions.begin()+i);
718                                 if(status>0)
719                                         fail=true;
720                                 if(actions.empty() && fail)
721                                         finish=true;
722                         }
723                         else
724                                 ++i;
725                 }
726         }
727
728         if(fail)
729                 cout<<"Build failed\n";
730
731         return fail?-1:0;
732 }
733
734 /**
735 Prints out information about the default package.
736 */
737 void Builder::package_help()
738 {
739         const Config &config=default_pkg->get_config();
740         const Config::OptionMap &options=config.get_options();
741
742         cout<<"Required packages:\n  ";
743         const PkgRefList &requires=default_pkg->get_requires();
744         for(PkgRefList::const_iterator i=requires.begin(); i!=requires.end(); ++i)
745         {
746                 if(i!=requires.begin())
747                         cout<<", ";
748                 cout<<i->get_name();
749         }
750         cout<<"\n\n";
751         cout<<"Package configuration:\n";
752         for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
753         {
754                 const Config::Option &opt=i->second;
755                 cout<<"  "<<opt.name<<": "<<opt.descr<<" ("<<opt.value<<") ["<<opt.defv<<"]\n";
756         }
757 }
758
759 Application::RegApp<Builder> Builder::reg;
760
761 Builder::Loader::Loader(Builder &b, const Path::Path &s):
762         bld(b),
763         src(s)
764 {
765         add("package", &Loader::package);
766 }
767
768 void Builder::Loader::package(const string &n)
769 {
770         Package *pkg=new Package(bld, n, src);
771         load_sub(*pkg);
772         bld.packages.insert(PackageMap::value_type(n, pkg));
773         bld.new_pkgs.push_back(pkg);
774 }
775