]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /****************************************************************************** |
2 | * | |
3 | * Copyright (C) 2000-2001, 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]; | |
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 *copyCommands = NULL;*/ | |
72 | ||
73 | const char *baseName; | |
74 | ||
75 | T_FileStream_writeLine(makefile, "\n.PHONY: $(NAME) all install clean\n\nall: $(NAME)\n\n"); | |
76 | ||
77 | /* Dont' copy files already in tmp */ | |
78 | for(infiles = o->filePaths;infiles;infiles = infiles->next) | |
79 | { | |
80 | baseName = findBasename(infiles->str); | |
81 | ||
82 | uprv_strcpy(tmp, o->targetDir); | |
83 | uprv_strcat(tmp, U_FILE_SEP_STRING); | |
84 | uprv_strcat(tmp, baseName); | |
85 | ||
86 | o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp)); | |
87 | ||
88 | if(strcmp(tmp, infiles->str) == 0) | |
89 | { | |
90 | /* fprintf(stderr, "### NOT copying: %s\n", tmp); */ | |
91 | /* no copy needed.. */ | |
92 | continue; | |
93 | } | |
94 | ||
95 | sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp, infiles->str); | |
96 | T_FileStream_writeLine(makefile, stanza); | |
97 | ||
98 | uprv_strcpy(tmp2, o->targetDir); | |
99 | uprv_strcat(tmp2, U_FILE_SEP_STRING); | |
100 | uprv_strcat(tmp2, U_FILE_SEP_STRING); | |
101 | uprv_strcat(tmp2, baseName); | |
102 | ||
103 | if(strcmp(tmp2, infiles->str) == 0) | |
104 | { | |
105 | /* fprintf(stderr, "### NOT copying: %s\n", tmp2); */ | |
106 | /* no copy needed.. */ | |
107 | continue; | |
108 | } | |
109 | ||
110 | uprv_strcpy(tmp2, "$(INSTALLTO)" U_FILE_SEP_STRING); | |
111 | uprv_strcat(tmp2, baseName); | |
112 | ||
113 | if(strcmp(tmp2, infiles->str) == 0) | |
114 | { | |
115 | /* fprintf(stderr, "### NOT copying: %s\n", tmp2); */ | |
116 | /* no copy needed.. */ | |
117 | continue; | |
118 | } | |
119 | ||
120 | sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp2, tmp); | |
121 | T_FileStream_writeLine(makefile, stanza); | |
122 | ||
123 | /* left hand side: target path, target name */ | |
124 | copyFilesLeft = pkg_appendToList(copyFilesLeft, ©FilesLeftTail, uprv_strdup(tmp)); | |
125 | ||
126 | /* fprintf(stderr, "##### COPY %s from %s\n", tmp, infiles->str); */ | |
127 | /* rhs: source path */ | |
128 | copyFilesRight = pkg_appendToList(copyFilesRight, ©FilesRightTail, uprv_strdup(infiles->str)); | |
129 | ||
130 | /* install: installed path */ | |
131 | copyFilesInstall = pkg_appendToList(copyFilesInstall, ©FilesInstallTail, uprv_strdup(tmp2)); | |
132 | } | |
133 | ||
134 | if(o->nooutput || o->verbose) { | |
135 | CharList *i; | |
136 | fprintf(stdout, "# Output files: "); | |
137 | for(i = o->outFiles; i; i=i->next) { | |
138 | printf("%s ", i->str); | |
139 | } | |
140 | printf("\n"); | |
141 | } | |
142 | ||
143 | if(o->nooutput) { | |
144 | *status = U_ZERO_ERROR; | |
145 | return; | |
146 | } | |
147 | ||
148 | /* these are also the files to delete */ | |
149 | T_FileStream_writeLine(makefile, "COPIEDDEST= "); | |
150 | pkg_writeCharListWrap(makefile, copyFilesLeft, " ", " \\\n", 0); | |
151 | T_FileStream_writeLine(makefile, "\n\n"); | |
152 | ||
153 | ||
154 | T_FileStream_writeLine(makefile, "INSTALLEDDEST= "); | |
155 | pkg_writeCharListWrap(makefile, copyFilesInstall, " ", " \\\n", 0); | |
156 | T_FileStream_writeLine(makefile, "\n\n"); | |
157 | ||
158 | if(copyFilesRight != NULL) | |
159 | { | |
160 | T_FileStream_writeLine(makefile, "$(NAME): $(COPIEDDEST)\n\n"); | |
161 | ||
162 | T_FileStream_writeLine(makefile, "clean:\n\t-$(RMV) $(COPIEDDEST) $(MAKEFILE)"); | |
163 | T_FileStream_writeLine(makefile, "\n\n"); | |
164 | ||
165 | } | |
166 | else | |
167 | { | |
168 | T_FileStream_writeLine(makefile, "clean:\n\n"); | |
169 | } | |
170 | T_FileStream_writeLine(makefile, "install: $(INSTALLEDDEST)\n\n"); | |
171 | } | |
172 |