]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/pkgdata/make.c
ICU-8.11.1.tar.gz
[apple/icu.git] / icuSources / tools / pkgdata / make.c
CommitLineData
374ca955
A
1/**************************************************************************
2*
73c04bcf 3* Copyright (C) 2000-2006, International Business Machines
374ca955
A
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"
73c04bcf 27#include "cmemory.h"
374ca955
A
28#include <stdio.h>
29
30#ifdef U_MAKE_IS_NMAKE
31
32char linebuf[2048];
33
34/* Write any setup/initialization stuff */
35void
36pkg_mak_writeHeader(FileStream *f, const UPKGOptions *o)
37{
38 const char *appendVersion = NULL;
73c04bcf
A
39 char *srcDir = convertToNativePathSeparators(uprv_strdup(o->srcDir));
40
374ca955
A
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"
73c04bcf
A
65 "INSTALL_DATA=copy\n"
66 "RMV=del /F"
374ca955
A
67 "\n\n\n",
68 o->shortName,
69 (appendVersion ? appendVersion : ""),
70 o->cShortName,
71 o->libName,
73c04bcf 72 srcDir,
374ca955
A
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
73c04bcf 110 uprv_free(srcDir);
374ca955
A
111}
112
113/* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
114void
115pkg_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 */
134void
135pkg_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
73c04bcf 142#else /* #ifdef U_MAKE_IS_NMAKE */
374ca955
A
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
152char linebuf[2048];
153
154/* Write any setup/initialization stuff */
155void
156pkg_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] */
241void
242pkg_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 */
261void
262pkg_mak_writeFooter(FileStream *f, const UPKGOptions *o)
263{
264 T_FileStream_writeLine(f, "\nrebuild: clean all\n");
265}
266
267
268void
269pkg_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 int32_t genFileOffset = 0; /* offset from beginning of .c and .o file name, use to chop off package name for AS/400 */
73c04bcf
A
280 char *parentPath;
281 const char *tchar;
282 char tree[1024];
374ca955 283
73c04bcf 284 infiles = o->files; /* raw files - no paths other than tree paths */
374ca955
A
285
286#if defined (OS400)
287 if(infiles != NULL) {
288 baseName = findBasename(infiles->str);
289 p = uprv_strchr(baseName, '_');
290 if(p != NULL) {
291 genFileOffset = (p-baseName)+1; /* "package_" - name + underscore */
292 }
293 }
294#endif
295
296 for(;infiles;infiles = infiles->next) {
73c04bcf 297 baseName = infiles->str; /* skip the icudt28b/ part */
374ca955
A
298 p = uprv_strrchr(baseName, '.');
299 if( (p == NULL) || (*p == '\0' ) ) {
300 continue;
301 }
302
73c04bcf
A
303 uprv_strncpy(tmp, baseName, p-baseName);
304 p++;
305
306 uprv_strcpy(tmp+(p-1-baseName), "_"); /* to append */
307 uprv_strcat(tmp, p);
308 uprv_strcat(tmp, objSuffix );
309
310 /* iSeries cannot have '-' in the .o objects. */
311 for( tmpPtr = tmp; *tmpPtr; tmpPtr++ ) {
312 if ( *tmpPtr == U_FILE_SEP_CHAR ) { /* map tree names with underscores */
313 *tmpPtr = '_';
314 }
315 if ( *tmpPtr == '-' ) {
316 *tmpPtr = '_';
374ca955
A
317 }
318 }
319
320 *objects = pkg_appendToList(*objects, &oTail, uprv_strdup(tmp + genFileOffset)); /* Offset for AS/400 */
321
322 /* write source list */
323 uprv_strcpy(cfile,tmp);
324 uprv_strcpy(cfile+uprv_strlen(cfile)-uprv_strlen(objSuffix), ".c" ); /* replace .o with .c */
325
326 /* Make up parents.. */
73c04bcf
A
327 parentPath = uprv_malloc(1+uprv_strlen(baseName) + uprv_strlen("$(SRCDIR)/"));
328 sprintf(parentPath, "$(SRCDIR)/%s", baseName);
329 parents = pkg_appendToList(parents, NULL, parentPath);
374ca955
A
330
331 /* make up commands.. */
374ca955 332 /* search for tree.. */
374ca955
A
333 if((tchar=uprv_strchr(baseName, '/'))) {
334 tree[0]='_';
335 strncpy(tree+1,baseName,tchar-baseName);
336 tree[tchar-baseName+1]=0;
337 } else {
338 tree[0] = 0;
339 }
340#ifdef OS400
341 sprintf(stanza, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $(SRCDIR)/%s", tree, infiles->str);
342#else
343 sprintf(stanza, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $<", tree);
344#endif
374ca955 345
73c04bcf 346 if(uprv_strchr(baseName, '/')) {
374ca955
A
347 /* append actual file - ex: coll_en_res otherwise the tree name will be lost */
348 strcat(stanza, " -f ");
349 strncat(stanza, tmp, (strlen(tmp)-strlen(objSuffix)));
350 }
351
352 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
353
354#ifdef OS400
355 /* This builds the file into one .c file */
356 sprintf(stanza, "@cat $(TEMP_PATH)%s >> $(TEMP_PATH)/$(NAME)all.c", cfile);
357 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
358
359 sprintf(stanza, "@$(RMV) $(TEMP_DIR)/%s", cfile);
360 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
361
362 T_FileStream_write(makefile, "\t", 1);
363 pkg_writeCharList(makefile, commands, "\n\t",0);
364 T_FileStream_write(makefile, "\n\n", 2);
365#else
366 if(genFileOffset > 0) { /* for AS/400 */
367 sprintf(stanza, "@mv $(TEMP_PATH)%s $(TEMP_PATH)%s", cfile, cfile+genFileOffset);
368 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
369 }
370
73c04bcf 371 sprintf(stanza, "@$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $(TEMP_DIR)/%s", cfile+genFileOffset); /* for AS/400 */
374ca955
A
372 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
373
374 sprintf(stanza, "@$(RMV) $(TEMP_DIR)/%s", cfile+genFileOffset);
375 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
376
377 sprintf(stanza, "$(TEMP_PATH)%s", tmp+genFileOffset); /* for AS/400 */
378 pkg_mak_writeStanza(makefile, o, stanza, parents, commands);
379#endif
380
381 pkg_deleteList(parents);
382 pkg_deleteList(commands);
383 parents = NULL;
384 commands = NULL;
385 }
386}
387
73c04bcf 388#endif /* #ifdef U_MAKE_IS_NMAKE */
374ca955
A
389
390void
391pkg_mak_writeAssemblyHeader(FileStream *f, const UPKGOptions *o)
392{
393 T_FileStream_writeLine(f, "\n");
394 T_FileStream_writeLine(f, "ifneq ($(GENCCODE_ASSEMBLY),)\n");
395 T_FileStream_writeLine(f, "\n");
396 T_FileStream_writeLine(f, "BASE_OBJECTS=$(NAME)_dat.o\n");
397 T_FileStream_writeLine(f, "\n");
398 T_FileStream_writeLine(f, "$(TEMP_DIR)/$(NAME).dat: $(CMNLIST) $(DATAFILEPATHS)\n");
73c04bcf 399 T_FileStream_writeLine(f, "\t$(INVOKE) $(GENCMN) -c -e $(ENTRYPOINT) -n $(NAME) -s $(SRCDIR) -t dat -d $(TEMP_DIR) 0 $(CMNLIST)\n");
374ca955
A
400 T_FileStream_writeLine(f, "\n");
401 T_FileStream_writeLine(f, "$(TEMP_DIR)/$(NAME)_dat.o : $(TEMP_DIR)/$(NAME).dat\n");
402 T_FileStream_writeLine(f, "\t$(INVOKE) $(GENCCODE) $(GENCCODE_ASSEMBLY) -n $(NAME) -e $(ENTRYPOINT) -d $(TEMP_DIR) $<\n");
403 T_FileStream_writeLine(f, "\t$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $(TEMP_DIR)/$(NAME)_dat"ASM_SUFFIX"\n");
404 T_FileStream_writeLine(f, "\t$(RMV) $(TEMP_DIR)/$(NAME)_dat"ASM_SUFFIX"\n");
405 T_FileStream_writeLine(f, "\n");
406 T_FileStream_writeLine(f, "else\n");
407 T_FileStream_writeLine(f, "\n");
408}
409
410void
411pkg_mak_writeAssemblyFooter(FileStream *f, const UPKGOptions *o)
412{
413 T_FileStream_writeLine(f, "\nendif\n");
414}
415