Subversion Repositories tendra.SVN

Rev

Rev 2 | Rev 6 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "config.h"
32
#include "object.h"
33
#include "hash.h"
34
#include "name.h"
35
#include "type.h"
36
#include "utility.h"
37
 
38
 
39
/*
40
    IS A FILE NEEDED IN THE MAKEFILE?
41
 
42
    This routine tests whether a file with information i is needed in the
43
    makefile for the given api.
44
*/
45
 
46
static boolean need_info
47
    PROTO_N ( ( i, api ) )
48
    PROTO_T ( info *i X char *api )
49
{
50
    if ( restrict_depth && !streq ( api, i->api ) ) return ( 0 ) ;
51
    return ( i->implemented && i->tokens && i->src ) ;
52
}
53
 
54
 
55
/*
56
    PRINT A MAKEFILE
57
 
58
    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
60
    by whole.
61
*/
62
 
63
void print_makefile
64
    PROTO_N ( ( api, f, whole ) )
65
    PROTO_T ( char *api X hash_elem *f X int whole )
66
{
67
    char *nm ;
68
    FILE *output ;
69
    hash_elem *e ;
70
    char *api2 = hack_name ( api, "_Aa0" ) ;
71
    int li = output_incl_len ;
72
    int ls = output_src_len ;
73
 
74
    /* Open output file */
75
    nm = ( whole ? MAKEFILE_API : MAKEFILE ) ;
76
    nm = string_printf ( nm, output_src_dir, api, api2 ) ;
77
    if ( verbose > 1 ) error ( ERR_INFO, "Creating %s ...", nm ) ;
78
    create_dir ( nm ) ;
79
    output = fopen ( nm, "w" ) ;
80
    if ( output == null ) {
81
	error ( ERR_SERIOUS, "Can't open output file, %s", nm ) ;
82
	return ;
83
    }
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 ) ;
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 ) ;
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 ) {
136
	info *i = e->obj->u.u_info ;
137
	if ( need_info ( i, api ) ) {
138
	    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 ) ) ;
143
	    m = ( int ) strlen ( buffer ) - 1 ;
144
	    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 ) ;
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
		}
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
	}
166
    }
167
 
168
    /* 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 ) ;
172
    return ;
173
}