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