source: SVN/cambria/redboot/host/tools/configtool/common/common/build.cxx @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 24.6 KB
Line 
1//####COPYRIGHTBEGIN####
2//                                                                         
3// ----------------------------------------------------------------------------
4// Copyright (C) 2003 Bart Veer
5// Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
6//
7// This program is part of the eCos host tools.
8//
9// This program is free software; you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by the Free
11// Software Foundation; either version 2 of the License, or (at your option)
12// any later version.
13//
14// This program is distributed in the hope that it will be useful, but WITHOUT
15// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17// more details.
18//
19// You should have received a copy of the GNU General Public License along with
20// this program; if not, write to the Free Software Foundation, Inc.,
21// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22//
23// ----------------------------------------------------------------------------
24//                                                                         
25//####COPYRIGHTEND####
26//==========================================================================
27//
28//      build.cxx
29//
30//      The implementation of build tree and makefile generation using
31//      CDL data
32//
33//==========================================================================
34//==========================================================================
35//#####DESCRIPTIONBEGIN####                                             
36//
37// Author(s):           jld
38// Date:                1999-11-08
39//
40//####DESCRIPTIONEND####
41//==========================================================================
42
43#if defined(_WIN32) || defined(__CYGWIN__)
44        #include <windows.h> /* for GetShortPathNameA() */
45#endif
46#ifdef __CYGWIN__
47        #include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() */
48#endif
49#ifdef __WXMSW__
50// We take advantage of wxWindows' recursive wxFileName::Mkdir function
51// to workaround a bug in Tcl on Windows 9x
52#include "wx/filename.h"
53#  ifdef new
54#    undef new
55#  endif
56#endif
57#include "flags.hxx"
58#include "build.hxx"
59
60// Two methods of generating Cygwin filenames
61// ECOS_USE_CYGDRIVE = 0: use e.g. //c/, but this is deprecated in new versions of Cygwin
62// ECOS_USE_CYGDRIVE = 1: use e.g. /cygdrive/c/
63// ECOS_USE_CYGDRIVE = 2: use e.g. c:/ notation
64// ECOS_USE_CYGDRIVE = 3: use e.g. /ecos-x notation where x is a drive name.
65#define ECOS_USE_CYGDRIVE 3
66
67// Use registry functions to find out location of /cygdrive
68#define ECOS_USE_REGISTRY 1
69
70// Don't use Reg... functions in command-line version until we know how
71// to add advapi32.lib
72#if defined(_WIN32) && !defined(__WXMSW__) && !defined(ECOS_CT)
73#undef ECOS_USE_REGISTRY
74#define ECOS_USE_REGISTRY 0
75#endif
76
77std::string makefile_header = "# eCos makefile\n\n# This is a generated file - do not edit\n\n";
78
79// This code seems to crash Tcl under Windows ME and Linux, so
80// disable for now. What should the criterion be? TCL version?
81#define SET_STDOUT_TO_NULL 0
82
83bool eval_tcl_command (const std::string command) {
84        Tcl_Interp * interp = Tcl_CreateInterp ();
85#if SET_STDOUT_TO_NULL
86        Tcl_Channel outchan = Tcl_OpenFileChannel (interp, "nul", "a+", 777);
87        Tcl_SetStdChannel (outchan, TCL_STDOUT); // direct standard output to the null device
88#endif
89        int nStatus = Tcl_Eval (interp, CDL_TCL_CONST_CAST(char*, command.c_str()));
90#if SET_STDOUT_TO_NULL
91        Tcl_SetStdChannel (NULL, TCL_STDOUT);
92        Tcl_UnregisterChannel (interp, outchan);
93#endif
94        Tcl_DeleteInterp (interp);
95        return (TCL_OK == nStatus);
96}
97
98// generate a copy of a string where each occurance of a specified char is replaced with another char
99std::string replace_char (const std::string input, const char old_char, const char new_char) {
100        std::string output;
101        for (unsigned int n = 0; n < input.size (); n++) { // for each char
102                output += (old_char == input [n]) ? new_char : input [n]; // convert during copy
103        }
104        return output;
105}
106
107// convert a filepath into a vector of path components
108static void path_to_vector (std::string input, std::vector <std::string> & output) {
109        std::string component;
110        output.clear ();
111
112        for (unsigned int n = 0; n < input.size (); n++) { // for each char in the path
113                if (('/' == input [n]) || ('\\' == input [n])) { // if char is a directory separator
114                        output.push_back (component); // add path component to output vector
115                        component.erase (); // clear path component string
116                } else { // char is not a separator
117                        component += input [n]; // add char to path component string
118                }
119        }
120        output.push_back (component); // add final path component to output vector
121}
122
123// eliminate spaces from a DOS filepath by substituting the
124// short form of path components containing spaces
125#if defined(_WIN32) || defined(__CYGWIN__)
126std::string nospace_path (const std::string input) {
127        // split the path into a vector of path components
128        std::vector <std::string> long_path_vector;
129        path_to_vector (input, long_path_vector);
130
131        // convert the path to its short form and split
132        // the result into a vector of path components
133        char buffer [MAX_PATH + 1];
134        GetShortPathNameA (input.c_str (), buffer, sizeof (buffer));
135        std::vector <std::string> short_path_vector;
136        path_to_vector (buffer, short_path_vector);
137
138        // append the short or long form of each path component to the output string as appropriate
139        std::string output;
140        for (unsigned int n = 0; n < long_path_vector.size (); n++) { // for each component of the path
141                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
142                        output += short_path_vector [n]; // add the short form of the path component
143                } else { // there is no space in the path component
144                        output += long_path_vector [n]; // add the long form of the path component
145                }
146                output += '\\'; // add a directory separator
147        }
148        output.resize (output.size () - 1); // remove the trailing separator
149
150        return output;
151}
152#endif
153
154// convert a DOS filepath to a Cygwin filepath
155std::string cygpath (const std::string input) {
156#if defined(_WIN32) || defined(__CYGWIN__)
157        // remove spaces from the DOS filepath
158        const std::string path = nospace_path (input);
159        std::string output;
160
161        // convert the DOS filepath to Cygwin notation - using Cygwin if available
162    // 2001-10-15: should now do the same thing under Cygwin as under VC++, namely
163    // use the /ecos-x form.
164#if 0 // def __CYGWIN__
165        char buffer [MAX_PATH + 1];
166        cygwin_conv_to_posix_path (path.c_str (), buffer);
167        output = buffer;
168#else
169
170#if ECOS_USE_CYGDRIVE == 1
171    std::string strCygdrive("/cygdrive");
172
173#if ECOS_USE_REGISTRY
174    HKEY hKey = 0;
175    if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cygnus Solutions\\Cygwin\\mounts v2",
176        0, KEY_READ, &hKey))
177    {
178        DWORD type;
179        BYTE value[256];
180        DWORD sz;
181        if (ERROR_SUCCESS == RegQueryValueEx(hKey, "cygdrive prefix", NULL, & type, value, & sz))
182        {
183            strCygdrive = (const char*) value;
184        }
185
186        RegCloseKey(hKey);
187    }
188#endif
189    strCygdrive = strCygdrive + "/";
190
191        for (unsigned int n = 0; n < path.size (); n++) { // for each char
192                if ((1 == n) && (':' == path [n])) { // if a DOS logical drive letter is present
193                        output = strCygdrive + output; // convert to Cygwin notation
194                } else {
195                        output += ('\\' == path [n]) ? '/' : path [n]; // convert backslash to slash
196                }
197        }
198#elif ECOS_USE_CYGDRIVE == 2
199    // Convert to c:/foo/bar notation
200        for (unsigned int n = 0; n < path.size (); n++) { // for each char
201                        output += ('\\' == path [n]) ? '/' : path [n]; // convert backslash to slash
202        }
203#elif ECOS_USE_CYGDRIVE == 3
204    // Convert to /ecos-x notation, assuming that this mount point will be created
205    // by the application.
206
207    std::string output1;
208
209    if (path.size() > 1 && path[1] == ':')
210    {
211        output1 = "/ecos-";
212        output1 += tolower(path[0]);
213        output1 += "/";
214
215        // Append the rest of the path
216        if (path.size() > 2)
217        {
218            unsigned int n = 2;
219            unsigned int i;
220
221            if (path[n] == '\\' || path[n] == '/')
222                n ++;
223           
224            for (i = n; i < path.size(); i++)
225                output1 += path[i];
226        }
227    }
228    else
229        output1 = path;
230
231    for (unsigned int n = 0; n < output1.size (); n++) { // for each char
232        output += ('\\' == output1 [n]) ? '/' : output1 [n]; // convert backslash to slash
233        }
234#else
235        for (unsigned int n = 0; n < path.size (); n++) { // for each char
236                if ((1 == n) && (':' == path [n])) { // if a DOS logical drive letter is present
237                        output = "//" + output; // convert to Cygwin notation
238                } else {
239                        output += ('\\' == path [n]) ? '/' : path [n]; // convert backslash to slash
240                }
241        }
242#endif
243    // ECOS_USE_CYGDRIVE
244#endif
245        return output;
246#else
247        return input;
248#endif
249}
250
251// create a directory
252bool create_directory (const std::string directory) {
253// We take advantage of wxWindows' recursive wxFileName::Mkdir function
254// to workaround a bug in Tcl on Windows 9x
255#if defined(__WXMSW__)
256    if (wxDirExists(directory.c_str()))
257        return TRUE;
258    return wxFileName::Mkdir(directory.c_str(), 0777, TRUE);
259#else
260    return eval_tcl_command ("file mkdir \"" + directory + "\"");
261#endif
262}
263
264// copy a file
265bool copy_file (const std::string file, const std::string destination) {
266        return eval_tcl_command ("file copy \"" + file + "\" \"" + destination + "\"");
267        return true;
268}
269
270// returns the directory of the specified file
271std::string file_to_directory (const std::string file) {
272        for (unsigned int n = file.size (); n >= 0; n--) {
273                if ('/' == file [n]) {
274                        std::string directory = file;
275                        directory.resize (n);
276                        return directory;
277                }
278        }
279        return "";
280}
281
282std::string tab_indent (const std::string input) {
283        std::string output;
284        bool indent = true;
285        for (unsigned int n = 0; n < input.size (); n++) {
286                if (indent) {
287                        output += '\t';
288                        indent = false;
289                } else {
290                        indent = ('\n' == input [n]);
291                }
292                output += input [n];
293        }
294        return output;
295}
296
297// return the tests of the specified loadable
298std::string get_tests (const CdlConfiguration config, const CdlBuildInfo_Loadable & build_info) {
299        CdlValuable tests = dynamic_cast <CdlValuable> (config->lookup (build_info.name + "_TESTS"));
300    // check if there are tests active and enabled
301        if (tests && tests->is_active() && tests->is_enabled()) {
302                return tests->get_value ();
303        } else { // there are no tests
304                return "";
305        }
306}
307
308// replaces all occurances of a substring with a new substring
309std::string replace_substr (const std::string input, const std::string old_substring, const std::string new_substring) {
310        std::string output = input;
311        std::string::size_type index = 0;
312        while (index = output.find (old_substring, index), std::string::npos != index) {
313                output.replace (index, old_substring.size (), new_substring);
314        }
315        return output;
316}
317
318// resolve tokens in custom make rule targets and dependencies
319std::string resolve_tokens (const std::string input) {
320        std::string output = input;
321        output = replace_substr (output, "<PREFIX>", "$(PREFIX)");
322        output = replace_substr (output, "<PACKAGE>", "$(REPOSITORY)/$(PACKAGE)");
323        return output;
324}
325
326// create the makefile for a loadable
327bool generate_makefile (const CdlConfiguration config, const CdlBuildInfo_Loadable & info, const std::string install_tree, const std::string filename) {
328        unsigned int count;
329        unsigned int library;
330
331        // obtain the command prefix
332        std::string command_prefix = get_flags (config, NULL, "COMMAND_PREFIX");
333        if (! command_prefix.empty ()) { // if there is a command prefix
334                command_prefix += '-'; // add a trailing hyphen
335        }
336
337        // generate the prefix for archived objects
338        unsigned int final_separator = 0; // the index of the last directory separator
339        std::string object_prefix = info.directory; // start with the loadable directory
340        for (count = 0; count < object_prefix.size (); count++) { // for each char
341                if ('/' == object_prefix [count]) { // if the char is a directory separator
342                        object_prefix [count] = '_'; // replace the char with an underscore
343                        final_separator = count;
344                }
345        }
346        object_prefix.resize (final_separator); // remove the version directory
347       
348        // open the makefile
349        FILE * stream = fopen (filename.c_str (), "wt");
350        if (stream == NULL) // if the file could not be opened
351                return false;
352
353        // generate the header
354        fprintf (stream, makefile_header.c_str ());
355
356        // generate the global variables
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");
363#else
364    fprintf (stream, "export HOST := UNIX\n");
365#endif
366        fprintf (stream, "export AR := $(COMMAND_PREFIX)ar\n\n");
367
368        // generate the package variables
369        fprintf (stream, "export REPOSITORY := %s\n", cygpath (info.repository).c_str());
370        fprintf (stream, "PACKAGE := %s\n", info.directory.c_str ());
371        fprintf (stream, "OBJECT_PREFIX := %s\n", object_prefix.c_str ());
372        fprintf (stream, "CFLAGS := %s\n", get_flags (config, &info, "CFLAGS").c_str ());
373        fprintf (stream, "LDFLAGS := %s\n", get_flags (config, &info, "LDFLAGS").c_str ());
374        fprintf (stream, "VPATH := $(REPOSITORY)/$(PACKAGE)\n");
375        fprintf (stream, "INCLUDE_PATH := $(INCLUDE_PATH) -I$(PREFIX)/include $(foreach dir,$(VPATH),-I$(dir) -I$(dir)/src -I$(dir)/tests) -I.\n");
376        fprintf (stream, "MLT := $(wildcard $(REPOSITORY)/$(PACKAGE)/include/pkgconf/mlt*.ldi $(REPOSITORY)/$(PACKAGE)/include/pkgconf/mlt*.h)\n");
377        fprintf (stream, "TESTS := %s\n\n", get_tests (config, info).c_str ());
378
379        // create a vector of libraries
380        std::vector <std::string> library_vector;
381        for (count = 0; count < info.compiles.size (); count++) { // for each compilable file
382                const std::string & library = info.compiles [count].library;
383                if (library_vector.end () == std::find (library_vector.begin (), library_vector.end (), library)) { // if a new library
384                        library_vector.push_back (library); // add the library to the vector
385                }
386        }
387        for (count = 0; count < info.objects.size (); count++) { // for each object file
388                const std::string & library = info.objects [count].library;
389                if (library_vector.end () == std::find (library_vector.begin (), library_vector.end (), library)) { // if a new library
390                        library_vector.push_back (library); // add the library to the vector
391                }
392        }
393        for (count = 0; count < info.make_objects.size (); count++) { // for each make object
394                const std::string & library = info.make_objects [count].library;
395                if (library_vector.end () == std::find (library_vector.begin (), library_vector.end (), library)) { // if a new library
396                        library_vector.push_back (library); // add the library to the vector
397                }
398        }
399
400        // generate the default rule
401        fprintf (stream, "build: headers");
402        for (library = 0; library < library_vector.size (); library++) { // for each library
403                fprintf (stream, " %s.stamp", library_vector [library].c_str ());
404        }
405        fprintf (stream, "\n\n");
406
407        // generate library rules
408        for (library = 0; library < library_vector.size (); library++) { // for each library
409                fprintf (stream, "LIBRARY := %s\n", library_vector [library].c_str ());
410                fprintf (stream, "COMPILE :=");
411                for (count = 0; count < info.compiles.size (); count++) { // for each compilable file
412                        if (library_vector [library] == info.compiles [count].library) { // if the file and library are related
413                                fprintf (stream, " %s", info.compiles [count].source.c_str ());
414                        }
415                }
416                for (count = 0; count < info.objects.size (); count++) { // for each object file
417                        if (library_vector [library] == info.objects [count].library) { // if the file and library are related
418                                fprintf (stream, " %s", info.objects [count].object.c_str ());
419                        }
420                }
421                for (count = 0; count < info.make_objects.size (); count++) { // for each make object
422                        if (library_vector [library] == info.make_objects [count].library) { // if the object and library are related
423                                fprintf (stream, " %s", info.make_objects [count].object.c_str ());
424                        }
425                }
426
427                fprintf (stream, "\nOBJECTS := $(COMPILE:.cxx=.o.d)\n");
428                fprintf (stream, "OBJECTS := $(OBJECTS:.c=.o.d)\n");
429                fprintf (stream, "OBJECTS := $(OBJECTS:.S=.o.d)\n\n");
430                fprintf (stream, "$(LIBRARY).stamp: $(OBJECTS)\n");
431                fprintf (stream, "\t$(AR) rcs $(PREFIX)/lib/$(@:.stamp=) $(foreach obj,$?,$(dir $(obj))$(OBJECT_PREFIX)_$(notdir $(obj:.o.d=.o)))\n");
432                fprintf (stream, "\t@cat $^ > $(@:.stamp=.deps)\n");
433                fprintf (stream, "\t@touch $@\n\n");
434        }       
435
436        // generate make objects rules
437        for (count = 0; count < info.make_objects.size (); count++) { // for each make object
438                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 ());
439        }
440
441        // generate makes rules
442        for (count = 0; count < info.makes.size (); count++) { // for each make
443                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 ());
444        }
445
446        // generate header rules
447        fprintf (stream, "headers: mlt_headers");
448        for (count = 0; count < info.headers.size (); count++) { // for each header
449                fprintf (stream, " $(PREFIX)/include/%s", info.headers [count].destination.c_str ());
450        }
451        fprintf (stream, "\n\n");
452        for (count = 0; count < info.headers.size (); count++) { // for each header
453                fprintf (stream, "$(PREFIX)/include/%s: $(REPOSITORY)/$(PACKAGE)/%s\n", info.headers [count].destination.c_str (), info.headers [count].source.c_str ());
454#if (defined(_WIN32) || defined(__CYGWIN__)) && (ECOS_USE_CYGDRIVE > 0)
455        fprintf (stream, "ifeq ($(HOST),CYGWIN)\n");
456            fprintf (stream, "\t@mkdir -p `cygpath -w \"$(dir $@)\" | sed \"s@\\\\\\\\\\\\\\\\@/@g\"`\n");
457        fprintf (stream, "else\n");
458            fprintf (stream, "\t@mkdir -p $(dir $@)\n");
459        fprintf (stream, "endif\n");
460#else
461        // This prevents older versions of mkdir failing
462        fprintf (stream, "\t@mkdir -p $(dir $@)\n");
463#endif
464
465                fprintf (stream, "\t@cp $< $@\n");
466                fprintf (stream, "\t@chmod u+w $@\n\n");
467        }
468
469        // include default rules
470        fprintf (stream, "include $(REPOSITORY)/pkgconf/rules.mak\n\n");
471
472        // close the makefile
473        return (0 == fclose (stream));
474}
475
476// a structure and operator for sorting custom make rules by priority
477struct info_make {
478        std::vector <CdlBuildInfo_Loadable>::const_iterator loadable;
479        unsigned int make;
480};
481bool operator < (info_make op1, info_make op2) {
482        return op1.loadable->makes [op1.make].priority < op2.loadable->makes [op2.make].priority;
483}
484
485// create the top-level makefile
486bool generate_toplevel_makefile (const CdlConfiguration config, const std::string install_tree, const std::string filename) {
487        unsigned int loadable;
488        unsigned int make;
489
490        // obtain the command prefix
491        std::string command_prefix = get_flags (config, NULL, "COMMAND_PREFIX");
492        if (! command_prefix.empty ()) { // if there is a command prefix
493                command_prefix += '-'; // add a trailing hyphen
494        }
495
496        // obtain build information from the specified configuration
497        CdlBuildInfo build_info;
498        config->get_build_info (build_info);
499        std::vector <CdlBuildInfo_Loadable> info_vector = build_info.entries;
500
501        // create a vector of makes and sort them by priority
502        std::vector <info_make> info_make_vector;
503        for (std::vector <CdlBuildInfo_Loadable>::iterator info = info_vector.begin (); info != info_vector.end (); info++) { // for each buildable loaded package
504                for (unsigned int count = 0; count < info->makes.size (); count++) { // for each make
505                        info_make make_info = {info, count};
506                        info_make_vector.push_back (make_info);
507                }
508        }
509        std::sort (info_make_vector.begin (), info_make_vector.end ());
510
511        // open the makefile
512        FILE * stream = fopen (filename.c_str (), "wt");
513        if (stream == NULL) // if the file could not be opened
514                return false;
515
516        // generate the header
517        fprintf (stream, makefile_header.c_str ());
518
519        // generate the variables
520#if defined(_WIN32) || defined(__CYGWIN__)
521    fprintf (stream, "export HOST := CYGWIN\n");
522#else
523    fprintf (stream, "export HOST := UNIX\n");
524#endif
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");
530
531    // generate the makefile contents
532        fprintf (stream, ".PHONY: default build clean tests headers\n\n");
533
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 ());
538                }
539        }
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 ());
543        }
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 ());
547                }
548        }
549        fprintf (stream, "\t@echo $@ finished\n\n");
550
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 ());
555        }
556        fprintf (stream, "\t@echo $@ finished\n\n");
557
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 ());
562        }
563        fprintf (stream, "\t@echo $@ finished\n\n");
564
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 ());
569        }
570        fprintf (stream, "\t@echo $@ finished\n\n");
571
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");
576
577        // close the makefile
578        return (0 == fclose (stream));
579}
580
581// generates the directory structure for the build and install trees
582bool 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, '\\', '/');
587#else
588        const std::string build_dir = build_tree;
589        const std::string install_dir = install_tree.empty () ? build_dir + "/install" : install_tree;
590#endif
591
592        // create build and install directories to ensure they are in writable locations
593        if (! create_directory (build_dir))
594                return false;
595        if (! create_directory (install_dir + "/lib"))
596                return false;
597        if (! create_directory (install_dir + "/include/pkgconf"))
598                return false;
599
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;
604
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;
607
608                // create loadable directory in build tree
609                if (! create_directory (build_dir_loadable))
610                        return false;
611
612                // generate makefile
613                generate_makefile (config, info_vector [loadable], install_dir, build_dir_loadable + "/makefile");
614        }
615
616        generate_toplevel_makefile (config, install_dir, build_dir + "/makefile");
617
618        return true;
619}
Note: See TracBrowser for help on using the repository browser.