]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/make.c
1 /**************************************************************************
3 * Copyright (C) 2000-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
6 ***************************************************************************
8 * encoding: ANSI X3.4 (1968)
9 * tab size: 8 (not used)
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
20 * Emit a NMAKE or GNU makefile
23 #include "unicode/utypes.h"
24 #include "unicode/putil.h"
29 #ifdef U_MAKE_IS_NMAKE
33 /* Write any setup/initialization stuff */
35 pkg_mak_writeHeader(FileStream
*f
, const UPKGOptions
*o
)
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
;
43 sprintf(linebuf
, "## Makefile for %s (%s) created by pkgdata\n"
44 "## from ICU Version %s\n"
49 T_FileStream_writeLine(f
, linebuf
);
51 sprintf(linebuf
, "NAME=%s%s\n"
61 "MKINSTALLDIRS=mkdir\n"
64 (appendVersion
? appendVersion
: ""),
74 T_FileStream_writeLine(f
, linebuf
);
76 sprintf(linebuf
, "## List files [%d] containing data files to process (note: - means stdin)\n"
78 pkg_countCharList(o
->fileListFiles
));
79 T_FileStream_writeLine(f
, linebuf
);
81 pkg_writeCharListWrap(f
, o
->fileListFiles
, " ", " \\\n", 0);
83 T_FileStream_writeLine(f
, "\n\n\n");
85 sprintf(linebuf
, "## Data Files [%d]\n"
87 pkg_countCharList(o
->files
));
89 T_FileStream_writeLine(f
, linebuf
);
91 pkg_writeCharListWrap(f
, o
->files
, " ", " \\\n", -1);
93 T_FileStream_writeLine(f
, "\n\n\n");
95 sprintf(linebuf
, "## Data File Paths [%d]\n"
97 pkg_countCharList(o
->filePaths
));
99 T_FileStream_writeLine(f
, linebuf
);
101 pkg_writeCharListWrap(f
, o
->filePaths
, " ", " \\\n", 1);
103 T_FileStream_writeLine(f
, "\n\n\n");
107 /* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
109 pkg_mak_writeStanza(FileStream
*f
, const UPKGOptions
*o
,
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);
121 T_FileStream_write(f
, "\t", 1);
122 pkg_writeCharList(f
, commands
, "\n\t",0);
124 T_FileStream_write(f
, "\n\n", 2);
127 /* write any cleanup/post stuff */
129 pkg_mak_writeFooter(FileStream
*f
, const UPKGOptions
*o
)
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
));
136 #else /* #ifdef WIN32 */
139 #include "filestrm.h"
140 #include "toolutil.h"
141 #include "unewdata.h"
142 #include "uoptions.h"
143 #include "pkgtypes.h"
148 /* Write any setup/initialization stuff */
150 pkg_mak_writeHeader(FileStream
*f
, const UPKGOptions
*o
)
152 sprintf(linebuf
, "## Makefile for %s created by pkgdata\n"
153 "## from ICU Version %s\n"
157 T_FileStream_writeLine(f
, linebuf
);
159 sprintf(linebuf
, "NAME=%s\n"
164 "srcdir=$(TEMP_DIR)\n"
181 T_FileStream_writeLine(f
, linebuf
);
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
,"."))
187 T_FileStream_writeLine(f
, "TEMP_PATH=\n");
191 T_FileStream_writeLine(f
, "TEMP_PATH=$(TEMP_DIR)/\n");
194 if(!strcmp(o
->targetDir
,"."))
196 T_FileStream_writeLine(f
, "TARG_PATH=\n");
200 T_FileStream_writeLine(f
, "TARG_PATH=$(TARGETDIR)/\n");
203 sprintf(linebuf
, "## List files [%u] containing data files to process (note: - means stdin)\n"
205 (int)pkg_countCharList(o
->fileListFiles
));
206 T_FileStream_writeLine(f
, linebuf
);
208 pkg_writeCharListWrap(f
, o
->fileListFiles
, " ", " \\\n",0);
210 T_FileStream_writeLine(f
, "\n\n\n");
212 sprintf(linebuf
, "## Data Files [%u]\n"
214 (int)pkg_countCharList(o
->files
));
216 T_FileStream_writeLine(f
, linebuf
);
218 pkg_writeCharListWrap(f
, o
->files
, " ", " \\\n",-1);
220 T_FileStream_writeLine(f
, "\n\n\n");
222 sprintf(linebuf
, "## Data File Paths [%u]\n"
224 (int)pkg_countCharList(o
->filePaths
));
226 T_FileStream_writeLine(f
, linebuf
);
228 pkg_writeCharListWrap(f
, o
->filePaths
, " ", " \\\n",0);
230 T_FileStream_writeLine(f
, "\n\n\n");
234 /* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
236 pkg_mak_writeStanza(FileStream
*f
, const UPKGOptions
*o
,
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);
248 T_FileStream_write(f
, "\t", 1);
249 pkg_writeCharList(f
, commands
, "\n\t",0);
251 T_FileStream_write(f
, "\n\n", 2);
254 /* write any cleanup/post stuff */
256 pkg_mak_writeFooter(FileStream
*f
, const UPKGOptions
*o
)
258 T_FileStream_writeLine(f
, "\nrebuild: clean all\n");
263 pkg_mak_writeObjRules(UPKGOptions
*o
, FileStream
*makefile
, CharList
**objects
, const char* objSuffix
)
265 const char *p
, *baseName
;
270 CharList
*oTail
= NULL
;
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 */
278 infiles
= o
->filePaths
;
280 infiles
= o
->files
; /* raw files - no paths other than tree paths */
284 if(infiles
!= NULL
) {
285 baseName
= findBasename(infiles
->str
);
286 p
= uprv_strchr(baseName
, '_');
288 genFileOffset
= (p
-baseName
)+1; /* "package_" - name + underscore */
293 for(;infiles
;infiles
= infiles
->next
) {
295 baseName
= findBasename(infiles
->str
);
297 baseName
= infiles
->str
; /* skip the icudt28b/ part */
299 p
= uprv_strrchr(baseName
, '.');
300 if( (p
== NULL
) || (*p
== '\0' ) ) {
305 sprintf(serName
, "t%04x", serNo
++);
306 uprv_strcpy(tmp
,serName
);
307 uprv_strcat(tmp
, objSuffix
);
309 uprv_strncpy(tmp
, baseName
, p
-baseName
);
312 uprv_strcpy(tmp
+(p
-1-baseName
), "_"); /* to append */
314 uprv_strcat(tmp
, objSuffix
);
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 */
321 if ( *tmpPtr
== '-' ) {
327 *objects
= pkg_appendToList(*objects
, &oTail
, uprv_strdup(tmp
+ genFileOffset
)); /* Offset for AS/400 */
329 /* write source list */
330 uprv_strcpy(cfile
,tmp
);
331 uprv_strcpy(cfile
+uprv_strlen(cfile
)-uprv_strlen(objSuffix
), ".c" ); /* replace .o with .c */
333 /* Make up parents.. */
336 parentPath
= uprv_malloc(1+uprv_strlen(baseName
) + uprv_strlen("$(SRCDIR)/"));
337 sprintf(parentPath
, "$(SRCDIR)/%s", baseName
);
338 parents
= pkg_appendToList(parents
, NULL
, parentPath
);
340 parents
= pkg_appendToList(parents
, NULL
, uprv_strdup(infiles
->str
));
343 /* make up commands.. */
345 /* search for tree.. */
348 if((tchar
=uprv_strchr(baseName
, '/'))) {
350 strncpy(tree
+1,baseName
,tchar
-baseName
);
351 tree
[tchar
-baseName
+1]=0;
356 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $(SRCDIR)/%s", tree
, infiles
->str
);
358 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $<", tree
);
362 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -d $(TEMP_DIR) %s", infiles
->str
);
364 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -d $(TEMP_DIR) $<");
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
)));
377 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
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
));
384 sprintf(stanza
, "@$(RMV) $(TEMP_DIR)/%s", cfile
);
385 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
387 T_FileStream_write(makefile
, "\t", 1);
388 pkg_writeCharList(makefile
, commands
, "\n\t",0);
389 T_FileStream_write(makefile
, "\n\n", 2);
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
));
396 sprintf(stanza
, "@$(COMPILE.c) -o $@ $(TEMP_DIR)/%s", cfile
+genFileOffset
); /* for AS/400 */
397 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
399 sprintf(stanza
, "@$(RMV) $(TEMP_DIR)/%s", cfile
+genFileOffset
);
400 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
402 sprintf(stanza
, "$(TEMP_PATH)%s", tmp
+genFileOffset
); /* for AS/400 */
403 pkg_mak_writeStanza(makefile
, o
, stanza
, parents
, commands
);
406 pkg_deleteList(parents
);
407 pkg_deleteList(commands
);
413 #endif /* #ifdef WIN32 */
416 pkg_mak_writeAssemblyHeader(FileStream
*f
, const UPKGOptions
*o
)
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");
425 T_FileStream_writeLine(f
, "\t$(INVOKE) $(GENCMN) -c -e $(ENTRYPOINT) -n $(NAME) -s $(SRCDIR) -t dat -d $(TEMP_DIR) 0 $(CMNLIST)\n");
427 T_FileStream_writeLine(f
, "\t$(INVOKE) $(GENCMN) -c -e $(ENTRYPOINT) -n $(NAME) -E -t dat -d $(TEMP_DIR) 0 $(CMNLIST)\n");
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");
440 pkg_mak_writeAssemblyFooter(FileStream
*f
, const UPKGOptions
*o
)
442 T_FileStream_writeLine(f
, "\nendif\n");