1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /******************************************************************************
4 * Copyright (C) 2000-2016, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *******************************************************************************
7 * file name: pkgdata.cpp
8 * encoding: ANSI X3.4 (1968)
9 * tab size: 8 (not used)
12 * created on: 2000may15
13 * created by: Steven \u24C7 Loomis
15 * This program packages the ICU data into different forms
16 * (DLL, common data, etc.)
19 // Defines _XOPEN_SOURCE for access to POSIX functions.
20 // Must be before any other #includes.
21 #include "uposixdefs.h"
23 #include "unicode/utypes.h"
25 #include "unicode/putil.h"
29 #if (U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(__STRICT_ANSI__)
30 /* popen/pclose aren't defined in strict ANSI on Cygwin and MinGW */
31 #undef __STRICT_ANSI__
39 #include "unicode/uclean.h"
45 #include "pkg_gencmn.h"
46 #include "flagparser.h"
47 #include "filetools.h"
63 using icu::LocalPointerBase
;
65 U_DEFINE_LOCAL_OPEN_POINTER(LocalPipeFilePointer
, FILE, pclose
);
69 static void loadLists(UPKGOptions
*o
, UErrorCode
*status
);
71 static int32_t pkg_executeOptions(UPKGOptions
*o
);
73 #ifdef WINDOWS_WITH_MSVC
74 static int32_t pkg_createWindowsDLL(const char mode
, const char *gencFilePath
, UPKGOptions
*o
);
76 static int32_t pkg_createSymLinks(const char *targetDir
, UBool specialHandling
=FALSE
);
77 static int32_t pkg_installLibrary(const char *installDir
, const char *dir
, UBool noVersion
);
78 static int32_t pkg_installFileMode(const char *installDir
, const char *srcDir
, const char *fileListName
);
79 static int32_t pkg_installCommonMode(const char *installDir
, const char *fileName
);
81 #ifdef BUILD_DATA_WITHOUT_ASSEMBLY
82 static int32_t pkg_createWithoutAssemblyCode(UPKGOptions
*o
, const char *targetDir
, const char mode
);
85 #ifdef CAN_WRITE_OBJ_CODE
86 static void pkg_createOptMatchArch(char *optMatchArch
);
87 static void pkg_destroyOptMatchArch(char *optMatchArch
);
90 static int32_t pkg_createWithAssemblyCode(const char *targetDir
, const char mode
, const char *gencFilePath
);
91 static int32_t pkg_generateLibraryFile(const char *targetDir
, const char mode
, const char *objectFile
, char *command
= NULL
, UBool specialHandling
=FALSE
);
92 static int32_t pkg_archiveLibrary(const char *targetDir
, const char *version
, UBool reverseExt
);
93 static void createFileNames(UPKGOptions
*o
, const char mode
, const char *version_major
, const char *version
, const char *libName
, const UBool reverseExt
, UBool noVersion
);
94 static int32_t initializePkgDataFlags(UPKGOptions
*o
);
96 static int32_t pkg_getOptionsFromICUConfig(UBool verbose
, UOption
*option
);
97 static int runCommand(const char* command
, UBool specialHandling
=FALSE
);
99 #define IN_COMMON_MODE(mode) (mode == 'a' || mode == 'c')
100 #define IN_DLL_MODE(mode) (mode == 'd' || mode == 'l')
101 #define IN_STATIC_MODE(mode) (mode == 's')
102 #define IN_FILES_MODE(mode) (mode == 'f')
129 /* This sets the modes that are available */
131 const char *name
, *alt_name
;
134 { "files", 0, "Uses raw data files (no effect). Installation copies all files to the target location." },
135 #if U_PLATFORM_HAS_WIN32_API
136 { "dll", "library", "Generates one common data file and one shared library, <package>.dll"},
137 { "common", "archive", "Generates just the common file, <package>.dat"},
138 { "static", "static", "Generates one statically linked library, " LIB_PREFIX
"<package>" UDATA_LIB_SUFFIX
}
140 #ifdef UDATA_SO_SUFFIX
141 { "dll", "library", "Generates one shared library, <package>" UDATA_SO_SUFFIX
},
143 { "common", "archive", "Generates one common data file, <package>.dat" },
144 { "static", "static", "Generates one statically linked library, " LIB_PREFIX
"<package>" UDATA_LIB_SUFFIX
}
148 static UOption options
[]={
149 /*00*/ UOPTION_DEF( "name", 'p', UOPT_REQUIRES_ARG
),
150 /*01*/ UOPTION_DEF( "bldopt", 'O', UOPT_REQUIRES_ARG
), /* on Win32 it is release or debug */
151 /*02*/ UOPTION_DEF( "mode", 'm', UOPT_REQUIRES_ARG
),
152 /*03*/ UOPTION_HELP_H
, /* -h */
153 /*04*/ UOPTION_HELP_QUESTION_MARK
, /* -? */
154 /*05*/ UOPTION_VERBOSE
, /* -v */
155 /*06*/ UOPTION_COPYRIGHT
, /* -c */
156 /*07*/ UOPTION_DEF( "comment", 'C', UOPT_REQUIRES_ARG
),
157 /*08*/ UOPTION_DESTDIR
, /* -d */
158 /*11*/ UOPTION_DEF( "rebuild", 'F', UOPT_NO_ARG
),
159 /*12*/ UOPTION_DEF( "tempdir", 'T', UOPT_REQUIRES_ARG
),
160 /*13*/ UOPTION_DEF( "install", 'I', UOPT_REQUIRES_ARG
),
161 /*14*/ UOPTION_SOURCEDIR
,
162 /*15*/ UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG
),
163 /*16*/ UOPTION_DEF( "revision", 'r', UOPT_REQUIRES_ARG
),
164 /*17*/ UOPTION_DEF( "force-prefix", 'f', UOPT_NO_ARG
),
165 /*18*/ UOPTION_DEF( "libname", 'L', UOPT_REQUIRES_ARG
),
166 /*19*/ UOPTION_DEF( "quiet", 'q', UOPT_NO_ARG
),
167 /*20*/ UOPTION_DEF( "without-assembly", 'w', UOPT_NO_ARG
),
168 /*21*/ UOPTION_DEF("zos-pds-build", 'z', UOPT_NO_ARG
),
169 /*22*/ UOPTION_DEF("windows-uwp-build", 'u', UOPT_NO_ARG
),
170 /*23*/ UOPTION_DEF("windows-uwp-arm-build", 'a', UOPT_NO_ARG
)
173 /* This enum and the following char array should be kept in sync. */
175 GENCCODE_ASSEMBLY_TYPE
,
194 static const char* FLAG_NAMES
[PKGDATA_FLAGS_SIZE
] = {
195 "GENCCODE_ASSEMBLY_TYPE",
213 static char **pkgDataFlags
= NULL
;
217 LIB_FILE_VERSION_MAJOR
,
219 LIB_FILE_VERSION_TMP
,
220 #if U_PLATFORM == U_PF_CYGWIN
222 LIB_FILE_CYGWIN_VERSION
,
223 #elif U_PLATFORM == U_PF_MINGW
225 #elif U_PLATFORM == U_PF_OS390
226 LIB_FILE_OS390BATCH_MAJOR
,
227 LIB_FILE_OS390BATCH_VERSION
,
231 static char libFileNames
[LIB_FILENAMES_SIZE
][256];
233 static UPKGOptions
*pkg_checkFlag(UPKGOptions
*o
);
235 const char options_help
[][320]={
237 #ifdef U_MAKE_IS_NMAKE
238 "The directory where the ICU is located (e.g. <ICUROOT> which contains the bin directory)",
240 "Specify options for the builder.",
242 "Specify the mode of building (see below; default: common)",
245 "Make the output verbose",
246 "Use the standard ICU copyright",
247 "Use a custom comment (instead of the copyright)",
248 "Specify the destination directory for files",
249 "Force rebuilding of all data",
250 "Specify temporary dir (default: output dir)",
251 "Install the data (specify target)",
252 "Specify a custom source directory",
253 "Specify a custom entrypoint name (default: short name)",
254 "Specify a version when packaging in dll or static mode",
255 "Add package to all file names if not present",
256 "Library name to build (if different than package name)",
257 "Quiet mode. (e.g. Do not output a readme file for static libraries)",
258 "Build the data without assembly code",
259 "Build PDS dataset (zOS build only)",
260 "Build for Universal Windows Platform (Windows build only)",
261 "Set DLL machine type for UWP to target windows ARM (Windows UWP build only)"
264 const char *progname
= "PKGDATA";
267 main(int argc
, char* argv
[]) {
269 /* FileStream *out; */
272 UBool needsHelp
= FALSE
;
273 UErrorCode status
= U_ZERO_ERROR
;
274 /* char tmp[1024]; */
278 U_MAIN_INIT_ARGS(argc
, argv
);
282 options
[MODE
].value
= "common";
284 /* read command line options */
285 argc
=u_parseArgs(argc
, argv
, UPRV_LENGTHOF(options
), options
);
287 /* error handling, printing usage message */
288 /* I've decided to simply print an error and quit. This tool has too
289 many options to just display them all of the time. */
291 if(options
[HELP
].doesOccur
|| options
[HELP_QUESTION_MARK
].doesOccur
) {
295 if(!needsHelp
&& argc
<0) {
297 "%s: error in command line argument \"%s\"\n",
300 fprintf(stderr
, "Run '%s --help' for help.\n", progname
);
305 #if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
306 if(!options
[BLDOPT
].doesOccur
&& uprv_strcmp(options
[MODE
].value
, "common") != 0) {
307 if (pkg_getOptionsFromICUConfig(options
[VERBOSE
].doesOccur
, &options
[BLDOPT
]) != 0) {
308 fprintf(stderr
, " required parameter is missing: -O is required for static and shared builds.\n");
309 fprintf(stderr
, "Run '%s --help' for help.\n", progname
);
314 if(options
[BLDOPT
].doesOccur
) {
315 fprintf(stdout
, "Warning: You are using the -O option which is not needed for MSVC build on Windows.\n");
319 if(!options
[NAME
].doesOccur
) /* -O we already have - don't report it. */
321 fprintf(stderr
, " required parameter -p is missing \n");
322 fprintf(stderr
, "Run '%s --help' for help.\n", progname
);
328 "No input files specified.\n"
329 "Run '%s --help' for help.\n", progname
);
332 } /* end !needsHelp */
334 if(argc
<0 || needsHelp
) {
336 "usage: %s [-options] [-] [packageFile] \n"
337 "\tProduce packaged ICU data from the given list(s) of files.\n"
338 "\t'-' by itself means to read from stdin.\n"
339 "\tpackageFile is a text file containing the list of files to package.\n",
342 fprintf(stderr
, "\n options:\n");
343 for(i
=0;i
<UPRV_LENGTHOF(options
);i
++) {
344 fprintf(stderr
, "%-5s -%c %s%-10s %s\n",
346 options
[i
].shortName
,
347 options
[i
].longName
? "or --" : " ",
348 options
[i
].longName
? options
[i
].longName
: "",
352 fprintf(stderr
, "modes: (-m option)\n");
353 for(i
=0;i
<UPRV_LENGTHOF(modes
);i
++) {
354 fprintf(stderr
, " %-9s ", modes
[i
].name
);
355 if (modes
[i
].alt_name
) {
356 fprintf(stderr
, "/ %-9s", modes
[i
].alt_name
);
358 fprintf(stderr
, " ");
360 fprintf(stderr
, " %s\n", modes
[i
].desc
);
365 /* OK, fill in the options struct */
366 uprv_memset(&o
, 0, sizeof(o
));
368 o
.mode
= options
[MODE
].value
;
369 o
.version
= options
[REVISION
].doesOccur
? options
[REVISION
].value
: 0;
371 o
.shortName
= options
[NAME
].value
;
373 int32_t len
= (int32_t)uprv_strlen(o
.shortName
);
377 cp
= csname
= (char *) uprv_malloc((len
+ 1 + 1) * sizeof(*o
.cShortName
));
378 if (*(sp
= o
.shortName
)) {
379 *cp
++ = isalpha(*sp
) ? * sp
: '_';
380 for (++sp
; *sp
; ++sp
) {
381 *cp
++ = isalnum(*sp
) ? *sp
: '_';
386 o
.cShortName
= csname
;
389 if(options
[LIBNAME
].doesOccur
) { /* get libname from shortname, or explicit -L parameter */
390 o
.libName
= options
[LIBNAME
].value
;
392 o
.libName
= o
.shortName
;
395 if(options
[QUIET
].doesOccur
) {
401 if(options
[PDS_BUILD
].doesOccur
) {
402 #if U_PLATFORM == U_PF_OS390
406 fprintf(stdout
, "Warning: You are using the -z option which only works on z/OS.\n");
413 o
.verbose
= options
[VERBOSE
].doesOccur
;
416 #if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) /* on UNIX, we'll just include the file... */
417 if (options
[BLDOPT
].doesOccur
) {
418 o
.options
= options
[BLDOPT
].value
;
423 if(options
[COPYRIGHT
].doesOccur
) {
424 o
.comment
= U_COPYRIGHT_STRING
;
425 } else if (options
[COMMENT
].doesOccur
) {
426 o
.comment
= options
[COMMENT
].value
;
429 if( options
[DESTDIR
].doesOccur
) {
430 o
.targetDir
= options
[DESTDIR
].value
;
432 o
.targetDir
= "."; /* cwd */
435 o
.rebuild
= options
[REBUILD
].doesOccur
;
437 if( options
[TEMPDIR
].doesOccur
) {
438 o
.tmpDir
= options
[TEMPDIR
].value
;
440 o
.tmpDir
= o
.targetDir
;
443 if( options
[INSTALL
].doesOccur
) {
444 o
.install
= options
[INSTALL
].value
;
449 if( options
[SOURCEDIR
].doesOccur
) {
450 o
.srcDir
= options
[SOURCEDIR
].value
;
455 if( options
[ENTRYPOINT
].doesOccur
) {
456 o
.entryName
= options
[ENTRYPOINT
].value
;
458 o
.entryName
= o
.cShortName
;
461 o
.withoutAssembly
= FALSE
;
462 if (options
[WITHOUT_ASSEMBLY
].doesOccur
) {
463 #ifndef BUILD_DATA_WITHOUT_ASSEMBLY
464 fprintf(stdout
, "Warning: You are using the option to build without assembly code which is not supported on this platform.\n");
465 fprintf(stdout
, "Warning: This option will be ignored.\n");
467 o
.withoutAssembly
= TRUE
;
471 /* OK options are set up. Now the file lists. */
473 for( n
=1; n
<argc
; n
++) {
474 o
.fileListFiles
= pkg_appendToList(o
.fileListFiles
, &tail
, uprv_strdup(argv
[n
]));
478 loadLists(&o
, &status
);
479 if( U_FAILURE(status
) ) {
480 fprintf(stderr
, "error loading input file lists: %s\n", u_errorName(status
));
484 result
= pkg_executeOptions(&o
);
486 if (pkgDataFlags
!= NULL
) {
487 for (n
= 0; n
< PKGDATA_FLAGS_SIZE
; n
++) {
488 if (pkgDataFlags
[n
] != NULL
) {
489 uprv_free(pkgDataFlags
[n
]);
492 uprv_free(pkgDataFlags
);
495 if (o
.cShortName
!= NULL
) {
496 uprv_free((char *)o
.cShortName
);
498 if (o
.fileListFiles
!= NULL
) {
499 pkg_deleteList(o
.fileListFiles
);
501 if (o
.filePaths
!= NULL
) {
502 pkg_deleteList(o
.filePaths
);
504 if (o
.files
!= NULL
) {
505 pkg_deleteList(o
.files
);
510 static int runCommand(const char* command
, UBool specialHandling
) {
512 char cmdBuffer
[SMALL_BUFFER_MAX_SIZE
];
513 int32_t len
= static_cast<int32_t>(strlen(command
));
519 if (!specialHandling
) {
520 #if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400
521 if ((len
+ BUFFER_PADDING_SIZE
) >= SMALL_BUFFER_MAX_SIZE
) {
522 cmd
= (char *)uprv_malloc(len
+ BUFFER_PADDING_SIZE
);
526 #if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW
527 sprintf(cmd
, "bash -c \"%s\"", command
);
529 #elif U_PLATFORM == U_PF_OS400
530 sprintf(cmd
, "QSH CMD('%s')", command
);
533 goto normal_command_mode
;
536 #if !(defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400)
539 cmd
= (char *)command
;
542 printf("pkgdata: %s\n", cmd
);
543 int result
= system(cmd
);
545 fprintf(stderr
, "-- return status = %d\n", result
);
546 result
= 1; // system() result code is platform specific.
549 if (cmd
!= cmdBuffer
&& cmd
!= command
) {
556 #define LN_CMD "ln -s"
557 #define RM_CMD "rm -f"
559 static int32_t pkg_executeOptions(UPKGOptions
*o
) {
562 const char mode
= o
->mode
[0];
563 char targetDir
[SMALL_BUFFER_MAX_SIZE
] = "";
564 char tmpDir
[SMALL_BUFFER_MAX_SIZE
] = "";
565 char datFileName
[SMALL_BUFFER_MAX_SIZE
] = "";
566 char datFileNamePath
[LARGE_BUFFER_MAX_SIZE
] = "";
567 char checkLibFile
[LARGE_BUFFER_MAX_SIZE
] = "";
569 initializePkgDataFlags(o
);
571 if (IN_FILES_MODE(mode
)) {
572 /* Copy the raw data to the installation directory. */
573 if (o
->install
!= NULL
) {
574 uprv_strcpy(targetDir
, o
->install
);
575 if (o
->shortName
!= NULL
) {
576 uprv_strcat(targetDir
, PKGDATA_FILE_SEP_STRING
);
577 uprv_strcat(targetDir
, o
->shortName
);
581 fprintf(stdout
, "# Install: Files mode, copying files to %s..\n", targetDir
);
583 result
= pkg_installFileMode(targetDir
, o
->srcDir
, o
->fileListFiles
->str
);
586 } else /* if (IN_COMMON_MODE(mode) || IN_DLL_MODE(mode) || IN_STATIC_MODE(mode)) */ {
587 UBool noVersion
= FALSE
;
589 uprv_strcpy(targetDir
, o
->targetDir
);
590 uprv_strcat(targetDir
, PKGDATA_FILE_SEP_STRING
);
592 uprv_strcpy(tmpDir
, o
->tmpDir
);
593 uprv_strcat(tmpDir
, PKGDATA_FILE_SEP_STRING
);
595 uprv_strcpy(datFileNamePath
, tmpDir
);
597 uprv_strcpy(datFileName
, o
->shortName
);
598 uprv_strcat(datFileName
, UDATA_CMN_SUFFIX
);
600 uprv_strcat(datFileNamePath
, datFileName
);
603 fprintf(stdout
, "# Writing package file %s ..\n", datFileNamePath
);
605 result
= writePackageDatFile(datFileNamePath
, o
->comment
, o
->srcDir
, o
->fileListFiles
->str
, NULL
, U_CHARSET_FAMILY
? 'e' : U_IS_BIG_ENDIAN
? 'b' : 'l');
607 fprintf(stderr
,"Error writing package dat file.\n");
611 if (IN_COMMON_MODE(mode
)) {
612 char targetFileNamePath
[LARGE_BUFFER_MAX_SIZE
] = "";
614 uprv_strcpy(targetFileNamePath
, targetDir
);
615 uprv_strcat(targetFileNamePath
, datFileName
);
617 /* Move the dat file created to the target directory. */
618 if (uprv_strcmp(datFileNamePath
, targetFileNamePath
) != 0) {
619 if (T_FileStream_file_exists(targetFileNamePath
)) {
620 if ((result
= remove(targetFileNamePath
)) != 0) {
621 fprintf(stderr
, "Unable to remove old dat file: %s\n",
627 result
= rename(datFileNamePath
, targetFileNamePath
);
630 fprintf(stdout
, "# Moving package file to %s ..\n",
636 "Unable to move dat file (%s) to target location (%s).\n",
637 datFileNamePath
, targetFileNamePath
);
642 if (o
->install
!= NULL
) {
643 result
= pkg_installCommonMode(o
->install
, targetFileNamePath
);
647 } else /* if (IN_STATIC_MODE(mode) || IN_DLL_MODE(mode)) */ {
648 char gencFilePath
[SMALL_BUFFER_MAX_SIZE
] = "";
649 char version_major
[10] = "";
650 UBool reverseExt
= FALSE
;
652 #if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
653 /* Get the version major number. */
654 if (o
->version
!= NULL
) {
655 for (uint32_t i
= 0;i
< sizeof(version_major
);i
++) {
656 if (o
->version
[i
] == '.') {
657 version_major
[i
] = 0;
660 version_major
[i
] = o
->version
[i
];
664 if (IN_DLL_MODE(mode
)) {
665 fprintf(stdout
, "Warning: Providing a revision number with the -r option is recommended when packaging data in the current mode.\n");
669 #if U_PLATFORM != U_PF_OS400
670 /* Certain platforms have different library extension ordering. (e.g. libicudata.##.so vs libicudata.so.##)
671 * reverseExt is FALSE if the suffix should be the version number.
673 if (pkgDataFlags
[LIB_EXT_ORDER
][uprv_strlen(pkgDataFlags
[LIB_EXT_ORDER
])-1] == pkgDataFlags
[SO_EXT
][uprv_strlen(pkgDataFlags
[SO_EXT
])-1]) {
677 /* Using the base libName and version number, generate the library file names. */
678 createFileNames(o
, mode
, version_major
, o
->version
== NULL
? "" : o
->version
, o
->libName
, reverseExt
, noVersion
);
680 if ((o
->version
!=NULL
|| IN_STATIC_MODE(mode
)) && o
->rebuild
== FALSE
&& o
->pdsbuild
== FALSE
) {
681 /* Check to see if a previous built data library file exists and check if it is the latest. */
682 sprintf(checkLibFile
, "%s%s", targetDir
, libFileNames
[LIB_FILE_VERSION
]);
683 if (T_FileStream_file_exists(checkLibFile
)) {
684 if (isFileModTimeLater(checkLibFile
, o
->srcDir
, TRUE
) && isFileModTimeLater(checkLibFile
, o
->options
)) {
685 if (o
->install
!= NULL
) {
687 fprintf(stdout
, "# Installing already-built library into %s\n", o
->install
);
689 result
= pkg_installLibrary(o
->install
, targetDir
, noVersion
);
692 printf("# Not rebuilding %s - up to date.\n", checkLibFile
);
696 } else if (o
->verbose
&& (o
->install
!=NULL
)) {
697 fprintf(stdout
, "# Not installing up-to-date library %s into %s\n", checkLibFile
, o
->install
);
699 } else if(o
->verbose
&& (o
->install
!=NULL
)) {
700 fprintf(stdout
, "# Not installing missing %s into %s\n", checkLibFile
, o
->install
);
704 if (pkg_checkFlag(o
) == NULL
) {
705 /* Error occurred. */
710 if (!o
->withoutAssembly
&& pkgDataFlags
[GENCCODE_ASSEMBLY_TYPE
][0] != 0) {
711 const char* genccodeAssembly
= pkgDataFlags
[GENCCODE_ASSEMBLY_TYPE
];
714 fprintf(stdout
, "# Generating assembly code %s of type %s ..\n", gencFilePath
, genccodeAssembly
);
717 /* Offset genccodeAssembly by 3 because "-a " */
718 if (genccodeAssembly
&&
719 (uprv_strlen(genccodeAssembly
)>3) &&
720 checkAssemblyHeaderName(genccodeAssembly
+3)) {
721 writeAssemblyCode(datFileNamePath
, o
->tmpDir
, o
->entryName
, NULL
, gencFilePath
);
723 result
= pkg_createWithAssemblyCode(targetDir
, mode
, gencFilePath
);
725 fprintf(stderr
, "Error generating assembly code for data.\n");
727 } else if (IN_STATIC_MODE(mode
)) {
728 if(o
->install
!= NULL
) {
730 fprintf(stdout
, "# Installing static library into %s\n", o
->install
);
732 result
= pkg_installLibrary(o
->install
, targetDir
, noVersion
);
737 fprintf(stderr
,"Assembly type \"%s\" is unknown.\n", genccodeAssembly
);
742 fprintf(stdout
, "# Writing object code to %s ..\n", gencFilePath
);
744 if (o
->withoutAssembly
) {
745 #ifdef BUILD_DATA_WITHOUT_ASSEMBLY
746 result
= pkg_createWithoutAssemblyCode(o
, targetDir
, mode
);
748 /* This error should not occur. */
749 fprintf(stderr
, "Error- BUILD_DATA_WITHOUT_ASSEMBLY is not defined. Internal error.\n");
752 #ifdef CAN_WRITE_OBJ_CODE
753 /* Try to detect the arch type, use NULL if unsuccessful */
754 char optMatchArch
[10] = { 0 };
755 pkg_createOptMatchArch(optMatchArch
);
756 writeObjectCode(datFileNamePath
, o
->tmpDir
, o
->entryName
, (optMatchArch
[0] == 0 ? NULL
: optMatchArch
), NULL
, gencFilePath
);
757 pkg_destroyOptMatchArch(optMatchArch
);
758 #if U_PLATFORM_IS_LINUX_BASED
759 result
= pkg_generateLibraryFile(targetDir
, mode
, gencFilePath
);
760 #elif defined(WINDOWS_WITH_MSVC)
761 result
= pkg_createWindowsDLL(mode
, gencFilePath
, o
);
763 #elif defined(BUILD_DATA_WITHOUT_ASSEMBLY)
764 result
= pkg_createWithoutAssemblyCode(o
, targetDir
, mode
);
766 fprintf(stderr
, "Error- neither CAN_WRITE_OBJ_CODE nor BUILD_DATA_WITHOUT_ASSEMBLY are defined. Internal error.\n");
772 fprintf(stderr
, "Error generating package data.\n");
776 #if !U_PLATFORM_USES_ONLY_WIN32_API
777 if(!IN_STATIC_MODE(mode
)) {
778 /* Certain platforms uses archive library. (e.g. AIX) */
780 fprintf(stdout
, "# Creating data archive library file ..\n");
782 result
= pkg_archiveLibrary(targetDir
, o
->version
, reverseExt
);
784 fprintf(stderr
, "Error creating data archive library file.\n");
787 #if U_PLATFORM != U_PF_OS400
789 /* Create symbolic links for the final library file. */
790 #if U_PLATFORM == U_PF_OS390
791 result
= pkg_createSymLinks(targetDir
, o
->pdsbuild
);
793 result
= pkg_createSymLinks(targetDir
, noVersion
);
796 fprintf(stderr
, "Error creating symbolic links of the data library file.\n");
801 } /* !IN_STATIC_MODE */
804 #if !U_PLATFORM_USES_ONLY_WIN32_API
805 /* Install the libraries if option was set. */
806 if (o
->install
!= NULL
) {
808 fprintf(stdout
, "# Installing library file to %s ..\n", o
->install
);
810 result
= pkg_installLibrary(o
->install
, targetDir
, noVersion
);
812 fprintf(stderr
, "Error installing the data library.\n");
822 /* Initialize the pkgDataFlags with the option file given. */
823 static int32_t initializePkgDataFlags(UPKGOptions
*o
) {
824 UErrorCode status
= U_ZERO_ERROR
;
826 int32_t currentBufferSize
= SMALL_BUFFER_MAX_SIZE
;
827 int32_t tmpResult
= 0;
829 /* Initialize pkgdataFlags */
830 pkgDataFlags
= (char**)uprv_malloc(sizeof(char*) * PKGDATA_FLAGS_SIZE
);
832 /* If we run out of space, allocate more */
833 #if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
836 if (pkgDataFlags
!= NULL
) {
837 for (int32_t i
= 0; i
< PKGDATA_FLAGS_SIZE
; i
++) {
838 pkgDataFlags
[i
] = (char*)uprv_malloc(sizeof(char) * currentBufferSize
);
839 if (pkgDataFlags
[i
] != NULL
) {
840 pkgDataFlags
[i
][0] = 0;
842 fprintf(stderr
,"Error allocating memory for pkgDataFlags.\n");
843 /* If an error occurs, ensure that the rest of the array is NULL */
844 for (int32_t n
= i
+ 1; n
< PKGDATA_FLAGS_SIZE
; n
++) {
845 pkgDataFlags
[n
] = NULL
;
851 fprintf(stderr
,"Error allocating memory for pkgDataFlags.\n");
855 if (o
->options
== NULL
) {
859 #if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
860 /* Read in options file. */
862 fprintf(stdout
, "# Reading options file %s\n", o
->options
);
864 status
= U_ZERO_ERROR
;
865 tmpResult
= parseFlagsFile(o
->options
, pkgDataFlags
, currentBufferSize
, FLAG_NAMES
, (int32_t)PKGDATA_FLAGS_SIZE
, &status
);
866 if (status
== U_BUFFER_OVERFLOW_ERROR
) {
867 for (int32_t i
= 0; i
< PKGDATA_FLAGS_SIZE
; i
++) {
868 if (pkgDataFlags
[i
]) {
869 uprv_free(pkgDataFlags
[i
]);
870 pkgDataFlags
[i
] = NULL
;
873 currentBufferSize
= tmpResult
;
874 } else if (U_FAILURE(status
)) {
875 fprintf(stderr
,"Unable to open or read \"%s\" option file. status = %s\n", o
->options
, u_errorName(status
));
880 fprintf(stdout
, "# pkgDataFlags=\n");
881 for(int32_t i
=0;i
<PKGDATA_FLAGS_SIZE
;i
++) {
882 fprintf(stdout
, " [%d] %s: %s\n", i
, FLAG_NAMES
[i
], pkgDataFlags
[i
]);
884 fprintf(stdout
, "\n");
886 #if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
887 } while (status
== U_BUFFER_OVERFLOW_ERROR
);
895 * Given the base libName and version numbers, generate the libary file names and store it in libFileNames.
896 * Depending on the configuration, the library name may either end with version number or shared object suffix.
898 static void createFileNames(UPKGOptions
*o
, const char mode
, const char *version_major
, const char *version
, const char *libName
, UBool reverseExt
, UBool noVersion
) {
899 const char* FILE_EXTENSION_SEP
= uprv_strlen(pkgDataFlags
[SO_EXT
]) == 0 ? "" : ".";
900 const char* FILE_SUFFIX
= pkgDataFlags
[LIB_EXT_ORDER
][0] == '.' ? "." : "";
902 #if U_PLATFORM == U_PF_MINGW
903 /* MinGW does not need the library prefix when building in dll mode. */
904 if (IN_DLL_MODE(mode
)) {
905 sprintf(libFileNames
[LIB_FILE
], "%s", libName
);
907 sprintf(libFileNames
[LIB_FILE
], "%s%s%s",
908 (strstr(libName
, "icudt") ? "lib" : ""),
909 pkgDataFlags
[LIBPREFIX
],
913 sprintf(libFileNames
[LIB_FILE
], "%s%s",
914 pkgDataFlags
[LIBPREFIX
],
919 fprintf(stdout
, "# libFileName[LIB_FILE] = %s\n", libFileNames
[LIB_FILE
]);
922 #if U_PLATFORM == U_PF_MINGW
923 // Name the import library lib*.dll.a
924 sprintf(libFileNames
[LIB_FILE_MINGW
], "lib%s.dll.a", libName
);
925 #elif U_PLATFORM == U_PF_CYGWIN
926 sprintf(libFileNames
[LIB_FILE_CYGWIN
], "cyg%s%s%s",
929 pkgDataFlags
[SO_EXT
]);
930 sprintf(libFileNames
[LIB_FILE_CYGWIN_VERSION
], "cyg%s%s%s%s",
934 pkgDataFlags
[SO_EXT
]);
936 uprv_strcat(pkgDataFlags
[SO_EXT
], ".");
937 uprv_strcat(pkgDataFlags
[SO_EXT
], pkgDataFlags
[A_EXT
]);
938 #elif U_PLATFORM == U_PF_OS400 || defined(_AIX)
939 sprintf(libFileNames
[LIB_FILE_VERSION_TMP
], "%s%s%s",
940 libFileNames
[LIB_FILE
],
942 pkgDataFlags
[SOBJ_EXT
]);
943 #elif U_PLATFORM == U_PF_OS390
944 sprintf(libFileNames
[LIB_FILE_VERSION_TMP
], "%s%s%s%s%s",
945 libFileNames
[LIB_FILE
],
946 pkgDataFlags
[LIB_EXT_ORDER
][0] == '.' ? "." : "",
947 reverseExt
? version
: pkgDataFlags
[SOBJ_EXT
],
949 reverseExt
? pkgDataFlags
[SOBJ_EXT
] : version
);
951 sprintf(libFileNames
[LIB_FILE_OS390BATCH_VERSION
], "%s%s.x",
952 libFileNames
[LIB_FILE
],
954 sprintf(libFileNames
[LIB_FILE_OS390BATCH_MAJOR
], "%s%s.x",
955 libFileNames
[LIB_FILE
],
958 if (noVersion
&& !reverseExt
) {
959 sprintf(libFileNames
[LIB_FILE_VERSION_TMP
], "%s%s%s",
960 libFileNames
[LIB_FILE
],
962 pkgDataFlags
[SOBJ_EXT
]);
964 sprintf(libFileNames
[LIB_FILE_VERSION_TMP
], "%s%s%s%s%s",
965 libFileNames
[LIB_FILE
],
967 reverseExt
? version
: pkgDataFlags
[SOBJ_EXT
],
969 reverseExt
? pkgDataFlags
[SOBJ_EXT
] : version
);
972 if (noVersion
&& !reverseExt
) {
973 sprintf(libFileNames
[LIB_FILE_VERSION_MAJOR
], "%s%s%s",
974 libFileNames
[LIB_FILE
],
976 pkgDataFlags
[SO_EXT
]);
978 sprintf(libFileNames
[LIB_FILE_VERSION
], "%s%s%s",
979 libFileNames
[LIB_FILE
],
981 pkgDataFlags
[SO_EXT
]);
983 sprintf(libFileNames
[LIB_FILE_VERSION_MAJOR
], "%s%s%s%s%s",
984 libFileNames
[LIB_FILE
],
986 reverseExt
? version_major
: pkgDataFlags
[SO_EXT
],
988 reverseExt
? pkgDataFlags
[SO_EXT
] : version_major
);
990 sprintf(libFileNames
[LIB_FILE_VERSION
], "%s%s%s%s%s",
991 libFileNames
[LIB_FILE
],
993 reverseExt
? version
: pkgDataFlags
[SO_EXT
],
995 reverseExt
? pkgDataFlags
[SO_EXT
] : version
);
999 fprintf(stdout
, "# libFileName[LIB_FILE_VERSION] = %s\n", libFileNames
[LIB_FILE_VERSION
]);
1002 #if U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
1003 /* Cygwin and MinGW only deals with the version major number. */
1004 uprv_strcpy(libFileNames
[LIB_FILE_VERSION_TMP
], libFileNames
[LIB_FILE_VERSION_MAJOR
]);
1007 if(IN_STATIC_MODE(mode
)) {
1008 sprintf(libFileNames
[LIB_FILE_VERSION
], "%s.%s", libFileNames
[LIB_FILE
], pkgDataFlags
[A_EXT
]);
1009 libFileNames
[LIB_FILE_VERSION_MAJOR
][0]=0;
1011 fprintf(stdout
, "# libFileName[LIB_FILE_VERSION] = %s (static)\n", libFileNames
[LIB_FILE_VERSION
]);
1016 /* Create the symbolic links for the final library file. */
1017 static int32_t pkg_createSymLinks(const char *targetDir
, UBool specialHandling
) {
1019 char cmd
[LARGE_BUFFER_MAX_SIZE
];
1020 char name1
[SMALL_BUFFER_MAX_SIZE
]; /* symlink file name */
1021 char name2
[SMALL_BUFFER_MAX_SIZE
]; /* file name to symlink */
1022 const char* FILE_EXTENSION_SEP
= uprv_strlen(pkgDataFlags
[SO_EXT
]) == 0 ? "" : ".";
1024 #if U_PLATFORM != U_PF_CYGWIN
1025 /* No symbolic link to make. */
1026 if (uprv_strlen(libFileNames
[LIB_FILE_VERSION
]) == 0 || uprv_strlen(libFileNames
[LIB_FILE_VERSION_MAJOR
]) == 0 ||
1027 uprv_strcmp(libFileNames
[LIB_FILE_VERSION
], libFileNames
[LIB_FILE_VERSION_MAJOR
]) == 0) {
1031 sprintf(cmd
, "cd %s && %s %s && %s %s %s",
1034 libFileNames
[LIB_FILE_VERSION_MAJOR
],
1036 libFileNames
[LIB_FILE_VERSION
],
1037 libFileNames
[LIB_FILE_VERSION_MAJOR
]);
1038 result
= runCommand(cmd
);
1040 fprintf(stderr
, "Error creating symbolic links. Failed command: %s\n", cmd
);
1045 if (specialHandling
) {
1046 #if U_PLATFORM == U_PF_CYGWIN
1047 sprintf(name1
, "%s", libFileNames
[LIB_FILE_CYGWIN
]);
1048 sprintf(name2
, "%s", libFileNames
[LIB_FILE_CYGWIN_VERSION
]);
1049 #elif U_PLATFORM == U_PF_OS390
1050 /* Create the symbolic links for the import data */
1051 /* Use the cmd buffer to store path to import data file to check its existence */
1052 sprintf(cmd
, "%s/%s", targetDir
, libFileNames
[LIB_FILE_OS390BATCH_VERSION
]);
1053 if (T_FileStream_file_exists(cmd
)) {
1054 sprintf(cmd
, "cd %s && %s %s && %s %s %s",
1057 libFileNames
[LIB_FILE_OS390BATCH_MAJOR
],
1059 libFileNames
[LIB_FILE_OS390BATCH_VERSION
],
1060 libFileNames
[LIB_FILE_OS390BATCH_MAJOR
]);
1061 result
= runCommand(cmd
);
1063 fprintf(stderr
, "Error creating symbolic links. Failed command: %s\n", cmd
);
1067 sprintf(cmd
, "cd %s && %s %s.x && %s %s %s.x",
1070 libFileNames
[LIB_FILE
],
1072 libFileNames
[LIB_FILE_OS390BATCH_VERSION
],
1073 libFileNames
[LIB_FILE
]);
1074 result
= runCommand(cmd
);
1076 fprintf(stderr
, "Error creating symbolic links. Failed command: %s\n", cmd
);
1081 /* Needs to be set here because special handling skips it */
1082 sprintf(name1
, "%s%s%s", libFileNames
[LIB_FILE
], FILE_EXTENSION_SEP
, pkgDataFlags
[SO_EXT
]);
1083 sprintf(name2
, "%s", libFileNames
[LIB_FILE_VERSION
]);
1085 goto normal_symlink_mode
;
1088 #if U_PLATFORM != U_PF_CYGWIN
1089 normal_symlink_mode
:
1091 sprintf(name1
, "%s%s%s", libFileNames
[LIB_FILE
], FILE_EXTENSION_SEP
, pkgDataFlags
[SO_EXT
]);
1092 sprintf(name2
, "%s", libFileNames
[LIB_FILE_VERSION
]);
1095 sprintf(cmd
, "cd %s && %s %s && %s %s %s",
1103 result
= runCommand(cmd
);
1108 static int32_t pkg_installLibrary(const char *installDir
, const char *targetDir
, UBool noVersion
) {
1110 char cmd
[SMALL_BUFFER_MAX_SIZE
];
1112 sprintf(cmd
, "cd %s && %s %s %s%s%s",
1114 pkgDataFlags
[INSTALL_CMD
],
1115 libFileNames
[LIB_FILE_VERSION
],
1116 installDir
, PKGDATA_FILE_SEP_STRING
, libFileNames
[LIB_FILE_VERSION
]
1119 result
= runCommand(cmd
);
1122 fprintf(stderr
, "Error installing library. Failed command: %s\n", cmd
);
1127 sprintf(cmd
, "cd %s && %s %s.lib %s",
1129 pkgDataFlags
[INSTALL_CMD
],
1130 libFileNames
[LIB_FILE
],
1133 result
= runCommand(cmd
);
1136 fprintf(stderr
, "Error installing library. Failed command: %s\n", cmd
);
1139 #elif U_PLATFORM == U_PF_CYGWIN
1140 sprintf(cmd
, "cd %s && %s %s %s",
1142 pkgDataFlags
[INSTALL_CMD
],
1143 libFileNames
[LIB_FILE_CYGWIN_VERSION
],
1146 result
= runCommand(cmd
);
1149 fprintf(stderr
, "Error installing library. Failed command: %s\n", cmd
);
1153 #elif U_PLATFORM == U_PF_OS390
1154 if (T_FileStream_file_exists(libFileNames
[LIB_FILE_OS390BATCH_VERSION
])) {
1155 sprintf(cmd
, "%s %s %s",
1156 pkgDataFlags
[INSTALL_CMD
],
1157 libFileNames
[LIB_FILE_OS390BATCH_VERSION
],
1160 result
= runCommand(cmd
);
1163 fprintf(stderr
, "Error installing library. Failed command: %s\n", cmd
);
1172 return pkg_createSymLinks(installDir
, TRUE
);
1176 static int32_t pkg_installCommonMode(const char *installDir
, const char *fileName
) {
1178 char cmd
[SMALL_BUFFER_MAX_SIZE
] = "";
1180 if (!T_FileStream_file_exists(installDir
)) {
1181 UErrorCode status
= U_ZERO_ERROR
;
1183 uprv_mkdir(installDir
, &status
);
1184 if (U_FAILURE(status
)) {
1185 fprintf(stderr
, "Error creating installation directory: %s\n", installDir
);
1189 #ifndef U_WINDOWS_WITH_MSVC
1190 sprintf(cmd
, "%s %s %s", pkgDataFlags
[INSTALL_CMD
], fileName
, installDir
);
1192 sprintf(cmd
, "%s %s %s %s", WIN_INSTALL_CMD
, fileName
, installDir
, WIN_INSTALL_CMD_FLAGS
);
1195 result
= runCommand(cmd
);
1197 fprintf(stderr
, "Failed to install data file with command: %s\n", cmd
);
1203 #ifdef U_WINDOWS_MSVC
1204 /* Copy commands for installing the raw data files on Windows. */
1205 #define WIN_INSTALL_CMD "xcopy"
1206 #define WIN_INSTALL_CMD_FLAGS "/E /Y /K"
1208 static int32_t pkg_installFileMode(const char *installDir
, const char *srcDir
, const char *fileListName
) {
1210 char cmd
[SMALL_BUFFER_MAX_SIZE
] = "";
1212 if (!T_FileStream_file_exists(installDir
)) {
1213 UErrorCode status
= U_ZERO_ERROR
;
1215 uprv_mkdir(installDir
, &status
);
1216 if (U_FAILURE(status
)) {
1217 fprintf(stderr
, "Error creating installation directory: %s\n", installDir
);
1221 #ifndef U_WINDOWS_WITH_MSVC
1222 char buffer
[SMALL_BUFFER_MAX_SIZE
] = "";
1223 int32_t bufferLength
= 0;
1225 FileStream
*f
= T_FileStream_open(fileListName
, "r");
1228 if (T_FileStream_readLine(f
, buffer
, SMALL_BUFFER_MAX_SIZE
) != NULL
) {
1229 bufferLength
= static_cast<int32_t>(uprv_strlen(buffer
));
1230 /* Remove new line character. */
1231 if (bufferLength
> 0) {
1232 buffer
[bufferLength
-1] = 0;
1235 sprintf(cmd
, "%s %s%s%s %s%s%s",
1236 pkgDataFlags
[INSTALL_CMD
],
1237 srcDir
, PKGDATA_FILE_SEP_STRING
, buffer
,
1238 installDir
, PKGDATA_FILE_SEP_STRING
, buffer
);
1240 result
= runCommand(cmd
);
1242 fprintf(stderr
, "Failed to install data file with command: %s\n", cmd
);
1246 if (!T_FileStream_eof(f
)) {
1247 fprintf(stderr
, "Failed to read line from file: %s\n", fileListName
);
1253 T_FileStream_close(f
);
1256 fprintf(stderr
, "Unable to open list file: %s\n", fileListName
);
1259 sprintf(cmd
, "%s %s %s %s", WIN_INSTALL_CMD
, srcDir
, installDir
, WIN_INSTALL_CMD_FLAGS
);
1260 result
= runCommand(cmd
);
1262 fprintf(stderr
, "Failed to install data file with command: %s\n", cmd
);
1269 /* Archiving of the library file may be needed depending on the platform and options given.
1270 * If archiving is not needed, copy over the library file name.
1272 static int32_t pkg_archiveLibrary(const char *targetDir
, const char *version
, UBool reverseExt
) {
1274 char cmd
[LARGE_BUFFER_MAX_SIZE
];
1276 /* If the shared object suffix and the final object suffix is different and the final object suffix and the
1277 * archive file suffix is the same, then the final library needs to be archived.
1279 if (uprv_strcmp(pkgDataFlags
[SOBJ_EXT
], pkgDataFlags
[SO_EXT
]) != 0 && uprv_strcmp(pkgDataFlags
[A_EXT
], pkgDataFlags
[SO_EXT
]) == 0) {
1280 sprintf(libFileNames
[LIB_FILE_VERSION
], "%s%s%s.%s",
1281 libFileNames
[LIB_FILE
],
1282 pkgDataFlags
[LIB_EXT_ORDER
][0] == '.' ? "." : "",
1283 reverseExt
? version
: pkgDataFlags
[SO_EXT
],
1284 reverseExt
? pkgDataFlags
[SO_EXT
] : version
);
1286 sprintf(cmd
, "%s %s %s%s %s%s",
1288 pkgDataFlags
[ARFLAGS
],
1290 libFileNames
[LIB_FILE_VERSION
],
1292 libFileNames
[LIB_FILE_VERSION_TMP
]);
1294 result
= runCommand(cmd
);
1296 fprintf(stderr
, "Error creating archive library. Failed command: %s\n", cmd
);
1300 sprintf(cmd
, "%s %s%s",
1301 pkgDataFlags
[RANLIB
],
1303 libFileNames
[LIB_FILE_VERSION
]);
1305 result
= runCommand(cmd
);
1307 fprintf(stderr
, "Error creating archive library. Failed command: %s\n", cmd
);
1311 /* Remove unneeded library file. */
1312 sprintf(cmd
, "%s %s%s",
1315 libFileNames
[LIB_FILE_VERSION_TMP
]);
1317 result
= runCommand(cmd
);
1319 fprintf(stderr
, "Error creating archive library. Failed command: %s\n", cmd
);
1324 uprv_strcpy(libFileNames
[LIB_FILE_VERSION
], libFileNames
[LIB_FILE_VERSION_TMP
]);
1331 * Using the compiler information from the configuration file set by -O option, generate the library file.
1332 * command may be given to allow for a larger buffer for cmd.
1334 static int32_t pkg_generateLibraryFile(const char *targetDir
, const char mode
, const char *objectFile
, char *command
, UBool specialHandling
) {
1337 UBool freeCmd
= FALSE
;
1340 (void)specialHandling
; // Suppress unused variable compiler warnings on platforms where all usage
1341 // of this parameter is #ifdefed out.
1343 /* This is necessary because if packaging is done without assembly code, objectFile might be extremely large
1344 * containing many object files and so the calling function should supply a command buffer that is large
1345 * enough to handle this. Otherwise, use the default size.
1347 if (command
!= NULL
) {
1351 if (IN_STATIC_MODE(mode
)) {
1353 length
= static_cast<int32_t>(uprv_strlen(pkgDataFlags
[AR
]) + uprv_strlen(pkgDataFlags
[ARFLAGS
]) + uprv_strlen(targetDir
) +
1354 uprv_strlen(libFileNames
[LIB_FILE_VERSION
]) + uprv_strlen(objectFile
) + uprv_strlen(pkgDataFlags
[RANLIB
]) + BUFFER_PADDING_SIZE
);
1355 if ((cmd
= (char *)uprv_malloc(sizeof(char) * length
)) == NULL
) {
1356 fprintf(stderr
, "Unable to allocate memory for command.\n");
1361 sprintf(cmd
, "%s %s %s%s %s",
1363 pkgDataFlags
[ARFLAGS
],
1365 libFileNames
[LIB_FILE_VERSION
],
1368 result
= runCommand(cmd
);
1370 sprintf(cmd
, "%s %s%s",
1371 pkgDataFlags
[RANLIB
],
1373 libFileNames
[LIB_FILE_VERSION
]);
1375 result
= runCommand(cmd
);
1377 } else /* if (IN_DLL_MODE(mode)) */ {
1379 length
= static_cast<int32_t>(uprv_strlen(pkgDataFlags
[GENLIB
]) + uprv_strlen(pkgDataFlags
[LDICUDTFLAGS
]) +
1380 ((uprv_strlen(targetDir
) + uprv_strlen(libFileNames
[LIB_FILE_VERSION_TMP
])) * 2) +
1381 uprv_strlen(objectFile
) + uprv_strlen(pkgDataFlags
[LD_SONAME
]) +
1382 uprv_strlen(pkgDataFlags
[LD_SONAME
][0] == 0 ? "" : libFileNames
[LIB_FILE_VERSION_MAJOR
]) +
1383 uprv_strlen(pkgDataFlags
[RPATH_FLAGS
]) + uprv_strlen(pkgDataFlags
[BIR_FLAGS
]) + BUFFER_PADDING_SIZE
);
1384 #if U_PLATFORM == U_PF_CYGWIN
1385 length
+= static_cast<int32_t>(uprv_strlen(targetDir
) + uprv_strlen(libFileNames
[LIB_FILE_CYGWIN_VERSION
]));
1386 #elif U_PLATFORM == U_PF_MINGW
1387 length
+= static_cast<int32_t>(uprv_strlen(targetDir
) + uprv_strlen(libFileNames
[LIB_FILE_MINGW
]));
1389 if ((cmd
= (char *)uprv_malloc(sizeof(char) * length
)) == NULL
) {
1390 fprintf(stderr
, "Unable to allocate memory for command.\n");
1395 #if U_PLATFORM == U_PF_MINGW
1396 sprintf(cmd
, "%s%s%s %s -o %s%s %s %s%s %s %s",
1397 pkgDataFlags
[GENLIB
],
1399 libFileNames
[LIB_FILE_MINGW
],
1400 pkgDataFlags
[LDICUDTFLAGS
],
1402 libFileNames
[LIB_FILE_VERSION_TMP
],
1403 #elif U_PLATFORM == U_PF_CYGWIN
1404 sprintf(cmd
, "%s%s%s %s -o %s%s %s %s%s %s %s",
1405 pkgDataFlags
[GENLIB
],
1407 libFileNames
[LIB_FILE_VERSION_TMP
],
1408 pkgDataFlags
[LDICUDTFLAGS
],
1410 libFileNames
[LIB_FILE_CYGWIN_VERSION
],
1411 #elif U_PLATFORM == U_PF_AIX
1412 sprintf(cmd
, "%s %s%s;%s %s -o %s%s %s %s%s %s %s",
1415 libFileNames
[LIB_FILE_VERSION_TMP
],
1416 pkgDataFlags
[GENLIB
],
1417 pkgDataFlags
[LDICUDTFLAGS
],
1419 libFileNames
[LIB_FILE_VERSION_TMP
],
1421 sprintf(cmd
, "%s %s -o %s%s %s %s%s %s %s",
1422 pkgDataFlags
[GENLIB
],
1423 pkgDataFlags
[LDICUDTFLAGS
],
1425 libFileNames
[LIB_FILE_VERSION_TMP
],
1428 pkgDataFlags
[LD_SONAME
],
1429 pkgDataFlags
[LD_SONAME
][0] == 0 ? "" : libFileNames
[LIB_FILE_VERSION_MAJOR
],
1430 pkgDataFlags
[RPATH_FLAGS
],
1431 pkgDataFlags
[BIR_FLAGS
]);
1433 /* Generate the library file. */
1434 result
= runCommand(cmd
);
1436 #if U_PLATFORM == U_PF_OS390
1438 char PDS_LibName
[512];
1443 if (specialHandling
&& uprv_strcmp(libFileNames
[LIB_FILE
],"libicudata") == 0) {
1444 if (env_tmp
= getenv("ICU_PDS_NAME")) {
1445 sprintf(PDS_Name
, "%s%s",
1448 strcat(PDS_Name
, getenv("ICU_PDS_NAME_SUFFIX"));
1449 } else if (env_tmp
= getenv("PDS_NAME_PREFIX")) {
1450 sprintf(PDS_Name
, "%s%s",
1452 U_ICU_VERSION_SHORT
"DA");
1454 sprintf(PDS_Name
, "%s%s",
1456 U_ICU_VERSION_SHORT
"DA");
1458 } else if (!specialHandling
&& uprv_strcmp(libFileNames
[LIB_FILE
],"libicudata_stub") == 0) {
1459 if (env_tmp
= getenv("ICU_PDS_NAME")) {
1460 sprintf(PDS_Name
, "%s%s",
1463 strcat(PDS_Name
, getenv("ICU_PDS_NAME_SUFFIX"));
1464 } else if (env_tmp
= getenv("PDS_NAME_PREFIX")) {
1465 sprintf(PDS_Name
, "%s%s",
1467 U_ICU_VERSION_SHORT
"D1");
1469 sprintf(PDS_Name
, "%s%s",
1471 U_ICU_VERSION_SHORT
"D1");
1476 sprintf(PDS_LibName
,"%s%s%s%s%s",
1482 sprintf(cmd
, "%s %s -o %s %s %s%s %s %s",
1483 pkgDataFlags
[GENLIB
],
1484 pkgDataFlags
[LDICUDTFLAGS
],
1487 pkgDataFlags
[LD_SONAME
],
1488 pkgDataFlags
[LD_SONAME
][0] == 0 ? "" : libFileNames
[LIB_FILE_VERSION_MAJOR
],
1489 pkgDataFlags
[RPATH_FLAGS
],
1490 pkgDataFlags
[BIR_FLAGS
]);
1492 result
= runCommand(cmd
);
1498 fprintf(stderr
, "Error generating library file. Failed command: %s\n", cmd
);
1508 static int32_t pkg_createWithAssemblyCode(const char *targetDir
, const char mode
, const char *gencFilePath
) {
1509 char tempObjectFile
[SMALL_BUFFER_MAX_SIZE
] = "";
1515 /* Remove the ending .s and replace it with .o for the new object file. */
1516 uprv_strcpy(tempObjectFile
, gencFilePath
);
1517 tempObjectFile
[uprv_strlen(tempObjectFile
)-1] = 'o';
1519 length
= static_cast<int32_t>(uprv_strlen(pkgDataFlags
[COMPILER
]) + uprv_strlen(pkgDataFlags
[LIBFLAGS
])
1520 + uprv_strlen(tempObjectFile
) + uprv_strlen(gencFilePath
) + BUFFER_PADDING_SIZE
);
1522 cmd
= (char *)uprv_malloc(sizeof(char) * length
);
1527 /* Generate the object file. */
1528 sprintf(cmd
, "%s %s -o %s %s",
1529 pkgDataFlags
[COMPILER
],
1530 pkgDataFlags
[LIBFLAGS
],
1534 result
= runCommand(cmd
);
1537 fprintf(stderr
, "Error creating with assembly code. Failed command: %s\n", cmd
);
1541 return pkg_generateLibraryFile(targetDir
, mode
, tempObjectFile
);
1544 #ifdef BUILD_DATA_WITHOUT_ASSEMBLY
1546 * Generation of the data library without assembly code needs to compile each data file
1547 * individually and then link it all together.
1548 * Note: Any update to the directory structure of the data needs to be reflected here.
1557 DATA_PREFIX_TRANSLIT
,
1563 const static char DATA_PREFIX
[DATA_PREFIX_LENGTH
][10] = {
1575 static int32_t pkg_createWithoutAssemblyCode(UPKGOptions
*o
, const char *targetDir
, const char mode
) {
1577 CharList
*list
= o
->filePaths
;
1578 CharList
*listNames
= o
->files
;
1579 int32_t listSize
= pkg_countCharList(list
);
1582 char gencmnFile
[SMALL_BUFFER_MAX_SIZE
] = "";
1583 char tempObjectFile
[SMALL_BUFFER_MAX_SIZE
] = "";
1584 #ifdef USE_SINGLE_CCODE_FILE
1585 char icudtAll
[SMALL_BUFFER_MAX_SIZE
] = "";
1586 FileStream
*icudtAllFile
= NULL
;
1588 sprintf(icudtAll
, "%s%s%sall.c",
1590 PKGDATA_FILE_SEP_STRING
,
1591 libFileNames
[LIB_FILE
]);
1592 /* Remove previous icudtall.c file. */
1593 if (T_FileStream_file_exists(icudtAll
) && (result
= remove(icudtAll
)) != 0) {
1594 fprintf(stderr
, "Unable to remove old icudtall file: %s\n", icudtAll
);
1598 if((icudtAllFile
= T_FileStream_open(icudtAll
, "w"))==NULL
) {
1599 fprintf(stderr
, "Unable to write to icudtall file: %s\n", icudtAll
);
1604 if (list
== NULL
|| listNames
== NULL
) {
1605 /* list and listNames should never be NULL since we are looping through the CharList with
1611 if ((cmd
= (char *)uprv_malloc((listSize
+ 2) * SMALL_BUFFER_MAX_SIZE
)) == NULL
) {
1612 fprintf(stderr
, "Unable to allocate memory for cmd.\n");
1614 } else if ((buffer
= (char *)uprv_malloc((listSize
+ 1) * SMALL_BUFFER_MAX_SIZE
)) == NULL
) {
1615 fprintf(stderr
, "Unable to allocate memory for buffer.\n");
1620 for (int32_t i
= 0; i
< (listSize
+ 1); i
++) {
1625 /* The first iteration calls the gencmn function and initailizes the buffer. */
1626 createCommonDataFile(o
->tmpDir
, o
->shortName
, o
->entryName
, NULL
, o
->srcDir
, o
->comment
, o
->fileListFiles
->str
, 0, TRUE
, o
->verbose
, gencmnFile
);
1628 #ifdef USE_SINGLE_CCODE_FILE
1629 uprv_strcpy(tempObjectFile
, gencmnFile
);
1630 tempObjectFile
[uprv_strlen(tempObjectFile
) - 1] = 'o';
1632 sprintf(cmd
, "%s %s -o %s %s",
1633 pkgDataFlags
[COMPILER
],
1634 pkgDataFlags
[LIBFLAGS
],
1638 result
= runCommand(cmd
);
1643 sprintf(buffer
, "%s",tempObjectFile
);
1646 char newName
[SMALL_BUFFER_MAX_SIZE
];
1647 char dataName
[SMALL_BUFFER_MAX_SIZE
];
1648 char dataDirName
[SMALL_BUFFER_MAX_SIZE
];
1649 const char *pSubstring
;
1651 name
= listNames
->str
;
1653 newName
[0] = dataName
[0] = 0;
1654 for (int32_t n
= 0; n
< DATA_PREFIX_LENGTH
; n
++) {
1656 sprintf(dataDirName
, "%s%s", DATA_PREFIX
[n
], PKGDATA_FILE_SEP_STRING
);
1657 /* If the name contains a prefix (indicating directory), alter the new name accordingly. */
1658 pSubstring
= uprv_strstr(name
, dataDirName
);
1659 if (pSubstring
!= NULL
) {
1660 char newNameTmp
[SMALL_BUFFER_MAX_SIZE
] = "";
1661 const char *p
= name
+ uprv_strlen(dataDirName
);
1662 for (int32_t i
= 0;;i
++) {
1664 newNameTmp
[i
] = '_';
1667 newNameTmp
[i
] = p
[i
];
1672 sprintf(newName
, "%s_%s",
1675 sprintf(dataName
, "%s_%s",
1679 if (newName
[0] != 0) {
1685 printf("# Generating %s \n", gencmnFile
);
1688 writeCCode(file
, o
->tmpDir
, dataName
[0] != 0 ? dataName
: o
->shortName
, newName
[0] != 0 ? newName
: NULL
, gencmnFile
);
1690 #ifdef USE_SINGLE_CCODE_FILE
1691 sprintf(cmd
, "#include \"%s\"\n", gencmnFile
);
1692 T_FileStream_writeLine(icudtAllFile
, cmd
);
1693 /* don't delete the file */
1697 #ifndef USE_SINGLE_CCODE_FILE
1698 uprv_strcpy(tempObjectFile
, gencmnFile
);
1699 tempObjectFile
[uprv_strlen(tempObjectFile
) - 1] = 'o';
1701 sprintf(cmd
, "%s %s -o %s %s",
1702 pkgDataFlags
[COMPILER
],
1703 pkgDataFlags
[LIBFLAGS
],
1706 result
= runCommand(cmd
);
1708 fprintf(stderr
, "Error creating library without assembly code. Failed command: %s\n", cmd
);
1712 uprv_strcat(buffer
, " ");
1713 uprv_strcat(buffer
, tempObjectFile
);
1719 listNames
= listNames
->next
;
1723 #ifdef USE_SINGLE_CCODE_FILE
1724 T_FileStream_close(icudtAllFile
);
1725 uprv_strcpy(tempObjectFile
, icudtAll
);
1726 tempObjectFile
[uprv_strlen(tempObjectFile
) - 1] = 'o';
1728 sprintf(cmd
, "%s %s -I. -o %s %s",
1729 pkgDataFlags
[COMPILER
],
1730 pkgDataFlags
[LIBFLAGS
],
1734 result
= runCommand(cmd
);
1736 uprv_strcat(buffer
, " ");
1737 uprv_strcat(buffer
, tempObjectFile
);
1739 fprintf(stderr
, "Error creating library without assembly code. Failed command: %s\n", cmd
);
1744 /* Generate the library file. */
1745 #if U_PLATFORM == U_PF_OS390
1746 result
= pkg_generateLibraryFile(targetDir
, mode
, buffer
, cmd
, (o
->pdsbuild
&& IN_DLL_MODE(mode
)));
1748 result
= pkg_generateLibraryFile(targetDir
,mode
, buffer
, cmd
);
1759 #ifdef WINDOWS_WITH_MSVC
1760 #define LINK_CMD "link.exe /nologo /release /out:"
1761 #define LINK_FLAGS "/DLL /NOENTRY /MANIFEST:NO /implib:"
1763 #define LINK_EXTRA_UWP_FLAGS "/NXCOMPAT /DYNAMICBASE /APPCONTAINER "
1765 #define LINK_EXTRA_UWP_FLAGS "/NXCOMPAT /SAFESEH /DYNAMICBASE /APPCONTAINER /MACHINE:X86"
1767 #define LINK_EXTRA_UWP_FLAGS_ARM "/NXCOMPAT /DYNAMICBASE /APPCONTAINER /MACHINE:ARM"
1768 #define LINK_EXTRA_NO_UWP_FLAGS "/base:0x4ad00000 "
1769 #define LIB_CMD "LIB.exe /nologo /out:"
1770 #define LIB_FILE "icudt.lib"
1771 #define LIB_EXT UDATA_LIB_SUFFIX
1772 #define DLL_EXT UDATA_SO_SUFFIX
1774 static int32_t pkg_createWindowsDLL(const char mode
, const char *gencFilePath
, UPKGOptions
*o
) {
1776 char cmd
[LARGE_BUFFER_MAX_SIZE
];
1777 if (IN_STATIC_MODE(mode
)) {
1778 char staticLibFilePath
[SMALL_BUFFER_MAX_SIZE
] = "";
1781 sprintf(staticLibFilePath
, "%s%s%s%s%s",
1783 PKGDATA_FILE_SEP_STRING
,
1784 pkgDataFlags
[LIBPREFIX
],
1788 sprintf(staticLibFilePath
, "%s%s%s%s%s",
1790 PKGDATA_FILE_SEP_STRING
,
1791 (strstr(o
->libName
, "icudt") ? "s" : ""),
1796 sprintf(cmd
, "%s\"%s\" \"%s\"",
1800 } else if (IN_DLL_MODE(mode
)) {
1801 char dllFilePath
[SMALL_BUFFER_MAX_SIZE
] = "";
1802 char libFilePath
[SMALL_BUFFER_MAX_SIZE
] = "";
1803 char resFilePath
[SMALL_BUFFER_MAX_SIZE
] = "";
1804 char tmpResFilePath
[SMALL_BUFFER_MAX_SIZE
] = "";
1807 uprv_strcpy(dllFilePath
, o
->targetDir
);
1809 uprv_strcpy(dllFilePath
, o
->srcDir
);
1811 uprv_strcat(dllFilePath
, PKGDATA_FILE_SEP_STRING
);
1812 uprv_strcpy(libFilePath
, dllFilePath
);
1815 uprv_strcat(libFilePath
, o
->libName
);
1816 uprv_strcat(libFilePath
, ".lib");
1818 uprv_strcat(dllFilePath
, o
->libName
);
1819 uprv_strcat(dllFilePath
, o
->version
);
1821 if (strstr(o
->libName
, "icudt")) {
1822 uprv_strcat(libFilePath
, LIB_FILE
);
1824 uprv_strcat(libFilePath
, o
->libName
);
1825 uprv_strcat(libFilePath
, ".lib");
1827 uprv_strcat(dllFilePath
, o
->entryName
);
1829 uprv_strcat(dllFilePath
, DLL_EXT
);
1831 uprv_strcpy(tmpResFilePath
, o
->tmpDir
);
1832 uprv_strcat(tmpResFilePath
, PKGDATA_FILE_SEP_STRING
);
1833 uprv_strcat(tmpResFilePath
, ICUDATA_RES_FILE
);
1835 if (T_FileStream_file_exists(tmpResFilePath
)) {
1836 sprintf(resFilePath
, "\"%s\"", tmpResFilePath
);
1839 /* Check if dll file and lib file exists and that it is not newer than genc file. */
1840 if (!o
->rebuild
&& (T_FileStream_file_exists(dllFilePath
) && isFileModTimeLater(dllFilePath
, gencFilePath
)) &&
1841 (T_FileStream_file_exists(libFilePath
) && isFileModTimeLater(libFilePath
, gencFilePath
))) {
1843 printf("# Not rebuilding %s - up to date.\n", gencFilePath
);
1848 char *extraFlags
= "";
1849 #ifdef WINDOWS_WITH_MSVC
1850 if (options
[UWP_BUILD
].doesOccur
)
1852 if (options
[UWP_ARM_BUILD
].doesOccur
)
1854 extraFlags
= LINK_EXTRA_UWP_FLAGS_ARM
;
1858 extraFlags
= LINK_EXTRA_UWP_FLAGS
;
1863 extraFlags
= LINK_EXTRA_NO_UWP_FLAGS
;
1866 sprintf(cmd
, "%s\"%s\" %s %s\"%s\" \"%s\" %s",
1877 result
= runCommand(cmd
, TRUE
);
1879 fprintf(stderr
, "Error creating Windows DLL library. Failed command: %s\n", cmd
);
1886 static UPKGOptions
*pkg_checkFlag(UPKGOptions
*o
) {
1887 #if U_PLATFORM == U_PF_AIX
1888 /* AIX needs a map file. */
1891 char tmpbuffer
[SMALL_BUFFER_MAX_SIZE
];
1892 const char MAP_FILE_EXT
[] = ".map";
1893 FileStream
*f
= NULL
;
1894 char mapFile
[SMALL_BUFFER_MAX_SIZE
] = "";
1897 const char rm_cmd
[] = "rm -f all ;";
1899 flag
= pkgDataFlags
[GENLIB
];
1901 /* This portion of the code removes 'rm -f all' in the GENLIB.
1902 * Only occurs in AIX.
1904 if (uprv_strstr(flag
, rm_cmd
) != NULL
) {
1905 char *tmpGenlibFlagBuffer
= NULL
;
1908 length
= static_cast<int32_t>(uprv_strlen(flag
) + 1);
1909 tmpGenlibFlagBuffer
= (char *)uprv_malloc(length
);
1910 if (tmpGenlibFlagBuffer
== NULL
) {
1911 /* Memory allocation error */
1912 fprintf(stderr
,"Unable to allocate buffer of size: %d.\n", length
);
1916 uprv_strcpy(tmpGenlibFlagBuffer
, flag
);
1918 offset
= static_cast<int32_t>(uprv_strlen(rm_cmd
));
1920 for (i
= 0; i
< (length
- offset
); i
++) {
1921 flag
[i
] = tmpGenlibFlagBuffer
[offset
+ i
];
1924 /* Zero terminate the string */
1927 uprv_free(tmpGenlibFlagBuffer
);
1930 flag
= pkgDataFlags
[BIR_FLAGS
];
1931 length
= static_cast<int32_t>(uprv_strlen(pkgDataFlags
[BIR_FLAGS
]));
1933 for (int32_t i
= 0; i
< length
; i
++) {
1934 if (flag
[i
] == MAP_FILE_EXT
[count
]) {
1943 if (count
== uprv_strlen(MAP_FILE_EXT
)) {
1950 for (int32_t i
= 0;;i
++) {
1952 for (int32_t n
= 0;;n
++) {
1953 if (o
->shortName
[n
] == 0) {
1956 tmpbuffer
[index
++] = o
->shortName
[n
];
1960 tmpbuffer
[index
++] = flag
[i
];
1967 uprv_memset(flag
, 0, length
);
1968 uprv_strcpy(flag
, tmpbuffer
);
1970 uprv_strcpy(mapFile
, o
->shortName
);
1971 uprv_strcat(mapFile
, MAP_FILE_EXT
);
1973 f
= T_FileStream_open(mapFile
, "w");
1975 fprintf(stderr
,"Unable to create map file: %s.\n", mapFile
);
1978 sprintf(tmpbuffer
, "%s%s ", o
->entryName
, UDATA_CMN_INTERMEDIATE_SUFFIX
);
1980 T_FileStream_writeLine(f
, tmpbuffer
);
1982 T_FileStream_close(f
);
1985 #elif U_PLATFORM == U_PF_CYGWIN || U_PLATFORM == U_PF_MINGW
1986 /* Cygwin needs to change flag options. */
1990 flag
= pkgDataFlags
[GENLIB
];
1991 length
= static_cast<int32_t>(uprv_strlen(pkgDataFlags
[GENLIB
]));
1993 int32_t position
= length
- 1;
1995 for(;position
>= 0;position
--) {
1996 if (flag
[position
] == '=') {
2002 uprv_memset(flag
+ position
, 0, length
- position
);
2003 #elif U_PLATFORM == U_PF_OS400
2004 /* OS/400 needs to fix the ld options (swap single quote with double quote) */
2008 flag
= pkgDataFlags
[GENLIB
];
2009 length
= static_cast<int32_t>(uprv_strlen(pkgDataFlags
[GENLIB
]));
2011 int32_t position
= length
- 1;
2013 for(int32_t i
= 0; i
< length
; i
++) {
2014 if (flag
[i
] == '\'') {
2019 // Don't really need a return value, just need to stop compiler warnings about
2020 // the unused parameter 'o' on platforms where it is not otherwise used.
2024 static void loadLists(UPKGOptions
*o
, UErrorCode
*status
)
2026 CharList
*l
, *tail
= NULL
, *tail2
= NULL
;
2029 char *linePtr
, *lineNext
;
2030 const uint32_t lineMax
= 16300;
2032 int32_t tmpLength
= 0;
2034 int32_t ln
=0; /* line number */
2036 for(l
= o
->fileListFiles
; l
; l
= l
->next
) {
2038 fprintf(stdout
, "# pkgdata: Reading %s..\n", l
->str
);
2041 in
= T_FileStream_open(l
->str
, "r"); /* open files list */
2044 fprintf(stderr
, "Error opening <%s>.\n", l
->str
);
2045 *status
= U_FILE_ACCESS_ERROR
;
2049 while(T_FileStream_readLine(in
, line
, sizeof(line
))!=NULL
) { /* for each line */
2051 if(uprv_strlen(line
)>lineMax
) {
2052 fprintf(stderr
, "%s:%d - line too long (over %d chars)\n", l
->str
, (int)ln
, (int)lineMax
);
2055 /* remove spaces at the beginning */
2057 /* On z/OS, disable call to isspace (#9996). Investigate using uprv_isspace instead (#9999) */
2058 #if U_PLATFORM != U_PF_OS390
2059 while(isspace(*linePtr
)) {
2064 /* remove trailing newline characters */
2066 if(*s
=='\r' || *s
=='\n') {
2072 if((*linePtr
== 0) || (*linePtr
== '#')) {
2073 continue; /* comment or empty line */
2076 /* Now, process the line */
2079 while(linePtr
&& *linePtr
) { /* process space-separated items */
2080 while(*linePtr
== ' ') {
2083 /* Find the next quote */
2084 if(linePtr
[0] == '"')
2086 lineNext
= uprv_strchr(linePtr
+1, '"');
2087 if(lineNext
== NULL
) {
2088 fprintf(stderr
, "%s:%d - missing trailing double quote (\")\n",
2094 if(*lineNext
!= ' ') {
2095 fprintf(stderr
, "%s:%d - malformed quoted line at position %d, expected ' ' got '%c'\n",
2096 l
->str
, (int)ln
, (int)(lineNext
-line
), (*lineNext
)?*lineNext
:'0');
2104 lineNext
= uprv_strchr(linePtr
, ' ');
2106 *lineNext
= 0; /* terminate at space */
2112 s
= (char*)getLongPathname(linePtr
);
2114 /* normal mode.. o->files is just the bare list without package names */
2115 o
->files
= pkg_appendToList(o
->files
, &tail
, uprv_strdup(linePtr
));
2116 if(uprv_pathIsAbsolute(s
) || s
[0] == '.') {
2117 fprintf(stderr
, "pkgdata: Error: absolute path encountered. Old style paths are not supported. Use relative paths such as 'fur.res' or 'translit%cfur.res'.\n\tBad path: '%s'\n", U_FILE_SEP_CHAR
, s
);
2118 exit(U_ILLEGAL_ARGUMENT_ERROR
);
2120 /* The +5 is to add a little extra space for, among other things, PKGDATA_FILE_SEP_STRING */
2121 tmpLength
= static_cast<int32_t>(uprv_strlen(o
->srcDir
) + uprv_strlen(s
) + 5);
2122 if((tmp
= (char *)uprv_malloc(tmpLength
)) == NULL
) {
2123 fprintf(stderr
, "pkgdata: Error: Unable to allocate tmp buffer size: %d\n", tmpLength
);
2124 exit(U_MEMORY_ALLOCATION_ERROR
);
2126 uprv_strcpy(tmp
, o
->srcDir
);
2127 uprv_strcat(tmp
, o
->srcDir
[uprv_strlen(o
->srcDir
)-1] == U_FILE_SEP_CHAR
? "" : PKGDATA_FILE_SEP_STRING
);
2128 uprv_strcat(tmp
, s
);
2129 o
->filePaths
= pkg_appendToList(o
->filePaths
, &tail2
, tmp
);
2131 } /* for each entry on line */
2132 } /* for each line */
2133 T_FileStream_close(in
);
2134 } /* for each file list file */
2137 /* Try calling icu-config directly to get the option file. */
2138 static int32_t pkg_getOptionsFromICUConfig(UBool verbose
, UOption
*option
) {
2140 LocalPipeFilePointer p
;
2142 static char buf
[512] = "";
2143 icu::CharString cmdBuf
;
2144 UErrorCode status
= U_ZERO_ERROR
;
2145 const char cmd
[] = "icu-config --incpkgdatafile";
2146 char dirBuf
[1024] = "";
2147 /* #1 try the same path where pkgdata was called from. */
2148 findDirname(progname
, dirBuf
, UPRV_LENGTHOF(dirBuf
), &status
);
2149 if(U_SUCCESS(status
)) {
2150 cmdBuf
.append(dirBuf
, status
);
2151 if (cmdBuf
[0] != 0) {
2152 cmdBuf
.append( U_FILE_SEP_STRING
, status
);
2154 cmdBuf
.append( cmd
, status
);
2157 fprintf(stdout
, "# Calling icu-config: %s\n", cmdBuf
.data());
2159 p
.adoptInstead(popen(cmdBuf
.data(), "r"));
2162 if(p
.isNull() || (n
= fread(buf
, 1, UPRV_LENGTHOF(buf
)-1, p
.getAlias())) <= 0) {
2164 fprintf(stdout
, "# Calling icu-config: %s\n", cmd
);
2167 p
.adoptInstead(popen(cmd
, "r"));
2168 if(p
.isNull() || (n
= fread(buf
, 1, UPRV_LENGTHOF(buf
)-1, p
.getAlias())) <= 0) {
2169 fprintf(stderr
, "%s: icu-config: No icu-config found. (fix PATH or use -O option)\n", progname
);
2174 for (int32_t length
= strlen(buf
) - 1; length
>= 0; length
--) {
2175 if (buf
[length
] == '\n' || buf
[length
] == ' ') {
2182 if(buf
[strlen(buf
)-1]=='\n')
2184 buf
[strlen(buf
)-1]=0;
2189 fprintf(stderr
, "%s: icu-config: invalid response from icu-config (fix PATH or use -O option)\n", progname
);
2194 fprintf(stdout
, "# icu-config said: %s\n", buf
);
2197 option
->value
= buf
;
2198 option
->doesOccur
= TRUE
;
2206 #ifdef CAN_WRITE_OBJ_CODE
2207 /* Create optMatchArch for genccode architecture detection */
2208 static void pkg_createOptMatchArch(char *optMatchArch
) {
2209 #if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
2210 const char* code
= "void oma(){}";
2211 const char* source
= "oma.c";
2212 const char* obj
= "oma.obj";
2213 FileStream
* stream
= NULL
;
2215 stream
= T_FileStream_open(source
,"w");
2216 if (stream
!= NULL
) {
2217 T_FileStream_writeLine(stream
, code
);
2218 T_FileStream_close(stream
);
2220 char cmd
[LARGE_BUFFER_MAX_SIZE
];
2221 sprintf(cmd
, "%s %s -o %s",
2222 pkgDataFlags
[COMPILER
],
2226 if (runCommand(cmd
) == 0){
2227 sprintf(optMatchArch
, "%s", obj
);
2230 fprintf(stderr
, "Failed to compile %s\n", source
);
2232 if(!T_FileStream_remove(source
)){
2233 fprintf(stderr
, "T_FileStream_remove failed to delete %s\n", source
);
2237 fprintf(stderr
, "T_FileStream_open failed to open %s for writing\n", source
);
2241 static void pkg_destroyOptMatchArch(char *optMatchArch
) {
2242 if(T_FileStream_file_exists(optMatchArch
) && !T_FileStream_remove(optMatchArch
)){
2243 fprintf(stderr
, "T_FileStream_remove failed to delete %s\n", optMatchArch
);