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