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