]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/make.c
1 /**************************************************************************
3 * Copyright (C) 2000-2008, 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
;
283 infiles
= o
->files
; /* raw files - no paths other than tree paths */
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' ) ) {
292 uprv_strncpy(tmp
, baseName
, p
-baseName
);
295 uprv_strcpy(tmp
+(p
-1-baseName
), "_"); /* to append */
297 uprv_strcat(tmp
, objSuffix
);
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 */
304 if ( *tmpPtr
== '-' ) {
309 *objects
= pkg_appendToList(*objects
, &oTail
, uprv_strdup(tmp
));
311 /* write source list */
312 uprv_strcpy(cfile
,tmp
);
313 uprv_strcpy(cfile
+uprv_strlen(cfile
)-uprv_strlen(objSuffix
), ".c" ); /* replace .o with .c */
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
);
320 /* make up commands.. */
321 /* search for tree.. */
322 if((tchar
=uprv_strchr(baseName
, '/'))) {
324 strncpy(tree
+1,baseName
,tchar
-baseName
);
325 tree
[tchar
-baseName
+1]=0;
330 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $(SRCDIR)/%s", tree
, infiles
->str
);
332 sprintf(stanza
, "$(INVOKE) $(GENCCODE) -n $(CNAME)%s -d $(TEMP_DIR) $<", tree
);
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
)));
341 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
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
));
348 sprintf(stanza
, "@$(RMV) $(TEMP_DIR)/%s", cfile
);
349 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
351 T_FileStream_write(makefile
, "\t", 1);
352 pkg_writeCharList(makefile
, commands
, "\n\t",0);
353 T_FileStream_write(makefile
, "\n\n", 2);
355 sprintf(stanza
, "@$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $(TEMP_DIR)/%s", cfile
);
356 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
358 sprintf(stanza
, "@$(RMV) $(TEMP_DIR)/%s", cfile
);
359 commands
= pkg_appendToList(commands
, NULL
, uprv_strdup(stanza
));
361 sprintf(stanza
, "$(TEMP_PATH)%s", tmp
);
362 pkg_mak_writeStanza(makefile
, o
, stanza
, parents
, commands
);
365 pkg_deleteList(parents
);
366 pkg_deleteList(commands
);
372 #endif /* #ifdef U_MAKE_IS_NMAKE */
375 pkg_mak_writeAssemblyHeader(FileStream
*f
, const UPKGOptions
*o
)
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");
395 pkg_mak_writeAssemblyFooter(FileStream
*f
, const UPKGOptions
*o
)
397 T_FileStream_writeLine(f
, "\nendif\n");