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