• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2 *
3 *   Copyright (C) 2000-2006, 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 #ifdef U_MAKE_IS_NMAKE
55 #define DEPENDENT_FILE_RULE "$?"
56 #else
57 #define DEPENDENT_FILE_RULE "$<"
58 #endif
59 
pkg_mode_files(UPKGOptions * o,FileStream * makefile,UErrorCode * status)60 void pkg_mode_files(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
61 {
62     char tmp[1024], tmp2[1024], srcPath[1024];
63     char stanza[3072];
64 
65     CharList *tail = NULL, *infiles = NULL;
66 
67     CharList *copyFilesLeft = NULL;  /* left hand side of the copy rule*/
68     CharList *copyFilesRight = NULL; /* rhs "" "" */
69     CharList *copyFilesInstall = NULL;
70 
71     CharList *copyFilesLeftTail = NULL;
72     CharList *copyFilesRightTail = NULL;
73     CharList *copyFilesInstallTail = NULL;
74 
75     CharList *copyDirs = NULL; /* list of dirs to create for copying */
76     CharList *installDirs = NULL; /* list of dirs to create for installation */
77 
78     /*  CharList *copyCommands = NULL;*/
79 
80     const char *baseName;
81 
82 #ifndef U_MAKE_IS_NMAKE
83     T_FileStream_writeLine(makefile, "\n.PHONY: $(NAME) all install clean\n");
84 #endif
85     T_FileStream_writeLine(makefile, "\nall: $(NAME)\n\n");
86 
87     infiles = o->files; /* raw files - no paths other than tree paths */
88 
89     /* Dont' copy files already in tmp */
90     for(;infiles;infiles = infiles->next)
91     {
92         uprv_strcpy(tmp, o->targetDir);
93         uprv_strcat(tmp, U_FILE_SEP_STRING);
94         baseName = infiles->str;
95         uprv_strcat(tmp, o->shortName);
96         uprv_strcat(tmp, U_FILE_SEP_STRING);
97         uprv_strcpy(srcPath, "$(SRCDIR)/");
98         uprv_strcat(srcPath, infiles->str);
99         uprv_strcat(tmp, baseName);
100 
101         copyDirs = pkg_appendUniqueDirToList(copyDirs, NULL, tmp);
102 
103         o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp));
104 
105         if(strcmp(tmp, infiles->str) == 0)
106         {
107             /* fprintf(stderr, "### NOT copying: %s\n", tmp); */
108             /*  no copy needed.. */
109         } else {
110             sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) "DEPENDENT_FILE_RULE" $@\n", tmp, srcPath);
111             convertToNativePathSeparators(stanza);
112             T_FileStream_writeLine(makefile, stanza);
113         }
114 
115         uprv_strcpy(tmp2, "$(INSTALLTO)" U_FILE_SEP_STRING);
116         uprv_strcat(tmp2, o->shortName);
117         uprv_strcat(tmp2, U_FILE_SEP_STRING);
118         uprv_strcat(tmp2, baseName);
119 
120         installDirs = pkg_appendUniqueDirToList(installDirs, NULL, tmp2);
121 
122         if(strcmp(tmp2, infiles->str) == 0) {
123             /* fprintf(stderr, "### NOT copying: %s\n", tmp2);   */
124             /*  no copy needed.. */
125         } else {
126             sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) "DEPENDENT_FILE_RULE" $@\n", tmp2, tmp);
127             convertToNativePathSeparators(stanza);
128             T_FileStream_writeLine(makefile, stanza);
129 
130             /* left hand side: target path, target name */
131             copyFilesLeft = pkg_appendToList(copyFilesLeft, &copyFilesLeftTail, uprv_strdup(tmp));
132 
133             /* fprintf(stderr, "##### COPY %s from %s\n", tmp, infiles->str); */
134             /* rhs:  source path */
135             copyFilesRight = pkg_appendToList(copyFilesRight, &copyFilesRightTail, uprv_strdup(infiles->str));
136 
137             /* install:  installed path */
138             copyFilesInstall = pkg_appendToList(copyFilesInstall, &copyFilesInstallTail, uprv_strdup(tmp2));
139         }
140     }
141 
142     if(o->nooutput || o->verbose) {
143         CharList *i;
144         fprintf(stdout, "# Output files: ");
145         for(i = o->outFiles; i; i=i->next) {
146             printf("%s ", i->str);
147         }
148         printf("\n");
149     }
150 
151     if(o->nooutput) {
152         *status = U_ZERO_ERROR;
153         return;
154     }
155 
156     /* these are also the files to delete */
157     T_FileStream_writeLine(makefile, "COPIEDDEST= ");
158     pkg_writeCharListWrap(makefile, copyFilesLeft, " ", " \\\n", 0);
159     T_FileStream_writeLine(makefile, "\n\n");
160 
161 
162     T_FileStream_writeLine(makefile, "INSTALLEDDEST= ");
163     pkg_writeCharListWrap(makefile, copyFilesInstall, " ", " \\\n", 0);
164     T_FileStream_writeLine(makefile, "\n\n");
165 
166     T_FileStream_writeLine(makefile, "COPYDIRS= ");
167     pkg_writeCharListWrap(makefile, copyDirs, " ", " \\\n", 0);
168     T_FileStream_writeLine(makefile, "\n\n");
169 
170 
171     T_FileStream_writeLine(makefile, "INSTALLDIRS= ");
172     pkg_writeCharListWrap(makefile, installDirs, " ", " \\\n", 0);
173     T_FileStream_writeLine(makefile, "\n\n");
174 
175     if(copyFilesRight != NULL)
176     {
177         T_FileStream_writeLine(makefile, "$(NAME): copy-dirs $(COPIEDDEST)\n\n");
178 
179         T_FileStream_writeLine(makefile, "clean:\n\t-$(RMV) $(COPIEDDEST) $(MAKEFILE)");
180         T_FileStream_writeLine(makefile, "\n\n");
181 
182     }
183     else
184     {
185         T_FileStream_writeLine(makefile, "clean:\n\n");
186     }
187     T_FileStream_writeLine(makefile, "install: install-dirs $(INSTALLEDDEST)\n\n");
188     T_FileStream_writeLine(makefile, "install-dirs:\n\t$(MKINSTALLDIRS) $(INSTALLDIRS)\n\n");
189     T_FileStream_writeLine(makefile, "copy-dirs:\n\t$(MKINSTALLDIRS) $(COPYDIRS)\n\n");
190 }
191 
192