]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /****************************************************************************** |
2 | * | |
374ca955 | 3 | * Copyright (C) 2002-2004, International Business Machines |
b75a7d8f A |
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" | |
374ca955 | 21 | #include "unicode/putil.h" |
b75a7d8f A |
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 | /** set if AR is NOT to be called implicitly by gnumake | |
36 | ** (i.e. if the form libblah.a($(OBJECTS) doesnt work) | |
37 | **/ | |
38 | #if defined(OS400) || defined(OS390) | |
39 | # define NO_IMPLICIT_AR 1 | |
40 | #else | |
41 | # define NO_IMPLICIT_AR 0 | |
42 | #endif | |
43 | ||
44 | void pkg_sttc_writeReadme(struct UPKGOptions_ *o, const char *libName, UErrorCode *status) | |
45 | { | |
46 | char tmp[1024]; | |
47 | FileStream *out; | |
48 | ||
49 | if(U_FAILURE(*status)) | |
50 | { | |
51 | return; | |
52 | } | |
53 | ||
54 | /* Makefile pathname */ | |
55 | uprv_strcpy(tmp, o->targetDir); | |
56 | uprv_strcat(tmp, U_FILE_SEP_STRING "README_"); | |
57 | uprv_strcat(tmp, o->shortName); | |
58 | uprv_strcat(tmp, ".txt"); | |
59 | ||
60 | out = T_FileStream_open(tmp, "w"); | |
61 | if (!out) { | |
62 | fprintf(stderr, "err: couldn't create README file %s\n", tmp); | |
63 | *status = U_FILE_ACCESS_ERROR; | |
64 | return; | |
65 | } | |
66 | ||
67 | sprintf(tmp, "## README for \"%s\"'s static data (%s)\n" | |
68 | "## created by pkgdata, ICU Version %s\n", | |
69 | o->shortName, | |
70 | libName, | |
71 | U_ICU_VERSION); | |
72 | ||
73 | T_FileStream_writeLine(out, tmp); | |
74 | ||
75 | sprintf(tmp, "\n\nTo use this data in your application:\n\n" | |
76 | "1. At the top of your source file, add the following lines:\n" | |
77 | "\n" | |
78 | " #include \"unicode/utypes.h\"\n" | |
79 | " #include \"unicode/udata.h\"\n" | |
80 | " U_CFUNC char %s_dat[];\n", | |
81 | o->cShortName); | |
82 | T_FileStream_writeLine(out, tmp); | |
83 | ||
84 | sprintf(tmp, "2. *Early* in your application, call the following function:\n" | |
85 | "\n" | |
86 | " UErrorCode myError = U_ZERO_ERROR;\n" | |
87 | " udata_setAppData( \"%s\", (const void*) %s_dat, &myError);\n" | |
88 | " if(U_FAILURE(myError))\n" | |
89 | " {\n" | |
90 | " handle error condition ...\n" | |
91 | " }\n" | |
92 | "\n", | |
93 | o->cShortName, o->cShortName); | |
94 | T_FileStream_writeLine(out, tmp); | |
95 | ||
96 | sprintf(tmp, "3. Link your application against %s\n" | |
97 | "\n\n" | |
98 | "4. Now, you may access this data with a 'path' of \"%s\" as in the following example:\n" | |
99 | "\n" | |
374ca955 A |
100 | " ... ures_open( \"%s\", NULL /* Get the default locale */, &err ); \n", |
101 | libName, o->shortName, o->shortName); | |
b75a7d8f A |
102 | T_FileStream_writeLine(out, tmp); |
103 | ||
104 | T_FileStream_close(out); | |
105 | } | |
106 | ||
107 | ||
374ca955 | 108 | #ifndef U_MAKE_IS_NMAKE |
b75a7d8f A |
109 | |
110 | ||
111 | #include "makefile.h" | |
112 | ||
113 | ||
114 | void pkg_mode_static(UPKGOptions *o, FileStream *makefile, UErrorCode *status) | |
115 | { | |
116 | char tmp[1024]; | |
117 | CharList *tail = NULL; | |
118 | CharList *objects = NULL; | |
119 | ||
120 | if(U_FAILURE(*status)) { | |
121 | return; | |
122 | } | |
123 | ||
374ca955 A |
124 | uprv_strcpy(tmp, LIB_STATIC_PREFIX); |
125 | uprv_strcat(tmp, o->libName); | |
b75a7d8f A |
126 | uprv_strcat(tmp, UDATA_LIB_SUFFIX); |
127 | ||
128 | o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp)); | |
129 | ||
374ca955 A |
130 | if (!o->quiet) { |
131 | pkg_sttc_writeReadme(o, tmp, status); | |
132 | } | |
b75a7d8f A |
133 | if(U_FAILURE(*status)) { |
134 | return; | |
135 | } | |
136 | ||
137 | ||
138 | if(o->nooutput || o->verbose) { | |
139 | fprintf(stdout, "# Output file: %s%s%s\n", o->targetDir, U_FILE_SEP_STRING, tmp); | |
140 | } | |
141 | ||
142 | if(o->nooutput) { | |
143 | *status = U_ZERO_ERROR; | |
144 | return; | |
145 | } | |
146 | ||
147 | /* begin writing makefile ========================= */ | |
148 | ||
149 | ||
150 | T_FileStream_writeLine(makefile, "# Version numbers:\nVERSIONED="); | |
151 | if (o->version) { | |
152 | sprintf(tmp, ".%s", o->version); | |
153 | if (!uprv_strchr(o->version, '.')) { | |
154 | uprv_strcat(tmp, ".0"); | |
155 | } | |
156 | T_FileStream_writeLine(makefile, tmp); | |
157 | T_FileStream_writeLine(makefile, "\nDLL_LDFLAGS=$(LD_SONAME) $(RPATH_LDFLAGS)\n"); | |
158 | } else { | |
159 | T_FileStream_writeLine(makefile, "\nDLL_LDFLAGS=$(BIR_LDFLAGS)\n"); | |
160 | } | |
161 | T_FileStream_writeLine(makefile, "\n"); | |
162 | ||
163 | sprintf(tmp, "# File to make:\nTARGET=%s\n\n", o->outFiles->str); | |
164 | T_FileStream_writeLine(makefile, tmp); | |
165 | T_FileStream_writeLine(makefile, "LIB_TARGET=$(TARGET)\n"); | |
166 | ||
167 | uprv_strcpy(tmp, "all: $(TARG_PATH)$(LIB_TARGET)"); | |
168 | uprv_strcat(tmp, "\n\n"); | |
169 | T_FileStream_writeLine(makefile, tmp); | |
170 | ||
374ca955 A |
171 | #ifdef OS400 |
172 | /* New for iSeries: All packaged data in one .c */ | |
173 | sprintf(tmp, "# Create a file which contains all .c data files/structures\n" | |
174 | "$(TEMP_DIR)/$(NAME)all.c: $(CMNLIST)\n\n"); | |
175 | T_FileStream_writeLine(makefile, tmp); | |
176 | #endif | |
177 | ||
b75a7d8f A |
178 | /* Write compile rules */ |
179 | pkg_mak_writeObjRules(o, makefile, &objects, ".$(STATIC_O)"); /* use special .o suffix */ | |
180 | ||
181 | sprintf(tmp, "# List file for gencmn:\n" | |
182 | "CMNLIST=%s%s$(NAME)_static.lst\n\n", | |
183 | o->tmpDir, | |
184 | U_FILE_SEP_STRING); | |
185 | T_FileStream_writeLine(makefile, tmp); | |
186 | ||
187 | if(o->hadStdin == FALSE) { /* shortcut */ | |
188 | T_FileStream_writeLine(makefile, "$(CMNLIST): $(LISTFILES)\n" | |
189 | "\tcat $(LISTFILES) > $(CMNLIST)\n\n"); | |
190 | } else { | |
191 | T_FileStream_writeLine(makefile, "$(CMNLIST): \n" | |
192 | "\t@echo \"generating $@ (list of data files)\"\n" | |
193 | "\t@-$(RMV) $@\n" | |
194 | "\t@for file in $(DATAFILEPATHS); do \\\n" | |
195 | "\t echo $$file >> $@; \\\n" | |
196 | "\tdone;\n\n"); | |
197 | } | |
198 | ||
374ca955 A |
199 | pkg_mak_writeAssemblyHeader(makefile, o); |
200 | ||
b75a7d8f A |
201 | sprintf(tmp,"$(TEMP_PATH)$(NAME)_dat.$(STATIC_O) : $(TEMP_PATH)$(NAME)_dat.c\n" |
202 | "\t$(COMPILE.c) -o $@ $<\n\n"); | |
203 | T_FileStream_writeLine(makefile, tmp); | |
204 | ||
205 | T_FileStream_writeLine(makefile, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n"); | |
206 | ||
374ca955 | 207 | if(!o->embed) { |
b75a7d8f | 208 | sprintf(tmp, "$(TEMP_PATH)$(NAME)_dat.c: $(CMNLIST)\n" |
374ca955 A |
209 | "\t$(INVOKE) $(GENCMN) -e $(ENTRYPOINT) -n $(NAME) -S -s $(SRCDIR) -d $(TEMP_DIR) 0 $(CMNLIST)\n\n"); |
210 | } else { | |
211 | sprintf(tmp, "$(TEMP_PATH)$(NAME)_dat.c: $(CMNLIST)\n" | |
212 | "\t$(INVOKE) $(GENCMN) -e $(ENTRYPOINT) -n $(NAME) -S -E -d $(TEMP_DIR) 0 $(CMNLIST)\n\n"); | |
213 | } | |
214 | T_FileStream_writeLine(makefile, tmp); | |
215 | ||
216 | sprintf(tmp, "TOCOBJ= $(NAME)_dat.$(STATIC_O)\n\n"); | |
b75a7d8f A |
217 | T_FileStream_writeLine(makefile, tmp); |
218 | ||
374ca955 A |
219 | #ifdef OS400 |
220 | /* New for iSeries: All packaged data in one .c */ | |
221 | sprintf(tmp,"$(TEMP_PATH)$(NAME)all.$(STATIC_O) : $(TEMP_PATH)$(NAME)all.c\n" | |
222 | "\t$(COMPILE.c) -o $@ $<\n\n"); | |
b75a7d8f | 223 | T_FileStream_writeLine(makefile, tmp); |
374ca955 A |
224 | |
225 | T_FileStream_writeLine(makefile, "# 'ALLDATAOBJ' contains all .c data structures\n"); | |
226 | ||
227 | sprintf(tmp, "ALLDATAOBJ= $(NAME)all%s \n\n", OBJ_SUFFIX); | |
228 | T_FileStream_writeLine(makefile, tmp); | |
229 | #endif | |
230 | ||
b75a7d8f A |
231 | sprintf(tmp, "TOCSYM= $(ENTRYPOINT)_dat \n\n"); /* entrypoint not always shortname! */ |
232 | T_FileStream_writeLine(makefile, tmp); | |
233 | ||
234 | T_FileStream_writeLine(makefile, "BASE_OBJECTS= $(TOCOBJ) "); | |
235 | ||
374ca955 A |
236 | #ifdef OS400 |
237 | T_FileStream_writeLine(makefile, "$(ALLDATAOBJ) "); | |
238 | #else | |
b75a7d8f | 239 | pkg_writeCharListWrap(makefile, objects, " ", " \\\n",0); |
374ca955 A |
240 | #endif |
241 | pkg_mak_writeAssemblyFooter(makefile, o); | |
242 | ||
b75a7d8f A |
243 | T_FileStream_writeLine(makefile, "\n\n"); |
244 | T_FileStream_writeLine(makefile, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_PATH)%)\n\n"); | |
245 | ||
246 | T_FileStream_writeLine(makefile,"$(TEMP_PATH)%.$(STATIC_O): $(TEMP_PATH)%.c\n\t $(COMPILE.c) -o $@ $<\n\n"); | |
247 | ||
248 | #if NO_IMPLICIT_AR | |
249 | T_FileStream_writeLine(makefile, "$(TARG_PATH)$(LIB_TARGET):$(TARG_PATH)$(LIB_TARGET) $(OBJECTS) $(LISTFILES)\n" | |
250 | "\t$(AR) $(ARFLAGS) $(TARG_PATH)$(LIB_TARGET) $(OBJECTS)\n" | |
251 | "\t$(RANLIB) $@\n\n"); | |
252 | #else | |
253 | T_FileStream_writeLine(makefile, "$(TARG_PATH)$(LIB_TARGET):$(TARG_PATH)$(LIB_TARGET)($(OBJECTS)) $(LISTFILES)\n" | |
254 | "\t$(RANLIB) $@\n\n"); | |
255 | #endif | |
256 | ||
257 | ||
258 | 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)"); | |
259 | T_FileStream_writeLine(makefile, "\n\n"); | |
260 | ||
261 | T_FileStream_writeLine(makefile, "# static mode shouldn't need to be installed, but we will install the header and static library for them.\n"); | |
262 | ||
263 | T_FileStream_writeLine(makefile, "install: $(TARG_PATH)$(LIB_TARGET)\n" | |
264 | "\t$(INSTALL-L) $(TARG_PATH)$(LIB_TARGET) $(INSTALLTO)/$(LIB_TARGET)\n"); | |
265 | T_FileStream_writeLine(makefile, "\t$(RANLIB) $(INSTALLTO)/$(LIB_TARGET)\n"); | |
266 | if (o->version) { | |
267 | 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"); | |
268 | T_FileStream_writeLine(makefile, "\t$(RANLIB) $(INSTALLTO)/$(STATIC_LIB_TARGET)\n\n"); | |
269 | ||
270 | } | |
271 | ||
272 | *status = U_ZERO_ERROR; | |
273 | ||
274 | } | |
275 | ||
276 | ||
277 | ||
278 | #endif |