Subversion Repositories tendra.SVN

Rev

Rev 2 | Rev 38 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 32... Line 62...
32
#include "object.h"
62
#include "object.h"
33
#include "hash.h"
63
#include "hash.h"
34
#include "name.h"
64
#include "name.h"
35
#include "type.h"
65
#include "type.h"
36
#include "utility.h"
66
#include "utility.h"
-
 
67
#include "makefile.h"
37
 
68
 
38
 
69
 
39
/*
70
/*
40
    IS A FILE NEEDED IN THE MAKEFILE?
71
    IS A FILE NEEDED IN THE MAKEFILE?
41
 
72
 
42
    This routine tests whether a file with information i is needed in the
73
    This routine tests whether a file with information i is needed in the
43
    makefile for the given api.
74
    makefile for the given api.
44
*/
75
*/
45
 
76
 
46
static boolean need_info
77
static
47
    PROTO_N ( ( i, api ) )
-
 
48
    PROTO_T ( info *i X char *api )
78
boolean need_info(info *i, char *api)
49
{
79
{
50
    if ( restrict_depth && !streq ( api, i->api ) ) return ( 0 ) ;
80
    if (restrict_depth && !streq(api, i->api)) return(0);
51
    return ( i->implemented && i->tokens && i->src ) ;
81
    return(i->implemented && i->tokens && i->src);
52
}
82
}
53
 
83
 
54
 
84
 
55
/*
85
/*
56
    PRINT A MAKEFILE
86
    PRINT A MAKEFILE
57
 
87
 
58
    This routine prints a makefile to build a TDF library for the API api
88
    This routine prints a makefile to build a TDF library for the API api
59
    from the list of files f.  There are two forms of the output, indicated
89
    from the list of files f.  There are two forms of the output, indicated
60
    by whole.
90
    by whole.
61
*/
91
*/
62
 
92
 
63
void print_makefile
93
void
64
    PROTO_N ( ( api, f, whole ) )
-
 
65
    PROTO_T ( char *api X hash_elem *f X int whole )
