1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //==========================================================================
29 // The implementation of build tree and makefile generation using
32 //==========================================================================
33 //==========================================================================
34 //#####DESCRIPTIONBEGIN####
39 //####DESCRIPTIONEND####
40 //==========================================================================
42 #if defined(_WIN32) || defined(__CYGWIN__)
43 #include <windows.h> /* for GetShortPathNameA() */
46 #include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() */
49 // We take advantage of wxWindows' recursive wxFileName::Mkdir function
50 // to workaround a bug in Tcl on Windows 9x
51 #include "wx/filename.h"
59 // Two methods of generating Cygwin filenames
60 // ECOS_USE_CYGDRIVE = 0: use e.g. //c/, but this is deprecated in new versions of Cygwin
61 // ECOS_USE_CYGDRIVE = 1: use e.g. /cygdrive/c/
62 // ECOS_USE_CYGDRIVE = 2: use e.g. c:/ notation
63 // ECOS_USE_CYGDRIVE = 3: use e.g. /ecos-x notation where x is a drive name.
64 #define ECOS_USE_CYGDRIVE 3
66 // Use registry functions to find out location of /cygdrive
67 #define ECOS_USE_REGISTRY 1
69 // Don't use Reg... functions in command-line version until we know how
70 // to add advapi32.lib
71 #if defined(_WIN32) && !defined(__WXMSW__) && !defined(ECOS_CT)
72 #undef ECOS_USE_REGISTRY
73 #define ECOS_USE_REGISTRY 0
76 std::string makefile_header = "# eCos makefile\n\n# This is a generated file - do not edit\n\n";
78 // This code seems to crash Tcl under Windows ME and Linux, so
79 // disable for now. What should the criterion be? TCL version?
80 #define SET_STDOUT_TO_NULL 0
82 bool eval_tcl_command (const std::string command) {
83 Tcl_Interp * interp = Tcl_CreateInterp ();
84 #if SET_STDOUT_TO_NULL
85 Tcl_Channel outchan = Tcl_OpenFileChannel (interp, "nul", "a+", 777);
86 Tcl_SetStdChannel (outchan, TCL_STDOUT); // direct standard output to the null device
88 int nStatus = Tcl_Eval (interp, CDL_TCL_CONST_CAST(char*, command.c_str()));
89 #if SET_STDOUT_TO_NULL
90 Tcl_SetStdChannel (NULL, TCL_STDOUT);
91 Tcl_UnregisterChannel (interp, outchan);
93 Tcl_DeleteInterp (interp);
94 return (TCL_OK == nStatus);
97 // generate a copy of a string where each occurance of a specified char is replaced with another char
98 std::string replace_char (const std::string input, const char old_char, const char new_char) {
100 for (unsigned int n = 0; n < input.size (); n++) { // for each char
101 output += (old_char == input [n]) ? new_char : input [n]; // convert during copy
106 // convert a filepath into a vector of path components
107 static void path_to_vector (std::string input, std::vector <std::string> & output) {
108 std::string component;
111 for (unsigned int n = 0; n < input.size (); n++) { // for each char in the path
112 if (('/' == input [n]) || ('\\' == input [n])) { // if char is a directory separator
113 output.push_back (component); // add path component to output vector
114 component.erase (); // clear path component string
115 } else { // char is not a separator
116 component += input [n]; // add char to path component string
119 output.push_back (component); // add final path component to output vector
122 // eliminate spaces from a DOS filepath by substituting the
123 // short form of path components containing spaces
124 #if defined(_WIN32) || defined(__CYGWIN__)
125 std::string nospace_path (const std::string input) {
126 // split the path into a vector of path components
127 std::vector <std::string> long_path_vector;
128 path_to_vector (input, long_path_vector);
130 // convert the path to its short form and split
131 // the result into a vector of path components
132 char buffer [MAX_PATH + 1];
133 GetShortPathNameA (input.c_str (), buffer, sizeof (buffer));
134 std::vector <std::string> short_path_vector;
135 path_to_vector (buffer, short_path_vector);
137 // append the short or long form of each path component to the output string as appropriate
139 for (unsigned int n = 0; n < long_path_vector.size (); n++) { // for each component of the path
140 if (long_path_vector [n].end () != std::find (long_path_vector [n].begin (), long_path_vector [n].end (), ' ')) { // if there is a space in the path component
141 output += short_path_vector [n]; // add the short form of the path component
142 } else { // there is no space in the path component
143 output += long_path_vector [n]; // add the long form of the path component
145 output += '\\'; // add a directory separator
147 output.resize (output.size () - 1); // remove the trailing separator
153 // convert a DOS filepath to a Cygwin filepath
154 std::string cygpath (const std::string input) {
155 #if defined(_WIN32) || defined(__CYGWIN__)
156 // remove spaces from the DOS filepath
157 const std::string path = nospace_path (input);
160 // convert the DOS filepath to Cygwin notation - using Cygwin if available
161 // 2001-10-15: should now do the same thing under Cygwin as under VC++, namely
162 // use the /ecos-x form.
163 #if 0 // def __CYGWIN__
164 char buffer [MAX_PATH + 1];
165 cygwin_conv_to_posix_path (path.c_str (), buffer);
169 #if ECOS_USE_CYGDRIVE == 1
170 std::string strCygdrive("/cygdrive");
172 #if ECOS_USE_REGISTRY
174 if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cygnus Solutions\\Cygwin\\mounts v2",
180 if (ERROR_SUCCESS == RegQueryValueEx(hKey, "cygdrive prefix", NULL, & type, value, & sz))
182 strCygdrive = (const char*) value;
188 strCygdrive = strCygdrive + "/";
190 for (unsigned int n = 0; n < path.size (); n++) { // for each char
191 if ((1 == n) && (':' == path [n])) { // if a DOS logical drive letter is present
192 output = strCygdrive + output; // convert to Cygwin notation
194 output += ('\\' == path [n]) ? '/' : path [n]; // convert backslash to slash
197 #elif ECOS_USE_CYGDRIVE == 2
198 // Convert to c:/foo/bar notation
199 for (unsigned int n = 0; n < path.size (); n++) { // for each char
200 output += ('\\' == path [n]) ? '/' : path [n]; // convert backslash to slash
202 #elif ECOS_USE_CYGDRIVE == 3
203 // Convert to /ecos-x notation, assuming that this mount point will be created
204 // by the application.
208 if (path.size() > 1 && path[1] == ':')
211 output1 += tolower(path[0]);
214 // Append the rest of the path
220 if (path[n] == '\\' || path[n] == '/')
223 for (i = n; i < path.size(); i++)
230 for (unsigned int n = 0; n < output1.size (); n++) { // for each char
231 output += ('\\' == output1 [n]) ? '/' : output1 [n]; // convert backslash to slash
234 for (unsigned int n = 0; n < path.size (); n++) { // for each char
235 if ((1 == n) && (':' == path [n])) { // if a DOS logical drive letter is present
236 output = "//" + output; // convert to Cygwin notation
238 output += ('\\' == path [n]) ? '/' : path [n]; // convert backslash to slash
250 // create a directory
251 bool create_directory (const std::string directory) {
252 // We take advantage of wxWindows' recursive wxFileName::Mkdir function
253 // to workaround a bug in Tcl on Windows 9x
254 #if defined(__WXMSW__)
255 if (wxDirExists(directory.c_str()))
257 return wxFileName::Mkdir(directory.c_str(), 0777, TRUE);
259 return eval_tcl_command ("file mkdir \"" + directory + "\"");
264 bool copy_file (const std::string file, const std::string destination) {
265 return eval_tcl_command ("file copy \"" + file + "\" \"" + destination + "\"");
269 // returns the directory of the specified file
270 std::string file_to_directory (const std::string file) {
271 for (unsigned int n = file.size (); n >= 0; n--) {
272 if ('/' == file [n]) {
273 std::string directory = file;
274 directory.resize (n);
281 std::string tab_indent (const std::string input) {
284 for (unsigned int n = 0; n < input.size (); n++) {
289 indent = ('\n' == input [n]);
296 // return the tests of the specified loadable
297 std::string get_tests (const CdlConfiguration config, const CdlBuildInfo_Loadable & build_info) {
298 CdlValuable tests = dynamic_cast <CdlValuable> (config->lookup (build_info.name + "_TESTS"));
299 // check if there are tests active and enabled
300 if (tests && tests->is_active() && tests->is_enabled()) {
301 return tests->get_value ();
302 } else { // there are no tests
307 // replaces all occurances of a substring with a new substring
308 std::string replace_substr (const std::string input, const std::string old_substring, const std::string new_substring) {
309 std::string output = input;
310 std::string::size_type index = 0;
311 while (index = output.find (old_substring, index), std::string::npos != index) {
312 output.replace (index, old_substring.size (), new_substring);
317 // resolve tokens in custom make rule targets and dependencies
318 std::string resolve_tokens (const std::string input) {
319 std::string output = input;
320 output = replace_substr (output, "<PREFIX>", "$(PREFIX)");
321 output = replace_substr (output, "<PACKAGE>", "$(REPOSITORY)/$(PACKAGE)");
325 // create the makefile for a loadable
326 bool generate_makefile (const CdlConfiguration config, const CdlBuildInfo_Loadable & info, const std::string install_tree, const std::string filename) {
328 unsigned int library;
330 // obtain the command prefix
331 std::string command_prefix = get_flags (config, NULL, "COMMAND_PREFIX");
332 if (! command_prefix.empty ()) { // if there is a command prefix
333 command_prefix += '-'; // add a trailing hyphen
336 // generate the prefix for archived objects
337 unsigned int final_separator = 0; // the index of the last directory separator
338 std::string object_prefix = info.directory; // start with the loadable directory
339 for (count = 0; count < object_prefix.size (); count++) { // for each char
340 if ('/' == object_prefix [count]) { // if the char is a directory separator
341 object_prefix [count] = '_'; // replace the char with an underscore
342 final_separator = count;
345 object_prefix.resize (final_separator); // remove the version directory
348 FILE * stream = fopen (filename.c_str (), "wt");
349 if (stream == NULL) // if the file could not be opened
352 // generate the header
353 fprintf (stream, makefile_header.c_str ());
355 // generate the global variables
356 fprintf (stream, "export REPOSITORY := %s\n", cygpath (config->get_database ()->get_component_repository ()).c_str ());
357 fprintf (stream, "export PREFIX := %s\n", cygpath (install_tree).c_str ());
358 fprintf (stream, "export COMMAND_PREFIX := %s\n", command_prefix.c_str ());
359 fprintf (stream, "export CC := $(COMMAND_PREFIX)gcc\n");
360 fprintf (stream, "export OBJCOPY := $(COMMAND_PREFIX)objcopy\n");
361 #if defined(_WIN32) || defined(__CYGWIN__)
362 fprintf (stream, "export HOST := CYGWIN\n");
364 fprintf (stream, "export HOST := UNIX\n");
366 fprintf (stream, "export AR := $(COMMAND_PREFIX)ar\n\n");
368 // generate the package variables
369 fprintf (stream, "PACKAGE := %s\n", info.directory.c_str ());
370 fprintf (stream, "OBJECT_PREFIX := %s\n", object_prefix.c_str ());
371 fprintf (stream, "CFLAGS := %s\n", get_flags (config, &info, "CFLAGS").c_str ());
372 fprintf (stream, "LDFLAGS := %s\n", get_flags (config, &info, "LDFLAGS").c_str ());
373 fprintf (stream, "VPATH := $(REPOSITORY)/$(PACKAGE)\n");
374 fprintf (stream, "INCLUDE_PATH := $(INCLUDE_PATH) -I$(PREFIX)/include $(foreach dir,$(VPATH),-I$(dir) -I$(dir)/src -I$(dir)/tests) -I.\n");
375 fprintf (stream, "MLT := $(wildcard $(REPOSITORY)/$(PACKAGE)/include/pkgconf/mlt*.ldi $(REPOSITORY)/$(PACKAGE)/include/pkgconf/mlt*.h)\n");
376 fprintf (stream, "TESTS := %s\n\n", get_tests (config, info).c_str ());
378 // create a vector of libraries
379 std::vector <std::string> library_vector;
380 for (count = 0; count < info.compiles.size (); count++) { // for each compilable file
381 const std::string & library = info.compiles [count].library;
382 if (library_vector.end () == std::find (library_vector.begin (), library_vector.end (), library)) { // if a new library
383 library_vector.push_back (library); // add the library to the vector
386 for (count = 0; count < info.objects.size (); count++) { // for each object file
387 const std::string & library = info.objects [count].library;
388 if (library_vector.end () == std::find (library_vector.begin (), library_vector.end (), library)) { // if a new library
389 library_vector.push_back (library); // add the library to the vector
392 for (count = 0; count < info.make_objects.size (); count++) { // for each make object
393 const std::string & library = info.make_objects [count].library;
394 if (library_vector.end () == std::find (library_vector.begin (), library_vector.end (), library)) { // if a new library
395 library_vector.push_back (library); // add the library to the vector
399 // generate the default rule
400 fprintf (stream, "build: headers");
401 for (library = 0; library < library_vector.size (); library++) { // for each library
402 fprintf (stream, " %s.stamp", library_vector [library].c_str ());
404 fprintf (stream, "\n\n");
406 // generate library rules
407 for (library = 0; library < library_vector.size (); library++) { // for each library
408 fprintf (stream, "LIBRARY := %s\n", library_vector [library].c_str ());
409 fprintf (stream, "COMPILE :=");
410 for (count = 0; count < info.compiles.size (); count++) { // for each compilable file
411 if (library_vector [library] == info.compiles [count].library) { // if the file and library are related
412 fprintf (stream, " %s", info.compiles [count].source.c_str ());
415 for (count = 0; count < info.objects.size (); count++) { // for each object file
416 if (library_vector [library] == info.objects [count].library) { // if the file and library are related
417 fprintf (stream, " %s", info.objects [count].object.c_str ());
420 for (count = 0; count < info.make_objects.size (); count++) { // for each make object
421 if (library_vector [library] == info.make_objects [count].library) { // if the object and library are related
422 fprintf (stream, " %s", info.make_objects [count].object.c_str ());
426 fprintf (stream, "\nOBJECTS := $(COMPILE:.cxx=.o.d)\n");
427 fprintf (stream, "OBJECTS := $(OBJECTS:.c=.o.d)\n");
428 fprintf (stream, "OBJECTS := $(OBJECTS:.S=.o.d)\n\n");
429 fprintf (stream, "$(LIBRARY).stamp: $(OBJECTS)\n");
430 fprintf (stream, "\t$(AR) rcs $(PREFIX)/lib/$(@:.stamp=) $(foreach obj,$?,$(dir $(obj))$(OBJECT_PREFIX)_$(notdir $(obj:.o.d=.o)))\n");
431 fprintf (stream, "\t@cat $^ > $(@:.stamp=.deps)\n");
432 fprintf (stream, "\t@touch $@\n\n");
435 // generate make objects rules
436 for (count = 0; count < info.make_objects.size (); count++) { // for each make object
437 fprintf (stream, "%s: %s\n%s\n", info.make_objects [count].object.c_str (), info.make_objects [count].deps.c_str (), tab_indent (info.make_objects [count].rules).c_str ());
440 // generate makes rules
441 for (count = 0; count < info.makes.size (); count++) { // for each make
442 fprintf (stream, "%s: $(wildcard %s)\n%s\n", resolve_tokens (info.makes [count].target).c_str (), resolve_tokens (info.makes [count].deps).c_str (), tab_indent (info.makes [count].rules).c_str ());
445 // generate header rules
446 fprintf (stream, "headers: mlt_headers");
447 for (count = 0; count < info.headers.size (); count++) { // for each header
448 fprintf (stream, " $(PREFIX)/include/%s", info.headers [count].destination.c_str ());
450 fprintf (stream, "\n\n");
451 for (count = 0; count < info.headers.size (); count++) { // for each header
452 fprintf (stream, "$(PREFIX)/include/%s: $(REPOSITORY)/$(PACKAGE)/%s\n", info.headers [count].destination.c_str (), info.headers [count].source.c_str ());
453 #if (defined(_WIN32) || defined(__CYGWIN__)) && (ECOS_USE_CYGDRIVE > 0)
454 fprintf (stream, "ifeq ($(HOST),CYGWIN)\n");
455 fprintf (stream, "\t@mkdir -p `cygpath -w \"$(dir $@)\" | sed \"s@\\\\\\\\\\\\\\\\@/@g\"`\n");
456 fprintf (stream, "else\n");
457 fprintf (stream, "\t@mkdir -p $(dir $@)\n");
458 fprintf (stream, "endif\n");
460 // This prevents older versions of mkdir failing
461 fprintf (stream, "\t@mkdir -p $(dir $@)\n");
464 fprintf (stream, "\t@cp $< $@\n");
465 fprintf (stream, "\t@chmod u+w $@\n\n");
468 // include default rules
469 fprintf (stream, "include $(REPOSITORY)/pkgconf/rules.mak\n\n");
471 // close the makefile
472 return (0 == fclose (stream));
475 // a structure and operator for sorting custom make rules by priority
477 std::vector <CdlBuildInfo_Loadable>::const_iterator loadable;
480 bool operator < (info_make op1, info_make op2) {
481 return op1.loadable->makes [op1.make].priority < op2.loadable->makes [op2.make].priority;
484 // create the top-level makefile
485 bool generate_toplevel_makefile (const CdlConfiguration config, const std::string install_tree, const std::string filename) {
486 unsigned int loadable;
489 // obtain the command prefix
490 std::string command_prefix = get_flags (config, NULL, "COMMAND_PREFIX");
491 if (! command_prefix.empty ()) { // if there is a command prefix
492 command_prefix += '-'; // add a trailing hyphen
495 // obtain build information from the specified configuration
496 CdlBuildInfo build_info;
497 config->get_build_info (build_info);
498 std::vector <CdlBuildInfo_Loadable> info_vector = build_info.entries;
500 // create a vector of makes and sort them by priority
501 std::vector <info_make> info_make_vector;
502 for (std::vector <CdlBuildInfo_Loadable>::iterator info = info_vector.begin (); info != info_vector.end (); info++) { // for each buildable loaded package
503 for (unsigned int count = 0; count < info->makes.size (); count++) { // for each make
504 info_make make_info = {info, count};
505 info_make_vector.push_back (make_info);
508 std::sort (info_make_vector.begin (), info_make_vector.end ());
511 FILE * stream = fopen (filename.c_str (), "wt");
512 if (stream == NULL) // if the file could not be opened
515 // generate the header
516 fprintf (stream, makefile_header.c_str ());
518 // generate the variables
519 fprintf (stream, "export REPOSITORY := %s\n", cygpath (config->get_database ()->get_component_repository ()).c_str ());
520 #if defined(_WIN32) || defined(__CYGWIN__)
521 fprintf (stream, "export HOST := CYGWIN\n");
523 fprintf (stream, "export HOST := UNIX\n");
525 fprintf (stream, "export PREFIX := %s\n", cygpath (install_tree).c_str ());
526 fprintf (stream, "export COMMAND_PREFIX := %s\n", command_prefix.c_str ());
527 fprintf (stream, "export CC := $(COMMAND_PREFIX)gcc\n");
528 fprintf (stream, "export OBJCOPY := $(COMMAND_PREFIX)objcopy\n");
529 fprintf (stream, "export AR := $(COMMAND_PREFIX)ar\n\n");
531 // generate the makefile contents
532 fprintf (stream, ".PHONY: default build clean tests headers\n\n");
534 fprintf (stream, "build: headers $(PREFIX)/include/pkgconf/ecos.mak\n");
535 for (make = 0; make < info_make_vector.size (); make++) { // for each make
536 if (info_make_vector [make].loadable->makes [info_make_vector [make].make].priority < 100) { // if priority higher than default complilation
537 fprintf (stream, "\t$(MAKE) -r -C %s %s\n", info_make_vector [make].loadable->directory.c_str (), resolve_tokens (info_make_vector [make].loadable->makes [info_make_vector [make].make].target).c_str ());
540 for (loadable = 0; loadable < info_vector.size (); loadable++) { // for each buildable loaded package
541 const std::string source_path = info_vector [loadable].directory;
542 fprintf (stream, "\t$(MAKE) -r -C %s $@\n", source_path.c_str ());
544 for (make = 0; make < info_make_vector.size (); make++) { // for each make
545 if (info_make_vector [make].loadable->makes [info_make_vector [make].make].priority >= 100) { // if priority lower than or equal to default complilation
546 fprintf (stream, "\t$(MAKE) -r -C %s %s\n", info_make_vector [make].loadable->directory.c_str (), resolve_tokens (info_make_vector [make].loadable->makes [info_make_vector [make].make].target).c_str ());
549 fprintf (stream, "\t@echo $@ finished\n\n");
551 fprintf (stream, "clean:\n");
552 for (loadable = 0; loadable < info_vector.size (); loadable++) { // for each buildable loaded package
553 const std::string source_path = info_vector [loadable].directory;
554 fprintf (stream, "\t$(MAKE) -r -C %s $@\n", source_path.c_str ());
556 fprintf (stream, "\t@echo $@ finished\n\n");
558 fprintf (stream, "tests: build\n");
559 for (loadable = 0; loadable < info_vector.size (); loadable++) { // for each buildable loaded package
560 const std::string source_path = info_vector [loadable].directory;
561 fprintf (stream, "\t$(MAKE) -r -C %s $@\n", source_path.c_str ());
563 fprintf (stream, "\t@echo $@ finished\n\n");
565 fprintf (stream, "headers:\n");
566 for (loadable = 0; loadable < info_vector.size (); loadable++) { // for each buildable loaded package
567 const std::string source_path = info_vector [loadable].directory;
568 fprintf (stream, "\t$(MAKE) -r -C %s $@\n", source_path.c_str ());
570 fprintf (stream, "\t@echo $@ finished\n\n");
572 fprintf (stream, "$(PREFIX)/include/pkgconf/ecos.mak: makefile\n");
573 fprintf (stream, "\t@echo 'ECOS_GLOBAL_CFLAGS = %s' > $@\n", get_flags (config, NULL, "CFLAGS").c_str ());
574 fprintf (stream, "\t@echo 'ECOS_GLOBAL_LDFLAGS = %s' >> $@\n", get_flags (config, NULL, "LDFLAGS").c_str ());
575 fprintf (stream, "\t@echo 'ECOS_COMMAND_PREFIX = $(COMMAND_PREFIX)' >> $@\n\n");
577 // close the makefile
578 return (0 == fclose (stream));
581 // generates the directory structure for the build and install trees
582 bool generate_build_tree (const CdlConfiguration config, const std::string build_tree, const std::string install_tree /* = "" */ ) {
583 #if defined(_WIN32) || defined(__CYGWIN__)
584 // convert backslash directory separators to forward slashes under Win32
585 const std::string build_dir = replace_char (build_tree, '\\', '/');
586 const std::string install_dir = install_tree.empty () ? build_dir + "/install" : replace_char (install_tree, '\\', '/');
588 const std::string build_dir = build_tree;
589 const std::string install_dir = install_tree.empty () ? build_dir + "/install" : install_tree;
592 // create build and install directories to ensure they are in writable locations
593 if (! create_directory (build_dir))
595 if (! create_directory (install_dir + "/lib"))
597 if (! create_directory (install_dir + "/include/pkgconf"))
600 // obtain build information from the specified configuration
601 CdlBuildInfo build_info;
602 config->get_build_info (build_info);
603 std::vector <CdlBuildInfo_Loadable> info_vector = build_info.entries;
605 for (unsigned int loadable = 0; loadable < info_vector.size (); loadable++) { // for each buildable loaded package
606 const std::string build_dir_loadable = build_dir + "/" + info_vector [loadable].directory;
608 // create loadable directory in build tree
609 if (! create_directory (build_dir_loadable))
613 generate_makefile (config, info_vector [loadable], install_dir, build_dir_loadable + "/makefile");
616 generate_toplevel_makefile (config, install_dir, build_dir + "/makefile");