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