]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/make.c
ICU-400.40.tar.gz
[apple/icu.git] / icuSources / tools / pkgdata / make.c
1 /**************************************************************************
2 *
3 * Copyright (C) 2000-2008, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *
6 ***************************************************************************
7 * file name: make.c
8 * encoding: ANSI X3.4 (1968)
9 * tab size: 8 (not used)
10 * indentation:4
11 *
12 * created on: 2000jul18
13 * created by: Vladimir Weinstein
14 * created on: 2000may17
15 * created by: Steven \u24C7 Loomis
16 * merged on: 2003sep14
17 * merged by: George Rhoten
18 * merged from nmake.c and gmake.c
19 *
20 * Emit a NMAKE or GNU makefile
21 */
22
23 #include "unicode/utypes.h"
24 #include "unicode/putil.h"
25 #include "makefile.h"
26 #include "cstring.h"
27 #include "cmemory.h"
28 #include <stdio.h>
29
30 #ifdef U_MAKE_IS_NMAKE
31
32 char linebuf[2048];
33
34 /* Write any setup/initialization stuff */
35 void
36 pkg_mak_writeHeader(FileStream *f, const UPKGOptions *o)
37 {
38 const char *appendVersion = NULL;
39 char *srcDir = convertToNativePathSeparators(uprv_strdup(o->srcDir));
40
41 if(o->version && !uprv_strstr(o->shortName,o->version)) { /* do not append version if
42 already contained in the name */
43 appendVersion = o->version;
44 }
45
46 sprintf(linebuf, "## Makefile for %s (%s) created by pkgdata\n"
47 "## from ICU Version %s\n"
48 "\n",
49 o->shortName,
50 o->libName,
51 U_ICU_VERSION);
52 T_FileStream_writeLine(f, linebuf);
53
54 sprintf(linebuf, "NAME=%s%s\n"
55 "CNAME=%s\n"
56 "LIBNAME=%s\n"
57 "SRCDIR=%s\n"
58 "TARGETDIR=%s\n"
59 "TEMP_DIR=%s\n"
60 "MODE=%s\n"
61 "MAKEFILE=%s\n"
62 "ENTRYPOINT=%s\n"
63 "TARGET_VERSION=%s\n"
64 "MKINSTALLDIRS=mkdir\n"
65 "INSTALL_DATA=copy\n"
66 "RMV=del /F"
67 "\n\n\n",
68 o->shortName,
69 (appendVersion ? appendVersion : ""),
70 o->cShortName,
71 o->libName,
72 srcDir,
73 o->targetDir,
74 o->tmpDir,
75 o->mode,
76 o->makeFile,
77 o->entryName,
78 o->version);
79 T_FileStream_writeLine(f, linebuf);
80
81 sprintf(linebuf, "## List files [%d] containing data files to process (note: - means stdin)\n"
82 "LISTFILES= ",
83 pkg_countCharList(o->fileListFiles));
84 T_FileStream_writeLine(f, linebuf);
85
86 pkg_writeCharListWrap(f, o->fileListFiles, " ", " \\\n", 0);
87
88 T_FileStream_writeLine(f, "\n\n\n");
89
90 sprintf(linebuf, "## Data Files [%d]\n"
91 "DATAFILES= ",
92 pkg_countCharList(o->files));
93
94 T_FileStream_writeLine(f, linebuf);
95
96 pkg_writeCharListWrap(f, o->files, " ", " \\\n", -1);
97
98 T_FileStream_writeLine(f, "\n\n\n");
99
100 sprintf(linebuf, "## Data File Paths [%d]\n"
101 "DATAFILEPATHS= ",
102 pkg_countCharList(o->filePaths));
103
104 T_FileStream_writeLine(f, linebuf);
105
106 pkg_writeCharListWrap(f, o->filePaths, " ", " \\\n", 1);
107
108 T_FileStream_writeLine(f, "\n\n\n");
109
110 uprv_free(srcDir);
111 }
112
113 /* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
114 void
115 pkg_mak_writeStanza(FileStream *f, const UPKGOptions *o,
116 const char *target,
117 CharList* parents,
118 CharList* commands )
119 {
120 T_FileStream_write(f, target, (int32_t)uprv_strlen(target));
121 T_FileStream_write(f, " : ", 3);
122 pkg_writeCharList(f, parents, " ",1);
123 T_FileStream_write(f, "\n", 1);
124
125 if(commands)
126 {
127 T_FileStream_write(f, "\t", 1);
128 pkg_writeCharList(f, commands, "\n\t",0);
129 }
130 T_FileStream_write(f, "\n\n", 2);
131 }
132
133 /* write any cleanup/post stuff */
134 void
135 pkg_mak_writeFooter(FileStream *f, const UPKGOptions *o)
136 {
137 char buf[256];
138 sprintf(buf, "\n\n# End of makefile for %s [%s mode]\n\n", o->shortName, o->mode);
139 T_FileStream_write(f, buf, (int32_t)uprv_strlen(buf));
140 }
141
142 #else /* #ifdef U_MAKE_IS_NMAKE */
143
144 #include "cmemory.h"
145 #include "filestrm.h"
146 #include "toolutil.h"
147 #include "unewdata.h"
148 #include "uoptions.h"
149 #include "pkgtypes.h"
150 #include <string.h>
151
152 char linebuf[2048];
153
154 /* Write any setup/initialization stuff */
155 void
156 pkg_mak_writeHeader(FileStream *f, const UPKGOptions *o)
157 {
158 sprintf(linebuf, "## Makefile for %s created by pkgdata\n"
159 "## from ICU Version %s\n"
160 "\n",
161 o->shortName,
162 U_ICU_VERSION);
163 T_FileStream_writeLine(f, linebuf);
164
165 sprintf(linebuf, "NAME=%s\n"
166 "LIBNAME=%s\n"
167 "CNAME=%s\n"
168 "TARGETDIR=%s\n"
169 "TEMP_DIR=%s\n"
170 "srcdir=$(TEMP_DIR)\n"
171 "SRCDIR=%s\n"
172 "MODE=%s\n"
173 "MAKEFILE=%s\n"
174 "ENTRYPOINT=%s\n"
175 "include %s\n"
176 "\n\n\n",
177 o->shortName,
178 o->libName,
179 o->cShortName,
180 o->targetDir,
181 o->tmpDir,
182 o->srcDir,
183 o->mode,
184 o->makeFile,
185 o->entryName,
186 o->options);
187 T_FileStream_writeLine(f, linebuf);
188
189 /* TEMP_PATH and TARG_PATH will be empty if the respective dir is . */
190 /* Avoid //'s and .'s which confuse make ! */
191 if(!strcmp(o->tmpDir,"."))
192 {
193 T_FileStream_writeLine(f, "TEMP_PATH=\n");
194 }
195 else
196 {
197 T_FileStream_writeLine(f, "TEMP_PATH=$(TEMP_DIR)/\n");
198 }
199
200 if(!strcmp(o->targetDir,"."))
201 {
202 T_FileStream_writeLine(f, "TARG_PATH=\n");
203 }
204 else
205 {
206 T_FileStream_writeLine(f, "TARG_PATH=$(TARGETDIR)/\n");
207 }
208
209 sprintf(linebuf, "## List files [%u] containing data files to process (note: - means stdin)\n"
210 "LISTFILES= ",
211 (int)pkg_countCharList(o->fileListFiles));
212 T_FileStream_writeLine(f, linebuf);
213
214 pkg_writeCharListWrap(f, o->fileListFiles, " ", " \\\n",0);
215
216 T_FileStream_writeLine(f, "\n\n\n");
217
218 sprintf(linebuf, "## Data Files [%u]\n"
219 "DATAFILES= ",
220 (int)pkg_countCharList(o->files));
221
222 T_FileStream_writeLine(f, linebuf);
223
224 pkg_writeCharListWrap(f, o->files, " ", " \\\n",-1);
225
226 T_FileStream_writeLine(f, "\n\n\n");
227
228 sprintf(linebuf, "## Data File Paths [%u]\n"
229 "DATAFILEPATHS= ",
230 (int)pkg_countCharList(o->filePaths));
231
232 T_FileStream_writeLine(f, linebuf);
233
234 pkg_writeCharListWrap(f, o->filePaths, " ", " \\\n",0);
235
236 T_FileStream_writeLine(f, "\n\n\n");
237
238 }
239
240 /* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
241 void
242 pkg_mak_writeStanza(FileStream *f, const UPKGOptions *o,
243 const char *target,
244 CharList* parents,
245 CharList* commands)
246 {
247 T_FileStream_write(f, target, uprv_strlen(target));
248 T_FileStream_write(f, " : ", 3);
249 pkg_writeCharList(f, parents, " ",0);
250 T_FileStream_write(f, "\n", 1);
251
252 if(commands)
253 {
254 T_FileStream_write(f, "\t", 1);
255 pkg_writeCharList(f, commands, "\n\t",0);
256 }
257 T_FileStream_write(f, "\n\n", 2);
258 }
259
260 /* write any cleanup/post stuff */
261 void
262 pkg_mak_writeFooter(FileStream *f, const UPKGOptions *o)
263 {
264 T_FileStream_writeLine(f, "\nrebuild: clean all\n");
265 }
266
267
268 void
269 pkg_mak_writeObjRules(UPKGOptions *o, FileStream *makefile, CharList **objects, const char* objSuffix)
270 {
271 const char *p, *baseName;
272 char *tmpPtr;
273 char tmp[1024];
274 char stanza[1024];
275 char cfile[1024];
276 CharList *oTail = NULL;
277 CharList *infiles;
278 CharList *parents = NULL, *commands = NULL;
279 char *parentPath;
280 const char *tchar;
281 char tree[1024];
282
283 infiles = o->files; /* raw files - no paths other than tree paths */
284
285 for(;infiles;infiles = infiles->next) {
286 baseName = infiles->str; /* skip the icudt28b/ part */
287 p = uprv_strrchr(baseName, '.');
288 if( (p == NULL) || (*p == '\0' ) ) {
289 continue;
290 }
291
292 uprv_strncpy(tmp, baseName, p-baseName);
293 p++;
294
295 uprv_strcpy(tmp+(p-1-baseName), "_"); /* to append */
296 uprv_strcat(tmp, p);
297 uprv_strcat(tmp, objSuffix );
298
299 /* iSeries cannot have '-' in the .o objects. */
300 for( tmpPtr = tmp; *tmpPtr; tmpPtr++ ) {
301 if ( *tmpPtr == U_FILE_SEP_CHAR ) { /* map tree names with underscores */
302 *tmpPtr = '_';
303 }
304 if ( *tmpPtr == '-' ) {
305 *tmpPtr = '_';
306 }
307 }
308
309 *objects = pkg_appendToList(*objects, &oTail, uprv_strdup(tmp));
310
311 /* write source list */
312 uprv_strcpy(cfile,tmp);
313 uprv_strcpy(cfile+uprv_strlen(cfile)-uprv_strlen(objSuffix), ".c" ); /* replace .o with .c */
314
315 /* Make up parents.. */
316 parentPath = uprv_malloc(1+uprv_strlen(baseName) + uprv_strlen("$(SRCDIR)/"));
317 sprintf(parentPath, "$(SRCDIR)/%s", baseName);
318 parents = pkg_appendToList(parents, NULL, parentPath);
319
320 /* make up commands.. */
321 /* search for tree.. */
322 if((tchar=uprv_strchr(baseName, '/'))) {
323 tree[0]='_';
324 strncpy(tree+1,baseName,tchar-baseName);
325 tree[tchar-baseName+1]=0;
326 } else {
327 tree[0] = 0;
328 }
329 #ifdef OS400
330 sprintf(stanza, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $(SRCDIR)/%s", tree, infiles->str);
331 #else
332 sprintf(stanza, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $<", tree);
333 #endif
334
335 if(uprv_strchr(baseName, '/')) {
336 /* append actual file - ex: coll_en_res otherwise the tree name will be lost */
337 strcat(stanza, " -f ");
338 strncat(stanza, tmp, (strlen(tmp)-strlen(objSuffix)));
339 }
340
341 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
342
343 #ifdef OS400
344 /* This builds the file into one .c file */
345 sprintf(stanza, "@cat $(TEMP_PATH)%s >> $(TEMP_PATH)/$(NAME)all.c", cfile);
346 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
347
348 sprintf(stanza, "@$(RMV) $(TEMP_DIR)/%s", cfile);
349 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
350
351 T_FileStream_write(makefile, "\t", 1);
352 pkg_writeCharList(makefile, commands, "\n\t",0);
353 T_FileStream_write(makefile, "\n\n", 2);
354 #else
355 sprintf(stanza, "@$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $(TEMP_DIR)/%s", cfile);
356 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
357
358 sprintf(stanza, "@$(RMV) $(TEMP_DIR)/%s", cfile);
359 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
360
361 sprintf(stanza, "$(TEMP_PATH)%s", tmp);
362 pkg_mak_writeStanza(makefile, o, stanza, parents, commands);
363 #endif
364
365 pkg_deleteList(parents);
366 pkg_deleteList(commands);
367 parents = NULL;
368 commands = NULL;
369 }
370 }
371
372 #endif /* #ifdef U_MAKE_IS_NMAKE */
373
374 void
375 pkg_mak_writeAssemblyHeader(FileStream *f, const UPKGOptions *o)
376 {
377 T_FileStream_writeLine(f, "\n");
378 T_FileStream_writeLine(f, "ifneq ($(GENCCODE_ASSEMBLY),)\n");
379 T_FileStream_writeLine(f, "\n");
380 T_FileStream_writeLine(f, "BASE_OBJECTS=$(NAME)_dat.o\n");
381 T_FileStream_writeLine(f, "\n");
382 T_FileStream_writeLine(f, "$(TEMP_DIR)/$(NAME).dat: $(CMNLIST) $(DATAFILEPATHS)\n");
383 T_FileStream_writeLine(f, "\t$(INVOKE) $(ICUPKG) -t$(ICUDATA_CHAR) -c -s $(SRCDIR) -a $(CMNLIST) new $(TEMP_DIR)/$(CNAME).dat\n");
384 T_FileStream_writeLine(f, "\n");
385 T_FileStream_writeLine(f, "$(TEMP_DIR)/$(NAME)_dat.o : $(TEMP_DIR)/$(NAME).dat\n");
386 T_FileStream_writeLine(f, "\t$(INVOKE) $(GENCCODE) $(GENCCODE_ASSEMBLY) -n $(NAME) -e $(ENTRYPOINT) -d $(TEMP_DIR) $<\n");
387 T_FileStream_writeLine(f, "\t$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $(TEMP_DIR)/$(NAME)_dat"ASM_SUFFIX"\n");
388 T_FileStream_writeLine(f, "\t$(RMV) $(TEMP_DIR)/$(NAME)_dat"ASM_SUFFIX"\n");
389 T_FileStream_writeLine(f, "\n");
390 T_FileStream_writeLine(f, "else\n");
391 T_FileStream_writeLine(f, "\n");
392 }
393
394 void
395 pkg_mak_writeAssemblyFooter(FileStream *f, const UPKGOptions *o)
396 {
397 T_FileStream_writeLine(f, "\nendif\n");
398 }
399