]> git.tdb.fi Git - builder.git/blob - source/builder.cpp
Turn the force rebuild logic around
[builder.git] / source / builder.cpp
1 #include <set>
2 #include <cstdlib>
3 #include <msp/core/getopt.h>
4 #include <msp/datafile/parser.h>
5 #include <msp/fs/dir.h>
6 #include <msp/fs/stat.h>
7 #include <msp/fs/utils.h>
8 #include <msp/io/buffered.h>
9 #include <msp/io/file.h>
10 #include <msp/io/print.h>
11 #include <msp/strings/format.h>
12 #include <msp/strings/regex.h>
13 #include <msp/strings/utils.h>
14 #include <msp/time/units.h>
15 #include <msp/time/utils.h>
16 #include "analyzer.h"
17 #include "binarypackage.h"
18 #include "builder.h"
19 #include "copy.h"
20 #include "externaltask.h"
21 #include "gnuarchiver.h"
22 #include "gnuccompiler.h"
23 #include "gnucxxcompiler.h"
24 #include "gnulinker.h"
25 #include "installedfile.h"
26 #include "package.h"
27 #include "pkgconfiggenerator.h"
28 #include "sharedlibrary.h"
29 #include "sourcepackage.h"
30 #include "tar.h"
31 #include "task.h"
32 #include "virtualtarget.h"
33
34 using namespace std;
35 using namespace Msp;
36
37 Builder::Builder(int argc, char **argv):
38         main_pkg(0),
39         native_arch(*this, string()),
40         vfs(*this),
41         analyzer(0),
42         build(false),
43         clean(0),
44         dry_run(false),
45         help(false),
46         verbose(1),
47         show_progress(false),
48         build_file("Build"),
49         jobs(1),
50         conf_all(false),
51         conf_only(false),
52         build_all(false),
53         create_makefile(false)
54 {
55         string analyze_mode;
56         string work_dir;
57         bool full_paths = false;
58         unsigned max_depth = 5;
59         StringList cmdline_warn;
60         string prfx;
61         string arch;
62
63         GetOpt getopt;
64         getopt.add_option('a', "analyze",    analyze_mode,  GetOpt::REQUIRED_ARG).set_help("Perform analysis.  MODE can be deps, alldeps or rebuild.", "MODE");
65         getopt.add_option('b', "build",      build,         GetOpt::NO_ARG).set_help("Perform build even if doing analysis.");
66         getopt.add_option('c', "clean",      clean,         GetOpt::NO_ARG).set_help("Clean buildable targets.");
67         getopt.add_option('f', "file",       build_file,    GetOpt::REQUIRED_ARG).set_help("Read info from FILE instead of Build.", "FILE");
68         getopt.add_option('h', "help",       help,          GetOpt::NO_ARG).set_help("Print this message.");
69         getopt.add_option('j', "jobs",       jobs,          GetOpt::REQUIRED_ARG).set_help("Run NUM commands at once, whenever possible.", "NUM");
70         getopt.add_option('n', "dry-run",    dry_run,       GetOpt::NO_ARG).set_help("Don't actually do anything, only show what would be done.");
71         getopt.add_option('v', "verbose",    verbose,       GetOpt::NO_ARG).set_help("Print more information about what's going on.");
72         getopt.add_option('x', "no-externals",  no_externals, GetOpt::NO_ARG).set_help("Do not load external source packages.");
73         getopt.add_option('A', "conf-all",   conf_all,      GetOpt::NO_ARG).set_help("Apply configuration to all packages.");
74         getopt.add_option('B', "build-all",  build_all,     GetOpt::NO_ARG).set_help("Build all targets unconditionally.");
75         getopt.add_option('C', "chdir",      work_dir,      GetOpt::REQUIRED_ARG).set_help("Change to DIR before doing anything else.", "DIR");
76         getopt.add_option('P', "progress",   show_progress, GetOpt::NO_ARG).set_help("Display progress while building.");
77         getopt.add_option('W', "what-if",    what_if,       GetOpt::REQUIRED_ARG).set_help("Pretend that FILE has changed.", "FILE");
78         getopt.add_option(     "arch",       arch,          GetOpt::REQUIRED_ARG).set_help("Architecture to build for.", "ARCH");
79         getopt.add_option(     "conf-only",  conf_only,     GetOpt::NO_ARG).set_help("Stop after configuring packages.");
80         getopt.add_option(     "full-paths", full_paths,    GetOpt::NO_ARG).set_help("Output full paths in analysis.");
81         getopt.add_option(     "max-depth",  max_depth,     GetOpt::REQUIRED_ARG).set_help("Maximum depth to show in analysis.", "NUM");
82         getopt.add_option(     "prefix",     prfx,          GetOpt::REQUIRED_ARG).set_help("Directory to install things to.", "DIR");
83         getopt.add_option(     "warnings",   cmdline_warn,  GetOpt::REQUIRED_ARG).set_help("Compiler warnings to use.", "LIST");
84         usagemsg = getopt.generate_usage(argv[0])+" [<target> ...]";
85         helpmsg = getopt.generate_help();
86         getopt(argc, argv);
87
88         if(!analyze_mode.empty())
89         {
90                 analyzer = new Analyzer(*this);
91
92                 if(analyze_mode=="deps")
93                         analyzer->set_mode(Analyzer::DEPS);
94                 else if(analyze_mode=="alldeps")
95                         analyzer->set_mode(Analyzer::ALLDEPS);
96                 else if(analyze_mode=="rebuild")
97                         analyzer->set_mode(Analyzer::REBUILD);
98                 else if(analyze_mode=="rdeps")
99                         analyzer->set_mode(Analyzer::RDEPS);
100                 else
101                         throw usage_error("Invalid analyze mode");
102
103                 analyzer->set_max_depth(max_depth);
104                 analyzer->set_full_paths(full_paths);
105         }
106         else if(!clean && !create_makefile)
107                 build = true;
108
109         const vector<string> &args = getopt.get_args();
110         for(vector<string>::const_iterator i=args.begin(); i!=args.end(); ++i)
111         {
112                 string::size_type equal = i->find('=');
113                 if(equal!=string::npos)
114                         cmdline_options.insert(StringMap::value_type(i->substr(0, equal), i->substr(equal+1)));
115                 else
116                         cmdline_targets.push_back(*i);
117         }
118
119         if(cmdline_targets.empty())
120                 cmdline_targets.push_back("default");
121
122         if(!work_dir.empty())
123                 FS::chdir(work_dir);
124
125         cwd = FS::getcwd();
126
127         load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str());
128         load_build_file((FS::get_user_data_dir("builder")/"rc").str());
129
130         if(arch.empty())
131                 current_arch = &native_arch;
132         else
133                 current_arch = new Architecture(*this, arch);
134
135         if(!current_arch->is_native())
136         {
137                 for(StringMap::const_iterator i=cross_prefixes.begin(); i!=cross_prefixes.end(); ++i)
138                         if(current_arch->match_name(i->first))
139                         {
140                                 current_arch->set_cross_prefix(i->second);
141                                 break;
142                         }
143         }
144
145         toolchain.add_tool(new GnuCCompiler(*this));
146         toolchain.add_tool(new GnuCxxCompiler(*this));
147         toolchain.add_tool(new GnuLinker(*this));
148         toolchain.add_tool(new GnuArchiver(*this));
149         toolchain.add_tool(new Copy(*this));
150         toolchain.add_tool(new Tar(*this));
151         toolchain.add_tool(new PkgConfigGenerator(*this));
152
153         if(prfx.empty())
154         {
155                 if(current_arch->is_native())
156                         prefix = (FS::get_home_dir()/"local").str();
157                 else
158                         prefix = (FS::get_home_dir()/"local"/current_arch->get_name()).str();
159         }
160         else
161                 prefix = FS::getcwd()/prfx;
162
163         warnings.push_back("all");
164         warnings.push_back("extra");
165         warnings.push_back("shadow");
166         warnings.push_back("pointer-arith");
167         warnings.push_back("error");
168         for(StringList::iterator i=cmdline_warn.begin(); i!=cmdline_warn.end(); ++i)
169         {
170                 vector<string> warns = split(*i, ',');
171                 warnings.insert(warnings.end(), warns.begin(), warns.end());
172         }
173
174         pkg_path.push_back(cwd/".");
175         pkg_path.push_back(cwd/"..");
176 }
177
178 Builder::~Builder()
179 {
180         for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
181                 delete i->second;
182         for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
183                 delete i->second;
184         delete analyzer;
185 }
186
187 int Builder::main()
188 {
189         if(prefix.str()!="/usr")
190         {
191                 FS::Path pcdir = prefix/"lib"/"pkgconfig";
192                 if(const char *pcp = getenv("PKG_CONFIG_PATH"))
193                 {
194                         vector<string> path = split(pcp, ':');
195                         bool found = false;
196                         for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
197                                 found = (*i==pcdir.str());
198                         if(!found)
199                         {
200                                 path.push_back(pcdir.str());
201                                 setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
202                         }
203                 }
204                 else
205                         setenv("PKG_CONFIG_PATH", pcdir.str().c_str(), true);
206         }
207
208         if(load_build_file(cwd/build_file))
209         {
210                 if(help)
211                 {
212                         usage(0, "builder", false);
213                         return 0;
214                 }
215                 else
216                 {
217                         IO::print(IO::cerr, "No build info here.\n");
218                         return 1;
219                 }
220         }
221
222         main_pkg->configure(cmdline_options, conf_all?2:1);
223
224         if(help)
225         {
226                 usage(0, "builder", false);
227                 IO::print("\n");
228                 package_help();
229                 return 0;
230         }
231
232         if(conf_only)
233                 return 0;
234
235         if(create_targets())
236                 return 1;
237
238         if(verbose>=2)
239         {
240                 IO::print("Building on %s, for %s%s\n", native_arch.get_name(),
241                         current_arch->get_name(), (current_arch->is_native() ? " (native)" : ""));
242                 IO::print("Prefix is %s\n", prefix);
243         }
244
245         if(verbose>=1)
246         {
247                 unsigned n_packages = 0;
248                 for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
249                         if(i->second && i->second->is_configured())
250                                 ++n_packages;
251                 IO::print("%d active packages, %d targets\n", n_packages, targets.size());
252         }
253
254         if(verbose>=2)
255         {
256                 for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
257                 {
258                         if(!i->second->is_configured())
259                                 continue;
260
261                         IO::print(" %s", i->second->get_name());
262                         if(dynamic_cast<SourcePackage *>(i->second))
263                                 IO::print("*");
264                         unsigned count = 0;
265                         unsigned to_be_built = 0;
266                         for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
267                                 if(j->second->get_package()==i->second)
268                                 {
269                                         ++count;
270                                         if(j->second->needs_rebuild())
271                                                 ++to_be_built;
272                                 }
273                         if(count)
274                         {
275                                 IO::print(" (%d targets", count);
276                                 if(to_be_built)
277                                         IO::print(", %d to be built", to_be_built);
278                                 IO::print(")");
279                         }
280                         IO::print("\n");
281                 }
282         }
283
284         if(analyzer)
285                 analyzer->analyze();
286
287         if(!problems.empty())
288         {
289                 IO::print(IO::cerr, "The following problems were detected:\n");
290                 for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i)
291                         IO::print(IO::cerr, "  %s: %s\n", i->package, i->descr);
292                 if(!analyzer)
293                         IO::print(IO::cerr, "Please fix them and try again.\n");
294                 return 1;
295         }
296
297         if(clean)
298                 exit_code = do_clean();
299         else if(build)
300                 exit_code = do_build();
301
302         return exit_code;
303 }
304
305 string Builder::run_pkgconfig(const string &pkg, const string &what)
306 {
307         ExternalTask::Arguments argv;
308         argv.push_back("pkg-config");
309         if(what=="cflags" || what=="libs")
310                 argv.push_back("--"+what);
311         else if(what=="flags")
312         {
313                 argv.push_back("--cflags");
314                 argv.push_back("--libs");
315         }
316         else
317                 argv.push_back("--variable="+what);
318         argv.push_back(pkg);
319
320         if(verbose>=4)
321                 IO::print("Running %s\n", join(argv.begin(), argv.end()));
322
323         ExternalTask task(argv);
324         task.set_stdout(ExternalTask::CAPTURE);
325         task.set_stderr(ExternalTask::IGNORE);
326         task.start();
327         Task::Status status;
328         while((status=task.check())==Task::RUNNING)
329                 Time::sleep(10*Time::msec);
330         if(status==Task::ERROR)
331                 throw runtime_error(format("pkg-config for package %s failed", pkg));
332
333         return task.get_output();
334 }
335
336 Package *Builder::get_package(const string &name)
337 {
338         PackageMap::iterator i = packages.find(format("%s/%s", name, current_arch->get_system()));
339         if(i==packages.end())
340                 i = packages.find(name);
341         if(i!=packages.end())
342                 return i->second;
343
344         if(!no_externals)
345         {
346                 FS::Path path = get_package_location(name);
347                 if(!path.empty() && !load_build_file(path/"Build"))
348                 {
349                         i = packages.find(name);
350                         if(i!=packages.end())
351                                 return i->second;
352                 }
353         }
354
355         Package *pkg = 0;
356         try
357         {
358                 // Package source not found - create a binary package
359                 pkg = BinaryPackage::from_pkgconfig(*this, name);
360         }
361         catch(...)
362         {
363                 problem(name, "not found");
364         }
365
366         packages.insert(PackageMap::value_type(name, pkg));
367
368         return pkg;
369 }
370
371 Target *Builder::get_target(const string &n) const
372 {
373         TargetMap::const_iterator i = targets.find(n);
374         if(i!=targets.end())
375                 return i->second;
376         return 0;
377 }
378
379 void Builder::apply_profile_template(Config &config, const string &pt) const
380 {
381         vector<string> parts = split(pt, '-');
382
383         for(vector<string>::iterator i=parts.begin(); i!=parts.end(); ++i)
384         {
385                 ProfileTemplateMap::const_iterator j = profile_tmpl.find(*i);
386                 if(j==profile_tmpl.end())
387                         continue;
388
389                 config.update(j->second);
390         }
391 }
392
393 void Builder::problem(const string &p, const string &d)
394 {
395         problems.push_back(Problem(p, d));
396 }
397
398 void Builder::add_target(Target *t)
399 {
400         targets.insert(TargetMap::value_type(t->get_name(), t));
401         new_tgts.push_back(t);
402 }
403
404 void Builder::usage(const char *reason, const char *argv0, bool brief)
405 {
406         if(reason)
407                 IO::print(IO::cerr, "%s\n", reason);
408
409         if(brief)
410                 IO::print(IO::cerr, "Usage: %s\n", usagemsg);
411         else
412         {
413                 IO::print(IO::cerr, "Builder 1.0\n\n");
414                 IO::print(IO::cerr, "Usage: %s [options] [<target> ...]\n\n", argv0);
415                 IO::print(IO::cerr, "Options:\n");
416                 IO::print(IO::cerr, helpmsg);
417         }
418 }
419
420 FS::Path Builder::get_package_location(const string &name)
421 {
422         if(verbose>=3)
423                 IO::print("Looking for package %s\n", name);
424
425         try
426         {
427                 // Try to get source directory with pkgconfig
428                 string srcdir = strip(run_pkgconfig(name, "source"));
429                 if(!srcdir.empty())
430                         return srcdir;
431         }
432         catch(...)
433         { }
434
435         if(pkg_dirs.empty())
436         {
437                 for(list<FS::Path>::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i)
438                 {
439                         list<string> files = list_files(*i);
440                         for(list<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
441                         {
442                                 FS::Path full = *i / *j;
443                                 if(FS::exists(full/"Build"))
444                                         pkg_dirs.push_back(full);
445                         }
446                 }
447                 if(verbose>=3)
448                         IO::print("%d packages found in path\n", pkg_dirs.size());
449         }
450
451         bool msp = !name.compare(0, 3, "msp");
452         for(list<FS::Path>::const_iterator i=pkg_dirs.begin(); i!=pkg_dirs.end(); ++i)
453         {
454                 string base = basename(*i);
455                 unsigned dash = base.rfind('-');
456
457                 if(!base.compare(0, dash, name))
458                         return *i;
459                 else if(msp && !base.compare(0, dash-3, name, 3, string::npos))
460                         return *i;
461         }
462
463         return FS::Path();
464 }
465
466 int Builder::load_build_file(const FS::Path &fn)
467 {
468         if(!FS::exists(fn))
469                 return -1;
470
471         IO::BufferedFile in(fn.str());
472
473         if(verbose>=3)
474                 IO::print("Reading %s\n", fn);
475
476         DataFile::Parser parser(in, fn.str());
477         Loader loader(*this, fn.subpath(0, fn.size()-1));
478         loader.load(parser);
479
480         return 0;
481 }
482
483 int Builder::create_targets()
484 {
485         Target *world = new VirtualTarget(*this, "world");
486
487         Target *def_tgt = new VirtualTarget(*this, "default");
488         world->add_depend(def_tgt);
489
490         Target *install = new VirtualTarget(*this, "install");
491         world->add_depend(install);
492
493         Target *tarballs = new VirtualTarget(*this, "tarballs");
494         world->add_depend(tarballs);
495
496         for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
497                 if(i->second && i->second->is_configured())
498                         i->second->create_targets();
499
500         // Make the cmdline target depend on all targets mentioned on the command line
501         Target *cmdline = new VirtualTarget(*this, "cmdline");
502         for(list<string>::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
503         {
504                 Target *tgt = get_target(*i);
505                 if(!tgt)
506                         tgt = vfs.get_target(*i);
507                 if(!tgt)
508                         tgt = vfs.get_target(cwd/ *i);
509                 if(!tgt)
510                 {
511                         IO::print("I don't know anything about %s\n", *i);
512                         return -1;
513                 }
514
515                 cmdline->add_depend(tgt);
516         }
517
518         cmdline->prepare();
519
520         // Apply what-ifs
521         for(StringList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
522         {
523                 FileTarget *tgt = vfs.get_target(cwd/ *i);
524                 if(!tgt)
525                 {
526                         IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
527                         return -1;
528                 }
529                 tgt->touch();
530         }
531
532         if(build_all)
533         {
534                 for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
535                         if(i->second->is_buildable() && !i->second->needs_rebuild())
536                                 i->second->force_rebuild();
537         }
538
539         for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
540                 if(SourcePackage *spkg = dynamic_cast<SourcePackage *>(i->second))
541                         spkg->get_deps_cache().save();
542
543         return 0;
544 }
545
546 int Builder::do_build()
547 {
548         Target *cmdline = get_target("cmdline");
549
550         unsigned total = 0;
551         for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
552                 if(i->second->is_buildable() && i->second->needs_rebuild())
553                         ++total;
554
555         if(!total)
556         {
557                 IO::print("Already up to date\n");
558                 return 0;
559         }
560         if(verbose>=1)
561                 IO::print("Will build %d target%s\n", total, (total!=1 ? "s" : ""));
562
563         vector<Task *> tasks;
564
565         unsigned count = 0;
566
567         bool fail = false;
568         bool finish = false;
569
570         while(!finish)
571         {
572                 if(tasks.size()<jobs && !fail)
573                 {
574                         Target *tgt = cmdline->get_buildable_target();
575                         if(tgt)
576                         {
577                                 if(tgt->get_tool())
578                                         IO::print("%-4s  %s\n", tgt->get_tool()->get_tag(), tgt->get_name());
579                                 Task *task = tgt->build();
580                                 if(task)
581                                 {
582                                         if(verbose>=2)
583                                                 IO::print("%s\n", task->get_command());
584                                         if(dry_run)
585                                         {
586                                                 task->signal_finished.emit(true);
587                                                 delete task;
588                                         }
589                                         else
590                                         {
591                                                 task->start();
592                                                 tasks.push_back(task);
593                                         }
594                                 }
595
596                                 if(show_progress)
597                                         IO::print("%d of %d target%s built\033[1G", count, total, (total!=1 ? "s" : ""));
598                         }
599                         else if(tasks.empty())
600                                 finish = true;
601                 }
602                 else
603                         Time::sleep(10*Time::msec);
604
605                 for(unsigned i=0; i<tasks.size();)
606                 {
607                         Task::Status status = tasks[i]->check();
608                         if(status!=Task::RUNNING)
609                         {
610                                 ++count;
611
612                                 delete tasks[i];
613                                 tasks.erase(tasks.begin()+i);
614                                 if(status==Task::ERROR)
615                                         fail = true;
616                                 if(tasks.empty() && fail)
617                                         finish = true;
618                         }
619                         else
620                                 ++i;
621                 }
622         }
623
624         if(show_progress)
625                 IO::print("\033[K");
626         if(fail)
627                 IO::print("Build failed\n");
628         else if(show_progress)
629                 IO::print("Build complete\n");
630
631         return fail;
632 }
633
634 int Builder::do_clean()
635 {
636         // Cleaning doesn't care about ordering, so a simpler method can be used
637
638         set<Target *> clean_tgts;
639         list<Target *> queue;
640         queue.push_back(get_target("cmdline"));
641
642         while(!queue.empty())
643         {
644                 Target *tgt = queue.front();
645                 queue.erase(queue.begin());
646
647                 if(tgt->is_buildable() && (tgt->get_package()==main_pkg || clean>=2))
648                         clean_tgts.insert(tgt);
649
650                 const Target::Dependencies &deps = tgt->get_depends();
651                 for(list<Target *>::const_iterator i=deps.begin(); i!=deps.end(); ++i)
652                         if(!clean_tgts.count(*i))
653                                 queue.push_back(*i);
654         }
655
656         for(set<Target *>::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i)
657                 if(FileTarget *ft = dynamic_cast<FileTarget *>(*i))
658                         if(ft->get_mtime())
659                                 FS::unlink(ft->get_path());
660
661         return 0;
662 }
663
664 void Builder::package_help()
665 {
666         const Config &config = main_pkg->get_config();
667         const Config::OptionMap &options = config.get_options();
668
669         IO::print("Required packages:\n  ");
670         const PackageList &requires = main_pkg->get_requires();
671         for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i)
672         {
673                 if(i!=requires.begin())
674                         IO::print(", ");
675                 IO::print((*i)->get_name());
676         }
677         IO::print("\n\nPackage configuration:\n");
678         for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
679         {
680                 const Config::Option &opt = i->second;
681                 IO::print("  %s: %s (%s)", opt.name, opt.descr, opt.value);
682                 if(opt.value!=opt.defv)
683                         IO::print(" [%s]", opt.defv);
684                 IO::print("\n");
685         }
686 }
687
688 string Builder::usagemsg;
689 string Builder::helpmsg;
690
691
692 Builder::Loader::Loader(Builder &b, const FS::Path &s):
693         bld(b),
694         src(s)
695 {
696         add("binary_package", &Loader::binpkg);
697         add("cross_prefix", &Loader::cross_prefix);
698         add("profile", &Loader::profile);
699         add("package", &Loader::package);
700 }
701
702 void Builder::Loader::binpkg(const string &n)
703 {
704         BinaryPackage *pkg = new BinaryPackage(bld, n);
705         load_sub(*pkg);
706         bld.packages.insert(PackageMap::value_type(n, pkg));
707 }
708
709 void Builder::Loader::cross_prefix(const string &a, const string &p)
710 {
711         bld.cross_prefixes[a] = p;
712 }
713
714 void Builder::Loader::profile(const string &n)
715 {
716         StringMap prf;
717         ProfileLoader ldr(prf);
718         load_sub_with(ldr);
719         bld.profile_tmpl.insert(ProfileTemplateMap::value_type(n, prf));
720 }
721
722 void Builder::Loader::package(const string &n)
723 {
724         SourcePackage *pkg = new SourcePackage(bld, n, src);
725         if(!bld.main_pkg)
726                 bld.main_pkg = pkg;
727
728         load_sub(*pkg);
729         bld.packages.insert(PackageMap::value_type(n, pkg));
730 }
731
732
733 Builder::ProfileLoader::ProfileLoader(StringMap &p):
734         profile(p)
735 {
736         add("option", &ProfileLoader::option);
737 }
738
739 void Builder::ProfileLoader::option(const string &o, const string &v)
740 {
741         profile.insert(StringMap::value_type(o, v));
742 }