From 86bbf3821e77bc402a57b35c6f9bec4b34c2439a Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 15 Jun 2004 17:53:28 +0000 Subject: [PATCH] ICU-3847 files mode - create dirs as needed X-SVN-Rev: 15877 --- icu4c/source/tools/pkgdata/filemode.c | 105 +++++++++++++++----------- icu4c/source/tools/pkgdata/make.c | 1 + icu4c/source/tools/pkgdata/pkgtypes.c | 29 +++++++ icu4c/source/tools/pkgdata/pkgtypes.h | 12 +++ 4 files changed, 105 insertions(+), 42 deletions(-) diff --git a/icu4c/source/tools/pkgdata/filemode.c b/icu4c/source/tools/pkgdata/filemode.c index f8f242fae0..441062984f 100644 --- a/icu4c/source/tools/pkgdata/filemode.c +++ b/icu4c/source/tools/pkgdata/filemode.c @@ -55,7 +55,7 @@ install: all void pkg_mode_files(UPKGOptions *o, FileStream *makefile, UErrorCode *status) { - char tmp[1024], tmp2[1024]; + char tmp[1024], tmp2[1024], srcPath[1024]; char stanza[3072]; CharList *tail = NULL, *infiles = NULL; @@ -68,69 +68,79 @@ void pkg_mode_files(UPKGOptions *o, FileStream *makefile, UErrorCode *status) CharList *copyFilesRightTail = NULL; CharList *copyFilesInstallTail = NULL; + CharList *copyDirs = NULL; /* list of dirs to create for copying */ + CharList *installDirs = NULL; /* list of dirs to create for installation */ + /* CharList *copyCommands = NULL;*/ const char *baseName; T_FileStream_writeLine(makefile, "\n.PHONY: $(NAME) all install clean\n\nall: $(NAME)\n\n"); - /* Dont' copy files already in tmp */ - for(infiles = o->filePaths;infiles;infiles = infiles->next) - { - baseName = findBasename(infiles->str); + if(o->embed) { + infiles = o->filePaths; + } else { + infiles = o->files; /* raw files - no paths other than tree paths */ + } + /* Dont' copy files already in tmp */ + for(;infiles;infiles = infiles->next) + { uprv_strcpy(tmp, o->targetDir); uprv_strcat(tmp, U_FILE_SEP_STRING); + if(o->embed) { + baseName = findBasename(infiles->str); + uprv_strcpy(srcPath, baseName); + } else { + baseName = infiles->str; + uprv_strcat(tmp, o->shortName); + uprv_strcat(tmp, U_FILE_SEP_STRING); + uprv_strcpy(srcPath, "$(SRCDIR)/"); + uprv_strcat(srcPath, infiles->str); + } uprv_strcat(tmp, baseName); + copyDirs = pkg_appendUniqueDirToList(copyDirs, NULL, tmp); + o->outFiles = pkg_appendToList(o->outFiles, &tail, uprv_strdup(tmp)); if(strcmp(tmp, infiles->str) == 0) { - /* fprintf(stderr, "### NOT copying: %s\n", tmp); */ + /* fprintf(stderr, "### NOT copying: %s\n", tmp); */ /* no copy needed.. */ - continue; - } - - sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp, infiles->str); - T_FileStream_writeLine(makefile, stanza); - - uprv_strcpy(tmp2, o->targetDir); - uprv_strcat(tmp2, U_FILE_SEP_STRING); - uprv_strcat(tmp2, U_FILE_SEP_STRING); - uprv_strcat(tmp2, baseName); - - if(strcmp(tmp2, infiles->str) == 0) - { - /* fprintf(stderr, "### NOT copying: %s\n", tmp2); */ - /* no copy needed.. */ - continue; + } else { + sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp, srcPath); + T_FileStream_writeLine(makefile, stanza); } uprv_strcpy(tmp2, "$(INSTALLTO)" U_FILE_SEP_STRING); + if(!o->embed) { + uprv_strcat(tmp2, o->shortName); + uprv_strcat(tmp2, U_FILE_SEP_STRING); + } uprv_strcat(tmp2, baseName); - if(strcmp(tmp2, infiles->str) == 0) - { - /* fprintf(stderr, "### NOT copying: %s\n", tmp2); */ + installDirs = pkg_appendUniqueDirToList(installDirs, NULL, tmp2); + + if(strcmp(tmp2, infiles->str) == 0) { + /* fprintf(stderr, "### NOT copying: %s\n", tmp2); */ /* no copy needed.. */ - continue; + } else { + sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp2, tmp); + T_FileStream_writeLine(makefile, stanza); + + /* left hand side: target path, target name */ + copyFilesLeft = pkg_appendToList(copyFilesLeft, ©FilesLeftTail, uprv_strdup(tmp)); + + /* fprintf(stderr, "##### COPY %s from %s\n", tmp, infiles->str); */ + /* rhs: source path */ + copyFilesRight = pkg_appendToList(copyFilesRight, ©FilesRightTail, uprv_strdup(infiles->str)); + + /* install: installed path */ + copyFilesInstall = pkg_appendToList(copyFilesInstall, ©FilesInstallTail, uprv_strdup(tmp2)); } - - sprintf(stanza, "%s: %s\n\t$(INSTALL_DATA) $< $@\n", tmp2, tmp); - T_FileStream_writeLine(makefile, stanza); - - /* left hand side: target path, target name */ - copyFilesLeft = pkg_appendToList(copyFilesLeft, ©FilesLeftTail, uprv_strdup(tmp)); - - /* fprintf(stderr, "##### COPY %s from %s\n", tmp, infiles->str); */ - /* rhs: source path */ - copyFilesRight = pkg_appendToList(copyFilesRight, ©FilesRightTail, uprv_strdup(infiles->str)); - - /* install: installed path */ - copyFilesInstall = pkg_appendToList(copyFilesInstall, ©FilesInstallTail, uprv_strdup(tmp2)); } - + if(o->nooutput || o->verbose) { CharList *i; fprintf(stdout, "# Output files: "); @@ -155,9 +165,18 @@ void pkg_mode_files(UPKGOptions *o, FileStream *makefile, UErrorCode *status) pkg_writeCharListWrap(makefile, copyFilesInstall, " ", " \\\n", 0); T_FileStream_writeLine(makefile, "\n\n"); + T_FileStream_writeLine(makefile, "COPYDIRS= "); + pkg_writeCharListWrap(makefile, copyDirs, " ", " \\\n", 0); + T_FileStream_writeLine(makefile, "\n\n"); + + + T_FileStream_writeLine(makefile, "INSTALLDIRS= "); + pkg_writeCharListWrap(makefile, installDirs, " ", " \\\n", 0); + T_FileStream_writeLine(makefile, "\n\n"); + if(copyFilesRight != NULL) { - T_FileStream_writeLine(makefile, "$(NAME): $(COPIEDDEST)\n\n"); + T_FileStream_writeLine(makefile, "$(NAME): copy-dirs $(COPIEDDEST)\n\n"); T_FileStream_writeLine(makefile, "clean:\n\t-$(RMV) $(COPIEDDEST) $(MAKEFILE)"); T_FileStream_writeLine(makefile, "\n\n"); @@ -167,6 +186,8 @@ void pkg_mode_files(UPKGOptions *o, FileStream *makefile, UErrorCode *status) { T_FileStream_writeLine(makefile, "clean:\n\n"); } - T_FileStream_writeLine(makefile, "install: $(INSTALLEDDEST)\n\n"); + T_FileStream_writeLine(makefile, "install: install-dirs $(INSTALLEDDEST)\n\n"); + T_FileStream_writeLine(makefile, "install-dirs:\n\t$(MKINSTALLDIRS) $(INSTALLDIRS)\n\n"); + T_FileStream_writeLine(makefile, "copy-dirs:\n\t$(MKINSTALLDIRS) $(COPYDIRS)\n\n"); } diff --git a/icu4c/source/tools/pkgdata/make.c b/icu4c/source/tools/pkgdata/make.c index b1cc6df88a..32546009ae 100644 --- a/icu4c/source/tools/pkgdata/make.c +++ b/icu4c/source/tools/pkgdata/make.c @@ -57,6 +57,7 @@ pkg_mak_writeHeader(FileStream *f, const UPKGOptions *o) "MAKEFILE=%s\n" "ENTRYPOINT=%s\n" "TARGET_VERSION=%s\n" + "MKINSTALLDIRS=mkdir\n" "\n\n\n", o->shortName, (appendVersion ? appendVersion : ""), diff --git a/icu4c/source/tools/pkgdata/pkgtypes.c b/icu4c/source/tools/pkgdata/pkgtypes.c index e786a0bcec..b1eba58f79 100644 --- a/icu4c/source/tools/pkgdata/pkgtypes.c +++ b/icu4c/source/tools/pkgdata/pkgtypes.c @@ -198,6 +198,35 @@ CharList *pkg_appendToList(CharList *l, CharList** end, const char *str) return l; } +CharList *pkg_appendUniqueDirToList(CharList *l, CharList** end, const char *strAlias) { + char aBuf[1024]; + char *rPtr; + char *aPtr = NULL; + rPtr = uprv_strrchr(strAlias, U_FILE_SEP_CHAR); +#if defined(U_FILE_ALT_SEP_CHAR) && (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) + aPtr = uprv_strrchr(strAlias, U_FILE_ALT_SEP_CHAR); + if(!rPtr || /* regular char wasn't found or.. */ + (aPtr && (aPtr > rPtr))) { /* alt ptr exists and is to the right of r ptr */ + rPtr = aPtr; /* may copy NULL which is OK */ + } +#endif + if(!rPtr) { + return l; /* no dir path */ + } + if((rPtr-strAlias) > (sizeof(aBuf)/sizeof(aBuf[0]))) { + fprintf(stderr, "## ERR: Path too long [%d chars]: %s\n", sizeof(aBuf), strAlias); + return l; + } + strncpy(aBuf, strAlias,(rPtr-strAlias)); + aBuf[rPtr-strAlias]=0; /* no trailing slash */ + + if(!pkg_listContains(l, aBuf)) { + return pkg_appendToList(l, end, strdup(aBuf)); + } else { + return l; /* already found */ + } +} + static CharList * pkg_appendFromStrings(CharList *l, CharList** end, const char *s, int32_t len) { diff --git a/icu4c/source/tools/pkgdata/pkgtypes.h b/icu4c/source/tools/pkgdata/pkgtypes.h index f349e047a7..4bf24e8115 100644 --- a/icu4c/source/tools/pkgdata/pkgtypes.h +++ b/icu4c/source/tools/pkgdata/pkgtypes.h @@ -61,6 +61,18 @@ CharList *pkg_prependToList(CharList *l, const char *str); */ CharList *pkg_appendToList(CharList *l, CharList** end, const char *str); +/* + * strAlias is an alias to a full or relative path to a FILE. This function + * will search strAlias for the directory name (with strrchr). Then, it will + * determine if that directory is already in list l. If not, it will add it + * with strdup(strAlias). + * @param l list to append to , or NULL + * @param end end pointer-to-pointer. Can point to null, or be null. + * @param strAlias alias to full path string + * @return new list + */ +CharList *pkg_appendUniqueDirToList(CharList *l, CharList** end, const char *strAlias); + /* * does list contain string? Returns: t/f */