]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/sttcmode.c
1 /******************************************************************************
3 * Copyright (C) 2002, 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/uloc.h"
34 /** set if AR is NOT to be called implicitly by gnumake
35 ** (i.e. if the form libblah.a($(OBJECTS) doesnt work)
37 #if defined(OS400) || defined(OS390)
38 # define NO_IMPLICIT_AR 1
40 # define NO_IMPLICIT_AR 0
43 void pkg_sttc_writeReadme(struct UPKGOptions_
*o
, const char *libName
, UErrorCode
*status
)
48 if(U_FAILURE(*status
))
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");
59 out
= T_FileStream_open(tmp
, "w");
61 fprintf(stderr
, "err: couldn't create README file %s\n", tmp
);
62 *status
= U_FILE_ACCESS_ERROR
;
66 sprintf(tmp
, "## README for \"%s\"'s static data (%s)\n"
67 "## created by pkgdata, ICU Version %s\n",
72 T_FileStream_writeLine(out
, tmp
);
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"
77 " #include \"unicode/utypes.h\"\n"
78 " #include \"unicode/udata.h\"\n"
79 " U_CFUNC char %s_dat[];\n",
81 T_FileStream_writeLine(out
, tmp
);
83 sprintf(tmp
, "2. *Early* in your application, call the following function:\n"
85 " UErrorCode myError = U_ZERO_ERROR;\n"
86 " udata_setAppData( \"%s\", (const void*) %s_dat, &myError);\n"
87 " if(U_FAILURE(myError))\n"
89 " handle error condition ...\n"
92 o
->cShortName
, o
->cShortName
);
93 T_FileStream_writeLine(out
, tmp
);
95 sprintf(tmp
, "3. Link your application against %s\n"
97 "4. Now, you may access this data with a 'path' of \"%s\" as in the following example:\n"
99 " ... ures_open( \"%s\", \"%s\", &err ); \n",
100 libName
, o
->shortName
, o
->shortName
, uloc_getDefault());
101 T_FileStream_writeLine(out
, tmp
);
103 T_FileStream_close(out
);
110 #include "makefile.h"
113 void pkg_mode_static(UPKGOptions
*o
, FileStream
*makefile
, UErrorCode
*status
)
116 CharList
*tail
= NULL
;
117 CharList
*objects
= NULL
;
119 if(U_FAILURE(*status
)) {
123 uprv_strcpy(tmp
, LIB_PREFIX
);
124 uprv_strcat(tmp
, o
->cShortName
);
125 uprv_strcat(tmp
, UDATA_LIB_SUFFIX
);
127 o
->outFiles
= pkg_appendToList(o
->outFiles
, &tail
, uprv_strdup(tmp
));
129 pkg_sttc_writeReadme(o
, tmp
, status
);
130 if(U_FAILURE(*status
)) {
135 if(o
->nooutput
|| o
->verbose
) {
136 fprintf(stdout
, "# Output file: %s%s%s\n", o
->targetDir
, U_FILE_SEP_STRING
, tmp
);
140 *status
= U_ZERO_ERROR
;
144 /* begin writing makefile ========================= */
147 T_FileStream_writeLine(makefile
, "# Version numbers:\nVERSIONED=");
149 sprintf(tmp
, ".%s", o
->version
);
150 if (!uprv_strchr(o
->version
, '.')) {
151 uprv_strcat(tmp
, ".0");
153 T_FileStream_writeLine(makefile
, tmp
);
154 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(LD_SONAME) $(RPATH_LDFLAGS)\n");
156 T_FileStream_writeLine(makefile
, "\nDLL_LDFLAGS=$(BIR_LDFLAGS)\n");
158 T_FileStream_writeLine(makefile
, "\n");
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");
164 uprv_strcpy(tmp
, "all: $(TARG_PATH)$(LIB_TARGET)");
165 uprv_strcat(tmp
, "\n\n");
166 T_FileStream_writeLine(makefile
, tmp
);
168 /* Write compile rules */
169 pkg_mak_writeObjRules(o
, makefile
, &objects
, ".$(STATIC_O)"); /* use special .o suffix */
171 sprintf(tmp
, "# List file for gencmn:\n"
172 "CMNLIST=%s%s$(NAME)_static.lst\n\n",
175 T_FileStream_writeLine(makefile
, tmp
);
177 if(o
->hadStdin
== FALSE
) { /* shortcut */
178 T_FileStream_writeLine(makefile
, "$(CMNLIST): $(LISTFILES)\n"
179 "\tcat $(LISTFILES) > $(CMNLIST)\n\n");
181 T_FileStream_writeLine(makefile
, "$(CMNLIST): \n"
182 "\t@echo \"generating $@ (list of data files)\"\n"
184 "\t@for file in $(DATAFILEPATHS); do \\\n"
185 "\t echo $$file >> $@; \\\n"
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
);
193 T_FileStream_writeLine(makefile
, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n");
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
);
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
);
204 T_FileStream_writeLine(makefile
, "BASE_OBJECTS= $(TOCOBJ) ");
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");
210 T_FileStream_writeLine(makefile
,"$(TEMP_PATH)%.$(STATIC_O): $(TEMP_PATH)%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
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");
217 T_FileStream_writeLine(makefile
, "$(TARG_PATH)$(LIB_TARGET):$(TARG_PATH)$(LIB_TARGET)($(OBJECTS)) $(LISTFILES)\n"
218 "\t$(RANLIB) $@\n\n");
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");
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");
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");
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");
236 *status
= U_ZERO_ERROR
;