]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/sttcmode.c
1 /******************************************************************************
3 * Copyright (C) 2002-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
6 *******************************************************************************
7 * file name: staticmode.c
8 * encoding: ANSI X3.4 (1968)
9 * tab size: 8 (not used)
12 * created on: 2002mar14
13 * created by: Steven \u24C7 Loomis
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
20 #include "unicode/utypes.h"
21 #include "unicode/putil.h"
22 #include "unicode/uloc.h"
35 /** set if AR is NOT to be called implicitly by gnumake
36 ** (i.e. if the form libblah.a($(OBJECTS) doesnt work)
38 #if defined(OS400) || defined(OS390)
39 # define NO_IMPLICIT_AR 1
41 # define NO_IMPLICIT_AR 0
44 void pkg_sttc_writeReadme(struct UPKGOptions_
*o
, const char *libName
, UErrorCode
*status
)
49 if(U_FAILURE(*status
))
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");
60 out
= T_FileStream_open(tmp
, "w");
62 fprintf(stderr
, "err: couldn't create README file %s\n", tmp
);
63 *status
= U_FILE_ACCESS_ERROR
;
67 sprintf(tmp
, "## README for \"%s\"'s static data (%s)\n"
68 "## created by pkgdata, ICU Version %s\n",
73 T_FileStream_writeLine(out
, tmp
);
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"
78 " #include \"unicode/utypes.h\"\n"
79 " #include \"unicode/udata.h\"\n"
80 " U_CFUNC char %s_dat[];\n",
82 T_FileStream_writeLine(out
, tmp
);
84 sprintf(tmp
, "2. *Early* in your application, call the following function:\n"
86 " UErrorCode myError = U_ZERO_ERROR;\n"
87 " udata_setAppData( \"%s\", (const void*) %s_dat, &myError);\n"
88 " if(U_FAILURE(myError))\n"
90 " handle error condition ...\n"
93 o
->cShortName
, o
->cShortName
);
94 T_FileStream_writeLine(out
, tmp
);
96 sprintf(tmp
, "3. Link your application against %s\n"
98 "4. Now, you may access this data with a 'path' of \"%s\" as in the following example:\n"
100 " ... ures_open( \"%s\", NULL /* Get the default locale */, &err ); \n",
101 libName
, o
->shortName
, o
->shortName
);
102 T_FileStream_writeLine(out
, tmp
);
104 T_FileStream_close(out
);
108 #ifndef U_MAKE_IS_NMAKE
111 #include "makefile.h"
114 void pkg_mode_static(UPKGOptions
*o
, FileStream
*makefile
, UErrorCode
*status
)
117 CharList
*tail
= NULL
;
118 CharList
*objects
= NULL
;
120 if(U_FAILURE(*status
)) {
124 uprv_strcpy(tmp
, LIB_STATIC_PREFIX
);
125 uprv_strcat(tmp
, o
->libName
);
126 uprv_strcat(tmp
, UDATA_LIB_SUFFIX
);
128 o
->outFiles
= pkg_appendToList(o
->outFiles
, &tail
, uprv_strdup(tmp
));
131 pkg_sttc_writeReadme(o
, tmp
, status
);
133 if(U_FAILURE(*status
)) {
138 if(o
->nooutput
|| o
->verbose
) {
139 fprintf(stdout
, "# Output file: %s%s%s\n", o
->targetDir
, U_FILE_SEP_STRING
, tmp
);
143 *status
= U_ZERO_ERROR
;
147 /* begin writing makefile ========================= */
150 T_FileStream_writeLine(makefile
, "# Version numbers:\nVERSIONED=");
152 sprintf(tmp
, ".%s", o
->version
);
153 if (!uprv_strchr(o
->version
, '.')) {
154 uprv_strcat(tmp
, ".0");
156 T_FileStream_writeLine(makefile
, tmp
);
157 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(LD_SONAME) $(RPATH_LDFLAGS)\n");
159 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(BIR_LDFLAGS)\n");
161 T_FileStream_writeLine(makefile
, "\n");
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");
167 uprv_strcpy(tmp
, "all: $(TARG_PATH)$(LIB_TARGET)");
168 uprv_strcat(tmp
, "\n\n");
169 T_FileStream_writeLine(makefile
, tmp
);
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
);
178 /* Write compile rules */
179 pkg_mak_writeObjRules(o
, makefile
, &objects
, ".$(STATIC_O)"); /* use special .o suffix */
181 sprintf(tmp
, "# List file for gencmn:\n"
182 "CMNLIST=%s%s$(NAME)_static.lst\n\n",
185 T_FileStream_writeLine(makefile
, tmp
);
187 if(o
->hadStdin
== FALSE
) { /* shortcut */
188 T_FileStream_writeLine(makefile
, "$(CMNLIST): $(LISTFILES)\n"
189 "\tcat $(LISTFILES) > $(CMNLIST)\n\n");
191 T_FileStream_writeLine(makefile
, "$(CMNLIST): \n"
192 "\t@echo \"generating $@ (list of data files)\"\n"
194 "\t@for file in $(DATAFILEPATHS); do \\\n"
195 "\t echo $$file >> $@; \\\n"
199 pkg_mak_writeAssemblyHeader(makefile
, o
);
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
);
205 T_FileStream_writeLine(makefile
, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n");
208 sprintf(tmp
, "$(TEMP_PATH)$(NAME)_dat.c: $(CMNLIST)\n"
209 "\t$(INVOKE) $(GENCMN) -e $(ENTRYPOINT) -n $(NAME) -S -s $(SRCDIR) -d $(TEMP_DIR) 0 $(CMNLIST)\n\n");
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");
214 T_FileStream_writeLine(makefile
, tmp
);
216 sprintf(tmp
, "TOCOBJ= $(NAME)_dat.$(STATIC_O)\n\n");
217 T_FileStream_writeLine(makefile
, tmp
);
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");
223 T_FileStream_writeLine(makefile
, tmp
);
225 T_FileStream_writeLine(makefile
, "# 'ALLDATAOBJ' contains all .c data structures\n");
227 sprintf(tmp
, "ALLDATAOBJ= $(NAME)all%s \n\n", OBJ_SUFFIX
);
228 T_FileStream_writeLine(makefile
, tmp
);
231 sprintf(tmp
, "TOCSYM= $(ENTRYPOINT)_dat \n\n"); /* entrypoint not always shortname! */
232 T_FileStream_writeLine(makefile
, tmp
);
234 T_FileStream_writeLine(makefile
, "BASE_OBJECTS= $(TOCOBJ) ");
237 T_FileStream_writeLine(makefile
, "$(ALLDATAOBJ) ");
239 pkg_writeCharListWrap(makefile
, objects
, " ", " \\\n",0);
241 pkg_mak_writeAssemblyFooter(makefile
, o
);
243 T_FileStream_writeLine(makefile
, "\n\n");
244 T_FileStream_writeLine(makefile
, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_PATH)%)\n\n");
246 T_FileStream_writeLine(makefile
,"$(TEMP_PATH)%.$(STATIC_O): $(TEMP_PATH)%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
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");
253 T_FileStream_writeLine(makefile
, "$(TARG_PATH)$(LIB_TARGET):$(TARG_PATH)$(LIB_TARGET)($(OBJECTS)) $(LISTFILES)\n"
254 "\t$(RANLIB) $@\n\n");
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");
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");
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");
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");
272 *status
= U_ZERO_ERROR
;