]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/make.c
1 /**************************************************************************
3 * Copyright (C) 2000-2006, 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"
30 #ifdef U_MAKE_IS_NMAKE
34 /* Write any setup/initialization stuff */
36 pkg_mak_writeHeader(FileStream
*f
, const UPKGOptions
*o
)
38 const char *appendVersion
= NULL
;
39 char *srcDir
= convertToNativePathSeparators(uprv_strdup(o
->srcDir
));
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
;
46 sprintf(linebuf
, "## Makefile for %s (%s) created by pkgdata\n"
47 "## from ICU Version %s\n"
52 T_FileStream_writeLine(f
, linebuf
);
54 sprintf(linebuf
, "NAME=%s%s\n"
64 "MKINSTALLDIRS=mkdir\n"
69 (appendVersion
? appendVersion
: ""),
79 T_FileStream_writeLine(f
, linebuf
);
81 sprintf(linebuf
, "## List files [%d] containing data files to process (note: - means stdin)\n"
83 pkg_countCharList(o
->fileListFiles
));
84 T_FileStream_writeLine(f
, linebuf
);
86 pkg_writeCharListWrap(f
, o
->fileListFiles
, " ", " \\\n", 0);
88 T_FileStream_writeLine(f
, "\n\n\n");
90 sprintf(linebuf
, "## Data Files [%d]\n"
92 pkg_countCharList(o
->files
));
94 T_FileStream_writeLine(f
, linebuf
);
96 pkg_writeCharListWrap(f
, o
->files
, " ", " \\\n", -1);
98 T_FileStream_writeLine(f
, "\n\n\n");
100 sprintf(linebuf
, "## Data File Paths [%d]\n"
102 pkg_countCharList(o
->filePaths
));
104 T_FileStream_writeLine(f
, linebuf
);
106 pkg_writeCharListWrap(f
, o
->filePaths
, " ", " \\\n", 1);
108 T_FileStream_writeLine(f
, "\n\n\n");
113 /* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
115 pkg_mak_writeStanza(FileStream
*f
, const UPKGOptions
*o
,
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);
127 T_FileStream_write(f
, "\t", 1);
128 pkg_writeCharList(f
, commands
, "\n\t",0);
130 T_FileStream_write(f
, "\n\n", 2);
133 /* write any cleanup/post stuff */
135 pkg_mak_writeFooter(FileStream
*f
, const UPKGOptions
*o
)
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
));
142 #else /* #ifdef U_MAKE_IS_NMAKE */
145 #include "filestrm.h"
146 #include "toolutil.h"
147 #include "unewdata.h"
148 #include "uoptions.h"
149 #include "pkgtypes.h"
154 /* Write any setup/initialization stuff */
156 pkg_mak_writeHeader(FileStream
*f
, const UPKGOptions
*o
)
158 sprintf(linebuf
, "## Makefile for %s created by pkgdata\n"
159 "## from ICU Version %s\n"
163 T_FileStream_writeLine(f
, linebuf
);
165 sprintf(linebuf
, "NAME=%s\n"
170 "srcdir=$(TEMP_DIR)\n"
187 T_FileStream_writeLine(f
, linebuf
);
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
,"."))
193 T_FileStream_writeLine(f
, "TEMP_PATH=\n");
197 T_FileStream_writeLine(f
, "TEMP_PATH=$(TEMP_DIR)/\n");
200 if(!strcmp(o
->targetDir
,"."))
202 T_FileStream_writeLine(f
, "TARG_PATH=\n");
206 T_FileStream_writeLine(f
, "TARG_PATH=$(TARGETDIR)/\n");
209 sprintf(linebuf
, "## List files [%u] containing data files to process (note: - means stdin)\n"
211 (int)pkg_countCharList(o
->fileListFiles
));
212 T_FileStream_writeLine(f
, linebuf
);
214 pkg_writeCharListWrap(f
, o
->fileListFiles
, " ", " \\\n",0);
216 T_FileStream_writeLine(f
, "\n\n\n");
218 sprintf(linebuf
, "## Data Files [%u]\n"
220 (int)pkg_countCharList(o
->files
));
222 T_FileStream_writeLine(f
, linebuf
);
224 pkg_writeCharListWrap(f
, o
->files
, " ", " \\\n",-1);
226 T_FileStream_writeLine(f
, "\n\n\n");
228 sprintf(linebuf
, "## Data File Paths [%u]\n"
230 (int)pkg_countCharList(o
->filePaths
));
232 T_FileStream_writeLine(f
, linebuf
);
234 pkg_writeCharListWrap(f
, o
->filePaths
, " ", " \\\n",0);
236 T_FileStream_writeLine(f
, "\n\n\n");
240 /* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
242 pkg_mak_writeStanza(FileStream
*f
, const UPKGOptions
*o
,
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);
254 T_FileStream_write(f
, "\t", 1);
255 pkg_writeCharList(f
, commands
, "\n\t",0);
257 T_FileStream_write(f
, "\n\n", 2);
260 /* write any cleanup/post stuff */
262 pkg_mak_writeFooter(FileStream
*f
, const UPKGOptions
*o
)
264 T_FileStream_writeLine(f
, "\nrebuild: clean all\n");
269 pkg_mak_writeObjRules(UPKGOptions
*o
, FileStream
*makefile
, CharList
**objects
, const char* objSuffix
)
271 const char *p
, *baseName
;
276 CharList
*oTail
= NULL
;
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 */
284 infiles
= o
->files
; /* raw files - no paths other than tree paths */
287 if(infiles
!= NULL
) {
288 baseName
= findBasename(infiles
->str
);
289 p
= uprv_strchr(baseName
, '_');
291 genFileOffset
= (p
-baseName
)+1; /* "package_" - name + underscore */
296 for(;infiles
;infiles
= infiles
->next
) {
297 baseName
= infiles
->str
; /* skip the icudt28b/ part */
298 p
= uprv_strrchr(baseName
, '.');
299 if( (p
== NULL
) || (*p
== '\0' ) ) {
303 uprv_strncpy(tmp
, baseName
, p
-baseName
);
306 uprv_strcpy(tmp
+(p
-1-baseName
), "_"); /* to append */
308 uprv_strcat(tmp
, objSuffix
);
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 */
315 if ( *tmpPtr
== '-' ) {
320 *objects
= pkg_appendToList(*objects
, &oTail
, uprv_strdup(tmp
+ genFileOffset
)); /* Offset for AS/400 */
322 /* write source list */
323 uprv_strcpy(cfile
,tmp
);
324 uprv_strcpy(cfile
+uprv_strlen(cfile
)-uprv_strlen(objSuffix
), ".c" ); /* replace .o with .c */
326 /* Make up parents.. */
327 parentPath
= uprv_malloc(1+uprv_strlen(baseName
) + uprv_strlen("$(SRCDIR)/"));
328 sprintf(parentPath
, "$(SRCDIR)/%s", baseName
);
329 parents
= pkg_appendToList(parents
, NULL
, parentPath
);
331 /* make up commands.. */
332 /* search for tree.. */
333 if((tchar
=uprv_strchr(baseName
, '/'))) {
335 strncpy(tree
+1,baseName
,tchar
-baseName
);
336 tree
[tchar
-baseName
+1]=0;
341 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $(SRCDIR)/%s", tree
, infiles
->str
);
343 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $<", tree
);
346 if(uprv_strchr(baseName
, '/')) {
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
)));
352 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
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
));
359 sprintf(stanza
, "@$(RMV) $(TEMP_DIR)/%s", cfile
);
360 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
362 T_FileStream_write(makefile
, "\t", 1);
363 pkg_writeCharList(makefile
, commands
, "\n\t",0);
364 T_FileStream_write(makefile
, "\n\n", 2);
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
));
371 sprintf(stanza
, "@$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $(TEMP_DIR)/%s", cfile
+genFileOffset
); /* for AS/400 */
372 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
374 sprintf(stanza
, "@$(RMV) $(TEMP_DIR)/%s", cfile
+genFileOffset
);
375 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
377 sprintf(stanza
, "$(TEMP_PATH)%s", tmp
+genFileOffset
); /* for AS/400 */
378 pkg_mak_writeStanza(makefile
, o
, stanza
, parents
, commands
);
381 pkg_deleteList(parents
);
382 pkg_deleteList(commands
);
388 #endif /* #ifdef U_MAKE_IS_NMAKE */
391 pkg_mak_writeAssemblyHeader(FileStream
*f
, const UPKGOptions
*o
)
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");
399 T_FileStream_writeLine(f
, "\t$(INVOKE) $(GENCMN) -c -e $(ENTRYPOINT) -n $(NAME) -s $(SRCDIR) -t dat -d $(TEMP_DIR) 0 $(CMNLIST)\n");
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");
411 pkg_mak_writeAssemblyFooter(FileStream
*f
, const UPKGOptions
*o
)
413 T_FileStream_writeLine(f
, "\nendif\n");