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