]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/sttcmode.c
ICU-400.40.tar.gz
[apple/icu.git] / icuSources / tools / pkgdata / sttcmode.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2002-2007, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *
6 *******************************************************************************
7 * file name: staticmode.c
8 * encoding: ANSI X3.4 (1968)
9 * tab size: 8 (not used)
10 * indentation:4
11 *
12 * created on: 2002mar14
13 * created by: Steven \u24C7 Loomis
14 *
15 * This program packages the ICU data into a static library.
16 * It is *mainly* used by POSIX, but the top function (for writing READMEs) is
17 * shared with Win32.
18 */
19
20 #include "unicode/utypes.h"
21 #include "unicode/putil.h"
22 #include "unicode/uloc.h"
23 #include "cmemory.h"
24 #include "cstring.h"
25 #include "filestrm.h"
26 #include "toolutil.h"
27 #include "unewdata.h"
28 #include "uoptions.h"
29 #include "pkgtypes.h"
30 #include "filestrm.h"
31
32 #include <stdio.h>
33 #include <stdlib.h>
34
35 void pkg_sttc_writeReadme(struct UPKGOptions_ *o, const char *libName, UErrorCode *status)
36 {
37 char tmp[1024];
38 FileStream *out;
39
40 if(U_FAILURE(*status))
41 {
42 return;
43 }
44
45 /* Makefile pathname */
46 uprv_strcpy(tmp, o->targetDir);
47 uprv_strcat(tmp, U_FILE_SEP_STRING "README_");
48 uprv_strcat(tmp, o->shortName);
49 uprv_strcat(tmp, ".txt");
50
51 out = T_FileStream_open(tmp, "w");
52 if (!out) {
53 fprintf(stderr, "err: couldn't create README file %s\n", tmp);
54 *status = U_FILE_ACCESS_ERROR;
55 return;
56 }
57
58 sprintf(tmp, "## README for \"%s\"'s static data (%s)\n"
59 "## created by pkgdata, ICU Version %s\n",
60 o->shortName,
61 libName,
62 U_ICU_VERSION);
63
64 T_FileStream_writeLine(out, tmp);
65
66 sprintf(tmp, "\n\nTo use this data in your application:\n\n"
67 "1. At the top of your source file, add the following lines:\n"
68 "\n"
69 " #include \"unicode/utypes.h\"\n"
70 " #include \"unicode/udata.h\"\n"
71 " U_CFUNC char %s_dat[];\n",
72 o->cShortName);
73 T_FileStream_writeLine(out, tmp);
74
75 sprintf(tmp, "2. *Early* in your application, call the following function:\n"
76 "\n"
77 " UErrorCode myError = U_ZERO_ERROR;\n"
78 " udata_setAppData( \"%s\", (const void*) %s_dat, &myError);\n"
79 " if(U_FAILURE(myError))\n"
80 " {\n"
81 " handle error condition ...\n"
82 " }\n"
83 "\n",
84 o->cShortName, o->cShortName);
85 T_FileStream_writeLine(out, tmp);
86
87 sprintf(tmp, "3. Link your application against %s\n"
88 "\n\n"
89 "4. Now, you may access this data with a 'path' of \"%s\" as in the following example:\n"
90 "\n"
91 " ... ures_open( \"%s\", NULL /* Get the default locale */, &err ); \n",
92 libName, o->shortName, o->shortName);
93 T_FileStream_writeLine(out, tmp);
94
95 T_FileStream_close(out);
96 }
97
98
99 #ifndef U_MAKE_IS_NMAKE
100
101
102 #include "makefile.h"
103
104
105 void pkg_mode_static(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
106 {
107 char tmp[1024];
108 CharList *tail = NULL;
109 CharList *objects = NULL;
110
111 if(U_FAILURE(*status)) {
112 return;
113 }
114
115 uprv_strcpy(tmp, LIB_STATIC_PREFIX);
116 uprv_strcat(tmp, o->libName);
117 uprv_strcat(tmp, UDATA_LIB_SUFFIX);
118
119 o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp));
120
121 if (!o->quiet) {
122 pkg_sttc_writeReadme(o, tmp, status);
123 }
124 if(U_FAILURE(*status)) {
125 return;
126 }
127
128
129 if(o->nooutput || o->verbose) {
130 fprintf(stdout, "# Output file: %s%s%s\n", o->targetDir, U_FILE_SEP_STRING, tmp);
131 }
132
133 if(o->nooutput) {
134 *status = U_ZERO_ERROR;
135 return;
136 }
137
138 /* begin writing makefile ========================= */
139
140
141 T_FileStream_writeLine(makefile, "# Version numbers:\nVERSIONED=");
142 if (o->version) {
143 sprintf(tmp, ".%s", o->version);
144 if (!uprv_strchr(o->version, '.')) {
145 uprv_strcat(tmp, ".0");
146 }
147 T_FileStream_writeLine(makefile, tmp);
148 T_FileStream_writeLine(makefile, "\nDLL_LDFLAGS=$(LD_SONAME) $(RPATH_LDFLAGS)\n");
149 } else {
150 T_FileStream_writeLine(makefile, "\nDLL_LDFLAGS=$(BIR_LDFLAGS)\n");
151 }
152 T_FileStream_writeLine(makefile, "\n");
153
154 sprintf(tmp, "# File to make:\nTARGET=%s\n\n", o->outFiles->str);
155 T_FileStream_writeLine(makefile, tmp);
156 T_FileStream_writeLine(makefile, "LIB_TARGET=$(TARGET)\n");
157
158 uprv_strcpy(tmp, "all: $(TARG_PATH)$(LIB_TARGET)");
159 uprv_strcat(tmp, "\n\n");
160 T_FileStream_writeLine(makefile, tmp);
161
162 #ifdef OS400
163 /* New for iSeries: All packaged data in one .c */
164 sprintf(tmp, "# Create a file which contains all .c data files/structures\n"
165 "$(TEMP_DIR)/$(NAME)all.c: $(CMNLIST)\n\n");
166 T_FileStream_writeLine(makefile, tmp);
167 #endif
168
169 /* Write compile rules */
170 pkg_mak_writeObjRules(o, makefile, &objects, ".$(STATIC_O)"); /* use special .o suffix */
171
172 sprintf(tmp, "# List file for gencmn:\n"
173 "CMNLIST=%s%s$(NAME)_static.lst\n\n",
174 o->tmpDir,
175 U_FILE_SEP_STRING);
176 T_FileStream_writeLine(makefile, tmp);
177
178 if(o->hadStdin == FALSE) { /* shortcut */
179 T_FileStream_writeLine(makefile, "$(CMNLIST): $(LISTFILES)\n"
180 "\tcat $(LISTFILES) > $(CMNLIST)\n\n");
181 } else {
182 T_FileStream_writeLine(makefile, "$(CMNLIST): \n"
183 "\t@echo \"generating $@ (list of data files)\"\n"
184 "\t@-$(RMV) $@\n"
185 "\t@for file in $(DATAFILEPATHS); do \\\n"
186 "\t echo $$file >> $@; \\\n"
187 "\tdone;\n\n");
188 }
189
190 pkg_mak_writeAssemblyHeader(makefile, o);
191
192 sprintf(tmp,"$(TEMP_PATH)$(NAME)_dat.$(STATIC_O) : $(TEMP_PATH)$(NAME)_dat.c\n"
193 "\t$(COMPILE.c) -o $@ $<\n\n");
194 T_FileStream_writeLine(makefile, tmp);
195
196 T_FileStream_writeLine(makefile, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n");
197
198 sprintf(tmp, "$(TEMP_PATH)$(NAME)_dat.c: $(CMNLIST)\n"
199 "\t$(INVOKE) $(GENCMN) -e $(ENTRYPOINT) -n $(NAME) -S -s $(SRCDIR) -d $(TEMP_DIR) 0 $(CMNLIST)\n\n");
200 T_FileStream_writeLine(makefile, tmp);
201
202 sprintf(tmp, "TOCOBJ= $(NAME)_dat.$(STATIC_O)\n\n");
203 T_FileStream_writeLine(makefile, tmp);
204
205 #ifdef OS400
206 /* New for iSeries: All packaged data in one .c */
207 sprintf(tmp,"$(TEMP_PATH)$(NAME)all.$(STATIC_O) : $(TEMP_PATH)$(NAME)all.c\n"
208 "\t$(COMPILE.c) -o $@ $<\n\n");
209 T_FileStream_writeLine(makefile, tmp);
210
211 T_FileStream_writeLine(makefile, "# 'ALLDATAOBJ' contains all .c data structures\n");
212
213 sprintf(tmp, "ALLDATAOBJ= $(NAME)all%s \n\n", OBJ_SUFFIX);
214 T_FileStream_writeLine(makefile, tmp);
215 #endif
216
217 sprintf(tmp, "TOCSYM= $(ENTRYPOINT)_dat \n\n"); /* entrypoint not always shortname! */
218 T_FileStream_writeLine(makefile, tmp);
219
220 T_FileStream_writeLine(makefile, "BASE_OBJECTS= $(TOCOBJ) ");
221
222 #ifdef OS400
223 T_FileStream_writeLine(makefile, "$(ALLDATAOBJ) ");
224 #else
225 pkg_writeCharListWrap(makefile, objects, " ", " \\\n",0);
226 #endif
227 pkg_mak_writeAssemblyFooter(makefile, o);
228
229 T_FileStream_writeLine(makefile, "\n\n");
230 T_FileStream_writeLine(makefile, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_PATH)%)\n\n");
231
232 T_FileStream_writeLine(makefile,"$(TEMP_PATH)%.$(STATIC_O): $(TEMP_PATH)%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
233
234 T_FileStream_writeLine(makefile, "$(TARG_PATH)$(LIB_TARGET): $(OBJECTS) $(LISTFILES)\n"
235 "\t$(AR) $(ARFLAGS) $(AR_OUTOPT)$@ $(OBJECTS)\n"
236 "\t$(RANLIB) $@\n\n");
237
238
239 T_FileStream_writeLine(makefile, "CLEANFILES= $(CMNLIST) $(OBJECTS) $(TARG_PATH)$(LIB_TARGET) $(TARG_PATH)$(MIDDLE_STATIC_LIB_TARGET) $(TARG_PATH)$(TARGET)\n\nclean:\n\t-$(RMV) $(CLEANFILES) $(MAKEFILE)");
240 T_FileStream_writeLine(makefile, "\n\n");
241
242 T_FileStream_writeLine(makefile, "# static mode shouldn't need to be installed, but we will install the header and static library for them.\n");
243
244 T_FileStream_writeLine(makefile, "install: $(TARG_PATH)$(LIB_TARGET)\n"
245 "\t$(INSTALL-L) $(TARG_PATH)$(LIB_TARGET) $(INSTALLTO)/$(LIB_TARGET)\n");
246 T_FileStream_writeLine(makefile, "\t$(RANLIB) $(INSTALLTO)/$(LIB_TARGET)\n");
247 if (o->version) {
248 T_FileStream_writeLine(makefile, "\tcd $(INSTALLTO) && $(RM) $(MIDDLE_STATIC_LIB_TARGET) && ln -s $(LIB_TARGET) $(MIDDLE_STATIC_LIB_TARGET)\n\tcd $(INSTALLTO) && $(RM) $(STATIC_LIB_TARGET) && ln -s $(LIB_TARGET) $(STATIC_LIB_TARGET)\n");
249 T_FileStream_writeLine(makefile, "\t$(RANLIB) $(INSTALLTO)/$(STATIC_LIB_TARGET)\n\n");
250
251 }
252
253 *status = U_ZERO_ERROR;
254
255 }
256
257
258
259 #endif