]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/filemode.c
ICU-6.2.10.tar.gz
[apple/icu.git] / icuSources / tools / pkgdata / filemode.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2000-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *
6 *******************************************************************************
7 * file name: filemode.c
8 * encoding: ANSI X3.4 (1968)
9 * tab size: 8 (not used)
10 * indentation:4
11 *
12 * created on: 2000sep28
13 * created by: Steven \u24C7 Loomis
14 *
15 * The mode which uses raw files (i.e. does nothing until installation).
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "unicode/utypes.h"
21 #include "unicode/putil.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 /* The file we will make will look like this:
32
33 (where /out is the full path to the output dir)
34
35 SOURCES=/out/filea /out/fileb ./somewhere/filec ../somewhereelse/filed
36
37 TARGETS=/out/filea /out/fileb /out/filec /out/filed
38
39 all: $(TARGETS)
40
41 /out/filec /out/filed: ../somewhere/filec ../somewhereelse/filed
42 $(INSTALL_DATA) $? $(OUTDIR)
43
44 install: all
45 $(INSTALL_DATA) $(TARGETS) $(instdir)
46
47
48 ==Note:==
49 The only items in the first '$(INSTALL_DATA)' are files NOT already in the out dir!
50
51
52 */
53
54
55
56 void pkg_mode_files(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
57 {
58 char tmp[1024], tmp2[1024], srcPath[1024];
59 char stanza[3072];
60
61 CharList *tail = NULL, *infiles = NULL;
62
63 CharList *copyFilesLeft = NULL; /* left hand side of the copy rule*/
64 CharList *copyFilesRight = NULL; /* rhs "" "" */
65 CharList *copyFilesInstall = NULL;
66
67 CharList *copyFilesLeftTail = NULL;
68 CharList *copyFilesRightTail = NULL;
69 CharList *copyFilesInstallTail = NULL;
70
71 CharList *copyDirs = NULL; /* list of dirs to create for copying */
72 CharList *installDirs = NULL; /* list of dirs to create for installation */
73
74 /* CharList *copyCommands = NULL;*/
75
76 const char *baseName;
77
78 T_FileStream_writeLine(makefile, "\n.PHONY: $(NAME) all install clean\n\nall: $(NAME)\n\n");
79
80 if(o->embed) {
81 infiles = o->filePaths;
82 } else {
83 infiles = o->files; /* raw files - no paths other than tree paths */
84 }
85
86 /* Dont' copy files already in tmp */
87 for(;infiles;infiles = infiles->next)
88 {
89 uprv_strcpy(tmp, o->targetDir);
90 uprv_strcat(tmp, U_FILE_SEP_STRING);
91 if(o->embed) {
92 baseName = findBasename(infiles->str);
93 uprv_strcpy(srcPath, baseName);
94 } else {
95 baseName = infiles->str;
96 uprv_strcat(tmp, o->shortName);
97 uprv_strcat(tmp, U_FILE_SEP_STRING);
98 uprv_strcpy(srcPath, "$(SRCDIR)/");
99 uprv_strcat(srcPath, infiles->str);
100 }
101 uprv_strcat(tmp, baseName);
102
103 copyDirs = pkg_appendUniqueDirToList(copyDirs, NULL, tmp);
104
105 o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp));
106
107 if(strcmp(tmp, infiles->str) == 0)
108 {
109 /* fprintf(stderr, "### NOT copying: %s\n", tmp); */
110 /* no copy needed.. */
111 } else {
112 sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp, srcPath);
113 T_FileStream_writeLine(makefile, stanza);
114 }
115
116 uprv_strcpy(tmp2, "$(INSTALLTO)" U_FILE_SEP_STRING);
117 if(!o->embed) {
118 uprv_strcat(tmp2, o->shortName);
119 uprv_strcat(tmp2, U_FILE_SEP_STRING);
120 }
121 uprv_strcat(tmp2, baseName);
122
123 installDirs = pkg_appendUniqueDirToList(installDirs, NULL, tmp2);
124
125 if(strcmp(tmp2, infiles->str) == 0) {
126 /* fprintf(stderr, "### NOT copying: %s\n", tmp2); */
127 /* no copy needed.. */
128 } else {
129 sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp2, tmp);
130 T_FileStream_writeLine(makefile, stanza);
131
132 /* left hand side: target path, target name */
133 copyFilesLeft = pkg_appendToList(copyFilesLeft, &copyFilesLeftTail, uprv_strdup(tmp));
134
135 /* fprintf(stderr, "##### COPY %s from %s\n", tmp, infiles->str); */
136 /* rhs: source path */
137 copyFilesRight = pkg_appendToList(copyFilesRight, &copyFilesRightTail, uprv_strdup(infiles->str));
138
139 /* install: installed path */
140 copyFilesInstall = pkg_appendToList(copyFilesInstall, &copyFilesInstallTail, uprv_strdup(tmp2));
141 }
142 }
143
144 if(o->nooutput || o->verbose) {
145 CharList *i;
146 fprintf(stdout, "# Output files: ");
147 for(i = o->outFiles; i; i=i->next) {
148 printf("%s ", i->str);
149 }
150 printf("\n");
151 }
152
153 if(o->nooutput) {
154 *status = U_ZERO_ERROR;
155 return;
156 }
157
158 /* these are also the files to delete */
159 T_FileStream_writeLine(makefile, "COPIEDDEST= ");
160 pkg_writeCharListWrap(makefile, copyFilesLeft, " ", " \\\n", 0);
161 T_FileStream_writeLine(makefile, "\n\n");
162
163
164 T_FileStream_writeLine(makefile, "INSTALLEDDEST= ");
165 pkg_writeCharListWrap(makefile, copyFilesInstall, " ", " \\\n", 0);
166 T_FileStream_writeLine(makefile, "\n\n");
167
168 T_FileStream_writeLine(makefile, "COPYDIRS= ");
169 pkg_writeCharListWrap(makefile, copyDirs, " ", " \\\n", 0);
170 T_FileStream_writeLine(makefile, "\n\n");
171
172
173 T_FileStream_writeLine(makefile, "INSTALLDIRS= ");
174 pkg_writeCharListWrap(makefile, installDirs, " ", " \\\n", 0);
175 T_FileStream_writeLine(makefile, "\n\n");
176
177 if(copyFilesRight != NULL)
178 {
179 T_FileStream_writeLine(makefile, "$(NAME): copy-dirs $(COPIEDDEST)\n\n");
180
181 T_FileStream_writeLine(makefile, "clean:\n\t-$(RMV) $(COPIEDDEST) $(MAKEFILE)");
182 T_FileStream_writeLine(makefile, "\n\n");
183
184 }
185 else
186 {
187 T_FileStream_writeLine(makefile, "clean:\n\n");
188 }
189 T_FileStream_writeLine(makefile, "install: install-dirs $(INSTALLEDDEST)\n\n");
190 T_FileStream_writeLine(makefile, "install-dirs:\n\t$(MKINSTALLDIRS) $(INSTALLDIRS)\n\n");
191 T_FileStream_writeLine(makefile, "copy-dirs:\n\t$(MKINSTALLDIRS) $(COPYDIRS)\n\n");
192 }
193