2017-01-20 00:20:31 +00:00
// © 2016 and later: Unicode, Inc. and others.
2016-06-15 18:58:17 +00:00
// License & terms of use: http://www.unicode.org/copyright.html
2008-11-24 20:04:52 +00:00
/******************************************************************************
2016-05-31 21:45:07 +00:00
* Copyright ( C ) 2000 - 2016 , International Business Machines
* Corporation and others . All Rights Reserved .
2008-11-24 20:04:52 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2011-07-25 21:02:32 +00:00
* file name : pkgdata . cpp
2008-11-24 20:04:52 +00:00
* encoding : ANSI X3 .4 ( 1968 )
* tab size : 8 ( not used )
* indentation : 4
*
* created on : 2000 may15
* created by : Steven \ u24C7 Loomis
*
* This program packages the ICU data into different forms
* ( DLL , common data , etc . )
*/
2011-07-25 21:02:32 +00:00
// Defines _XOPEN_SOURCE for access to POSIX functions.
// Must be before any other #includes.
# include "uposixdefs.h"
2009-01-06 07:41:09 +00:00
2008-11-24 20:04:52 +00:00
# include "unicode/utypes.h"
2009-01-06 07:41:09 +00:00
2011-08-03 20:09:44 +00:00
# include "unicode/putil.h"
# include "putilimp.h"
2011-10-17 05:56:05 +00:00
# if U_HAVE_POPEN
2017-03-04 00:06:17 +00:00
# if (U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(__STRICT_ANSI__)
2011-10-17 05:56:05 +00:00
/* popen/pclose aren't defined in strict ANSI on Cygwin and MinGW */
# undef __STRICT_ANSI__
# endif
# endif
2008-11-24 20:04:52 +00:00
# include "cmemory.h"
# include "cstring.h"
# include "filestrm.h"
# include "toolutil.h"
# include "unicode/uclean.h"
# include "unewdata.h"
# include "uoptions.h"
# include "package.h"
# include "pkg_icu.h"
# include "pkg_genc.h"
# include "pkg_gencmn.h"
2009-01-09 22:30:44 +00:00
# include "flagparser.h"
2009-01-12 23:02:36 +00:00
# include "filetools.h"
2014-09-11 05:25:13 +00:00
# include "charstr.h"
2008-11-24 20:04:52 +00:00
# if U_HAVE_POPEN
# include <unistd.h>
# endif
2011-10-12 20:08:09 +00:00
2008-11-24 20:04:52 +00:00
# include <stdio.h>
# include <stdlib.h>
U_CDECL_BEGIN
# include "pkgtypes.h"
U_CDECL_END
2015-09-09 18:47:00 +00:00
# if U_HAVE_POPEN
using icu : : LocalPointerBase ;
U_DEFINE_LOCAL_OPEN_POINTER ( LocalPipeFilePointer , FILE , pclose ) ;
# endif
2008-11-24 20:04:52 +00:00
static void loadLists ( UPKGOptions * o , UErrorCode * status ) ;
static int32_t pkg_executeOptions ( UPKGOptions * o ) ;
2008-12-05 22:31:38 +00:00
# ifdef WINDOWS_WITH_MSVC
2008-11-24 20:04:52 +00:00
static int32_t pkg_createWindowsDLL ( const char mode , const char * gencFilePath , UPKGOptions * o ) ;
# endif
2010-04-26 05:36:56 +00:00
static int32_t pkg_createSymLinks ( const char * targetDir , UBool specialHandling = FALSE ) ;
2011-11-10 19:22:55 +00:00
static int32_t pkg_installLibrary ( const char * installDir , const char * dir , UBool noVersion ) ;
2009-02-06 17:42:16 +00:00
static int32_t pkg_installFileMode ( const char * installDir , const char * srcDir , const char * fileListName ) ;
2010-06-16 14:41:24 +00:00
static int32_t pkg_installCommonMode ( const char * installDir , const char * fileName ) ;
2008-12-05 22:31:38 +00:00
# ifdef BUILD_DATA_WITHOUT_ASSEMBLY
2008-11-24 20:04:52 +00:00
static int32_t pkg_createWithoutAssemblyCode ( UPKGOptions * o , const char * targetDir , const char mode ) ;
2008-12-05 22:31:38 +00:00
# endif
2015-01-08 20:13:48 +00:00
# ifdef CAN_WRITE_OBJ_CODE
static void pkg_createOptMatchArch ( char * optMatchArch ) ;
static void pkg_destroyOptMatchArch ( char * optMatchArch ) ;
# endif
2008-11-24 20:04:52 +00:00
static int32_t pkg_createWithAssemblyCode ( const char * targetDir , const char mode , const char * gencFilePath ) ;
2014-02-18 06:21:37 +00:00
static int32_t pkg_generateLibraryFile ( const char * targetDir , const char mode , const char * objectFile , char * command = NULL , UBool specialHandling = FALSE ) ;
2008-11-24 20:04:52 +00:00
static int32_t pkg_archiveLibrary ( const char * targetDir , const char * version , UBool reverseExt ) ;
2011-11-10 19:22:55 +00:00
static void createFileNames ( UPKGOptions * o , const char mode , const char * version_major , const char * version , const char * libName , const UBool reverseExt , UBool noVersion ) ;
2010-06-16 14:41:24 +00:00
static int32_t initializePkgDataFlags ( UPKGOptions * o ) ;
2008-11-24 20:04:52 +00:00
2010-02-27 06:38:11 +00:00
static int32_t pkg_getOptionsFromICUConfig ( UBool verbose , UOption * option ) ;
2010-04-26 05:36:56 +00:00
static int runCommand ( const char * command , UBool specialHandling = FALSE ) ;
2008-11-24 20:04:52 +00:00
2012-01-19 17:27:52 +00:00
# define IN_COMMON_MODE(mode) (mode == 'a' || mode == 'c')
# define IN_DLL_MODE(mode) (mode == 'd' || mode == 'l')
# define IN_STATIC_MODE(mode) (mode == 's')
# define IN_FILES_MODE(mode) (mode == 'f')
2008-11-24 20:04:52 +00:00
enum {
NAME ,
BLDOPT ,
MODE ,
HELP ,
HELP_QUESTION_MARK ,
VERBOSE ,
COPYRIGHT ,
COMMENT ,
DESTDIR ,
REBUILD ,
TEMPDIR ,
INSTALL ,
SOURCEDIR ,
ENTRYPOINT ,
REVISION ,
FORCE_PREFIX ,
LIBNAME ,
2011-11-03 23:55:49 +00:00
QUIET ,
2012-03-13 20:18:59 +00:00
WITHOUT_ASSEMBLY ,
2017-03-21 01:03:49 +00:00
PDS_BUILD ,
2019-07-19 20:54:02 +00:00
WIN_UWP_BUILD ,
WIN_DLL_ARCH ,
WIN_DYNAMICBASE
2008-11-24 20:04:52 +00:00
} ;
2009-02-06 17:42:16 +00:00
/* This sets the modes that are available */
static struct {
const char * name , * alt_name ;
const char * desc ;
} modes [ ] = {
{ " files " , 0 , " Uses raw data files (no effect). Installation copies all files to the target location. " } ,
2011-07-23 00:10:30 +00:00
# if U_PLATFORM_HAS_WIN32_API
2009-02-06 17:42:16 +00:00
{ " dll " , " library " , " Generates one common data file and one shared library, <package>.dll " } ,
{ " common " , " archive " , " Generates just the common file, <package>.dat " } ,
{ " static " , " static " , " Generates one statically linked library, " LIB_PREFIX " <package> " UDATA_LIB_SUFFIX }
# else
# ifdef UDATA_SO_SUFFIX
{ " dll " , " library " , " Generates one shared library, <package> " UDATA_SO_SUFFIX } ,
# endif
{ " common " , " archive " , " Generates one common data file, <package>.dat " } ,
{ " static " , " static " , " Generates one statically linked library, " LIB_PREFIX " <package> " UDATA_LIB_SUFFIX }
# endif
} ;
2008-11-24 20:04:52 +00:00
static UOption options [ ] = {
/*00*/ UOPTION_DEF ( " name " , ' p ' , UOPT_REQUIRES_ARG ) ,
/*01*/ UOPTION_DEF ( " bldopt " , ' O ' , UOPT_REQUIRES_ARG ) , /* on Win32 it is release or debug */
/*02*/ UOPTION_DEF ( " mode " , ' m ' , UOPT_REQUIRES_ARG ) ,
/*03*/ UOPTION_HELP_H , /* -h */
/*04*/ UOPTION_HELP_QUESTION_MARK , /* -? */
/*05*/ UOPTION_VERBOSE , /* -v */
/*06*/ UOPTION_COPYRIGHT , /* -c */
/*07*/ UOPTION_DEF ( " comment " , ' C ' , UOPT_REQUIRES_ARG ) ,
/*08*/ UOPTION_DESTDIR , /* -d */
/*11*/ UOPTION_DEF ( " rebuild " , ' F ' , UOPT_NO_ARG ) ,
/*12*/ UOPTION_DEF ( " tempdir " , ' T ' , UOPT_REQUIRES_ARG ) ,
/*13*/ UOPTION_DEF ( " install " , ' I ' , UOPT_REQUIRES_ARG ) ,
/*14*/ UOPTION_SOURCEDIR ,
/*15*/ UOPTION_DEF ( " entrypoint " , ' e ' , UOPT_REQUIRES_ARG ) ,
/*16*/ UOPTION_DEF ( " revision " , ' r ' , UOPT_REQUIRES_ARG ) ,
/*17*/ UOPTION_DEF ( " force-prefix " , ' f ' , UOPT_NO_ARG ) ,
/*18*/ UOPTION_DEF ( " libname " , ' L ' , UOPT_REQUIRES_ARG ) ,
2011-11-03 23:55:49 +00:00
/*19*/ UOPTION_DEF ( " quiet " , ' q ' , UOPT_NO_ARG ) ,
2012-03-13 20:18:59 +00:00
/*20*/ UOPTION_DEF ( " without-assembly " , ' w ' , UOPT_NO_ARG ) ,
2017-03-21 01:03:49 +00:00
/*21*/ UOPTION_DEF ( " zos-pds-build " , ' z ' , UOPT_NO_ARG ) ,
/*22*/ UOPTION_DEF ( " windows-uwp-build " , ' u ' , UOPT_NO_ARG ) ,
2019-07-19 20:54:02 +00:00
/*23*/ UOPTION_DEF ( " windows-DLL-arch " , ' a ' , UOPT_REQUIRES_ARG ) ,
/*24*/ UOPTION_DEF ( " windows-dynamicbase " , ' b ' , UOPT_NO_ARG ) ,
2008-11-24 20:04:52 +00:00
} ;
2011-06-27 21:58:09 +00:00
/* This enum and the following char array should be kept in sync. */
2008-11-24 20:04:52 +00:00
enum {
GENCCODE_ASSEMBLY_TYPE ,
SO_EXT ,
SOBJ_EXT ,
A_EXT ,
LIBPREFIX ,
LIB_EXT_ORDER ,
COMPILER ,
LIBFLAGS ,
GENLIB ,
LDICUDTFLAGS ,
LD_SONAME ,
RPATH_FLAGS ,
BIR_FLAGS ,
AR ,
ARFLAGS ,
RANLIB ,
2008-12-01 20:49:08 +00:00
INSTALL_CMD ,
2008-11-24 20:04:52 +00:00
PKGDATA_FLAGS_SIZE
} ;
2011-06-27 21:58:09 +00:00
static const char * FLAG_NAMES [ PKGDATA_FLAGS_SIZE ] = {
" GENCCODE_ASSEMBLY_TYPE " ,
" SO " ,
" SOBJ " ,
" A " ,
" LIBPREFIX " ,
" LIB_EXT_ORDER " ,
" COMPILE " ,
" LIBFLAGS " ,
" GENLIB " ,
" LDICUDTFLAGS " ,
" LD_SONAME " ,
" RPATH_FLAGS " ,
" BIR_LDFLAGS " ,
" AR " ,
" ARFLAGS " ,
" RANLIB " ,
" INSTALL_CMD "
} ;
2009-01-09 22:30:44 +00:00
static char * * pkgDataFlags = NULL ;
2008-11-24 20:04:52 +00:00
enum {
LIB_FILE ,
LIB_FILE_VERSION_MAJOR ,
LIB_FILE_VERSION ,
LIB_FILE_VERSION_TMP ,
2011-07-23 00:10:30 +00:00
# if U_PLATFORM == U_PF_CYGWIN
2008-11-24 20:04:52 +00:00
LIB_FILE_CYGWIN ,
2012-01-19 17:27:52 +00:00
LIB_FILE_CYGWIN_VERSION ,
2012-03-30 07:11:51 +00:00
# elif U_PLATFORM == U_PF_MINGW
LIB_FILE_MINGW ,
2014-02-18 06:21:37 +00:00
# elif U_PLATFORM == U_PF_OS390
LIB_FILE_OS390BATCH_MAJOR ,
LIB_FILE_OS390BATCH_VERSION ,
2008-11-24 20:04:52 +00:00
# endif
LIB_FILENAMES_SIZE
} ;
static char libFileNames [ LIB_FILENAMES_SIZE ] [ 256 ] ;
2009-07-10 18:58:35 +00:00
static UPKGOptions * pkg_checkFlag ( UPKGOptions * o ) ;
2008-11-24 20:04:52 +00:00
const char options_help [ ] [ 320 ] = {
" Set the data name " ,
# ifdef U_MAKE_IS_NMAKE
" The directory where the ICU is located (e.g. <ICUROOT> which contains the bin directory) " ,
# else
" Specify options for the builder. " ,
# endif
" Specify the mode of building (see below; default: common) " ,
" This usage text " ,
" This usage text " ,
" Make the output verbose " ,
" Use the standard ICU copyright " ,
" Use a custom comment (instead of the copyright) " ,
" Specify the destination directory for files " ,
" Force rebuilding of all data " ,
" Specify temporary dir (default: output dir) " ,
" Install the data (specify target) " ,
" Specify a custom source directory " ,
" Specify a custom entrypoint name (default: short name) " ,
2009-09-23 16:53:07 +00:00
" Specify a version when packaging in dll or static mode " ,
2008-11-24 20:04:52 +00:00
" Add package to all file names if not present " ,
" Library name to build (if different than package name) " ,
2017-03-21 01:03:49 +00:00
" Quiet mode. (e.g. Do not output a readme file for static libraries) " ,
2014-02-18 06:21:37 +00:00
" Build the data without assembly code " ,
2017-03-21 01:03:49 +00:00
" Build PDS dataset (zOS build only) " ,
" Build for Universal Windows Platform (Windows build only) " ,
2019-07-19 20:54:02 +00:00
" Specify the DLL machine architecture for LINK.exe (Windows build only) " ,
" Set DYNAMICBASE on for the DLL (Windows build only) " ,
2008-11-24 20:04:52 +00:00
} ;
const char * progname = " PKGDATA " ;
int
main ( int argc , char * argv [ ] ) {
int result = 0 ;
/* FileStream *out; */
UPKGOptions o ;
CharList * tail ;
UBool needsHelp = FALSE ;
UErrorCode status = U_ZERO_ERROR ;
/* char tmp[1024]; */
2008-12-05 22:31:38 +00:00
uint32_t i ;
int32_t n ;
2008-11-24 20:04:52 +00:00
U_MAIN_INIT_ARGS ( argc , argv ) ;
progname = argv [ 0 ] ;
options [ MODE ] . value = " common " ;
/* read command line options */
2016-02-23 10:40:09 +00:00
argc = u_parseArgs ( argc , argv , UPRV_LENGTHOF ( options ) , options ) ;
2008-11-24 20:04:52 +00:00
/* error handling, printing usage message */
/* I've decided to simply print an error and quit. This tool has too
many options to just display them all of the time . */
if ( options [ HELP ] . doesOccur | | options [ HELP_QUESTION_MARK ] . doesOccur ) {
needsHelp = TRUE ;
}
else {
if ( ! needsHelp & & argc < 0 ) {
fprintf ( stderr ,
" %s: error in command line argument \" %s \" \n " ,
progname ,
argv [ - argc ] ) ;
fprintf ( stderr , " Run '%s --help' for help. \n " , progname ) ;
return 1 ;
}
2010-04-26 05:36:56 +00:00
# if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
2009-09-23 16:53:07 +00:00
if ( ! options [ BLDOPT ] . doesOccur & & uprv_strcmp ( options [ MODE ] . value , " common " ) ! = 0 ) {
2010-02-27 06:38:11 +00:00
if ( pkg_getOptionsFromICUConfig ( options [ VERBOSE ] . doesOccur , & options [ BLDOPT ] ) ! = 0 ) {
2009-09-23 16:53:07 +00:00
fprintf ( stderr , " required parameter is missing: -O is required for static and shared builds. \n " ) ;
2008-12-01 21:57:14 +00:00
fprintf ( stderr , " Run '%s --help' for help. \n " , progname ) ;
return 1 ;
}
2008-11-24 20:04:52 +00:00
}
# else
if ( options [ BLDOPT ] . doesOccur ) {
fprintf ( stdout , " Warning: You are using the -O option which is not needed for MSVC build on Windows. \n " ) ;
}
# endif
if ( ! options [ NAME ] . doesOccur ) /* -O we already have - don't report it. */
{
fprintf ( stderr , " required parameter -p is missing \n " ) ;
fprintf ( stderr , " Run '%s --help' for help. \n " , progname ) ;
return 1 ;
}
if ( argc = = 1 ) {
fprintf ( stderr ,
" No input files specified. \n "
" Run '%s --help' for help. \n " , progname ) ;
return 1 ;
}
} /* end !needsHelp */
if ( argc < 0 | | needsHelp ) {
fprintf ( stderr ,
" usage: %s [-options] [-] [packageFile] \n "
" \t Produce packaged ICU data from the given list(s) of files. \n "
" \t '-' by itself means to read from stdin. \n "
" \t packageFile is a text file containing the list of files to package. \n " ,
progname ) ;
fprintf ( stderr , " \n options: \n " ) ;
2016-02-23 10:40:09 +00:00
for ( i = 0 ; i < UPRV_LENGTHOF ( options ) ; i + + ) {
2008-11-24 20:04:52 +00:00
fprintf ( stderr , " %-5s -%c %s%-10s %s \n " ,
( i < 1 ? " [REQ] " : " " ) ,
options [ i ] . shortName ,
options [ i ] . longName ? " or -- " : " " ,
options [ i ] . longName ? options [ i ] . longName : " " ,
options_help [ i ] ) ;
}
fprintf ( stderr , " modes: (-m option) \n " ) ;
2016-02-23 10:40:09 +00:00
for ( i = 0 ; i < UPRV_LENGTHOF ( modes ) ; i + + ) {
2008-11-24 20:04:52 +00:00
fprintf ( stderr , " %-9s " , modes [ i ] . name ) ;
if ( modes [ i ] . alt_name ) {
fprintf ( stderr , " / %-9s " , modes [ i ] . alt_name ) ;
} else {
fprintf ( stderr , " " ) ;
}
fprintf ( stderr , " %s \n " , modes [ i ] . desc ) ;
}
return 1 ;
}
/* OK, fill in the options struct */
uprv_memset ( & o , 0 , sizeof ( o ) ) ;
o . mode = options [ MODE ] . value ;
o . version = options [ REVISION ] . doesOccur ? options [ REVISION ] . value : 0 ;
o . shortName = options [ NAME ] . value ;
{
int32_t len = ( int32_t ) uprv_strlen ( o . shortName ) ;
char * csname , * cp ;
const char * sp ;
cp = csname = ( char * ) uprv_malloc ( ( len + 1 + 1 ) * sizeof ( * o . cShortName ) ) ;
if ( * ( sp = o . shortName ) ) {
* cp + + = isalpha ( * sp ) ? * sp : ' _ ' ;
for ( + + sp ; * sp ; + + sp ) {
* cp + + = isalnum ( * sp ) ? * sp : ' _ ' ;
}
}
* cp = 0 ;
o . cShortName = csname ;
}
if ( options [ LIBNAME ] . doesOccur ) { /* get libname from shortname, or explicit -L parameter */
o . libName = options [ LIBNAME ] . value ;
} else {
o . libName = o . shortName ;
}
if ( options [ QUIET ] . doesOccur ) {
o . quiet = TRUE ;
} else {
o . quiet = FALSE ;
}
2012-03-13 20:18:59 +00:00
if ( options [ PDS_BUILD ] . doesOccur ) {
2014-02-27 19:23:50 +00:00
# if U_PLATFORM == U_PF_OS390
2012-03-13 20:18:59 +00:00
o . pdsbuild = TRUE ;
2014-02-27 19:23:50 +00:00
# else
o . pdsbuild = FALSE ;
fprintf ( stdout , " Warning: You are using the -z option which only works on z/OS. \n " ) ;
# endif
2012-03-13 20:18:59 +00:00
} else {
o . pdsbuild = FALSE ;
}
2008-11-24 20:04:52 +00:00
o . verbose = options [ VERBOSE ] . doesOccur ;
2010-02-27 06:38:11 +00:00
2010-04-26 05:36:56 +00:00
# if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) /* on UNIX, we'll just include the file... */
2009-09-23 16:53:07 +00:00
if ( options [ BLDOPT ] . doesOccur ) {
o . options = options [ BLDOPT ] . value ;
} else {
o . options = NULL ;
}
2008-11-24 20:04:52 +00:00
# endif
if ( options [ COPYRIGHT ] . doesOccur ) {
o . comment = U_COPYRIGHT_STRING ;
} else if ( options [ COMMENT ] . doesOccur ) {
o . comment = options [ COMMENT ] . value ;
}
if ( options [ DESTDIR ] . doesOccur ) {
o . targetDir = options [ DESTDIR ] . value ;
} else {
o . targetDir = " . " ; /* cwd */
}
o . rebuild = options [ REBUILD ] . doesOccur ;
if ( options [ TEMPDIR ] . doesOccur ) {
o . tmpDir = options [ TEMPDIR ] . value ;
} else {
o . tmpDir = o . targetDir ;
}
if ( options [ INSTALL ] . doesOccur ) {
o . install = options [ INSTALL ] . value ;
2008-12-01 20:49:08 +00:00
} else {
o . install = NULL ;
2008-11-24 20:04:52 +00:00
}
if ( options [ SOURCEDIR ] . doesOccur ) {
o . srcDir = options [ SOURCEDIR ] . value ;
} else {
o . srcDir = " . " ;
}
if ( options [ ENTRYPOINT ] . doesOccur ) {
o . entryName = options [ ENTRYPOINT ] . value ;
} else {
o . entryName = o . cShortName ;
}
2011-11-03 23:55:49 +00:00
o . withoutAssembly = FALSE ;
if ( options [ WITHOUT_ASSEMBLY ] . doesOccur ) {
# ifndef BUILD_DATA_WITHOUT_ASSEMBLY
fprintf ( stdout , " Warning: You are using the option to build without assembly code which is not supported on this platform. \n " ) ;
fprintf ( stdout , " Warning: This option will be ignored. \n " ) ;
# else
o . withoutAssembly = TRUE ;
# endif
}
2008-11-24 20:04:52 +00:00
/* OK options are set up. Now the file lists. */
tail = NULL ;
2008-12-05 22:31:38 +00:00
for ( n = 1 ; n < argc ; n + + ) {
o . fileListFiles = pkg_appendToList ( o . fileListFiles , & tail , uprv_strdup ( argv [ n ] ) ) ;
2008-11-24 20:04:52 +00:00
}
/* load the files */
loadLists ( & o , & status ) ;
if ( U_FAILURE ( status ) ) {
fprintf ( stderr , " error loading input file lists: %s \n " , u_errorName ( status ) ) ;
return 2 ;
}
result = pkg_executeOptions ( & o ) ;
2009-01-09 22:30:44 +00:00
if ( pkgDataFlags ! = NULL ) {
2009-02-06 17:42:16 +00:00
for ( n = 0 ; n < PKGDATA_FLAGS_SIZE ; n + + ) {
if ( pkgDataFlags [ n ] ! = NULL ) {
uprv_free ( pkgDataFlags [ n ] ) ;
2009-01-09 22:30:44 +00:00
}
}
uprv_free ( pkgDataFlags ) ;
}
2008-11-24 20:04:52 +00:00
if ( o . cShortName ! = NULL ) {
uprv_free ( ( char * ) o . cShortName ) ;
}
if ( o . fileListFiles ! = NULL ) {
pkg_deleteList ( o . fileListFiles ) ;
}
if ( o . filePaths ! = NULL ) {
pkg_deleteList ( o . filePaths ) ;
}
if ( o . files ! = NULL ) {
pkg_deleteList ( o . files ) ;
}
return result ;
}
2010-04-26 05:36:56 +00:00
static int runCommand ( const char * command , UBool specialHandling ) {
2010-04-29 21:42:50 +00:00
char * cmd = NULL ;
char cmdBuffer [ SMALL_BUFFER_MAX_SIZE ] ;
2018-09-19 17:05:27 +00:00
int32_t len = static_cast < int32_t > ( strlen ( command ) ) ;
2010-04-29 21:42:50 +00:00
if ( len = = 0 ) {
return 0 ;
}
2010-04-26 05:36:56 +00:00
if ( ! specialHandling ) {
2011-07-29 22:47:25 +00:00
# if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400
2011-01-19 05:14:22 +00:00
if ( ( len + BUFFER_PADDING_SIZE ) > = SMALL_BUFFER_MAX_SIZE ) {
cmd = ( char * ) uprv_malloc ( len + BUFFER_PADDING_SIZE ) ;
2010-04-29 21:42:50 +00:00
} else {
cmd = cmdBuffer ;
}
2011-07-29 22:47:25 +00:00
# if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW
2010-04-26 05:36:56 +00:00
sprintf ( cmd , " bash -c \" %s \" " , command ) ;
2011-07-23 00:10:30 +00:00
# elif U_PLATFORM == U_PF_OS400
2010-04-26 05:36:56 +00:00
sprintf ( cmd , " QSH CMD('%s') " , command ) ;
2010-04-29 21:42:50 +00:00
# endif
2010-04-26 05:36:56 +00:00
# else
goto normal_command_mode ;
# endif
} else {
2011-08-12 21:16:53 +00:00
# if !(defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400)
2010-04-26 05:36:56 +00:00
normal_command_mode :
2011-08-12 21:16:53 +00:00
# endif
2010-04-29 21:42:50 +00:00
cmd = ( char * ) command ;
2010-04-26 05:36:56 +00:00
}
2010-04-29 21:42:50 +00:00
2010-04-26 05:36:56 +00:00
printf ( " pkgdata: %s \n " , cmd ) ;
int result = system ( cmd ) ;
2010-04-29 21:42:50 +00:00
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " -- return status = %d \n " , result ) ;
2019-04-03 19:35:22 +00:00
result = 1 ; // system() result code is platform specific.
2009-07-09 20:07:19 +00:00
}
2010-04-29 21:42:50 +00:00
if ( cmd ! = cmdBuffer & & cmd ! = command ) {
uprv_free ( cmd ) ;
}
return result ;
}
2009-06-30 16:58:49 +00:00
2008-11-24 20:04:52 +00:00
# define LN_CMD "ln -s"
# define RM_CMD "rm -f"
static int32_t pkg_executeOptions ( UPKGOptions * o ) {
int32_t result = 0 ;
2010-06-16 14:41:24 +00:00
2008-11-24 20:04:52 +00:00
const char mode = o - > mode [ 0 ] ;
char targetDir [ SMALL_BUFFER_MAX_SIZE ] = " " ;
char tmpDir [ SMALL_BUFFER_MAX_SIZE ] = " " ;
char datFileName [ SMALL_BUFFER_MAX_SIZE ] = " " ;
char datFileNamePath [ LARGE_BUFFER_MAX_SIZE ] = " " ;
char checkLibFile [ LARGE_BUFFER_MAX_SIZE ] = " " ;
2010-09-16 15:53:06 +00:00
initializePkgDataFlags ( o ) ;
2012-01-19 17:27:52 +00:00
if ( IN_FILES_MODE ( mode ) ) {
2009-02-06 17:42:16 +00:00
/* Copy the raw data to the installation directory. */
if ( o - > install ! = NULL ) {
uprv_strcpy ( targetDir , o - > install ) ;
if ( o - > shortName ! = NULL ) {
uprv_strcat ( targetDir , PKGDATA_FILE_SEP_STRING ) ;
uprv_strcat ( targetDir , o - > shortName ) ;
}
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Install: Files mode, copying files to %s.. \n " , targetDir ) ;
}
2009-02-06 17:42:16 +00:00
result = pkg_installFileMode ( targetDir , o - > srcDir , o - > fileListFiles - > str ) ;
}
2008-11-24 20:04:52 +00:00
return result ;
2012-01-19 17:27:52 +00:00
} else /* if (IN_COMMON_MODE(mode) || IN_DLL_MODE(mode) || IN_STATIC_MODE(mode)) */ {
2011-11-10 19:22:55 +00:00
UBool noVersion = FALSE ;
2008-11-24 20:04:52 +00:00
uprv_strcpy ( targetDir , o - > targetDir ) ;
2009-02-06 17:42:16 +00:00
uprv_strcat ( targetDir , PKGDATA_FILE_SEP_STRING ) ;
2008-11-24 20:04:52 +00:00
uprv_strcpy ( tmpDir , o - > tmpDir ) ;
2009-02-06 17:42:16 +00:00
uprv_strcat ( tmpDir , PKGDATA_FILE_SEP_STRING ) ;
2008-11-24 20:04:52 +00:00
uprv_strcpy ( datFileNamePath , tmpDir ) ;
uprv_strcpy ( datFileName , o - > shortName ) ;
2009-02-06 17:42:16 +00:00
uprv_strcat ( datFileName , UDATA_CMN_SUFFIX ) ;
2008-11-24 20:04:52 +00:00
uprv_strcat ( datFileNamePath , datFileName ) ;
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Writing package file %s .. \n " , datFileNamePath ) ;
}
2009-10-01 20:01:51 +00:00
result = writePackageDatFile ( datFileNamePath , o - > comment , o - > srcDir , o - > fileListFiles - > str , NULL , U_CHARSET_FAMILY ? ' e ' : U_IS_BIG_ENDIAN ? ' b ' : ' l ' ) ;
2008-11-24 20:04:52 +00:00
if ( result ! = 0 ) {
fprintf ( stderr , " Error writing package dat file. \n " ) ;
return result ;
}
2009-02-06 17:42:16 +00:00
2012-01-19 17:27:52 +00:00
if ( IN_COMMON_MODE ( mode ) ) {
2008-11-24 20:04:52 +00:00
char targetFileNamePath [ LARGE_BUFFER_MAX_SIZE ] = " " ;
uprv_strcpy ( targetFileNamePath , targetDir ) ;
uprv_strcat ( targetFileNamePath , datFileName ) ;
2012-01-19 17:27:52 +00:00
/* Move the dat file created to the target directory. */
if ( uprv_strcmp ( datFileNamePath , targetFileNamePath ) ! = 0 ) {
if ( T_FileStream_file_exists ( targetFileNamePath ) ) {
if ( ( result = remove ( targetFileNamePath ) ) ! = 0 ) {
fprintf ( stderr , " Unable to remove old dat file: %s \n " ,
targetFileNamePath ) ;
return result ;
}
2009-02-06 20:47:56 +00:00
}
2012-01-19 17:27:52 +00:00
result = rename ( datFileNamePath , targetFileNamePath ) ;
2010-02-27 06:38:11 +00:00
2012-01-19 17:27:52 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Moving package file to %s .. \n " ,
targetFileNamePath ) ;
}
if ( result ! = 0 ) {
fprintf (
stderr ,
" Unable to move dat file (%s) to target location (%s). \n " ,
datFileNamePath , targetFileNamePath ) ;
return result ;
}
2009-02-06 19:39:51 +00:00
}
2008-11-24 20:04:52 +00:00
2010-06-16 14:41:24 +00:00
if ( o - > install ! = NULL ) {
result = pkg_installCommonMode ( o - > install , targetFileNamePath ) ;
}
2009-02-06 19:39:51 +00:00
return result ;
2012-01-19 17:27:52 +00:00
} else /* if (IN_STATIC_MODE(mode) || IN_DLL_MODE(mode)) */ {
2008-11-24 20:04:52 +00:00
char gencFilePath [ SMALL_BUFFER_MAX_SIZE ] = " " ;
char version_major [ 10 ] = " " ;
UBool reverseExt = FALSE ;
2010-04-26 05:36:56 +00:00
# if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
2008-11-24 20:04:52 +00:00
/* Get the version major number. */
if ( o - > version ! = NULL ) {
2008-12-05 22:31:38 +00:00
for ( uint32_t i = 0 ; i < sizeof ( version_major ) ; i + + ) {
2008-11-24 20:04:52 +00:00
if ( o - > version [ i ] = = ' . ' ) {
version_major [ i ] = 0 ;
break ;
}
version_major [ i ] = o - > version [ i ] ;
}
2011-07-14 18:51:40 +00:00
} else {
2011-11-10 19:22:55 +00:00
noVersion = TRUE ;
2012-01-19 17:27:52 +00:00
if ( IN_DLL_MODE ( mode ) ) {
2011-11-10 19:22:55 +00:00
fprintf ( stdout , " Warning: Providing a revision number with the -r option is recommended when packaging data in the current mode. \n " ) ;
2011-07-14 18:51:40 +00:00
}
2008-11-24 20:04:52 +00:00
}
2011-07-23 00:10:30 +00:00
# if U_PLATFORM != U_PF_OS400
2008-11-24 20:04:52 +00:00
/* Certain platforms have different library extension ordering. (e.g. libicudata.##.so vs libicudata.so.##)
* reverseExt is FALSE if the suffix should be the version number .
*/
if ( pkgDataFlags [ LIB_EXT_ORDER ] [ uprv_strlen ( pkgDataFlags [ LIB_EXT_ORDER ] ) - 1 ] = = pkgDataFlags [ SO_EXT ] [ uprv_strlen ( pkgDataFlags [ SO_EXT ] ) - 1 ] ) {
reverseExt = TRUE ;
}
2009-05-18 05:41:02 +00:00
# endif
2008-11-24 20:04:52 +00:00
/* Using the base libName and version number, generate the library file names. */
2011-11-10 19:22:55 +00:00
createFileNames ( o , mode , version_major , o - > version = = NULL ? " " : o - > version , o - > libName , reverseExt , noVersion ) ;
2008-11-24 20:04:52 +00:00
2014-02-27 19:23:50 +00:00
if ( ( o - > version ! = NULL | | IN_STATIC_MODE ( mode ) ) & & o - > rebuild = = FALSE & & o - > pdsbuild = = FALSE ) {
2009-01-09 22:30:44 +00:00
/* Check to see if a previous built data library file exists and check if it is the latest. */
2009-07-17 23:59:37 +00:00
sprintf ( checkLibFile , " %s%s " , targetDir , libFileNames [ LIB_FILE_VERSION ] ) ;
2008-11-24 20:04:52 +00:00
if ( T_FileStream_file_exists ( checkLibFile ) ) {
2009-01-12 20:52:01 +00:00
if ( isFileModTimeLater ( checkLibFile , o - > srcDir , TRUE ) & & isFileModTimeLater ( checkLibFile , o - > options ) ) {
2009-01-09 22:30:44 +00:00
if ( o - > install ! = NULL ) {
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Installing already-built library into %s \n " , o - > install ) ;
}
2011-11-10 19:22:55 +00:00
result = pkg_installLibrary ( o - > install , targetDir , noVersion ) ;
2010-02-27 06:38:11 +00:00
} else {
if ( o - > verbose ) {
printf ( " # Not rebuilding %s - up to date. \n " , checkLibFile ) ;
}
2009-01-09 22:30:44 +00:00
}
return result ;
2010-02-27 06:38:11 +00:00
} else if ( o - > verbose & & ( o - > install ! = NULL ) ) {
fprintf ( stdout , " # Not installing up-to-date library %s into %s \n " , checkLibFile , o - > install ) ;
2008-12-01 20:49:08 +00:00
}
2010-02-27 06:38:11 +00:00
} else if ( o - > verbose & & ( o - > install ! = NULL ) ) {
fprintf ( stdout , " # Not installing missing %s into %s \n " , checkLibFile , o - > install ) ;
2008-11-24 20:04:52 +00:00
}
}
2011-06-12 02:42:44 +00:00
if ( pkg_checkFlag ( o ) = = NULL ) {
/* Error occurred. */
return result ;
}
2008-11-24 20:04:52 +00:00
# endif
2011-11-03 23:55:49 +00:00
if ( ! o - > withoutAssembly & & pkgDataFlags [ GENCCODE_ASSEMBLY_TYPE ] [ 0 ] ! = 0 ) {
2008-11-24 20:04:52 +00:00
const char * genccodeAssembly = pkgDataFlags [ GENCCODE_ASSEMBLY_TYPE ] ;
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Generating assembly code %s of type %s .. \n " , gencFilePath , genccodeAssembly ) ;
}
2008-11-24 20:04:52 +00:00
/* Offset genccodeAssembly by 3 because "-a " */
2010-02-27 06:38:11 +00:00
if ( genccodeAssembly & &
( uprv_strlen ( genccodeAssembly ) > 3 ) & &
checkAssemblyHeaderName ( genccodeAssembly + 3 ) ) {
2019-07-19 22:44:24 +00:00
writeAssemblyCode (
datFileNamePath ,
o - > tmpDir ,
o - > entryName ,
NULL ,
gencFilePath ,
sizeof ( gencFilePath ) ) ;
2008-11-24 20:04:52 +00:00
result = pkg_createWithAssemblyCode ( targetDir , mode , gencFilePath ) ;
if ( result ! = 0 ) {
fprintf ( stderr , " Error generating assembly code for data. \n " ) ;
return result ;
2012-01-19 17:27:52 +00:00
} else if ( IN_STATIC_MODE ( mode ) ) {
2010-02-27 06:38:11 +00:00
if ( o - > install ! = NULL ) {
if ( o - > verbose ) {
fprintf ( stdout , " # Installing static library into %s \n " , o - > install ) ;
}
2011-11-10 19:22:55 +00:00
result = pkg_installLibrary ( o - > install , targetDir , noVersion ) ;
2010-02-27 06:38:11 +00:00
}
return result ;
2008-11-24 20:04:52 +00:00
}
} else {
fprintf ( stderr , " Assembly type \" %s \" is unknown. \n " , genccodeAssembly ) ;
return - 1 ;
}
} else {
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Writing object code to %s .. \n " , gencFilePath ) ;
}
2011-11-03 23:55:49 +00:00
if ( o - > withoutAssembly ) {
2011-11-04 02:40:39 +00:00
# ifdef BUILD_DATA_WITHOUT_ASSEMBLY
2011-11-03 23:55:49 +00:00
result = pkg_createWithoutAssemblyCode ( o , targetDir , mode ) ;
2011-11-04 02:40:39 +00:00
# else
/* This error should not occur. */
fprintf ( stderr , " Error- BUILD_DATA_WITHOUT_ASSEMBLY is not defined. Internal error. \n " ) ;
# endif
2011-11-03 23:55:49 +00:00
} else {
2009-01-09 22:30:44 +00:00
# ifdef CAN_WRITE_OBJ_CODE
2015-01-08 20:13:48 +00:00
/* Try to detect the arch type, use NULL if unsuccessful */
char optMatchArch [ 10 ] = { 0 } ;
pkg_createOptMatchArch ( optMatchArch ) ;
2019-07-19 22:44:24 +00:00
writeObjectCode (
datFileNamePath ,
o - > tmpDir ,
o - > entryName ,
( optMatchArch [ 0 ] = = 0 ? NULL : optMatchArch ) ,
NULL ,
gencFilePath ,
sizeof ( gencFilePath ) ) ;
2015-01-08 20:13:48 +00:00
pkg_destroyOptMatchArch ( optMatchArch ) ;
2011-07-23 00:10:30 +00:00
# if U_PLATFORM_IS_LINUX_BASED
2011-11-03 23:55:49 +00:00
result = pkg_generateLibraryFile ( targetDir , mode , gencFilePath ) ;
2009-01-09 22:30:44 +00:00
# elif defined(WINDOWS_WITH_MSVC)
2011-11-03 23:55:49 +00:00
result = pkg_createWindowsDLL ( mode , gencFilePath , o ) ;
2008-11-24 20:04:52 +00:00
# endif
2008-12-05 22:31:38 +00:00
# elif defined(BUILD_DATA_WITHOUT_ASSEMBLY)
2011-11-03 23:55:49 +00:00
result = pkg_createWithoutAssemblyCode ( o , targetDir , mode ) ;
2011-09-21 20:00:24 +00:00
# else
2011-11-03 23:55:49 +00:00
fprintf ( stderr , " Error- neither CAN_WRITE_OBJ_CODE nor BUILD_DATA_WITHOUT_ASSEMBLY are defined. Internal error. \n " ) ;
return 1 ;
2008-11-24 20:04:52 +00:00
# endif
2011-11-03 23:55:49 +00:00
}
2008-11-24 20:04:52 +00:00
if ( result ! = 0 ) {
fprintf ( stderr , " Error generating package data. \n " ) ;
return result ;
}
}
2011-07-23 00:10:30 +00:00
# if !U_PLATFORM_USES_ONLY_WIN32_API
2012-01-19 17:27:52 +00:00
if ( ! IN_STATIC_MODE ( mode ) ) {
2009-09-25 01:56:41 +00:00
/* Certain platforms uses archive library. (e.g. AIX) */
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Creating data archive library file .. \n " ) ;
}
2009-09-25 01:56:41 +00:00
result = pkg_archiveLibrary ( targetDir , o - > version , reverseExt ) ;
if ( result ! = 0 ) {
fprintf ( stderr , " Error creating data archive library file. \n " ) ;
return result ;
}
2011-07-23 00:10:30 +00:00
# if U_PLATFORM != U_PF_OS400
2011-11-10 19:22:55 +00:00
if ( ! noVersion ) {
/* Create symbolic links for the final library file. */
2012-03-13 20:18:59 +00:00
# if U_PLATFORM == U_PF_OS390
2014-02-18 06:21:37 +00:00
result = pkg_createSymLinks ( targetDir , o - > pdsbuild ) ;
2012-03-13 20:18:59 +00:00
# else
2011-11-10 19:22:55 +00:00
result = pkg_createSymLinks ( targetDir , noVersion ) ;
2012-03-13 20:18:59 +00:00
# endif
2011-11-10 19:22:55 +00:00
if ( result ! = 0 ) {
fprintf ( stderr , " Error creating symbolic links of the data library file. \n " ) ;
return result ;
}
2009-09-25 01:56:41 +00:00
}
2009-05-18 05:41:02 +00:00
# endif
2012-01-19 17:27:52 +00:00
} /* !IN_STATIC_MODE */
2010-04-26 05:36:56 +00:00
# endif
2011-07-23 00:10:30 +00:00
# if !U_PLATFORM_USES_ONLY_WIN32_API
2008-12-01 20:49:08 +00:00
/* Install the libraries if option was set. */
if ( o - > install ! = NULL ) {
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # Installing library file to %s .. \n " , o - > install ) ;
}
2011-11-10 19:22:55 +00:00
result = pkg_installLibrary ( o - > install , targetDir , noVersion ) ;
2008-12-01 20:49:08 +00:00
if ( result ! = 0 ) {
fprintf ( stderr , " Error installing the data library. \n " ) ;
return result ;
}
}
2008-11-24 20:04:52 +00:00
# endif
}
}
return result ;
}
2010-06-16 14:41:24 +00:00
/* Initialize the pkgDataFlags with the option file given. */
static int32_t initializePkgDataFlags ( UPKGOptions * o ) {
UErrorCode status = U_ZERO_ERROR ;
int32_t result = 0 ;
2010-10-04 23:47:46 +00:00
int32_t currentBufferSize = SMALL_BUFFER_MAX_SIZE ;
2010-10-05 04:52:16 +00:00
int32_t tmpResult = 0 ;
2010-10-04 23:47:46 +00:00
2010-06-16 14:41:24 +00:00
/* Initialize pkgdataFlags */
pkgDataFlags = ( char * * ) uprv_malloc ( sizeof ( char * ) * PKGDATA_FLAGS_SIZE ) ;
2010-10-04 23:47:46 +00:00
/* If we run out of space, allocate more */
# if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
do {
# endif
if ( pkgDataFlags ! = NULL ) {
for ( int32_t i = 0 ; i < PKGDATA_FLAGS_SIZE ; i + + ) {
pkgDataFlags [ i ] = ( char * ) uprv_malloc ( sizeof ( char ) * currentBufferSize ) ;
if ( pkgDataFlags [ i ] ! = NULL ) {
pkgDataFlags [ i ] [ 0 ] = 0 ;
} else {
fprintf ( stderr , " Error allocating memory for pkgDataFlags. \n " ) ;
2015-07-28 17:29:43 +00:00
/* If an error occurs, ensure that the rest of the array is NULL */
for ( int32_t n = i + 1 ; n < PKGDATA_FLAGS_SIZE ; n + + ) {
pkgDataFlags [ n ] = NULL ;
}
2010-10-04 23:47:46 +00:00
return - 1 ;
}
2010-06-16 14:41:24 +00:00
}
2010-10-04 23:47:46 +00:00
} else {
fprintf ( stderr , " Error allocating memory for pkgDataFlags. \n " ) ;
return - 1 ;
2010-06-16 14:41:24 +00:00
}
2010-10-04 23:47:46 +00:00
if ( o - > options = = NULL ) {
return result ;
}
2010-06-16 14:41:24 +00:00
# if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
2010-10-04 23:47:46 +00:00
/* Read in options file. */
if ( o - > verbose ) {
fprintf ( stdout , " # Reading options file %s \n " , o - > options ) ;
}
status = U_ZERO_ERROR ;
2011-06-27 21:58:09 +00:00
tmpResult = parseFlagsFile ( o - > options , pkgDataFlags , currentBufferSize , FLAG_NAMES , ( int32_t ) PKGDATA_FLAGS_SIZE , & status ) ;
2010-10-04 23:47:46 +00:00
if ( status = = U_BUFFER_OVERFLOW_ERROR ) {
for ( int32_t i = 0 ; i < PKGDATA_FLAGS_SIZE ; i + + ) {
2015-07-28 17:29:43 +00:00
if ( pkgDataFlags [ i ] ) {
uprv_free ( pkgDataFlags [ i ] ) ;
pkgDataFlags [ i ] = NULL ;
}
2010-10-04 23:47:46 +00:00
}
2010-10-05 04:52:16 +00:00
currentBufferSize = tmpResult ;
2010-10-04 23:47:46 +00:00
} else if ( U_FAILURE ( status ) ) {
fprintf ( stderr , " Unable to open or read \" %s \" option file. status = %s \n " , o - > options , u_errorName ( status ) ) ;
return - 1 ;
}
2010-06-16 14:41:24 +00:00
# endif
2010-10-04 23:47:46 +00:00
if ( o - > verbose ) {
2011-06-27 21:58:09 +00:00
fprintf ( stdout , " # pkgDataFlags= \n " ) ;
for ( int32_t i = 0 ; i < PKGDATA_FLAGS_SIZE ; i + + ) {
fprintf ( stdout , " [%d] %s: %s \n " , i , FLAG_NAMES [ i ] , pkgDataFlags [ i ] ) ;
2010-10-04 23:47:46 +00:00
}
fprintf ( stdout , " \n " ) ;
2010-06-16 15:08:55 +00:00
}
2010-10-04 23:47:46 +00:00
# if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
} while ( status = = U_BUFFER_OVERFLOW_ERROR ) ;
# endif
2010-06-16 15:08:55 +00:00
2010-06-16 14:41:24 +00:00
return result ;
}
2008-11-24 20:04:52 +00:00
/*
* Given the base libName and version numbers , generate the libary file names and store it in libFileNames .
* Depending on the configuration , the library name may either end with version number or shared object suffix .
*/
2011-11-10 19:22:55 +00:00
static void createFileNames ( UPKGOptions * o , const char mode , const char * version_major , const char * version , const char * libName , UBool reverseExt , UBool noVersion ) {
2014-06-23 21:36:42 +00:00
const char * FILE_EXTENSION_SEP = uprv_strlen ( pkgDataFlags [ SO_EXT ] ) = = 0 ? " " : " . " ;
const char * FILE_SUFFIX = pkgDataFlags [ LIB_EXT_ORDER ] [ 0 ] = = ' . ' ? " . " : " " ;
2012-03-30 07:11:51 +00:00
# if U_PLATFORM == U_PF_MINGW
/* MinGW does not need the library prefix when building in dll mode. */
if ( IN_DLL_MODE ( mode ) ) {
sprintf ( libFileNames [ LIB_FILE ] , " %s " , libName ) ;
} else {
2018-08-13 16:18:20 +00:00
sprintf ( libFileNames [ LIB_FILE ] , " %s%s%s " ,
( strstr ( libName , " icudt " ) ? " lib " : " " ) ,
2012-03-30 07:11:51 +00:00
pkgDataFlags [ LIBPREFIX ] ,
libName ) ;
}
# else
2008-11-24 20:04:52 +00:00
sprintf ( libFileNames [ LIB_FILE ] , " %s%s " ,
pkgDataFlags [ LIBPREFIX ] ,
libName ) ;
2012-03-30 07:11:51 +00:00
# endif
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # libFileName[LIB_FILE] = %s \n " , libFileNames [ LIB_FILE ] ) ;
}
2012-03-30 07:11:51 +00:00
# if U_PLATFORM == U_PF_MINGW
2015-01-06 23:08:18 +00:00
// Name the import library lib*.dll.a
sprintf ( libFileNames [ LIB_FILE_MINGW ] , " lib%s.dll.a " , libName ) ;
2012-03-30 07:11:51 +00:00
# elif U_PLATFORM == U_PF_CYGWIN
2014-06-23 21:36:42 +00:00
sprintf ( libFileNames [ LIB_FILE_CYGWIN ] , " cyg%s%s%s " ,
2011-11-10 19:22:55 +00:00
libName ,
2014-06-23 21:36:42 +00:00
FILE_EXTENSION_SEP ,
2011-11-10 19:22:55 +00:00
pkgDataFlags [ SO_EXT ] ) ;
2014-06-23 21:36:42 +00:00
sprintf ( libFileNames [ LIB_FILE_CYGWIN_VERSION ] , " cyg%s%s%s%s " ,
2011-11-10 19:22:55 +00:00
libName ,
version_major ,
2014-06-23 21:36:42 +00:00
FILE_EXTENSION_SEP ,
2011-11-10 19:22:55 +00:00
pkgDataFlags [ SO_EXT ] ) ;
2008-11-24 20:04:52 +00:00
2011-11-10 19:22:55 +00:00
uprv_strcat ( pkgDataFlags [ SO_EXT ] , " . " ) ;
uprv_strcat ( pkgDataFlags [ SO_EXT ] , pkgDataFlags [ A_EXT ] ) ;
2011-07-23 00:10:30 +00:00
# elif U_PLATFORM == U_PF_OS400 || defined(_AIX)
2014-06-23 21:36:42 +00:00
sprintf ( libFileNames [ LIB_FILE_VERSION_TMP ] , " %s%s%s " ,
2011-11-10 19:22:55 +00:00
libFileNames [ LIB_FILE ] ,
2014-06-23 21:36:42 +00:00
FILE_EXTENSION_SEP ,
2011-11-10 19:22:55 +00:00
pkgDataFlags [ SOBJ_EXT ] ) ;
2014-02-18 06:21:37 +00:00
# elif U_PLATFORM == U_PF_OS390
2014-06-23 21:36:42 +00:00
sprintf ( libFileNames [ LIB_FILE_VERSION_TMP ] , " %s%s%s%s%s " ,
2014-02-18 06:21:37 +00:00
libFileNames [ LIB_FILE ] ,
pkgDataFlags [ LIB_EXT_ORDER ] [ 0 ] = = ' . ' ? " . " : " " ,
reverseExt ? version : pkgDataFlags [ SOBJ_EXT ] ,
2014-06-23 21:36:42 +00:00
FILE_EXTENSION_SEP ,
2014-02-18 06:21:37 +00:00
reverseExt ? pkgDataFlags [ SOBJ_EXT ] : version ) ;
sprintf ( libFileNames [ LIB_FILE_OS390BATCH_VERSION ] , " %s%s.x " ,
libFileNames [ LIB_FILE ] ,
version ) ;
sprintf ( libFileNames [ LIB_FILE_OS390BATCH_MAJOR ] , " %s%s.x " ,
libFileNames [ LIB_FILE ] ,
version_major ) ;
2011-11-10 19:22:55 +00:00
# else
if ( noVersion & & ! reverseExt ) {
sprintf ( libFileNames [ LIB_FILE_VERSION_TMP ] , " %s%s%s " ,
2009-05-18 05:41:02 +00:00
libFileNames [ LIB_FILE ] ,
2014-06-23 21:36:42 +00:00
FILE_SUFFIX ,
2009-05-18 05:41:02 +00:00
pkgDataFlags [ SOBJ_EXT ] ) ;
2011-11-10 19:22:55 +00:00
} else {
2014-06-23 21:36:42 +00:00
sprintf ( libFileNames [ LIB_FILE_VERSION_TMP ] , " %s%s%s%s%s " ,
2008-11-24 20:04:52 +00:00
libFileNames [ LIB_FILE ] ,
2014-06-23 21:36:42 +00:00
FILE_SUFFIX ,
2008-11-24 20:04:52 +00:00
reverseExt ? version : pkgDataFlags [ SOBJ_EXT ] ,
2014-06-23 21:36:42 +00:00
FILE_EXTENSION_SEP ,
2008-11-24 20:04:52 +00:00
reverseExt ? pkgDataFlags [ SOBJ_EXT ] : version ) ;
2011-11-10 19:22:55 +00:00
}
2008-11-24 20:04:52 +00:00
# endif
2011-11-10 19:22:55 +00:00
if ( noVersion & & ! reverseExt ) {
sprintf ( libFileNames [ LIB_FILE_VERSION_MAJOR ] , " %s%s%s " ,
libFileNames [ LIB_FILE ] ,
2014-06-23 21:36:42 +00:00
FILE_SUFFIX ,
2011-11-10 19:22:55 +00:00
pkgDataFlags [ SO_EXT ] ) ;
sprintf ( libFileNames [ LIB_FILE_VERSION ] , " %s%s%s " ,
libFileNames [ LIB_FILE ] ,
2014-06-23 21:36:42 +00:00
FILE_SUFFIX ,
2011-11-10 19:22:55 +00:00
pkgDataFlags [ SO_EXT ] ) ;
} else {
2014-06-23 21:36:42 +00:00
sprintf ( libFileNames [ LIB_FILE_VERSION_MAJOR ] , " %s%s%s%s%s " ,
2008-11-24 20:04:52 +00:00
libFileNames [ LIB_FILE ] ,
2014-06-23 21:36:42 +00:00
FILE_SUFFIX ,
2008-11-24 20:04:52 +00:00
reverseExt ? version_major : pkgDataFlags [ SO_EXT ] ,
2014-06-23 21:36:42 +00:00
FILE_EXTENSION_SEP ,
2008-11-24 20:04:52 +00:00
reverseExt ? pkgDataFlags [ SO_EXT ] : version_major ) ;
2014-06-23 21:36:42 +00:00
sprintf ( libFileNames [ LIB_FILE_VERSION ] , " %s%s%s%s%s " ,
2009-07-17 23:59:37 +00:00
libFileNames [ LIB_FILE ] ,
2014-06-23 21:36:42 +00:00
FILE_SUFFIX ,
2009-07-17 23:59:37 +00:00
reverseExt ? version : pkgDataFlags [ SO_EXT ] ,
2014-06-23 21:36:42 +00:00
FILE_EXTENSION_SEP ,
2009-07-17 23:59:37 +00:00
reverseExt ? pkgDataFlags [ SO_EXT ] : version ) ;
2011-11-10 19:22:55 +00:00
}
2009-07-17 23:59:37 +00:00
2011-11-10 19:22:55 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # libFileName[LIB_FILE_VERSION] = %s \n " , libFileNames [ LIB_FILE_VERSION ] ) ;
}
2008-11-24 20:04:52 +00:00
2011-07-23 00:10:30 +00:00
# if U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
2011-11-10 19:22:55 +00:00
/* Cygwin and MinGW only deals with the version major number. */
uprv_strcpy ( libFileNames [ LIB_FILE_VERSION_TMP ] , libFileNames [ LIB_FILE_VERSION_MAJOR ] ) ;
2008-11-24 20:04:52 +00:00
# endif
2011-11-10 19:22:55 +00:00
2012-01-19 17:27:52 +00:00
if ( IN_STATIC_MODE ( mode ) ) {
2009-09-25 01:56:41 +00:00
sprintf ( libFileNames [ LIB_FILE_VERSION ] , " %s.%s " , libFileNames [ LIB_FILE ] , pkgDataFlags [ A_EXT ] ) ;
libFileNames [ LIB_FILE_VERSION_MAJOR ] [ 0 ] = 0 ;
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
fprintf ( stdout , " # libFileName[LIB_FILE_VERSION] = %s (static) \n " , libFileNames [ LIB_FILE_VERSION ] ) ;
}
2009-09-25 01:56:41 +00:00
}
2008-11-24 20:04:52 +00:00
}
/* Create the symbolic links for the final library file. */
2010-04-26 05:36:56 +00:00
static int32_t pkg_createSymLinks ( const char * targetDir , UBool specialHandling ) {
2008-11-24 20:04:52 +00:00
int32_t result = 0 ;
2009-02-06 17:42:16 +00:00
char cmd [ LARGE_BUFFER_MAX_SIZE ] ;
2010-09-17 21:26:54 +00:00
char name1 [ SMALL_BUFFER_MAX_SIZE ] ; /* symlink file name */
char name2 [ SMALL_BUFFER_MAX_SIZE ] ; /* file name to symlink */
2014-06-23 21:36:42 +00:00
const char * FILE_EXTENSION_SEP = uprv_strlen ( pkgDataFlags [ SO_EXT ] ) = = 0 ? " " : " . " ;
2008-11-24 20:04:52 +00:00
2018-08-13 16:18:20 +00:00
# if U_PLATFORM != U_PF_CYGWIN
2009-03-13 03:13:43 +00:00
/* No symbolic link to make. */
2010-06-03 15:51:19 +00:00
if ( uprv_strlen ( libFileNames [ LIB_FILE_VERSION ] ) = = 0 | | uprv_strlen ( libFileNames [ LIB_FILE_VERSION_MAJOR ] ) = = 0 | |
uprv_strcmp ( libFileNames [ LIB_FILE_VERSION ] , libFileNames [ LIB_FILE_VERSION_MAJOR ] ) = = 0 ) {
2009-03-13 03:13:43 +00:00
return result ;
}
2008-11-24 20:04:52 +00:00
sprintf ( cmd , " cd %s && %s %s && %s %s %s " ,
targetDir ,
RM_CMD ,
libFileNames [ LIB_FILE_VERSION_MAJOR ] ,
LN_CMD ,
libFileNames [ LIB_FILE_VERSION ] ,
libFileNames [ LIB_FILE_VERSION_MAJOR ] ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2008-11-24 20:04:52 +00:00
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error creating symbolic links. Failed command: %s \n " , cmd ) ;
2008-11-24 20:04:52 +00:00
return result ;
}
# endif
2010-04-26 05:36:56 +00:00
if ( specialHandling ) {
2011-07-23 00:10:30 +00:00
# if U_PLATFORM == U_PF_CYGWIN
2010-04-26 05:36:56 +00:00
sprintf ( name1 , " %s " , libFileNames [ LIB_FILE_CYGWIN ] ) ;
sprintf ( name2 , " %s " , libFileNames [ LIB_FILE_CYGWIN_VERSION ] ) ;
2014-02-18 06:21:37 +00:00
# elif U_PLATFORM == U_PF_OS390
/* Create the symbolic links for the import data */
/* Use the cmd buffer to store path to import data file to check its existence */
sprintf ( cmd , " %s/%s " , targetDir , libFileNames [ LIB_FILE_OS390BATCH_VERSION ] ) ;
if ( T_FileStream_file_exists ( cmd ) ) {
sprintf ( cmd , " cd %s && %s %s && %s %s %s " ,
targetDir ,
RM_CMD ,
libFileNames [ LIB_FILE_OS390BATCH_MAJOR ] ,
LN_CMD ,
libFileNames [ LIB_FILE_OS390BATCH_VERSION ] ,
libFileNames [ LIB_FILE_OS390BATCH_MAJOR ] ) ;
result = runCommand ( cmd ) ;
if ( result ! = 0 ) {
fprintf ( stderr , " Error creating symbolic links. Failed command: %s \n " , cmd ) ;
return result ;
}
sprintf ( cmd , " cd %s && %s %s.x && %s %s %s.x " ,
targetDir ,
RM_CMD ,
libFileNames [ LIB_FILE ] ,
LN_CMD ,
libFileNames [ LIB_FILE_OS390BATCH_VERSION ] ,
libFileNames [ LIB_FILE ] ) ;
result = runCommand ( cmd ) ;
if ( result ! = 0 ) {
fprintf ( stderr , " Error creating symbolic links. Failed command: %s \n " , cmd ) ;
return result ;
}
}
/* Needs to be set here because special handling skips it */
2014-06-23 21:36:42 +00:00
sprintf ( name1 , " %s%s%s " , libFileNames [ LIB_FILE ] , FILE_EXTENSION_SEP , pkgDataFlags [ SO_EXT ] ) ;
2014-02-18 06:21:37 +00:00
sprintf ( name2 , " %s " , libFileNames [ LIB_FILE_VERSION ] ) ;
2010-04-26 05:36:56 +00:00
# else
goto normal_symlink_mode ;
# endif
} else {
2011-08-12 21:16:53 +00:00
# if U_PLATFORM != U_PF_CYGWIN
2010-04-26 05:36:56 +00:00
normal_symlink_mode :
2011-08-12 21:16:53 +00:00
# endif
2014-06-23 21:36:42 +00:00
sprintf ( name1 , " %s%s%s " , libFileNames [ LIB_FILE ] , FILE_EXTENSION_SEP , pkgDataFlags [ SO_EXT ] ) ;
2010-04-26 05:36:56 +00:00
sprintf ( name2 , " %s " , libFileNames [ LIB_FILE_VERSION ] ) ;
}
sprintf ( cmd , " cd %s && %s %s && %s %s %s " ,
2008-11-24 20:04:52 +00:00
targetDir ,
RM_CMD ,
2010-04-26 05:36:56 +00:00
name1 ,
2008-11-24 20:04:52 +00:00
LN_CMD ,
2010-04-26 05:36:56 +00:00
name2 ,
name1 ) ;
2008-11-24 20:04:52 +00:00
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2008-11-24 20:04:52 +00:00
return result ;
}
2011-11-10 19:22:55 +00:00
static int32_t pkg_installLibrary ( const char * installDir , const char * targetDir , UBool noVersion ) {
2008-12-01 20:49:08 +00:00
int32_t result = 0 ;
2009-02-06 17:42:16 +00:00
char cmd [ SMALL_BUFFER_MAX_SIZE ] ;
2008-12-01 20:49:08 +00:00
sprintf ( cmd , " cd %s && %s %s %s%s%s " ,
targetDir ,
pkgDataFlags [ INSTALL_CMD ] ,
libFileNames [ LIB_FILE_VERSION ] ,
2009-02-06 17:42:16 +00:00
installDir , PKGDATA_FILE_SEP_STRING , libFileNames [ LIB_FILE_VERSION ]
2008-12-01 20:49:08 +00:00
) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2008-12-01 20:49:08 +00:00
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error installing library. Failed command: %s \n " , cmd ) ;
2008-12-01 20:49:08 +00:00
return result ;
}
2010-04-26 05:36:56 +00:00
# ifdef CYGWINMSVC
sprintf ( cmd , " cd %s && %s %s.lib %s " ,
targetDir ,
pkgDataFlags [ INSTALL_CMD ] ,
libFileNames [ LIB_FILE ] ,
installDir
) ;
result = runCommand ( cmd ) ;
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error installing library. Failed command: %s \n " , cmd ) ;
2010-04-26 05:36:56 +00:00
return result ;
}
2011-07-23 00:10:30 +00:00
# elif U_PLATFORM == U_PF_CYGWIN
2010-04-26 05:36:56 +00:00
sprintf ( cmd , " cd %s && %s %s %s " ,
targetDir ,
pkgDataFlags [ INSTALL_CMD ] ,
libFileNames [ LIB_FILE_CYGWIN_VERSION ] ,
installDir
) ;
result = runCommand ( cmd ) ;
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error installing library. Failed command: %s \n " , cmd ) ;
2010-04-26 05:36:56 +00:00
return result ;
}
2014-02-18 06:21:37 +00:00
# elif U_PLATFORM == U_PF_OS390
if ( T_FileStream_file_exists ( libFileNames [ LIB_FILE_OS390BATCH_VERSION ] ) ) {
sprintf ( cmd , " %s %s %s " ,
pkgDataFlags [ INSTALL_CMD ] ,
libFileNames [ LIB_FILE_OS390BATCH_VERSION ] ,
installDir
) ;
result = runCommand ( cmd ) ;
if ( result ! = 0 ) {
fprintf ( stderr , " Error installing library. Failed command: %s \n " , cmd ) ;
return result ;
}
}
2010-04-26 05:36:56 +00:00
# endif
2011-11-10 19:22:55 +00:00
if ( noVersion ) {
return result ;
} else {
return pkg_createSymLinks ( installDir , TRUE ) ;
}
2008-12-01 20:49:08 +00:00
}
2010-06-16 14:41:24 +00:00
static int32_t pkg_installCommonMode ( const char * installDir , const char * fileName ) {
int32_t result = 0 ;
char cmd [ SMALL_BUFFER_MAX_SIZE ] = " " ;
if ( ! T_FileStream_file_exists ( installDir ) ) {
UErrorCode status = U_ZERO_ERROR ;
uprv_mkdir ( installDir , & status ) ;
if ( U_FAILURE ( status ) ) {
fprintf ( stderr , " Error creating installation directory: %s \n " , installDir ) ;
return - 1 ;
}
}
# ifndef U_WINDOWS_WITH_MSVC
sprintf ( cmd , " %s %s %s " , pkgDataFlags [ INSTALL_CMD ] , fileName , installDir ) ;
# else
sprintf ( cmd , " %s %s %s %s " , WIN_INSTALL_CMD , fileName , installDir , WIN_INSTALL_CMD_FLAGS ) ;
# endif
result = runCommand ( cmd ) ;
if ( result ! = 0 ) {
fprintf ( stderr , " Failed to install data file with command: %s \n " , cmd ) ;
}
return result ;
}
2009-02-06 17:42:16 +00:00
# ifdef U_WINDOWS_MSVC
/* Copy commands for installing the raw data files on Windows. */
# define WIN_INSTALL_CMD "xcopy"
# define WIN_INSTALL_CMD_FLAGS " / E / Y / K"
# endif
static int32_t pkg_installFileMode ( const char * installDir , const char * srcDir , const char * fileListName ) {
int32_t result = 0 ;
char cmd [ SMALL_BUFFER_MAX_SIZE ] = " " ;
if ( ! T_FileStream_file_exists ( installDir ) ) {
UErrorCode status = U_ZERO_ERROR ;
uprv_mkdir ( installDir , & status ) ;
if ( U_FAILURE ( status ) ) {
fprintf ( stderr , " Error creating installation directory: %s \n " , installDir ) ;
return - 1 ;
}
}
# ifndef U_WINDOWS_WITH_MSVC
char buffer [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2012-05-03 05:50:26 +00:00
int32_t bufferLength = 0 ;
2009-02-06 17:42:16 +00:00
FileStream * f = T_FileStream_open ( fileListName , " r " ) ;
if ( f ! = NULL ) {
for ( ; ; ) {
if ( T_FileStream_readLine ( f , buffer , SMALL_BUFFER_MAX_SIZE ) ! = NULL ) {
2018-09-19 17:05:27 +00:00
bufferLength = static_cast < int32_t > ( uprv_strlen ( buffer ) ) ;
2009-02-06 17:42:16 +00:00
/* Remove new line character. */
2012-05-03 05:50:26 +00:00
if ( bufferLength > 0 ) {
buffer [ bufferLength - 1 ] = 0 ;
}
2009-02-06 17:42:16 +00:00
sprintf ( cmd , " %s %s%s%s %s%s%s " ,
pkgDataFlags [ INSTALL_CMD ] ,
srcDir , PKGDATA_FILE_SEP_STRING , buffer ,
installDir , PKGDATA_FILE_SEP_STRING , buffer ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2009-02-06 17:42:16 +00:00
if ( result ! = 0 ) {
fprintf ( stderr , " Failed to install data file with command: %s \n " , cmd ) ;
break ;
}
} else {
if ( ! T_FileStream_eof ( f ) ) {
fprintf ( stderr , " Failed to read line from file: %s \n " , fileListName ) ;
result = - 1 ;
}
break ;
}
}
T_FileStream_close ( f ) ;
} else {
result = - 1 ;
fprintf ( stderr , " Unable to open list file: %s \n " , fileListName ) ;
}
# else
sprintf ( cmd , " %s %s %s %s " , WIN_INSTALL_CMD , srcDir , installDir , WIN_INSTALL_CMD_FLAGS ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2009-02-06 17:42:16 +00:00
if ( result ! = 0 ) {
fprintf ( stderr , " Failed to install data file with command: %s \n " , cmd ) ;
}
# endif
return result ;
}
2008-11-24 20:04:52 +00:00
/* Archiving of the library file may be needed depending on the platform and options given.
* If archiving is not needed , copy over the library file name .
*/
static int32_t pkg_archiveLibrary ( const char * targetDir , const char * version , UBool reverseExt ) {
int32_t result = 0 ;
2009-02-06 17:42:16 +00:00
char cmd [ LARGE_BUFFER_MAX_SIZE ] ;
2008-11-24 20:04:52 +00:00
2009-07-17 23:59:37 +00:00
/* If the shared object suffix and the final object suffix is different and the final object suffix and the
2008-11-24 20:04:52 +00:00
* archive file suffix is the same , then the final library needs to be archived .
*/
if ( uprv_strcmp ( pkgDataFlags [ SOBJ_EXT ] , pkgDataFlags [ SO_EXT ] ) ! = 0 & & uprv_strcmp ( pkgDataFlags [ A_EXT ] , pkgDataFlags [ SO_EXT ] ) = = 0 ) {
sprintf ( libFileNames [ LIB_FILE_VERSION ] , " %s%s%s.%s " ,
libFileNames [ LIB_FILE ] ,
pkgDataFlags [ LIB_EXT_ORDER ] [ 0 ] = = ' . ' ? " . " : " " ,
reverseExt ? version : pkgDataFlags [ SO_EXT ] ,
reverseExt ? pkgDataFlags [ SO_EXT ] : version ) ;
sprintf ( cmd , " %s %s %s%s %s%s " ,
pkgDataFlags [ AR ] ,
pkgDataFlags [ ARFLAGS ] ,
targetDir ,
libFileNames [ LIB_FILE_VERSION ] ,
targetDir ,
libFileNames [ LIB_FILE_VERSION_TMP ] ) ;
2009-07-09 20:07:19 +00:00
result = runCommand ( cmd ) ;
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error creating archive library. Failed command: %s \n " , cmd ) ;
2009-07-09 20:07:19 +00:00
return result ;
}
sprintf ( cmd , " %s %s%s " ,
pkgDataFlags [ RANLIB ] ,
targetDir ,
libFileNames [ LIB_FILE_VERSION ] ) ;
result = runCommand ( cmd ) ;
2008-11-24 20:04:52 +00:00
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error creating archive library. Failed command: %s \n " , cmd ) ;
2008-11-24 20:04:52 +00:00
return result ;
}
/* Remove unneeded library file. */
sprintf ( cmd , " %s %s%s " ,
RM_CMD ,
targetDir ,
libFileNames [ LIB_FILE_VERSION_TMP ] ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2008-11-24 20:04:52 +00:00
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error creating archive library. Failed command: %s \n " , cmd ) ;
2008-11-24 20:04:52 +00:00
return result ;
}
} else {
uprv_strcpy ( libFileNames [ LIB_FILE_VERSION ] , libFileNames [ LIB_FILE_VERSION_TMP ] ) ;
}
return result ;
}
/*
* Using the compiler information from the configuration file set by - O option , generate the library file .
* command may be given to allow for a larger buffer for cmd .
*/
2014-02-18 06:21:37 +00:00
static int32_t pkg_generateLibraryFile ( const char * targetDir , const char mode , const char * objectFile , char * command , UBool specialHandling ) {
2008-11-24 20:04:52 +00:00
int32_t result = 0 ;
2009-02-06 18:22:03 +00:00
char * cmd = NULL ;
UBool freeCmd = FALSE ;
2011-01-19 05:14:22 +00:00
int32_t length = 0 ;
2009-02-06 18:22:03 +00:00
2014-04-24 00:33:39 +00:00
( void ) specialHandling ; // Suppress unused variable compiler warnings on platforms where all usage
// of this parameter is #ifdefed out.
2009-02-06 18:22:03 +00:00
/* This is necessary because if packaging is done without assembly code, objectFile might be extremely large
* containing many object files and so the calling function should supply a command buffer that is large
* enough to handle this . Otherwise , use the default size .
*/
if ( command ! = NULL ) {
cmd = command ;
}
2008-11-24 20:04:52 +00:00
2012-01-19 17:27:52 +00:00
if ( IN_STATIC_MODE ( mode ) ) {
2011-01-19 05:14:22 +00:00
if ( cmd = = NULL ) {
2019-01-11 20:23:43 +00:00
length = static_cast < int32_t > ( uprv_strlen ( pkgDataFlags [ AR ] ) + uprv_strlen ( pkgDataFlags [ ARFLAGS ] ) + uprv_strlen ( targetDir ) +
uprv_strlen ( libFileNames [ LIB_FILE_VERSION ] ) + uprv_strlen ( objectFile ) + uprv_strlen ( pkgDataFlags [ RANLIB ] ) + BUFFER_PADDING_SIZE ) ;
2011-01-19 05:14:22 +00:00
if ( ( cmd = ( char * ) uprv_malloc ( sizeof ( char ) * length ) ) = = NULL ) {
fprintf ( stderr , " Unable to allocate memory for command. \n " ) ;
return - 1 ;
}
freeCmd = TRUE ;
}
2009-09-25 01:56:41 +00:00
sprintf ( cmd , " %s %s %s%s %s " ,
2008-11-24 20:04:52 +00:00
pkgDataFlags [ AR ] ,
pkgDataFlags [ ARFLAGS ] ,
targetDir ,
2009-09-25 01:56:41 +00:00
libFileNames [ LIB_FILE_VERSION ] ,
2008-11-24 20:04:52 +00:00
objectFile ) ;
2010-04-26 05:36:56 +00:00
result = runCommand ( cmd ) ;
2009-07-09 20:07:19 +00:00
if ( result = = 0 ) {
2009-09-25 01:56:41 +00:00
sprintf ( cmd , " %s %s%s " ,
2009-07-09 20:07:19 +00:00
pkgDataFlags [ RANLIB ] ,
targetDir ,
2009-09-25 01:56:41 +00:00
libFileNames [ LIB_FILE_VERSION ] ) ;
2009-07-09 20:07:19 +00:00
2010-04-26 05:36:56 +00:00
result = runCommand ( cmd ) ;
2009-07-09 20:07:19 +00:00
}
2012-01-19 17:27:52 +00:00
} else /* if (IN_DLL_MODE(mode)) */ {
2011-01-19 05:14:22 +00:00
if ( cmd = = NULL ) {
2019-01-11 20:23:43 +00:00
length = static_cast < int32_t > ( uprv_strlen ( pkgDataFlags [ GENLIB ] ) + uprv_strlen ( pkgDataFlags [ LDICUDTFLAGS ] ) +
2011-06-26 07:14:41 +00:00
( ( uprv_strlen ( targetDir ) + uprv_strlen ( libFileNames [ LIB_FILE_VERSION_TMP ] ) ) * 2 ) +
2011-01-19 05:14:22 +00:00
uprv_strlen ( objectFile ) + uprv_strlen ( pkgDataFlags [ LD_SONAME ] ) +
uprv_strlen ( pkgDataFlags [ LD_SONAME ] [ 0 ] = = 0 ? " " : libFileNames [ LIB_FILE_VERSION_MAJOR ] ) +
2019-01-11 20:23:43 +00:00
uprv_strlen ( pkgDataFlags [ RPATH_FLAGS ] ) + uprv_strlen ( pkgDataFlags [ BIR_FLAGS ] ) + BUFFER_PADDING_SIZE ) ;
2011-07-23 00:10:30 +00:00
# if U_PLATFORM == U_PF_CYGWIN
2019-01-11 20:23:43 +00:00
length + = static_cast < int32_t > ( uprv_strlen ( targetDir ) + uprv_strlen ( libFileNames [ LIB_FILE_CYGWIN_VERSION ] ) ) ;
2012-03-30 07:11:51 +00:00
# elif U_PLATFORM == U_PF_MINGW
2019-01-11 20:23:43 +00:00
length + = static_cast < int32_t > ( uprv_strlen ( targetDir ) + uprv_strlen ( libFileNames [ LIB_FILE_MINGW ] ) ) ;
2011-01-19 05:14:22 +00:00
# endif
if ( ( cmd = ( char * ) uprv_malloc ( sizeof ( char ) * length ) ) = = NULL ) {
fprintf ( stderr , " Unable to allocate memory for command. \n " ) ;
return - 1 ;
}
freeCmd = TRUE ;
}
2012-03-30 07:11:51 +00:00
# if U_PLATFORM == U_PF_MINGW
sprintf ( cmd , " %s%s%s %s -o %s%s %s %s%s %s %s " ,
pkgDataFlags [ GENLIB ] ,
targetDir ,
libFileNames [ LIB_FILE_MINGW ] ,
pkgDataFlags [ LDICUDTFLAGS ] ,
targetDir ,
libFileNames [ LIB_FILE_VERSION_TMP ] ,
# elif U_PLATFORM == U_PF_CYGWIN
2008-11-24 20:04:52 +00:00
sprintf ( cmd , " %s%s%s %s -o %s%s %s %s%s %s %s " ,
pkgDataFlags [ GENLIB ] ,
targetDir ,
libFileNames [ LIB_FILE_VERSION_TMP ] ,
pkgDataFlags [ LDICUDTFLAGS ] ,
2012-03-30 07:11:51 +00:00
targetDir ,
libFileNames [ LIB_FILE_CYGWIN_VERSION ] ,
2011-07-23 00:10:30 +00:00
# elif U_PLATFORM == U_PF_AIX
2011-06-26 07:14:41 +00:00
sprintf ( cmd , " %s %s%s;%s %s -o %s%s %s %s%s %s %s " ,
RM_CMD ,
targetDir ,
libFileNames [ LIB_FILE_VERSION_TMP ] ,
pkgDataFlags [ GENLIB ] ,
pkgDataFlags [ LDICUDTFLAGS ] ,
targetDir ,
libFileNames [ LIB_FILE_VERSION_TMP ] ,
2008-11-24 20:04:52 +00:00
# else
sprintf ( cmd , " %s %s -o %s%s %s %s%s %s %s " ,
pkgDataFlags [ GENLIB ] ,
pkgDataFlags [ LDICUDTFLAGS ] ,
targetDir ,
libFileNames [ LIB_FILE_VERSION_TMP ] ,
# endif
objectFile ,
pkgDataFlags [ LD_SONAME ] ,
pkgDataFlags [ LD_SONAME ] [ 0 ] = = 0 ? " " : libFileNames [ LIB_FILE_VERSION_MAJOR ] ,
pkgDataFlags [ RPATH_FLAGS ] ,
pkgDataFlags [ BIR_FLAGS ] ) ;
/* Generate the library file. */
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2013-05-08 19:53:01 +00:00
2014-02-18 06:21:37 +00:00
# if U_PLATFORM == U_PF_OS390
2014-02-27 19:23:50 +00:00
char * env_tmp ;
2013-05-08 19:53:01 +00:00
char PDS_LibName [ 512 ] ;
2014-02-27 19:23:50 +00:00
char PDS_Name [ 512 ] ;
PDS_Name [ 0 ] = 0 ;
2014-02-18 06:21:37 +00:00
PDS_LibName [ 0 ] = 0 ;
if ( specialHandling & & uprv_strcmp ( libFileNames [ LIB_FILE ] , " libicudata " ) = = 0 ) {
2014-02-27 19:23:50 +00:00
if ( env_tmp = getenv ( " ICU_PDS_NAME " ) ) {
sprintf ( PDS_Name , " %s%s " ,
env_tmp ,
" DA " ) ;
strcat ( PDS_Name , getenv ( " ICU_PDS_NAME_SUFFIX " ) ) ;
} else if ( env_tmp = getenv ( " PDS_NAME_PREFIX " ) ) {
sprintf ( PDS_Name , " %s%s " ,
env_tmp ,
U_ICU_VERSION_SHORT " DA " ) ;
} else {
sprintf ( PDS_Name , " %s%s " ,
" IXMI " ,
U_ICU_VERSION_SHORT " DA " ) ;
}
2014-02-18 06:21:37 +00:00
} else if ( ! specialHandling & & uprv_strcmp ( libFileNames [ LIB_FILE ] , " libicudata_stub " ) = = 0 ) {
2014-02-27 19:23:50 +00:00
if ( env_tmp = getenv ( " ICU_PDS_NAME " ) ) {
sprintf ( PDS_Name , " %s%s " ,
env_tmp ,
" D1 " ) ;
strcat ( PDS_Name , getenv ( " ICU_PDS_NAME_SUFFIX " ) ) ;
} else if ( env_tmp = getenv ( " PDS_NAME_PREFIX " ) ) {
sprintf ( PDS_Name , " %s%s " ,
env_tmp ,
U_ICU_VERSION_SHORT " D1 " ) ;
} else {
sprintf ( PDS_Name , " %s%s " ,
" IXMI " ,
U_ICU_VERSION_SHORT " D1 " ) ;
}
2014-02-18 06:21:37 +00:00
}
2014-02-27 19:23:50 +00:00
if ( PDS_Name [ 0 ] ) {
sprintf ( PDS_LibName , " %s%s%s%s%s " ,
" \" //' " ,
getenv ( " LOADMOD " ) ,
" ( " ,
PDS_Name ,
" )' \" " ) ;
sprintf ( cmd , " %s %s -o %s %s %s%s %s %s " ,
2013-05-08 19:53:01 +00:00
pkgDataFlags [ GENLIB ] ,
pkgDataFlags [ LDICUDTFLAGS ] ,
PDS_LibName ,
objectFile ,
pkgDataFlags [ LD_SONAME ] ,
pkgDataFlags [ LD_SONAME ] [ 0 ] = = 0 ? " " : libFileNames [ LIB_FILE_VERSION_MAJOR ] ,
pkgDataFlags [ RPATH_FLAGS ] ,
pkgDataFlags [ BIR_FLAGS ] ) ;
2014-02-18 06:21:37 +00:00
result = runCommand ( cmd ) ;
2013-05-08 19:53:01 +00:00
}
# endif
2008-11-24 20:04:52 +00:00
}
2011-06-27 18:51:52 +00:00
if ( result ! = 0 ) {
fprintf ( stderr , " Error generating library file. Failed command: %s \n " , cmd ) ;
}
2009-02-06 18:22:03 +00:00
if ( freeCmd ) {
uprv_free ( cmd ) ;
}
2008-11-24 20:04:52 +00:00
return result ;
}
static int32_t pkg_createWithAssemblyCode ( const char * targetDir , const char mode , const char * gencFilePath ) {
char tempObjectFile [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2010-10-04 23:47:46 +00:00
char * cmd ;
2008-11-24 20:04:52 +00:00
int32_t result = 0 ;
2010-10-04 23:47:46 +00:00
int32_t length = 0 ;
2008-11-24 20:04:52 +00:00
/* Remove the ending .s and replace it with .o for the new object file. */
uprv_strcpy ( tempObjectFile , gencFilePath ) ;
tempObjectFile [ uprv_strlen ( tempObjectFile ) - 1 ] = ' o ' ;
2019-01-11 20:23:43 +00:00
length = static_cast < int32_t > ( uprv_strlen ( pkgDataFlags [ COMPILER ] ) + uprv_strlen ( pkgDataFlags [ LIBFLAGS ] )
+ uprv_strlen ( tempObjectFile ) + uprv_strlen ( gencFilePath ) + BUFFER_PADDING_SIZE ) ;
2010-10-04 23:47:46 +00:00
cmd = ( char * ) uprv_malloc ( sizeof ( char ) * length ) ;
if ( cmd = = NULL ) {
return - 1 ;
}
2008-11-24 20:04:52 +00:00
/* Generate the object file. */
sprintf ( cmd , " %s %s -o %s %s " ,
pkgDataFlags [ COMPILER ] ,
pkgDataFlags [ LIBFLAGS ] ,
tempObjectFile ,
gencFilePath ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2010-10-04 23:47:46 +00:00
uprv_free ( cmd ) ;
2008-11-24 20:04:52 +00:00
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error creating with assembly code. Failed command: %s \n " , cmd ) ;
2008-11-24 20:04:52 +00:00
return result ;
}
2009-02-06 17:42:16 +00:00
return pkg_generateLibraryFile ( targetDir , mode , tempObjectFile ) ;
2008-11-24 20:04:52 +00:00
}
2008-12-05 22:31:38 +00:00
# ifdef BUILD_DATA_WITHOUT_ASSEMBLY
2008-11-24 20:04:52 +00:00
/*
* Generation of the data library without assembly code needs to compile each data file
* individually and then link it all together .
2009-11-15 18:30:44 +00:00
* Note : Any update to the directory structure of the data needs to be reflected here .
2008-11-24 20:04:52 +00:00
*/
enum {
DATA_PREFIX_BRKITR ,
DATA_PREFIX_COLL ,
2009-11-15 18:30:44 +00:00
DATA_PREFIX_CURR ,
DATA_PREFIX_LANG ,
2008-11-24 20:04:52 +00:00
DATA_PREFIX_RBNF ,
2009-11-15 18:30:44 +00:00
DATA_PREFIX_REGION ,
2008-11-24 20:04:52 +00:00
DATA_PREFIX_TRANSLIT ,
2009-11-15 18:30:44 +00:00
DATA_PREFIX_ZONE ,
2014-09-11 10:16:22 +00:00
DATA_PREFIX_UNIT ,
2008-11-24 20:04:52 +00:00
DATA_PREFIX_LENGTH
} ;
2009-11-15 18:30:44 +00:00
2009-02-06 18:22:03 +00:00
const static char DATA_PREFIX [ DATA_PREFIX_LENGTH ] [ 10 ] = {
2008-11-24 20:04:52 +00:00
" brkitr " ,
" coll " ,
2009-11-15 18:30:44 +00:00
" curr " ,
" lang " ,
2008-11-24 20:04:52 +00:00
" rbnf " ,
2009-11-15 18:30:44 +00:00
" region " ,
" translit " ,
2014-09-11 10:16:22 +00:00
" zone " ,
" unit "
2008-11-24 20:04:52 +00:00
} ;
2009-11-15 18:30:44 +00:00
2008-11-24 20:04:52 +00:00
static int32_t pkg_createWithoutAssemblyCode ( UPKGOptions * o , const char * targetDir , const char mode ) {
2009-02-06 17:42:16 +00:00
int32_t result = 0 ;
2008-11-24 20:04:52 +00:00
CharList * list = o - > filePaths ;
CharList * listNames = o - > files ;
int32_t listSize = pkg_countCharList ( list ) ;
char * buffer ;
char * cmd ;
char gencmnFile [ SMALL_BUFFER_MAX_SIZE ] = " " ;
char tempObjectFile [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2009-05-18 05:41:02 +00:00
# ifdef USE_SINGLE_CCODE_FILE
char icudtAll [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2011-09-21 20:00:24 +00:00
FileStream * icudtAllFile = NULL ;
2009-05-18 05:41:02 +00:00
sprintf ( icudtAll , " %s%s%sall.c " ,
o - > tmpDir ,
PKGDATA_FILE_SEP_STRING ,
libFileNames [ LIB_FILE ] ) ;
2009-05-20 18:35:10 +00:00
/* Remove previous icudtall.c file. */
if ( T_FileStream_file_exists ( icudtAll ) & & ( result = remove ( icudtAll ) ) ! = 0 ) {
fprintf ( stderr , " Unable to remove old icudtall file: %s \n " , icudtAll ) ;
return result ;
}
2011-09-21 20:00:24 +00:00
if ( ( icudtAllFile = T_FileStream_open ( icudtAll , " w " ) ) = = NULL ) {
fprintf ( stderr , " Unable to write to icudtall file: %s \n " , icudtAll ) ;
return result ;
}
2009-05-18 05:41:02 +00:00
# endif
2008-11-24 20:04:52 +00:00
2009-01-09 22:30:44 +00:00
if ( list = = NULL | | listNames = = NULL ) {
/* list and listNames should never be NULL since we are looping through the CharList with
* the given size .
*/
return - 1 ;
}
2009-02-06 18:22:03 +00:00
if ( ( cmd = ( char * ) uprv_malloc ( ( listSize + 2 ) * SMALL_BUFFER_MAX_SIZE ) ) = = NULL ) {
fprintf ( stderr , " Unable to allocate memory for cmd. \n " ) ;
return - 1 ;
} else if ( ( buffer = ( char * ) uprv_malloc ( ( listSize + 1 ) * SMALL_BUFFER_MAX_SIZE ) ) = = NULL ) {
fprintf ( stderr , " Unable to allocate memory for buffer. \n " ) ;
uprv_free ( cmd ) ;
return - 1 ;
}
2008-11-24 20:04:52 +00:00
for ( int32_t i = 0 ; i < ( listSize + 1 ) ; i + + ) {
const char * file ;
const char * name ;
if ( i = = 0 ) {
/* The first iteration calls the gencmn function and initailizes the buffer. */
createCommonDataFile ( o - > tmpDir , o - > shortName , o - > entryName , NULL , o - > srcDir , o - > comment , o - > fileListFiles - > str , 0 , TRUE , o - > verbose , gencmnFile ) ;
buffer [ 0 ] = 0 ;
2009-05-18 05:41:02 +00:00
# ifdef USE_SINGLE_CCODE_FILE
uprv_strcpy ( tempObjectFile , gencmnFile ) ;
tempObjectFile [ uprv_strlen ( tempObjectFile ) - 1 ] = ' o ' ;
2011-09-15 19:34:17 +00:00
sprintf ( cmd , " %s %s -o %s %s " ,
2009-05-18 05:41:02 +00:00
pkgDataFlags [ COMPILER ] ,
pkgDataFlags [ LIBFLAGS ] ,
tempObjectFile ,
gencmnFile ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2009-05-18 05:41:02 +00:00
if ( result ! = 0 ) {
break ;
}
sprintf ( buffer , " %s " , tempObjectFile ) ;
# endif
2008-11-24 20:04:52 +00:00
} else {
char newName [ SMALL_BUFFER_MAX_SIZE ] ;
char dataName [ SMALL_BUFFER_MAX_SIZE ] ;
2009-11-15 18:30:44 +00:00
char dataDirName [ SMALL_BUFFER_MAX_SIZE ] ;
2008-11-24 20:04:52 +00:00
const char * pSubstring ;
file = list - > str ;
name = listNames - > str ;
newName [ 0 ] = dataName [ 0 ] = 0 ;
for ( int32_t n = 0 ; n < DATA_PREFIX_LENGTH ; n + + ) {
2009-11-15 18:30:44 +00:00
dataDirName [ 0 ] = 0 ;
sprintf ( dataDirName , " %s%s " , DATA_PREFIX [ n ] , PKGDATA_FILE_SEP_STRING ) ;
/* If the name contains a prefix (indicating directory), alter the new name accordingly. */
pSubstring = uprv_strstr ( name , dataDirName ) ;
2008-11-24 20:04:52 +00:00
if ( pSubstring ! = NULL ) {
char newNameTmp [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2009-11-15 18:30:44 +00:00
const char * p = name + uprv_strlen ( dataDirName ) ;
2008-11-24 20:04:52 +00:00
for ( int32_t i = 0 ; ; i + + ) {
if ( p [ i ] = = ' . ' ) {
newNameTmp [ i ] = ' _ ' ;
continue ;
}
newNameTmp [ i ] = p [ i ] ;
if ( p [ i ] = = 0 ) {
break ;
}
}
sprintf ( newName , " %s_%s " ,
DATA_PREFIX [ n ] ,
newNameTmp ) ;
sprintf ( dataName , " %s_%s " ,
o - > shortName ,
DATA_PREFIX [ n ] ) ;
}
if ( newName [ 0 ] ! = 0 ) {
break ;
}
}
2011-09-21 20:00:24 +00:00
if ( o - > verbose ) {
printf ( " # Generating %s \n " , gencmnFile ) ;
}
2019-07-19 22:44:24 +00:00
writeCCode (
file ,
o - > tmpDir ,
dataName [ 0 ] ! = 0 ? dataName : o - > shortName ,
newName [ 0 ] ! = 0 ? newName : NULL ,
gencmnFile ,
sizeof ( gencmnFile ) ) ;
2011-09-21 20:00:24 +00:00
2009-05-18 05:41:02 +00:00
# ifdef USE_SINGLE_CCODE_FILE
2011-09-21 20:00:24 +00:00
sprintf ( cmd , " #include \" %s \" \n " , gencmnFile ) ;
T_FileStream_writeLine ( icudtAllFile , cmd ) ;
/* don't delete the file */
2009-05-18 05:41:02 +00:00
# endif
2008-11-24 20:04:52 +00:00
}
2009-05-18 05:41:02 +00:00
# ifndef USE_SINGLE_CCODE_FILE
2008-11-24 20:04:52 +00:00
uprv_strcpy ( tempObjectFile , gencmnFile ) ;
tempObjectFile [ uprv_strlen ( tempObjectFile ) - 1 ] = ' o ' ;
2009-05-18 05:41:02 +00:00
2008-11-24 20:04:52 +00:00
sprintf ( cmd , " %s %s -o %s %s " ,
pkgDataFlags [ COMPILER ] ,
pkgDataFlags [ LIBFLAGS ] ,
tempObjectFile ,
gencmnFile ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2008-11-24 20:04:52 +00:00
if ( result ! = 0 ) {
2011-06-27 18:51:52 +00:00
fprintf ( stderr , " Error creating library without assembly code. Failed command: %s \n " , cmd ) ;
2008-11-24 20:04:52 +00:00
break ;
}
2010-01-07 18:52:24 +00:00
uprv_strcat ( buffer , " " ) ;
uprv_strcat ( buffer , tempObjectFile ) ;
2009-05-18 05:41:02 +00:00
# endif
2008-11-24 20:04:52 +00:00
if ( i > 0 ) {
list = list - > next ;
listNames = listNames - > next ;
}
}
2009-05-18 05:41:02 +00:00
# ifdef USE_SINGLE_CCODE_FILE
2011-09-21 20:00:24 +00:00
T_FileStream_close ( icudtAllFile ) ;
2009-05-18 05:41:02 +00:00
uprv_strcpy ( tempObjectFile , icudtAll ) ;
tempObjectFile [ uprv_strlen ( tempObjectFile ) - 1 ] = ' o ' ;
2010-04-26 05:36:56 +00:00
2011-09-21 20:00:24 +00:00
sprintf ( cmd , " %s %s -I. -o %s %s " ,
2009-05-18 05:41:02 +00:00
pkgDataFlags [ COMPILER ] ,
pkgDataFlags [ LIBFLAGS ] ,
tempObjectFile ,
icudtAll ) ;
2009-06-30 16:58:49 +00:00
result = runCommand ( cmd ) ;
2009-05-18 05:41:02 +00:00
if ( result = = 0 ) {
2010-01-07 18:52:24 +00:00
uprv_strcat ( buffer , " " ) ;
uprv_strcat ( buffer , tempObjectFile ) ;
2011-06-27 18:51:52 +00:00
} else {
fprintf ( stderr , " Error creating library without assembly code. Failed command: %s \n " , cmd ) ;
2009-05-18 05:41:02 +00:00
}
# endif
2008-11-24 20:04:52 +00:00
2009-05-18 05:41:02 +00:00
if ( result = = 0 ) {
/* Generate the library file. */
2012-03-13 20:18:59 +00:00
# if U_PLATFORM == U_PF_OS390
2014-02-18 06:21:37 +00:00
result = pkg_generateLibraryFile ( targetDir , mode , buffer , cmd , ( o - > pdsbuild & & IN_DLL_MODE ( mode ) ) ) ;
2012-03-13 20:18:59 +00:00
# else
result = pkg_generateLibraryFile ( targetDir , mode , buffer , cmd ) ;
# endif
2009-05-18 05:41:02 +00:00
}
2009-05-20 18:35:10 +00:00
2008-11-24 20:04:52 +00:00
uprv_free ( buffer ) ;
uprv_free ( cmd ) ;
return result ;
}
2008-12-05 22:31:38 +00:00
# endif
2008-11-24 20:04:52 +00:00
2008-12-05 22:31:38 +00:00
# ifdef WINDOWS_WITH_MSVC
2008-11-24 20:04:52 +00:00
# define LINK_CMD "link.exe / nologo / release / out:"
2017-03-21 01:03:49 +00:00
# define LINK_FLAGS " / DLL / NOENTRY / MANIFEST:NO / implib:"
2019-07-19 20:54:02 +00:00
2017-03-21 01:03:49 +00:00
# define LINK_EXTRA_UWP_FLAGS " / NXCOMPAT / DYNAMICBASE / APPCONTAINER "
2019-07-19 20:54:02 +00:00
# define LINK_EXTRA_UWP_FLAGS_X86_ONLY " / SAFESEH "
# define LINK_EXTRA_NO_DYNAMICBASE " / base:0x4ad00000 "
# define LINK_EXTRA_DYNAMICBASE " / DYNAMICBASE "
# define LINK_EXTRA_FLAGS_MACHINE " / MACHINE:"
2008-11-24 20:04:52 +00:00
# define LIB_CMD "LIB.exe / nologo / out:"
2010-06-21 15:35:36 +00:00
# define LIB_FILE "icudt.lib"
2009-02-06 17:42:16 +00:00
# define LIB_EXT UDATA_LIB_SUFFIX
# define DLL_EXT UDATA_SO_SUFFIX
2008-11-24 20:04:52 +00:00
static int32_t pkg_createWindowsDLL ( const char mode , const char * gencFilePath , UPKGOptions * o ) {
2011-06-27 18:51:52 +00:00
int32_t result = 0 ;
2008-11-24 20:04:52 +00:00
char cmd [ LARGE_BUFFER_MAX_SIZE ] ;
2012-01-19 17:27:52 +00:00
if ( IN_STATIC_MODE ( mode ) ) {
2008-11-24 20:04:52 +00:00
char staticLibFilePath [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2012-03-30 17:58:31 +00:00
# ifdef CYGWINMSVC
sprintf ( staticLibFilePath , " %s%s%s%s%s " ,
o - > targetDir ,
PKGDATA_FILE_SEP_STRING ,
2012-04-04 17:15:36 +00:00
pkgDataFlags [ LIBPREFIX ] ,
2012-03-30 17:58:31 +00:00
o - > libName ,
LIB_EXT ) ;
# else
2012-03-09 19:40:54 +00:00
sprintf ( staticLibFilePath , " %s%s%s%s%s " ,
o - > targetDir ,
PKGDATA_FILE_SEP_STRING ,
( strstr ( o - > libName , " icudt " ) ? " s " : " " ) ,
o - > libName ,
LIB_EXT ) ;
2012-03-30 17:58:31 +00:00
# endif
2008-11-24 20:04:52 +00:00
sprintf ( cmd , " %s \" %s \" \" %s \" " ,
LIB_CMD ,
staticLibFilePath ,
gencFilePath ) ;
2012-01-19 17:27:52 +00:00
} else if ( IN_DLL_MODE ( mode ) ) {
2008-11-24 20:04:52 +00:00
char dllFilePath [ SMALL_BUFFER_MAX_SIZE ] = " " ;
char libFilePath [ SMALL_BUFFER_MAX_SIZE ] = " " ;
char resFilePath [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2010-06-21 15:14:35 +00:00
char tmpResFilePath [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2008-11-24 20:04:52 +00:00
# ifdef CYGWINMSVC
uprv_strcpy ( dllFilePath , o - > targetDir ) ;
# else
uprv_strcpy ( dllFilePath , o - > srcDir ) ;
# endif
2009-02-06 17:42:16 +00:00
uprv_strcat ( dllFilePath , PKGDATA_FILE_SEP_STRING ) ;
2008-11-24 20:04:52 +00:00
uprv_strcpy ( libFilePath , dllFilePath ) ;
2010-06-21 15:35:36 +00:00
# ifdef CYGWINMSVC
2010-01-07 18:52:24 +00:00
uprv_strcat ( libFilePath , o - > libName ) ;
uprv_strcat ( libFilePath , " .lib " ) ;
2009-08-26 20:09:59 +00:00
uprv_strcat ( dllFilePath , o - > libName ) ;
uprv_strcat ( dllFilePath , o - > version ) ;
# else
2010-06-21 15:35:36 +00:00
if ( strstr ( o - > libName , " icudt " ) ) {
uprv_strcat ( libFilePath , LIB_FILE ) ;
} else {
uprv_strcat ( libFilePath , o - > libName ) ;
uprv_strcat ( libFilePath , " .lib " ) ;
}
2008-11-24 20:04:52 +00:00
uprv_strcat ( dllFilePath , o - > entryName ) ;
2009-08-26 20:09:59 +00:00
# endif
uprv_strcat ( dllFilePath , DLL_EXT ) ;
2010-06-21 15:14:35 +00:00
uprv_strcpy ( tmpResFilePath , o - > tmpDir ) ;
uprv_strcat ( tmpResFilePath , PKGDATA_FILE_SEP_STRING ) ;
uprv_strcat ( tmpResFilePath , ICUDATA_RES_FILE ) ;
2008-11-24 20:04:52 +00:00
2010-06-21 15:14:35 +00:00
if ( T_FileStream_file_exists ( tmpResFilePath ) ) {
2010-06-21 15:35:36 +00:00
sprintf ( resFilePath , " \" %s \" " , tmpResFilePath ) ;
2008-11-24 20:04:52 +00:00
}
2009-01-28 18:47:36 +00:00
/* Check if dll file and lib file exists and that it is not newer than genc file. */
2009-02-06 17:42:16 +00:00
if ( ! o - > rebuild & & ( T_FileStream_file_exists ( dllFilePath ) & & isFileModTimeLater ( dllFilePath , gencFilePath ) ) & &
2009-01-28 18:47:36 +00:00
( T_FileStream_file_exists ( libFilePath ) & & isFileModTimeLater ( libFilePath , gencFilePath ) ) ) {
2010-02-27 06:38:11 +00:00
if ( o - > verbose ) {
printf ( " # Not rebuilding %s - up to date. \n " , gencFilePath ) ;
}
return 0 ;
2009-01-28 18:47:36 +00:00
}
2019-07-19 20:54:02 +00:00
char extraFlags [ SMALL_BUFFER_MAX_SIZE ] = " " ;
2017-03-21 01:03:49 +00:00
# ifdef WINDOWS_WITH_MSVC
2019-07-19 20:54:02 +00:00
if ( options [ WIN_UWP_BUILD ] . doesOccur ) {
uprv_strcat ( extraFlags , LINK_EXTRA_UWP_FLAGS ) ;
if ( options [ WIN_DLL_ARCH ] . doesOccur ) {
if ( uprv_strcmp ( options [ WIN_DLL_ARCH ] . value , " X86 " ) = = 0 ) {
uprv_strcat ( extraFlags , LINK_EXTRA_UWP_FLAGS_X86_ONLY ) ;
}
2017-03-21 01:03:49 +00:00
}
2019-07-19 20:54:02 +00:00
} else {
if ( options [ WIN_DYNAMICBASE ] . doesOccur ) {
uprv_strcat ( extraFlags , LINK_EXTRA_DYNAMICBASE ) ;
} else {
uprv_strcat ( extraFlags , LINK_EXTRA_NO_DYNAMICBASE ) ;
2017-03-21 01:03:49 +00:00
}
}
2019-07-19 20:54:02 +00:00
if ( options [ WIN_DLL_ARCH ] . doesOccur ) {
uprv_strcat ( extraFlags , LINK_EXTRA_FLAGS_MACHINE ) ;
uprv_strcat ( extraFlags , options [ WIN_DLL_ARCH ] . value ) ;
2017-03-21 01:03:49 +00:00
}
2019-07-19 20:54:02 +00:00
2017-03-21 01:03:49 +00:00
# endif
sprintf ( cmd , " %s \" %s \" %s %s \" %s \" \" %s \" %s " ,
LINK_CMD ,
dllFilePath ,
extraFlags ,
LINK_FLAGS ,
libFilePath ,
gencFilePath ,
resFilePath
) ;
2008-11-24 20:04:52 +00:00
}
2011-06-27 18:51:52 +00:00
result = runCommand ( cmd , TRUE ) ;
if ( result ! = 0 ) {
fprintf ( stderr , " Error creating Windows DLL library. Failed command: %s \n " , cmd ) ;
}
return result ;
2008-11-24 20:04:52 +00:00
}
# endif
2009-07-10 18:58:35 +00:00
static UPKGOptions * pkg_checkFlag ( UPKGOptions * o ) {
2011-07-23 00:10:30 +00:00
# if U_PLATFORM == U_PF_AIX
2009-02-06 17:42:16 +00:00
/* AIX needs a map file. */
2008-11-24 20:04:52 +00:00
char * flag = NULL ;
int32_t length = 0 ;
char tmpbuffer [ SMALL_BUFFER_MAX_SIZE ] ;
const char MAP_FILE_EXT [ ] = " .map " ;
FileStream * f = NULL ;
char mapFile [ SMALL_BUFFER_MAX_SIZE ] = " " ;
int32_t start = - 1 ;
2011-06-26 07:14:41 +00:00
uint32_t count = 0 ;
const char rm_cmd [ ] = " rm -f all ; " ;
2008-11-24 20:04:52 +00:00
2011-06-12 02:42:44 +00:00
flag = pkgDataFlags [ GENLIB ] ;
2011-06-26 07:14:41 +00:00
/* This portion of the code removes 'rm -f all' in the GENLIB.
2011-06-12 02:42:44 +00:00
* Only occurs in AIX .
*/
2011-06-26 07:14:41 +00:00
if ( uprv_strstr ( flag , rm_cmd ) ! = NULL ) {
2011-06-12 02:42:44 +00:00
char * tmpGenlibFlagBuffer = NULL ;
2011-06-26 07:14:41 +00:00
int32_t i , offset ;
2011-06-12 02:42:44 +00:00
2019-01-11 20:23:43 +00:00
length = static_cast < int32_t > ( uprv_strlen ( flag ) + 1 ) ;
2011-06-12 02:42:44 +00:00
tmpGenlibFlagBuffer = ( char * ) uprv_malloc ( length ) ;
if ( tmpGenlibFlagBuffer = = NULL ) {
/* Memory allocation error */
fprintf ( stderr , " Unable to allocate buffer of size: %d. \n " , length ) ;
return NULL ;
}
uprv_strcpy ( tmpGenlibFlagBuffer , flag ) ;
2019-01-11 20:23:43 +00:00
offset = static_cast < int32_t > ( uprv_strlen ( rm_cmd ) ) ;
2011-06-12 02:42:44 +00:00
2011-06-26 07:14:41 +00:00
for ( i = 0 ; i < ( length - offset ) ; i + + ) {
flag [ i ] = tmpGenlibFlagBuffer [ offset + i ] ;
2011-06-12 02:42:44 +00:00
}
/* Zero terminate the string */
2011-06-26 07:14:41 +00:00
flag [ i ] = 0 ;
2011-06-12 02:42:44 +00:00
uprv_free ( tmpGenlibFlagBuffer ) ;
}
2008-11-24 20:04:52 +00:00
flag = pkgDataFlags [ BIR_FLAGS ] ;
2019-01-11 20:23:43 +00:00
length = static_cast < int32_t > ( uprv_strlen ( pkgDataFlags [ BIR_FLAGS ] ) ) ;
2008-11-24 20:04:52 +00:00
for ( int32_t i = 0 ; i < length ; i + + ) {
if ( flag [ i ] = = MAP_FILE_EXT [ count ] ) {
if ( count = = 0 ) {
start = i ;
}
count + + ;
} else {
count = 0 ;
}
if ( count = = uprv_strlen ( MAP_FILE_EXT ) ) {
break ;
}
}
if ( start > = 0 ) {
int32_t index = 0 ;
for ( int32_t i = 0 ; ; i + + ) {
if ( i = = start ) {
for ( int32_t n = 0 ; ; n + + ) {
if ( o - > shortName [ n ] = = 0 ) {
break ;
}
tmpbuffer [ index + + ] = o - > shortName [ n ] ;
}
}
tmpbuffer [ index + + ] = flag [ i ] ;
if ( flag [ i ] = = 0 ) {
break ;
}
}
uprv_memset ( flag , 0 , length ) ;
uprv_strcpy ( flag , tmpbuffer ) ;
uprv_strcpy ( mapFile , o - > shortName ) ;
uprv_strcat ( mapFile , MAP_FILE_EXT ) ;
f = T_FileStream_open ( mapFile , " w " ) ;
if ( f = = NULL ) {
fprintf ( stderr , " Unable to create map file: %s. \n " , mapFile ) ;
2011-06-12 02:42:44 +00:00
return NULL ;
2009-07-13 20:21:54 +00:00
} else {
sprintf ( tmpbuffer , " %s%s " , o - > entryName , UDATA_CMN_INTERMEDIATE_SUFFIX ) ;
T_FileStream_writeLine ( f , tmpbuffer ) ;
T_FileStream_close ( f ) ;
2008-11-24 20:04:52 +00:00
}
}
2012-03-30 07:11:51 +00:00
# elif U_PLATFORM == U_PF_CYGWIN || U_PLATFORM == U_PF_MINGW
2009-02-06 17:42:16 +00:00
/* Cygwin needs to change flag options. */
2008-12-05 22:31:38 +00:00
char * flag = NULL ;
int32_t length = 0 ;
2008-11-24 20:04:52 +00:00
flag = pkgDataFlags [ GENLIB ] ;
2019-01-11 20:23:43 +00:00
length = static_cast < int32_t > ( uprv_strlen ( pkgDataFlags [ GENLIB ] ) ) ;
2008-11-24 20:04:52 +00:00
int32_t position = length - 1 ;
for ( ; position > = 0 ; position - - ) {
if ( flag [ position ] = = ' = ' ) {
position + + ;
break ;
}
}
uprv_memset ( flag + position , 0 , length - position ) ;
2011-07-23 00:10:30 +00:00
# elif U_PLATFORM == U_PF_OS400
/* OS/400 needs to fix the ld options (swap single quote with double quote) */
2009-05-18 05:41:02 +00:00
char * flag = NULL ;
int32_t length = 0 ;
flag = pkgDataFlags [ GENLIB ] ;
2019-01-11 20:23:43 +00:00
length = static_cast < int32_t > ( uprv_strlen ( pkgDataFlags [ GENLIB ] ) ) ;
2009-05-18 05:41:02 +00:00
int32_t position = length - 1 ;
for ( int32_t i = 0 ; i < length ; i + + ) {
if ( flag [ i ] = = ' \' ' ) {
flag [ i ] = ' \" ' ;
}
}
2008-11-24 20:04:52 +00:00
# endif
2009-07-10 18:58:35 +00:00
// Don't really need a return value, just need to stop compiler warnings about
// the unused parameter 'o' on platforms where it is not otherwise used.
return o ;
2008-11-24 20:04:52 +00:00
}
static void loadLists ( UPKGOptions * o , UErrorCode * status )
{
CharList * l , * tail = NULL , * tail2 = NULL ;
FileStream * in ;
char line [ 16384 ] ;
char * linePtr , * lineNext ;
const uint32_t lineMax = 16300 ;
2011-03-29 18:49:51 +00:00
char * tmp ;
int32_t tmpLength = 0 ;
2008-11-24 20:04:52 +00:00
char * s ;
int32_t ln = 0 ; /* line number */
for ( l = o - > fileListFiles ; l ; l = l - > next ) {
if ( o - > verbose ) {
2010-02-27 06:38:11 +00:00
fprintf ( stdout , " # pkgdata: Reading %s.. \n " , l - > str ) ;
2008-11-24 20:04:52 +00:00
}
/* TODO: stdin */
in = T_FileStream_open ( l - > str , " r " ) ; /* open files list */
if ( ! in ) {
fprintf ( stderr , " Error opening <%s>. \n " , l - > str ) ;
* status = U_FILE_ACCESS_ERROR ;
return ;
}
while ( T_FileStream_readLine ( in , line , sizeof ( line ) ) ! = NULL ) { /* for each line */
ln + + ;
if ( uprv_strlen ( line ) > lineMax ) {
fprintf ( stderr , " %s:%d - line too long (over %d chars) \n " , l - > str , ( int ) ln , ( int ) lineMax ) ;
exit ( 1 ) ;
}
/* remove spaces at the beginning */
linePtr = line ;
2013-02-28 18:32:54 +00:00
/* On z/OS, disable call to isspace (#9996). Investigate using uprv_isspace instead (#9999) */
2013-03-11 16:55:23 +00:00
# if U_PLATFORM != U_PF_OS390
2008-11-24 20:04:52 +00:00
while ( isspace ( * linePtr ) ) {
linePtr + + ;
}
2013-02-28 18:32:54 +00:00
# endif
2008-11-24 20:04:52 +00:00
s = linePtr ;
/* remove trailing newline characters */
while ( * s ! = 0 ) {
if ( * s = = ' \r ' | | * s = = ' \n ' ) {
* s = 0 ;
break ;
}
+ + s ;
}
if ( ( * linePtr = = 0 ) | | ( * linePtr = = ' # ' ) ) {
continue ; /* comment or empty line */
}
/* Now, process the line */
lineNext = NULL ;
while ( linePtr & & * linePtr ) { /* process space-separated items */
while ( * linePtr = = ' ' ) {
linePtr + + ;
}
/* Find the next quote */
if ( linePtr [ 0 ] = = ' " ' )
{
lineNext = uprv_strchr ( linePtr + 1 , ' " ' ) ;
if ( lineNext = = NULL ) {
fprintf ( stderr , " %s:%d - missing trailing double quote ( \" ) \n " ,
l - > str , ( int ) ln ) ;
exit ( 1 ) ;
} else {
lineNext + + ;
if ( * lineNext ) {
if ( * lineNext ! = ' ' ) {
fprintf ( stderr , " %s:%d - malformed quoted line at position %d, expected ' ' got '%c' \n " ,
l - > str , ( int ) ln , ( int ) ( lineNext - line ) , ( * lineNext ) ? * lineNext : ' 0 ' ) ;
exit ( 1 ) ;
}
* lineNext = 0 ;
lineNext + + ;
}
}
} else {
lineNext = uprv_strchr ( linePtr , ' ' ) ;
if ( lineNext ) {
* lineNext = 0 ; /* terminate at space */
lineNext + + ;
}
}
/* add the file */
s = ( char * ) getLongPathname ( linePtr ) ;
/* normal mode.. o->files is just the bare list without package names */
o - > files = pkg_appendToList ( o - > files , & tail , uprv_strdup ( linePtr ) ) ;
2011-07-14 18:51:40 +00:00
if ( uprv_pathIsAbsolute ( s ) | | s [ 0 ] = = ' . ' ) {
2008-11-24 20:04:52 +00:00
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 \t Bad path: '%s' \n " , U_FILE_SEP_CHAR , s ) ;
exit ( U_ILLEGAL_ARGUMENT_ERROR ) ;
}
2019-01-11 20:23:43 +00:00
/* The +5 is to add a little extra space for, among other things, PKGDATA_FILE_SEP_STRING */
tmpLength = static_cast < int32_t > ( uprv_strlen ( o - > srcDir ) + uprv_strlen ( s ) + 5 ) ;
2011-03-29 18:49:51 +00:00
if ( ( tmp = ( char * ) uprv_malloc ( tmpLength ) ) = = NULL ) {
fprintf ( stderr , " pkgdata: Error: Unable to allocate tmp buffer size: %d \n " , tmpLength ) ;
exit ( U_MEMORY_ALLOCATION_ERROR ) ;
}
2008-11-24 20:04:52 +00:00
uprv_strcpy ( tmp , o - > srcDir ) ;
2011-03-29 18:49:51 +00:00
uprv_strcat ( tmp , o - > srcDir [ uprv_strlen ( o - > srcDir ) - 1 ] = = U_FILE_SEP_CHAR ? " " : PKGDATA_FILE_SEP_STRING ) ;
2008-11-24 20:04:52 +00:00
uprv_strcat ( tmp , s ) ;
2011-03-29 18:49:51 +00:00
o - > filePaths = pkg_appendToList ( o - > filePaths , & tail2 , tmp ) ;
2008-11-24 20:04:52 +00:00
linePtr = lineNext ;
} /* for each entry on line */
} /* for each line */
T_FileStream_close ( in ) ;
} /* for each file list file */
}
2008-12-01 21:57:14 +00:00
/* Try calling icu-config directly to get the option file. */
2010-02-27 06:38:11 +00:00
static int32_t pkg_getOptionsFromICUConfig ( UBool verbose , UOption * option ) {
2008-12-01 21:57:14 +00:00
# if U_HAVE_POPEN
2015-09-09 18:47:00 +00:00
LocalPipeFilePointer p ;
2008-12-01 21:57:14 +00:00
size_t n ;
static char buf [ 512 ] = " " ;
2014-09-11 16:00:14 +00:00
icu : : CharString cmdBuf ;
2010-02-24 22:49:36 +00:00
UErrorCode status = U_ZERO_ERROR ;
2008-12-01 21:57:14 +00:00
const char cmd [ ] = " icu-config --incpkgdatafile " ;
2014-09-11 05:25:13 +00:00
char dirBuf [ 1024 ] = " " ;
2010-02-24 22:49:36 +00:00
/* #1 try the same path where pkgdata was called from. */
2014-09-11 05:25:13 +00:00
findDirname ( progname , dirBuf , UPRV_LENGTHOF ( dirBuf ) , & status ) ;
2010-02-24 22:49:36 +00:00
if ( U_SUCCESS ( status ) ) {
2014-09-11 05:25:13 +00:00
cmdBuf . append ( dirBuf , status ) ;
2011-11-10 23:11:19 +00:00
if ( cmdBuf [ 0 ] ! = 0 ) {
2014-09-11 05:25:13 +00:00
cmdBuf . append ( U_FILE_SEP_STRING , status ) ;
2011-11-10 23:11:19 +00:00
}
2014-09-11 05:25:13 +00:00
cmdBuf . append ( cmd , status ) ;
2010-02-27 06:38:11 +00:00
if ( verbose ) {
2014-09-11 05:25:13 +00:00
fprintf ( stdout , " # Calling icu-config: %s \n " , cmdBuf . data ( ) ) ;
2010-02-27 06:38:11 +00:00
}
2015-09-09 18:47:00 +00:00
p . adoptInstead ( popen ( cmdBuf . data ( ) , " r " ) ) ;
2010-02-24 22:49:36 +00:00
}
2015-09-09 18:47:00 +00:00
if ( p . isNull ( ) | | ( n = fread ( buf , 1 , UPRV_LENGTHOF ( buf ) - 1 , p . getAlias ( ) ) ) < = 0 ) {
if ( verbose ) {
fprintf ( stdout , " # Calling icu-config: %s \n " , cmd ) ;
}
2008-12-01 21:57:14 +00:00
2015-09-09 18:47:00 +00:00
p . adoptInstead ( popen ( cmd , " r " ) ) ;
if ( p . isNull ( ) | | ( n = fread ( buf , 1 , UPRV_LENGTHOF ( buf ) - 1 , p . getAlias ( ) ) ) < = 0 ) {
fprintf ( stderr , " %s: icu-config: No icu-config found. (fix PATH or use -O option) \n " , progname ) ;
return - 1 ;
}
2008-12-01 21:57:14 +00:00
}
2008-12-01 23:48:28 +00:00
for ( int32_t length = strlen ( buf ) - 1 ; length > = 0 ; length - - ) {
if ( buf [ length ] = = ' \n ' | | buf [ length ] = = ' ' ) {
buf [ length ] = 0 ;
} else {
break ;
}
}
2008-12-01 21:57:14 +00:00
if ( buf [ strlen ( buf ) - 1 ] = = ' \n ' )
{
buf [ strlen ( buf ) - 1 ] = 0 ;
}
if ( buf [ 0 ] = = 0 )
{
fprintf ( stderr , " %s: icu-config: invalid response from icu-config (fix PATH or use -O option) \n " , progname ) ;
return - 1 ;
}
2010-02-27 06:38:11 +00:00
if ( verbose ) {
fprintf ( stdout , " # icu-config said: %s \n " , buf ) ;
}
2008-12-01 21:57:14 +00:00
option - > value = buf ;
option - > doesOccur = TRUE ;
return 0 ;
2012-05-03 05:50:26 +00:00
# else
2008-12-01 21:57:14 +00:00
return - 1 ;
2012-05-03 05:50:26 +00:00
# endif
2008-12-01 21:57:14 +00:00
}
2015-01-08 20:13:48 +00:00
# ifdef CAN_WRITE_OBJ_CODE
/* Create optMatchArch for genccode architecture detection */
static void pkg_createOptMatchArch ( char * optMatchArch ) {
2015-01-09 06:45:59 +00:00
# if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN)
2015-01-08 20:13:48 +00:00
const char * code = " void oma(){} " ;
const char * source = " oma.c " ;
const char * obj = " oma.obj " ;
FileStream * stream = NULL ;
stream = T_FileStream_open ( source , " w " ) ;
if ( stream ! = NULL ) {
T_FileStream_writeLine ( stream , code ) ;
T_FileStream_close ( stream ) ;
2015-06-16 18:31:19 +00:00
char cmd [ LARGE_BUFFER_MAX_SIZE ] ;
2015-01-08 20:13:48 +00:00
sprintf ( cmd , " %s %s -o %s " ,
pkgDataFlags [ COMPILER ] ,
source ,
obj ) ;
if ( runCommand ( cmd ) = = 0 ) {
sprintf ( optMatchArch , " %s " , obj ) ;
}
else {
fprintf ( stderr , " Failed to compile %s \n " , source ) ;
}
if ( ! T_FileStream_remove ( source ) ) {
fprintf ( stderr , " T_FileStream_remove failed to delete %s \n " , source ) ;
}
}
else {
fprintf ( stderr , " T_FileStream_open failed to open %s for writing \n " , source ) ;
}
2015-01-09 06:45:59 +00:00
# endif
2015-01-08 20:13:48 +00:00
}
static void pkg_destroyOptMatchArch ( char * optMatchArch ) {
2015-01-09 06:45:59 +00:00
if ( T_FileStream_file_exists ( optMatchArch ) & & ! T_FileStream_remove ( optMatchArch ) ) {
2015-01-08 20:13:48 +00:00
fprintf ( stderr , " T_FileStream_remove failed to delete %s \n " , optMatchArch ) ;
}
}
# endif