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