]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/sttcmode.c
1 /******************************************************************************
3 * Copyright (C) 2002-2007, 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 void pkg_sttc_writeReadme(struct UPKGOptions_
*o
, const char *libName
, UErrorCode
*status
)
40 if(U_FAILURE(*status
))
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");
51 out
= T_FileStream_open(tmp
, "w");
53 fprintf(stderr
, "err: couldn't create README file %s\n", tmp
);
54 *status
= U_FILE_ACCESS_ERROR
;
58 sprintf(tmp
, "## README for \"%s\"'s static data (%s)\n"
59 "## created by pkgdata, ICU Version %s\n",
64 T_FileStream_writeLine(out
, tmp
);
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"
69 " #include \"unicode/utypes.h\"\n"
70 " #include \"unicode/udata.h\"\n"
71 " U_CFUNC char %s_dat[];\n",
73 T_FileStream_writeLine(out
, tmp
);
75 sprintf(tmp
, "2. *Early* in your application, call the following function:\n"
77 " UErrorCode myError = U_ZERO_ERROR;\n"
78 " udata_setAppData( \"%s\", (const void*) %s_dat, &myError);\n"
79 " if(U_FAILURE(myError))\n"
81 " handle error condition ...\n"
84 o
->cShortName
, o
->cShortName
);
85 T_FileStream_writeLine(out
, tmp
);
87 sprintf(tmp
, "3. Link your application against %s\n"
89 "4. Now, you may access this data with a 'path' of \"%s\" as in the following example:\n"
91 " ... ures_open( \"%s\", NULL /* Get the default locale */, &err ); \n",
92 libName
, o
->shortName
, o
->shortName
);
93 T_FileStream_writeLine(out
, tmp
);
95 T_FileStream_close(out
);
99 #ifndef U_MAKE_IS_NMAKE
102 #include "makefile.h"
105 void pkg_mode_static(UPKGOptions
*o
, FileStream
*makefile
, UErrorCode
*status
)
108 CharList
*tail
= NULL
;
109 CharList
*objects
= NULL
;
111 if(U_FAILURE(*status
)) {
115 uprv_strcpy(tmp
, LIB_STATIC_PREFIX
);
116 uprv_strcat(tmp
, o
->libName
);
117 uprv_strcat(tmp
, UDATA_LIB_SUFFIX
);
119 o
->outFiles
= pkg_appendToList(o
->outFiles
, &tail
, uprv_strdup(tmp
));
122 pkg_sttc_writeReadme(o
, tmp
, status
);
124 if(U_FAILURE(*status
)) {
129 if(o
->nooutput
|| o
->verbose
) {
130 fprintf(stdout
, "# Output file: %s%s%s\n", o
->targetDir
, U_FILE_SEP_STRING
, tmp
);
134 *status
= U_ZERO_ERROR
;
138 /* begin writing makefile ========================= */
141 T_FileStream_writeLine(makefile
, "# Version numbers:\nVERSIONED=");
143 sprintf(tmp
, ".%s", o
->version
);
144 if (!uprv_strchr(o
->version
, '.')) {
145 uprv_strcat(tmp
, ".0");
147 T_FileStream_writeLine(makefile
, tmp
);
148 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(LD_SONAME) $(RPATH_LDFLAGS)\n");
150 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(BIR_LDFLAGS)\n");
152 T_FileStream_writeLine(makefile
, "\n");
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");
158 uprv_strcpy(tmp
, "all: $(TARG_PATH)$(LIB_TARGET)");
159 uprv_strcat(tmp
, "\n\n");
160 T_FileStream_writeLine(makefile
, tmp
);
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
);
169 /* Write compile rules */
170 pkg_mak_writeObjRules(o
, makefile
, &objects
, ".$(STATIC_O)"); /* use special .o suffix */
172 sprintf(tmp
, "# List file for gencmn:\n"
173 "CMNLIST=%s%s$(NAME)_static.lst\n\n",
176 T_FileStream_writeLine(makefile
, tmp
);
178 if(o
->hadStdin
== FALSE
) { /* shortcut */
179 T_FileStream_writeLine(makefile
, "$(CMNLIST): $(LISTFILES)\n"
180 "\tcat $(LISTFILES) > $(CMNLIST)\n\n");
182 T_FileStream_writeLine(makefile
, "$(CMNLIST): \n"
183 "\t@echo \"generating $@ (list of data files)\"\n"
185 "\t@for file in $(DATAFILEPATHS); do \\\n"
186 "\t echo $$file >> $@; \\\n"
190 pkg_mak_writeAssemblyHeader(makefile
, o
);
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
);
196 T_FileStream_writeLine(makefile
, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n");
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
);
202 sprintf(tmp
, "TOCOBJ= $(NAME)_dat.$(STATIC_O)\n\n");
203 T_FileStream_writeLine(makefile
, tmp
);
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
);
211 T_FileStream_writeLine(makefile
, "# 'ALLDATAOBJ' contains all .c data structures\n");
213 sprintf(tmp
, "ALLDATAOBJ= $(NAME)all%s \n\n", OBJ_SUFFIX
);
214 T_FileStream_writeLine(makefile
, tmp
);
217 sprintf(tmp
, "TOCSYM= $(ENTRYPOINT)_dat \n\n"); /* entrypoint not always shortname! */
218 T_FileStream_writeLine(makefile
, tmp
);
220 T_FileStream_writeLine(makefile
, "BASE_OBJECTS= $(TOCOBJ) ");
223 T_FileStream_writeLine(makefile
, "$(ALLDATAOBJ) ");
225 pkg_writeCharListWrap(makefile
, objects
, " ", " \\\n",0);
227 pkg_mak_writeAssemblyFooter(makefile
, o
);
229 T_FileStream_writeLine(makefile
, "\n\n");
230 T_FileStream_writeLine(makefile
, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_PATH)%)\n\n");
232 T_FileStream_writeLine(makefile
,"$(TEMP_PATH)%.$(STATIC_O): $(TEMP_PATH)%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
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");
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");
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");
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");
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");
253 *status
= U_ZERO_ERROR
;