]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/sttcmode.c
1 /******************************************************************************
3 * Copyright (C) 2002-2006, 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(NO_IMPLICIT_AR)
39 #if defined(OS400) || defined(OS390)
40 # define NO_IMPLICIT_AR 1
42 # define NO_IMPLICIT_AR 0
46 void pkg_sttc_writeReadme(struct UPKGOptions_
*o
, const char *libName
, UErrorCode
*status
)
51 if(U_FAILURE(*status
))
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");
62 out
= T_FileStream_open(tmp
, "w");
64 fprintf(stderr
, "err: couldn't create README file %s\n", tmp
);
65 *status
= U_FILE_ACCESS_ERROR
;
69 sprintf(tmp
, "## README for \"%s\"'s static data (%s)\n"
70 "## created by pkgdata, ICU Version %s\n",
75 T_FileStream_writeLine(out
, tmp
);
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"
80 " #include \"unicode/utypes.h\"\n"
81 " #include \"unicode/udata.h\"\n"
82 " U_CFUNC char %s_dat[];\n",
84 T_FileStream_writeLine(out
, tmp
);
86 sprintf(tmp
, "2. *Early* in your application, call the following function:\n"
88 " UErrorCode myError = U_ZERO_ERROR;\n"
89 " udata_setAppData( \"%s\", (const void*) %s_dat, &myError);\n"
90 " if(U_FAILURE(myError))\n"
92 " handle error condition ...\n"
95 o
->cShortName
, o
->cShortName
);
96 T_FileStream_writeLine(out
, tmp
);
98 sprintf(tmp
, "3. Link your application against %s\n"
100 "4. Now, you may access this data with a 'path' of \"%s\" as in the following example:\n"
102 " ... ures_open( \"%s\", NULL /* Get the default locale */, &err ); \n",
103 libName
, o
->shortName
, o
->shortName
);
104 T_FileStream_writeLine(out
, tmp
);
106 T_FileStream_close(out
);
110 #ifndef U_MAKE_IS_NMAKE
113 #include "makefile.h"
116 void pkg_mode_static(UPKGOptions
*o
, FileStream
*makefile
, UErrorCode
*status
)
119 CharList
*tail
= NULL
;
120 CharList
*objects
= NULL
;
122 if(U_FAILURE(*status
)) {
126 uprv_strcpy(tmp
, LIB_STATIC_PREFIX
);
127 uprv_strcat(tmp
, o
->libName
);
128 uprv_strcat(tmp
, UDATA_LIB_SUFFIX
);
130 o
->outFiles
= pkg_appendToList(o
->outFiles
, &tail
, uprv_strdup(tmp
));
133 pkg_sttc_writeReadme(o
, tmp
, status
);
135 if(U_FAILURE(*status
)) {
140 if(o
->nooutput
|| o
->verbose
) {
141 fprintf(stdout
, "# Output file: %s%s%s\n", o
->targetDir
, U_FILE_SEP_STRING
, tmp
);
145 *status
= U_ZERO_ERROR
;
149 /* begin writing makefile ========================= */
152 T_FileStream_writeLine(makefile
, "# Version numbers:\nVERSIONED=");
154 sprintf(tmp
, ".%s", o
->version
);
155 if (!uprv_strchr(o
->version
, '.')) {
156 uprv_strcat(tmp
, ".0");
158 T_FileStream_writeLine(makefile
, tmp
);
159 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(LD_SONAME) $(RPATH_LDFLAGS)\n");
161 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(BIR_LDFLAGS)\n");
163 T_FileStream_writeLine(makefile
, "\n");
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");
169 uprv_strcpy(tmp
, "all: $(TARG_PATH)$(LIB_TARGET)");
170 uprv_strcat(tmp
, "\n\n");
171 T_FileStream_writeLine(makefile
, tmp
);
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
);
180 /* Write compile rules */
181 pkg_mak_writeObjRules(o
, makefile
, &objects
, ".$(STATIC_O)"); /* use special .o suffix */
183 sprintf(tmp
, "# List file for gencmn:\n"
184 "CMNLIST=%s%s$(NAME)_static.lst\n\n",
187 T_FileStream_writeLine(makefile
, tmp
);
189 if(o
->hadStdin
== FALSE
) { /* shortcut */
190 T_FileStream_writeLine(makefile
, "$(CMNLIST): $(LISTFILES)\n"
191 "\tcat $(LISTFILES) > $(CMNLIST)\n\n");
193 T_FileStream_writeLine(makefile
, "$(CMNLIST): \n"
194 "\t@echo \"generating $@ (list of data files)\"\n"
196 "\t@for file in $(DATAFILEPATHS); do \\\n"
197 "\t echo $$file >> $@; \\\n"
201 pkg_mak_writeAssemblyHeader(makefile
, o
);
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
);
207 T_FileStream_writeLine(makefile
, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n");
209 sprintf(tmp
, "$(TEMP_PATH)$(NAME)_dat.c: $(CMNLIST)\n"
210 "\t$(INVOKE) $(GENCMN) -e $(ENTRYPOINT) -n $(NAME) -S -s $(SRCDIR) -d $(TEMP_DIR) 0 $(CMNLIST)\n\n");
211 T_FileStream_writeLine(makefile
, tmp
);
213 sprintf(tmp
, "TOCOBJ= $(NAME)_dat.$(STATIC_O)\n\n");
214 T_FileStream_writeLine(makefile
, tmp
);
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");
220 T_FileStream_writeLine(makefile
, tmp
);
222 T_FileStream_writeLine(makefile
, "# 'ALLDATAOBJ' contains all .c data structures\n");
224 sprintf(tmp
, "ALLDATAOBJ= $(NAME)all%s \n\n", OBJ_SUFFIX
);
225 T_FileStream_writeLine(makefile
, tmp
);
228 sprintf(tmp
, "TOCSYM= $(ENTRYPOINT)_dat \n\n"); /* entrypoint not always shortname! */
229 T_FileStream_writeLine(makefile
, tmp
);
231 T_FileStream_writeLine(makefile
, "BASE_OBJECTS= $(TOCOBJ) ");
234 T_FileStream_writeLine(makefile
, "$(ALLDATAOBJ) ");
236 pkg_writeCharListWrap(makefile
, objects
, " ", " \\\n",0);
238 pkg_mak_writeAssemblyFooter(makefile
, o
);
240 T_FileStream_writeLine(makefile
, "\n\n");
241 T_FileStream_writeLine(makefile
, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_PATH)%)\n\n");
243 T_FileStream_writeLine(makefile
,"$(TEMP_PATH)%.$(STATIC_O): $(TEMP_PATH)%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
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");
250 T_FileStream_writeLine(makefile
, "$(TARG_PATH)$(LIB_TARGET):$(TARG_PATH)$(LIB_TARGET)($(OBJECTS)) $(LISTFILES)\n"
251 "\t$(RANLIB) $@\n\n");
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");
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");
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");
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");
269 *status
= U_ZERO_ERROR
;