]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/tools/pkgdata/dllmode.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / tools / pkgdata / dllmode.c
... / ...
CommitLineData
1/******************************************************************************
2*
3* Copyright (C) 2000-2003, International Business Machines
4* Corporation and others. All Rights Reserved.
5*
6*******************************************************************************
7* file name: pkgdata.c
8* encoding: ANSI X3.4 (1968)
9* tab size: 8 (not used)
10* indentation:4
11*
12* created on: 2000may15
13* created by: Steven \u24C7 Loomis
14*
15* This program packages the ICU data into different forms
16* (DLL, common data, etc.)
17*/
18
19#include <stdio.h>
20#include <stdlib.h>
21#include "unicode/utypes.h"
22#include "cmemory.h"
23#include "cstring.h"
24#include "filestrm.h"
25#include "toolutil.h"
26#include "unewdata.h"
27#include "uoptions.h"
28#include "pkgtypes.h"
29#include "makefile.h"
30
31
32void pkg_mode_dll(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
33{
34 char tmp[1024];
35 CharList *tail = NULL;
36 CharList *objects = NULL;
37
38 if(U_FAILURE(*status)) {
39 return;
40 }
41
42 uprv_strcpy(tmp, LIB_PREFIX "$(NAME)" UDATA_SO_SUFFIX);
43
44 /* We should be the only item. So we don't care about the order. */
45 o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp));
46
47 if(o->nooutput || o->verbose) {
48 fprintf(stdout, "# Output file: %s%s%s\n", o->targetDir, U_FILE_SEP_STRING, tmp);
49 }
50
51 if(o->nooutput) {
52 *status = U_ZERO_ERROR;
53 return;
54 }
55
56 /* begin writing makefile ========================= */
57
58
59 /*390port start*/
60#ifdef OS390BATCH
61 if (uprv_strcmp(o->shortName, U_LIBICUDATA_NAME) == 0)
62 sprintf(tmp, "# File to make:\nBATCH_TARGET=\"//'${LOADMOD}(IXMI" U_ICU_VERSION_SHORT "DA)'\"\n\n");
63 else if (uprv_strcmp(o->shortName, "testdata") == 0)
64 sprintf(tmp, "# File to make:\nBATCH_TARGET=\"//'${LOADMOD}(IXMI" U_ICU_VERSION_SHORT "TE)'\"\n\n");
65 else if (uprv_strcmp(o->shortName, U_LIBICUDATA_NAME"_stub") == 0)
66 sprintf(tmp, "# File to make:\nBATCH_TARGET=\"//'${LOADMOD}(IXMI" U_ICU_VERSION_SHORT "D1)'\"\n\n");
67 T_FileStream_writeLine(makefile, tmp);
68#endif
69
70 T_FileStream_writeLine(makefile, "# Version numbers:\nVERSIONED=");
71 if (o->version) {
72 sprintf(tmp, ".%s", o->version);
73 if (!uprv_strchr(o->version, '.')) {
74 uprv_strcat(tmp, ".0");
75 }
76 T_FileStream_writeLine(makefile, tmp);
77 T_FileStream_writeLine(makefile, "\nDLL_LDFLAGS=$(LD_SONAME) $(RPATH_LDFLAGS) $(BIR_LDFLAGS)\nDLL_DEPS=$(BIR_DEPS)\n");
78 } else {
79 T_FileStream_writeLine(makefile, "\nDLL_LDFLAGS=$(BIR_LDFLAGS)\nDLL_DEPS=$(BIR_DEPS)\n");
80 }
81 T_FileStream_writeLine(makefile, "\n");
82
83 sprintf(tmp, "# File to make:\nTARGET=%s\n\n", o->outFiles->str);
84 T_FileStream_writeLine(makefile, tmp);
85 if (o->version) {
86 char *p;
87 const char *v;
88
89 T_FileStream_writeLine(makefile, "SO_TARGET=$(TARGET)\n");
90 sprintf(tmp, "SO_TARGET_VERSION=%s\n", o->version);
91 T_FileStream_writeLine(makefile, tmp);
92 uprv_strcpy(tmp, "SO_TARGET_VERSION_MAJOR=");
93 for (p = tmp + uprv_strlen(tmp), v = o->version; *v && *v != '.'; ++v) {
94 *p++ = *v;
95 }
96 *p++ = '\n';
97 *p++ = '\n';
98 *p++ = 0;
99 T_FileStream_writeLine(makefile, tmp);
100 } else {
101 T_FileStream_writeLine(makefile, "FINAL_SO_TARGET=$(TARGET)\n");
102 T_FileStream_writeLine(makefile, "MIDDLE_SO_TARGET=$(TARGET)\n");
103 }
104
105 uprv_strcpy(tmp, "all: $(TARGETDIR)/$(FINAL_SO_TARGET) $(BATCH_TARGET)");
106 if (o->version) {
107 uprv_strcat(tmp, " $(TARGETDIR)/$(MIDDLE_SO_TARGET) $(TARGETDIR)/$(SO_TARGET)");
108 }
109 uprv_strcat(tmp, "\n\n");
110 T_FileStream_writeLine(makefile, tmp);
111
112 /* Write compile rules */
113 pkg_mak_writeObjRules(o, makefile, &objects, OBJ_SUFFIX);
114
115 sprintf(tmp, "# List file for gencmn:\n"
116 "CMNLIST=%s%s$(NAME)_dll.lst\n\n",
117 o->tmpDir,
118 U_FILE_SEP_STRING);
119 T_FileStream_writeLine(makefile, tmp);
120
121 if(o->hadStdin == FALSE) { /* shortcut */
122 T_FileStream_writeLine(makefile, "$(CMNLIST): $(LISTFILES)\n"
123 "\tcat $(LISTFILES) > $(CMNLIST)\n\n");
124 } else {
125 T_FileStream_writeLine(makefile, "$(CMNLIST): \n"
126 "\t@echo \"generating $@ (list of data files)\"\n"
127 "\t@-$(RMV) $@\n"
128 "\t@for file in $(DATAFILEPATHS); do \\\n"
129 "\t echo $$file >> $@; \\\n"
130 "\tdone;\n\n");
131 }
132
133 sprintf(tmp,"$(TEMP_DIR)/$(NAME)_dat.o : $(TEMP_DIR)/$(NAME)_dat.c\n"
134 "\t$(COMPILE.c) -o $@ $<\n\n");
135 T_FileStream_writeLine(makefile, tmp);
136
137 T_FileStream_writeLine(makefile, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n");
138
139 sprintf(tmp, "$(TEMP_DIR)/$(NAME)_dat.c: $(CMNLIST)\n"
140 "\t$(INVOKE) $(GENCMN) -e $(ENTRYPOINT) -n $(NAME) -S -d $(TEMP_DIR) 0 $(CMNLIST)\n\n");
141
142 T_FileStream_writeLine(makefile, tmp);
143 sprintf(tmp, "TOCOBJ= $(NAME)_dat%s \n\n", OBJ_SUFFIX);
144 T_FileStream_writeLine(makefile, tmp);
145 sprintf(tmp, "TOCSYM= %s_dat \n\n", o->entryName); /* entrypoint not always shortname! */
146 T_FileStream_writeLine(makefile, tmp);
147
148 T_FileStream_writeLine(makefile, "BASE_OBJECTS= $(TOCOBJ) ");
149
150 pkg_writeCharListWrap(makefile, objects, " ", " \\\n",0);
151 T_FileStream_writeLine(makefile, "\n\n");
152 T_FileStream_writeLine(makefile, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_DIR)/%)\n\n");
153
154 T_FileStream_writeLine(makefile,"$(TEMP_DIR)/%.o: $(TEMP_DIR)/%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
155
156 T_FileStream_writeLine(makefile,"build-objs: $(SOURCES) $(OBJECTS)\n\n$(OBJECTS): $(SOURCES)\n\n");
157
158#ifdef HPUX
159 T_FileStream_writeLine(makefile, "$(TARGETDIR)/$(FINAL_SO_TARGET): $(OBJECTS) $(HPUX_JUNK_OBJ) $(LISTFILES) $(DLL_DEPS)\n"
160 "\t$(SHLIB.cc) -o $@ $(OBJECTS) $(HPUX_JUNK_OBJ) $(DLL_LDFLAGS)\n"
161 "\t-ls -l $@\n\n");
162
163 T_FileStream_writeLine(makefile, "$(TEMP_DIR)/hpux_junk_obj.cpp:\n"
164 "\techo \"void to_emit_cxx_stuff_in_the_linker(){}\" >> $(TEMP_DIR)/hpux_junk_obj.cpp\n"
165 "\n"
166 "$(TEMP_DIR)/hpux_junk_obj.o: $(TEMP_DIR)/hpux_junk_obj.cpp\n"
167 "\t$(COMPILE.cc) -o $@ $<\n"
168 "\n");
169#else
170
171 /*390port*/
172#ifdef OS390BATCH
173 T_FileStream_writeLine(makefile, "$(BATCH_TARGET): $(OBJECTS) $(LISTFILES) $(DLL_DEPS)\n"
174 "\t$(SHLIB.c) -o $@ $(OBJECTS) $(DLL_LDFLAGS)\n\n");
175#endif
176
177 T_FileStream_writeLine(makefile, "$(TARGETDIR)/$(FINAL_SO_TARGET): $(OBJECTS) $(LISTFILES) $(DLL_DEPS)\n"
178 "\t$(SHLIB.c) -o $@ $(OBJECTS) $(DLL_LDFLAGS)\n"
179 "\t-ls -l $@\n\n");
180
181#ifdef OS390
182 /*
183 jdc26: The above link resolves to
184
185 -o ../data/out/libicudata26.0.dll
186
187 the first time or
188
189 -o ../data/out/libicudata_stub26.0.dll
190
191 the second time in the build. OS/390 puts each DLL into
192 the specified directory and the sidedeck into the current
193 directory. Move the sidedeck into the same directory as
194 the DLL so it can be found with the DLL later in the
195 build.
196
197 */
198 T_FileStream_writeLine(makefile, "\t-cp -f ./$(basename $(FINAL_SO_TARGET))$(IMPORT_LIB_EXT) $(TARGETDIR)/$(basename $(FINAL_SO_TARGET))$(IMPORT_LIB_EXT)\n");
199#endif /* OS/390 */
200#endif
201
202 T_FileStream_writeLine(makefile, "CLEANFILES= $(CMNLIST) $(OBJECTS) $(HPUX_JUNK_OBJ) $(TARGETDIR)/$(FINAL_SO_TARGET) $(TARGETDIR)/$(MIDDLE_SO_TARGET) $(TARGETDIR)/$(TARGET)\n\nclean:\n\t-$(RMV) $(CLEANFILES) $(MAKEFILE)");
203 T_FileStream_writeLine(makefile, "\n\n");
204
205 T_FileStream_writeLine(makefile, "install: $(TARGETDIR)/$(FINAL_SO_TARGET)\n"
206 "\t$(INSTALL-L) $(TARGETDIR)/$(FINAL_SO_TARGET) $(INSTALLTO)/$(FINAL_SO_TARGET)\n");
207
208 T_FileStream_writeLine(makefile, "ifneq ($(IMPORT_LIB_EXT),)\n");
209 T_FileStream_writeLine(makefile, "\t$(INSTALL-L) $(TARGETDIR)/$(basename $(FINAL_SO_TARGET))$(IMPORT_LIB_EXT) $(INSTALLTO)/$(basename( $(FINAL_SO_TARGET))$(IMPORT_LIB_EXT)\n");
210 T_FileStream_writeLine(makefile, "endif\n");
211 if (o->version) {
212 T_FileStream_writeLine(makefile, "ifneq ($(FINAL_SO_TARGET),$(SO_TARGET))\n");
213 T_FileStream_writeLine(makefile, "\tcd $(INSTALLTO) && $(RM) $(SO_TARGET) && ln -s $(FINAL_SO_TARGET) $(SO_TARGET)\n");
214 T_FileStream_writeLine(makefile, "ifneq ($(FINAL_SO_TARGET),$(MIDDLE_SO_TARGET))\n");
215 T_FileStream_writeLine(makefile, "\tcd $(INSTALLTO) && $(RM) $(MIDDLE_SO_TARGET) && ln -s $(FINAL_SO_TARGET) $(MIDDLE_SO_TARGET)\n");
216 T_FileStream_writeLine(makefile, "endif\n");
217 T_FileStream_writeLine(makefile, "endif\n");
218
219#ifdef OS390
220 T_FileStream_writeLine(makefile, "ifneq ($(IMPORT_LIB_EXT),)\n");
221 T_FileStream_writeLine(makefile, "\tcd $(INSTALLTO) && $(RM) $(basename $(MIDDLE_SO_TARGET))$(IMPORT_LIB_EXT) && ln -s $(basename $(FINAL_SO_TARGET))$(IMPORT_LIB_EXT) $(basename $(MIDDLE_SO_TARGET))$(IMPORT_LIB_EXT)\n");
222 T_FileStream_writeLine(makefile, "\tcd $(INSTALLTO) && $(RM) $(basename $(SO_TARGET))$(IMPORT_LIB_EXT) && ln -s $(basename $(FINAL_SO_TARGET))$(IMPORT_LIB_EXT) $(basename $(SO_TARGET))$(IMPORT_LIB_EXT)\n");
223 T_FileStream_writeLine(makefile, "endif\n");
224#endif
225 }
226 T_FileStream_writeLine(makefile, "\n");
227
228#ifdef U_SOLARIS
229 T_FileStream_writeLine(makefile, "$(NAME).map:\n\techo \"{global: $(TOCSYM); local: *; };\" > $@\n\n");
230#endif
231
232#ifdef AIX
233 T_FileStream_writeLine(makefile, "$(NAME).map:\n\techo \"$(TOCSYM)\" > $@\n\n");
234#endif
235
236
237 *status = U_ZERO_ERROR;
238
239}
240
241
242