94
print_makefile(char *api, hash_elem *f, int whole)
66
{
95
{
67
    char *nm ;
96
    char *nm;
68
    FILE *output ;
97
    FILE *output;
69
    hash_elem *e ;
98
    hash_elem *e;
70
    char *api2 = hack_name ( api, "_Aa0" ) ;
99
    char *api2 = hack_name(api, "_Aa0");
71
    int li = output_incl_len ;
-
 
72
    int ls = output_src_len ;
-
 
73
 
100
 
74
    /* Open output file */
101
    /* Open output file */
75
    nm = ( whole ? MAKEFILE_API : MAKEFILE ) ;
102
    nm = (whole ? MAKEFILE_API : MAKEFILE);
76
    nm = string_printf ( nm, output_src_dir, api, api2 ) ;
103
    nm = string_printf(nm, output_src_dir, api, api2);
77
    if ( verbose > 1 ) error ( ERR_INFO, "Creating %s ...", nm ) ;
104
    if (verbose > 1) IGNORE printf("Creating %s ...", nm);
78
    create_dir ( nm ) ;
105
    create_dir(nm);
79
    output = fopen ( nm, "w" ) ;
106
    output = fopen(nm, "w");
80
    if ( output == null ) {
107
    if (output == null) {
81
	error ( ERR_SERIOUS, "Can't open output file, %s", nm ) ;
108
	error(ERR_SERIOUS, "Can't open output file, %s", nm);
82
	return ;
109
	return;
83
    }
110
    }
84
 
-
 
85
    /* Print file header */
-
 
86
    IGNORE fprintf ( output, "# AUTOMATICALLY GENERATED BY %s %s\n",
-
 
87
		     progname, progvers ) ;
-
 
88
    IGNORE fprintf ( output, "# MAKEFILE FOR %s API\n\n", api ) ;
111
    fprintf(output, "APILIB=\t%s.tl\n\n", api);
89
    if ( whole ) {
-
 
90
	IGNORE fputs ( "TCC=tcc# Version of tcc\n", output ) ;
-
 
91
	IGNORE fprintf ( output, "LIB=%s.tl# TDF library\n", api2 ) ;
-
 
92
	IGNORE fputs ( "IMPL=/usr/include# API implementation directory\n",
-
 
93
		       output ) ;
-
 
94
	IGNORE fputs ( "WORK=.# Work directory\n\n", output ) ;
-
 
95
	IGNORE fprintf ( output, "INCL=%s# API header directory\n",
-
 
96
			 output_incl_dir ) ;
-
 
97
	IGNORE fprintf ( output, "SRC=%s# API auxiliary directory\n",
-
 
98
			 output_src_dir ) ;
-
 
99
	IGNORE fputs ( "PRE_FLAGS=\n", output ) ;
112
	fputs("APIOBJS=\t", output);
100
	IGNORE fprintf ( output, "INCL_FLAGS=-I${IMPL} -I${INCL}/%s%s\n",
-
 
101
		         api, OUTPUT_SUFFIX ) ;
-
 
102
	IGNORE fputs ( "POST_FLAGS=\n", output ) ;
-
 
103
	IGNORE fputs ( "TDI=${TCC} -D", output ) ;
-
 
104
	IGNORE fputs ( BUILDING_MACRO, output ) ;
-
 
105
	IGNORE fputs ( " ${PRE_FLAGS} ${INCL_FLAGS}", output ) ;
-
 
106
	IGNORE fputs ( " ${POST_FLAGS} -Fj\n", output ) ;
-
 
107
	IGNORE fputs ( "TDP=${TCC} -Ytdp ${INCL_FLAGS} -Fj\n", output ) ;
-
 
108
	IGNORE fputs ( "TNC=${TCC} -Ytnc -Fj\n", output ) ;
-
 
109
	IGNORE fputs ( "TLIB=${TCC} -Ymakelib\n\n", output ) ;
-
 
110
    }
-
 
111
    IGNORE fputs ( "SHELL=/bin/sh\n\n", output ) ;
-
 
112
 
-
 
113
    /* Print the list of files */
-
 
114
    IGNORE fputs ( "JFILES=", output ) ;
-
 
115
    for ( e = f ; e != null ; e = e->next ) {
-
 
116
	info *i = e->obj->u.u_info ;
-
 
117
	if ( need_info ( i, api ) ) {
-
 
118
	    int m ;
-
 
119
	    char *a = i->api ;
-
 
120
	    if ( strneq ( a, "shared/", 7 ) ) a += 7 ;
-
 
121
	    a = hack_name ( a, "_Aa0" ) ;
-
 
122
	    IGNORE sprintf ( buffer, "%s/%s", a, basename ( i->src ) ) ;
-
 
123
	    m = ( int ) strlen ( buffer ) - 1 ;
-
 
124
	    buffer [m] = 'j' ;
-
 
125
	    IGNORE fprintf ( output, "\\\n ${WORK}/%s", buffer ) ;
-
 
126
	}
-
 
127
    }
-
 
128
    IGNORE fputs ( "\n\nall : ${LIB}\n", output ) ;
-
 
129
    IGNORE fputs ( "\t@echo all done\n\n", output ) ;
-
 
130
    IGNORE fputs ( "${LIB} : ${JFILES}\n", output ) ;
-
 
131
    IGNORE fputs ( "\t@rm -f ${LIB}\n", output ) ;
-
 
132
    IGNORE fputs ( "\t${TLIB} -o ${LIB} ${JFILES}\n\n", output ) ;
-
 
133
 
-
 
134
    /* Print the construction for each file */
-
 
135
    for ( e = f ; e != null ; e = e->next ) {
113
	for ( e = f ; e != null ; e = e->next ) {
136
	info *i = e->obj->u.u_info ;
114
		info *i = e->obj->u.u_info ;
137
	if ( need_info ( i, api ) ) {
115
		if ( need_info ( i, api ) ) {
138
	    int m ;
116
			int m;
139
	    char *a = i->api ;
-
 
140
	    if ( strneq ( a, "shared/", 7 ) ) a += 7 ;
-
 
141
	    a = hack_name ( a, "_Aa0" ) ;
-
 
142
	    IGNORE sprintf ( buffer, "%s/%s", a, basename ( i->src ) ) ;
117
			strcpy(buffer, basename(i->src));
143
	    m = ( int ) strlen ( buffer ) - 1 ;
118
			m = strlen(buffer) - 1;
144
	    buffer [m] = 'j' ;
119
			buffer[m] = 'j';
145
	    IGNORE fprintf ( output, "${WORK}/%s : ${SRC}/%s",
-
 
146
			     buffer, i->src + ls ) ;
-
 
147
	    if ( whole && i->incl ) {
-
 
148
		IGNORE fprintf ( output, "\\\n ${INCL}/%s ${IMPL}/%s",
-
 
149
				 i->incl + li, i->file ) ;
-
 
150
	    }
-
 
151
	    if ( whole ) {
-
 
152
		IGNORE fprintf ( output, "\n\t@ test -d ${WORK}/%s", a ) ;
120
			fprintf(output, "\\\n\t\tbuilding/%s.api/%s", api, basename(buffer));
153
		IGNORE fprintf ( output, " || mkdir ${WORK}/%s", a ) ;
-
 
154
	    }
-
 
155
	    if ( i->method == null ) {
-
 
156
		IGNORE fputs ( "\n\t${TDI} ", output ) ;
-
 
157
		if ( !whole ) {
-
 
158
		    IGNORE fprintf ( output, "-f${STARTUP}/%s.h ", a ) ;
-
 
159
		}
121
		}
160
	    } else {
-
 
161
		IGNORE fprintf ( output, "\n\t${%s} ", i->method ) ;
-
 
162
	    }
-
 
163
	    IGNORE fprintf ( output, "-o ${WORK}/%s ${SRC}/%s\n\n",
-
 
164
			     buffer, i->src + ls ) ;
-
 
165
	}
122
	}
166
    }
123
	fputs("\n", output);
167
 
-
 
168
    /* End of makefile */
124
    /* End of makefile */
169
    IGNORE fputs ( "clean :\n\trm -f ${JFILES}\n\n", output ) ;
-
 
170
    IGNORE fputs ( "clobber : clean\n\trm -f ${LIB}\n", output ) ;
-
 
171
    IGNORE fclose ( output ) ;
125
    IGNORE fclose(output);
172
    return ;
126
    return;
173
}
127
}