]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/pkgdata/filemode.c
ICU-6.2.13.tar.gz
[apple/icu.git] / icuSources / tools / pkgdata / filemode.c
CommitLineData
b75a7d8f
A
1/******************************************************************************
2*
374ca955 3* Copyright (C) 2000-2004, International Business Machines
b75a7d8f
A
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
35SOURCES=/out/filea /out/fileb ./somewhere/filec ../somewhereelse/filed
36
37TARGETS=/out/filea /out/fileb /out/filec /out/filed
38
39all: $(TARGETS)
40
41/out/filec /out/filed: ../somewhere/filec ../somewhereelse/filed
42 $(INSTALL_DATA) $? $(OUTDIR)
43
44install: 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
56void pkg_mode_files(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
57{
374ca955 58 char tmp[1024], tmp2[1024], srcPath[1024];
b75a7d8f
A
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
374ca955
A
71 CharList *copyDirs = NULL; /* list of dirs to create for copying */
72 CharList *installDirs = NULL; /* list of dirs to create for installation */
73
b75a7d8f
A
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
374ca955
A
80 if(o->embed) {
81 infiles = o->filePaths;
82 } else {
83 infiles = o->files; /* raw files - no paths other than tree paths */
84 }
b75a7d8f 85
374ca955
A
86 /* Dont' copy files already in tmp */
87 for(;infiles;infiles = infiles->next)
88 {
b75a7d8f
A
89 uprv_strcpy(tmp, o->targetDir);
90 uprv_strcat(tmp, U_FILE_SEP_STRING);
374ca955
A
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 }
b75a7d8f
A
101 uprv_strcat(tmp, baseName);
102
374ca955
A
103 copyDirs = pkg_appendUniqueDirToList(copyDirs, NULL, tmp);
104
b75a7d8f
A
105 o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp));
106
107 if(strcmp(tmp, infiles->str) == 0)
108 {
374ca955 109 /* fprintf(stderr, "### NOT copying: %s\n", tmp); */
b75a7d8f 110 /* no copy needed.. */
374ca955
A
111 } else {
112 sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp, srcPath);
113 T_FileStream_writeLine(makefile, stanza);
b75a7d8f
A
114 }
115
116 uprv_strcpy(tmp2, "$(INSTALLTO)" U_FILE_SEP_STRING);
374ca955
A
117 if(!o->embed) {
118 uprv_strcat(tmp2, o->shortName);
119 uprv_strcat(tmp2, U_FILE_SEP_STRING);
120 }
b75a7d8f
A
121 uprv_strcat(tmp2, baseName);
122
374ca955
A
123 installDirs = pkg_appendUniqueDirToList(installDirs, NULL, tmp2);
124
125 if(strcmp(tmp2, infiles->str) == 0) {
126 /* fprintf(stderr, "### NOT copying: %s\n", tmp2); */
b75a7d8f 127 /* no copy needed.. */
374ca955
A
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));
b75a7d8f 141 }
b75a7d8f 142 }
374ca955 143
b75a7d8f
A
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
374ca955
A
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
b75a7d8f
A
177 if(copyFilesRight != NULL)
178 {
374ca955 179 T_FileStream_writeLine(makefile, "$(NAME): copy-dirs $(COPIEDDEST)\n\n");
b75a7d8f
A
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 }
374ca955
A
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");
b75a7d8f
A
192}
193