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