]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/pkgdata/gmake.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / tools / pkgdata / gmake.c
CommitLineData
b75a7d8f
A
1/**************************************************************************
2*
3* Copyright (C) 2000, International Business Machines
4* Corporation and others. All Rights Reserved.
5*
6***************************************************************************
7* file name: gmake.c
8* encoding: ANSI X3.4 (1968)
9* tab size: 8 (not used)
10* indentation:4
11*
12* created on: 2000may17
13* created by: Steven \u24C7 Loomis
14*
15* Emit a GNU makefile
16*/
17
18#include "unicode/utypes.h"
19#include "cmemory.h"
20#include "cstring.h"
21#include "filestrm.h"
22#include "toolutil.h"
23#include "unewdata.h"
24#include "uoptions.h"
25#include "pkgtypes.h"
26#include "makefile.h"
27#include <stdio.h>
28#include <string.h>
29
30char linebuf[2048];
31
32/* Write any setup/initialization stuff */
33void
34pkg_mak_writeHeader(FileStream *f, const UPKGOptions *o)
35{
36 sprintf(linebuf, "## Makefile for %s created by pkgdata\n"
37 "## from ICU Version %s\n"
38 "\n",
39 o->shortName,
40 U_ICU_VERSION);
41 T_FileStream_writeLine(f, linebuf);
42
43 sprintf(linebuf, "NAME=%s\n"
44 "CNAME=%s\n"
45 "TARGETDIR=%s\n"
46 "TEMP_DIR=%s\n"
47 "srcdir=$(TEMP_DIR)\n"
48 "MODE=%s\n"
49 "MAKEFILE=%s\n"
50 "ENTRYPOINT=%s\n"
51 "include %s\n"
52 "\n\n\n",
53 o->shortName,
54 o->cShortName,
55 o->targetDir,
56 o->tmpDir,
57 o->mode,
58 o->makeFile,
59 o->entryName,
60 o->options);
61 T_FileStream_writeLine(f, linebuf);
62
63 /* TEMP_PATH and TARG_PATH will be empty if the respective dir is . */
64 /* Avoid //'s and .'s which confuse make ! */
65 if(!strcmp(o->tmpDir,"."))
66 {
67 T_FileStream_writeLine(f, "TEMP_PATH=\n");
68 }
69 else
70 {
71 T_FileStream_writeLine(f, "TEMP_PATH=$(TEMP_DIR)/\n");
72 }
73
74 if(!strcmp(o->targetDir,"."))
75 {
76 T_FileStream_writeLine(f, "TARG_PATH=\n");
77 }
78 else
79 {
80 T_FileStream_writeLine(f, "TARG_PATH=$(TARGETDIR)/\n");
81 }
82
83 sprintf(linebuf, "## List files [%d] containing data files to process (note: - means stdin)\n"
84 "LISTFILES= ",
85 pkg_countCharList(o->fileListFiles));
86 T_FileStream_writeLine(f, linebuf);
87
88 pkg_writeCharListWrap(f, o->fileListFiles, " ", " \\\n",0);
89
90 T_FileStream_writeLine(f, "\n\n\n");
91
92 sprintf(linebuf, "## Data Files [%d]\n"
93 "DATAFILES= ",
94 pkg_countCharList(o->files));
95
96 T_FileStream_writeLine(f, linebuf);
97
98 pkg_writeCharListWrap(f, o->files, " ", " \\\n",-1);
99
100 T_FileStream_writeLine(f, "\n\n\n");
101
102 sprintf(linebuf, "## Data File Paths [%d]\n"
103 "DATAFILEPATHS= ",
104 pkg_countCharList(o->filePaths));
105
106 T_FileStream_writeLine(f, linebuf);
107
108 pkg_writeCharListWrap(f, o->filePaths, " ", " \\\n",0);
109
110 T_FileStream_writeLine(f, "\n\n\n");
111
112}
113
114/* Write a stanza in the makefile, with specified "target: parents... \n\n\tcommands" [etc] */
115void
116pkg_mak_writeStanza(FileStream *f, const UPKGOptions *o,
117 const char *target,
118 CharList* parents,
119 CharList* commands)
120{
121 T_FileStream_write(f, target, strlen(target));
122 T_FileStream_write(f, " : ", 3);
123 pkg_writeCharList(f, parents, " ",0);
124 T_FileStream_write(f, "\n", 1);
125
126 if(commands)
127 {
128 T_FileStream_write(f, "\t", 1);
129 pkg_writeCharList(f, commands, "\n\t",0);
130 }
131 T_FileStream_write(f, "\n\n", 2);
132}
133
134/* write any cleanup/post stuff */
135void
136pkg_mak_writeFooter(FileStream *f, const UPKGOptions *o)
137{
138 /* nothing */
139}
140
141
142void
143pkg_mak_writeObjRules(UPKGOptions *o, FileStream *makefile, CharList **objects, const char* objSuffix)
144{
145 const char *p, *baseName;
146 char *tmpPtr;
147 char tmp[1024];
148 char stanza[1024];
149 char cfile[1024];
150 CharList *oTail = NULL;
151 CharList *infiles;
152 CharList *parents = NULL, *commands = NULL;
153 int32_t genFileOffset = 0; /* offset from beginning of .c and .o file name, use to chop off package name for AS/400 */
154
155 infiles = o->filePaths;
156
157#if defined (OS400)
158 if(infiles != NULL) {
159 baseName = findBasename(infiles->str);
160 p = uprv_strchr(baseName, '_');
161 if(p != NULL) {
162 genFileOffset = (p-baseName)+1; /* "package_" - name + underscore */
163 }
164 }
165#endif
166
167 for(;infiles;infiles = infiles->next) {
168 baseName = findBasename(infiles->str);
169 p = uprv_strrchr(baseName, '.');
170 if( (p == NULL) || (*p == '\0' ) ) {
171 continue;
172 }
173
174 uprv_strncpy(tmp, baseName, p-baseName);
175 p++;
176
177 uprv_strcpy(tmp+(p-1-baseName), "_"); /* to append */
178 uprv_strcat(tmp, p);
179 uprv_strcat(tmp, objSuffix );
180
181 /* iSeries cannot have '-' in the .o objects. */
182 for( tmpPtr = tmp; *tmpPtr; tmpPtr++ ) {
183 if ( *tmpPtr == '-' ) {
184 *tmpPtr = '_';
185 }
186 }
187
188 *objects = pkg_appendToList(*objects, &oTail, uprv_strdup(tmp + genFileOffset)); /* Offset for AS/400 */
189
190 /* write source list */
191 strcpy(cfile,tmp);
192 strcpy(cfile+strlen(cfile)-strlen(objSuffix), ".c" ); /* replace .o with .c */
193
194 /* Make up parents.. */
195 parents = pkg_appendToList(parents, NULL, uprv_strdup(infiles->str));
196
197 /* make up commands.. */
198 sprintf(stanza, "@$(INVOKE) $(GENCCODE) -n $(ENTRYPOINT) -d $(TEMP_DIR) $<");
199 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
200
201 if(genFileOffset > 0) { /* for AS/400 */
202 sprintf(stanza, "@mv $(TEMP_PATH)%s $(TEMP_PATH)%s", cfile, cfile+genFileOffset);
203 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
204 }
205
206 sprintf(stanza, "@$(COMPILE.c) -o $@ $(TEMP_DIR)/%s", cfile+genFileOffset); /* for AS/400 */
207 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
208
209 sprintf(stanza, "@$(RMV) $(TEMP_DIR)/%s", cfile+genFileOffset);
210 commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
211
212 sprintf(stanza, "$(TEMP_PATH)%s", tmp+genFileOffset); /* for AS/400 */
213 pkg_mak_writeStanza(makefile, o, stanza, parents, commands);
214
215 pkg_deleteList(parents);
216 pkg_deleteList(commands);
217 parents = NULL;
218 commands = NULL;
219 }
220
221}