2000-06-14 00:50:58 +00:00
/******************************************************************************
2007-07-27 03:12:12 +00:00
* Copyright ( C ) 2000 - 2007 , International Business Machines
* Corporation and others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* file name : pkgdata . c
* 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 . )
*/
2000-06-14 00:50:58 +00:00
2007-06-01 07:17:26 +00:00
/*
2007-07-27 03:12:12 +00:00
* We define _XOPEN_SOURCE so that we can get popen and pclose .
*/
2007-06-01 07:17:26 +00:00
# if !defined(_XOPEN_SOURCE)
# if __STDC_VERSION__ >= 199901L
/* It is invalid to compile an XPG3, XPG4, XPG4v2 or XPG5 application using c99 on Solaris */
# define _XOPEN_SOURCE 600
# else
# define _XOPEN_SOURCE 4
# endif
# endif
2000-06-14 00:50:58 +00:00
# include "unicode/utypes.h"
2001-01-03 02:24:47 +00:00
# include "unicode/putil.h"
2000-06-14 00:50:58 +00:00
# include "cmemory.h"
# include "cstring.h"
# include "filestrm.h"
# include "toolutil.h"
2003-08-14 21:34:54 +00:00
# include "unicode/uclean.h"
2000-06-14 00:50:58 +00:00
# include "unewdata.h"
# include "uoptions.h"
2006-08-15 23:27:31 +00:00
# include "putilimp.h"
2000-08-15 02:41:58 +00:00
2002-05-29 22:05:20 +00:00
# if U_HAVE_POPEN
# include <unistd.h>
2002-05-10 20:31:01 +00:00
# endif
2003-12-04 21:11:55 +00:00
# include <stdio.h>
# include <stdlib.h>
2002-05-10 20:31:01 +00:00
2000-08-15 02:41:58 +00:00
U_CDECL_BEGIN
2000-06-14 00:50:58 +00:00
# include "pkgtypes.h"
# include "makefile.h"
2000-08-15 02:41:58 +00:00
U_CDECL_END
2000-09-30 02:35:31 +00:00
static int executeMakefile ( const UPKGOptions * o ) ;
2000-06-14 00:50:58 +00:00
static void loadLists ( UPKGOptions * o , UErrorCode * status ) ;
2002-05-29 22:05:20 +00:00
/* always have this fcn, just might not do anything */
2002-05-10 20:31:01 +00:00
static void fillInMakefileFromICUConfig ( UOption * option ) ;
2000-06-14 00:50:58 +00:00
/* This sets the modes that are available */
static struct
{
2002-03-15 23:41:40 +00:00
const char * name , * alt_name ;
UPKGMODE * fcn ;
const char * desc ;
2001-03-21 23:22:16 +00:00
} modes [ ] =
2000-06-14 00:50:58 +00:00
{
2002-03-15 23:41:40 +00:00
{ " files " , 0 , pkg_mode_files , " Uses raw data files (no effect). Installation copies all files to the target location. " } ,
2004-11-02 00:27:43 +00:00
# ifdef U_MAKE_IS_NMAKE
2002-03-15 23:41:40 +00:00
{ " dll " , " library " , pkg_mode_windows , " Generates one common data file and one shared library, <package>.dll " } ,
{ " common " , " archive " , pkg_mode_windows , " Generates just the common file, <package>.dat " } ,
{ " static " , " static " , pkg_mode_windows , " Generates one statically linked library, " LIB_PREFIX " <package> " UDATA_LIB_SUFFIX }
2004-11-02 00:27:43 +00:00
# else /*#ifdef U_MAKE_IS_NMAKE*/
2000-06-14 00:50:58 +00:00
# ifdef UDATA_SO_SUFFIX
2002-03-15 23:41:40 +00:00
{ " dll " , " library " , pkg_mode_dll , " Generates one shared library, <package> " UDATA_SO_SUFFIX } ,
2000-06-14 00:50:58 +00:00
# endif
2002-03-15 23:41:40 +00:00
{ " common " , " archive " , pkg_mode_common , " Generates one common data file, <package>.dat " } ,
{ " static " , " static " , pkg_mode_static , " Generates one statically linked library, " LIB_PREFIX " <package> " UDATA_LIB_SUFFIX }
2004-11-02 00:27:43 +00:00
# endif /*#ifdef U_MAKE_IS_NMAKE*/
2000-06-14 00:50:58 +00:00
} ;
2006-02-24 19:47:47 +00:00
enum {
NAME ,
BLDOPT ,
MODE ,
HELP ,
HELP_QUESTION_MARK ,
VERBOSE ,
COPYRIGHT ,
COMMENT ,
DESTDIR ,
CLEAN ,
NOOUTPUT ,
REBUILD ,
TEMPDIR ,
INSTALL ,
SOURCEDIR ,
ENTRYPOINT ,
REVISION ,
MAKEARG ,
FORCE_PREFIX ,
LIBNAME ,
QUIET
} ;
2000-06-14 00:50:58 +00:00
static UOption options [ ] = {
2002-03-15 23:41:40 +00:00
/*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 */
/*09*/ UOPTION_DEF ( " clean " , ' k ' , UOPT_NO_ARG ) ,
/*10*/ UOPTION_DEF ( " nooutput " , ' n ' , UOPT_NO_ARG ) ,
/*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 ) ,
2006-02-24 19:47:47 +00:00
/*17*/ UOPTION_DEF ( " makearg " , ' M ' , UOPT_REQUIRES_ARG ) ,
2003-07-18 00:46:04 +00:00
/*18*/ UOPTION_DEF ( " force-prefix " , ' f ' , UOPT_NO_ARG ) ,
2006-02-24 19:47:47 +00:00
/*19*/ UOPTION_DEF ( " libname " , ' L ' , UOPT_REQUIRES_ARG ) ,
/*20*/ UOPTION_DEF ( " quiet " , ' q ' , UOPT_NO_ARG )
2000-06-14 00:50:58 +00:00
} ;
2004-04-14 20:08:16 +00:00
const char options_help [ ] [ 320 ] = {
2002-03-15 23:41:40 +00:00
" Set the data name " ,
2004-11-02 00:27:43 +00:00
# ifdef U_MAKE_IS_NMAKE
2003-09-15 22:42:00 +00:00
" The directory where the ICU is located (e.g. <ICUROOT> which contains the bin directory) " ,
2000-07-19 20:58:13 +00:00
# else
2002-05-10 20:31:01 +00:00
" Specify options for the builder. (Autdetected if icu-config is available) " ,
2000-07-19 20:58:13 +00:00
# endif
2002-03-15 23:41:40 +00:00
" 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 " ,
" Clean out generated & temporary files " ,
" Suppress output of data, just list files to be created " ,
" 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) " ,
2002-03-16 02:26:17 +00:00
" Specify a version when packaging in DLL or static mode " ,
2002-07-31 20:28:32 +00:00
" Pass the next argument to make(1) " ,
2003-07-18 00:46:04 +00:00
" Add package to all file names if not present " ,
2004-04-14 20:08:16 +00:00
" Library name to build (if different than package name) " ,
2004-07-13 08:08:17 +00:00
" Quite mode. (e.g. Do not output a readme file for static libraries) "
2000-06-14 00:50:58 +00:00
} ;
2002-05-10 20:31:01 +00:00
const char * progname = " PKGDATA " ;
2000-06-14 00:50:58 +00:00
int
2000-09-21 21:49:32 +00:00
main ( int argc , char * argv [ ] ) {
2002-03-15 23:41:40 +00:00
FileStream * out ;
UPKGOptions o ;
CharList * tail ;
UBool needsHelp = FALSE ;
UErrorCode status = U_ZERO_ERROR ;
char tmp [ 1024 ] ;
int32_t i ;
U_MAIN_INIT_ARGS ( argc , argv ) ;
progname = argv [ 0 ] ;
2001-03-21 23:22:16 +00:00
2006-02-24 19:47:47 +00:00
options [ MODE ] . value = " common " ;
options [ MAKEARG ] . value = " " ;
2002-03-15 23:41:40 +00:00
/* read command line options */
argc = u_parseArgs ( argc , argv , sizeof ( options ) / sizeof ( options [ 0 ] ) , options ) ;
/* 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 . */
2006-02-24 19:47:47 +00:00
if ( options [ HELP ] . doesOccur | | options [ HELP_QUESTION_MARK ] . doesOccur ) {
2002-03-15 23:41:40 +00:00
needsHelp = TRUE ;
2000-06-14 00:50:58 +00:00
}
2002-03-15 23:41:40 +00:00
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 ;
}
2002-05-10 20:31:01 +00:00
2006-02-24 19:47:47 +00:00
if ( ! options [ BLDOPT ] . doesOccur ) {
2003-09-20 19:27:38 +00:00
/* Try to fill in from icu-config or equivalent */
fillInMakefileFromICUConfig ( & options [ 1 ] ) ;
2002-05-10 20:31:01 +00:00
}
2004-11-02 00:27:43 +00:00
# ifdef U_MAKE_IS_NMAKE
2003-09-20 19:27:38 +00:00
else {
fprintf ( stderr , " Warning: You are using the deprecated -O option \n "
" \t You can fix this warning by installing pkgdata, gencmn and genccode \n "
" \t into the same directory and not specifying the -O option to pkgdata. \n " ) ;
}
# endif
2002-05-10 20:31:01 +00:00
2006-02-24 19:47:47 +00:00
if ( ! options [ BLDOPT ] . doesOccur ) {
2003-09-20 19:27:38 +00:00
fprintf ( stderr , " required parameter is missing: -O is required \n " ) ;
fprintf ( stderr , " Run '%s --help' for help. \n " , progname ) ;
return 1 ;
2002-05-10 20:31:01 +00:00
}
2003-09-20 19:27:38 +00:00
2006-02-24 19:47:47 +00:00
if ( ! options [ NAME ] . doesOccur ) /* -O we already have - don't report it. */
2002-05-10 20:31:01 +00:00
{
2003-09-20 19:27:38 +00:00
fprintf ( stderr , " required parameter -p is missing \n " ) ;
fprintf ( stderr , " Run '%s --help' for help. \n " , progname ) ;
return 1 ;
2002-03-15 23:41:40 +00:00
}
if ( argc = = 1 ) {
fprintf ( stderr ,
" No input files specified. \n "
" Run '%s --help' for help. \n " , progname ) ;
return 1 ;
}
} /* end !needsHelp */
2000-06-14 00:50:58 +00:00
2002-03-15 23:41:40 +00:00
if ( argc < 0 | | needsHelp ) {
fprintf ( stderr ,
2001-10-16 16:49:49 +00:00
" usage: %s [-options] [-] [packageFile] \n "
2000-06-14 00:50:58 +00:00
" \t Produce packaged ICU data from the given list(s) of files. \n "
2001-10-16 16:49:49 +00:00
" \t '-' by itself means to read from stdin. \n "
" \t packageFile is a text file containing the list of files to package. \n " ,
2000-06-14 00:50:58 +00:00
progname ) ;
2001-03-21 23:22:16 +00:00
2002-03-15 23:41:40 +00:00
fprintf ( stderr , " \n options: \n " ) ;
for ( i = 0 ; i < ( sizeof ( options ) / sizeof ( options [ 0 ] ) ) ; i + + ) {
fprintf ( stderr , " %-5s -%c %s%-10s %s \n " ,
2004-05-06 05:48:45 +00:00
( i < 1 ? " [REQ] " : " " ) ,
2002-03-15 23:41:40 +00:00
options [ i ] . shortName ,
options [ i ] . longName ? " or -- " : " " ,
options [ i ] . longName ? options [ i ] . longName : " " ,
options_help [ i ] ) ;
}
2000-06-14 00:50:58 +00:00
2002-03-15 23:41:40 +00:00
fprintf ( stderr , " modes: (-m option) \n " ) ;
for ( i = 0 ; i < ( sizeof ( modes ) / sizeof ( modes [ 0 ] ) ) ; i + + ) {
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 ;
2000-06-14 00:50:58 +00:00
}
2002-03-15 23:41:40 +00:00
/* OK, fill in the options struct */
uprv_memset ( & o , 0 , sizeof ( o ) ) ;
2006-02-24 19:47:47 +00:00
o . mode = options [ MODE ] . value ;
o . version = options [ REVISION ] . doesOccur ? options [ REVISION ] . value : 0 ;
o . makeArgs = options [ MAKEARG ] . value ;
2002-03-15 23:41:40 +00:00
o . fcn = NULL ;
for ( i = 0 ; i < sizeof ( modes ) / sizeof ( modes [ 0 ] ) ; i + + ) {
if ( ! uprv_strcmp ( modes [ i ] . name , o . mode ) ) {
o . fcn = modes [ i ] . fcn ;
break ;
} else if ( modes [ i ] . alt_name & & ! uprv_strcmp ( modes [ i ] . alt_name , o . mode ) ) {
o . mode = modes [ i ] . name ;
o . fcn = modes [ i ] . fcn ;
break ;
}
2000-06-14 00:50:58 +00:00
}
2002-03-15 23:41:40 +00:00
if ( o . fcn = = NULL ) {
fprintf ( stderr , " Error: invalid mode '%s' specified. Run '%s --help' to list valid modes. \n " , o . mode , progname ) ;
return 1 ;
}
2000-06-14 00:50:58 +00:00
2002-03-15 23:41:40 +00:00
o . shortName = options [ 0 ] . value ;
2003-12-11 05:00:40 +00:00
{
int32_t len = ( int32_t ) uprv_strlen ( o . shortName ) ;
2002-03-16 21:16:02 +00:00
char * csname , * cp ;
const char * sp ;
2002-03-16 21:54:32 +00:00
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 : ' _ ' ;
}
2002-03-16 21:16:02 +00:00
}
* cp = 0 ;
o . cShortName = csname ;
}
2006-02-24 19:47:47 +00:00
if ( options [ LIBNAME ] . doesOccur ) { /* get libname from shortname, or explicit -L parameter */
o . libName = options [ LIBNAME ] . value ;
2004-04-14 20:08:16 +00:00
} else {
o . libName = o . shortName ;
}
2006-02-24 19:47:47 +00:00
if ( options [ QUIET ] . doesOccur ) {
2004-05-11 05:17:14 +00:00
o . quiet = TRUE ;
} else {
o . quiet = FALSE ;
}
2006-02-24 19:47:47 +00:00
o . verbose = options [ VERBOSE ] . doesOccur ;
2004-11-02 00:27:43 +00:00
# ifdef U_MAKE_IS_NMAKE /* format is R:pathtoICU or D:pathtoICU */
2002-03-15 23:41:40 +00:00
{
2006-02-24 19:47:47 +00:00
char * pathstuff = ( char * ) options [ BLDOPT ] . value ;
if ( options [ 1 ] . value [ uprv_strlen ( options [ BLDOPT ] . value ) - 1 ] = = ' \\ ' ) {
pathstuff [ uprv_strlen ( options [ BLDOPT ] . value ) - 1 ] = ' \0 ' ;
2002-03-15 23:41:40 +00:00
}
2003-09-20 19:27:38 +00:00
if ( * pathstuff = = PKGDATA_DERIVED_PATH | | * pathstuff = = ' R ' | | * pathstuff = = ' D ' ) {
2002-03-15 23:41:40 +00:00
o . options = pathstuff ;
pathstuff + + ;
if ( * pathstuff = = ' : ' ) {
* pathstuff = ' \0 ' ;
pathstuff + + ;
2003-09-15 22:42:00 +00:00
}
2003-09-20 19:27:38 +00:00
else {
fprintf ( stderr , " Error: invalid windows build mode, should be R (release) or D (debug). \n " ) ;
2002-03-15 23:41:40 +00:00
return 1 ;
}
} else {
2003-09-20 19:27:38 +00:00
fprintf ( stderr , " Error: invalid windows build mode, should be R (release) or D (debug). \n " ) ;
return 1 ;
2002-03-15 23:41:40 +00:00
}
o . icuroot = pathstuff ;
2003-09-20 19:27:38 +00:00
if ( o . verbose ) {
fprintf ( stdout , " # ICUROOT is %s \n " , o . icuroot ) ;
}
2002-03-15 23:41:40 +00:00
}
2000-07-19 20:58:13 +00:00
# else /* on UNIX, we'll just include the file... */
2006-02-24 19:47:47 +00:00
o . options = options [ BLDOPT ] . value ;
2000-07-19 20:58:13 +00:00
# endif
2006-02-24 19:47:47 +00:00
if ( options [ COPYRIGHT ] . doesOccur ) {
2002-03-15 23:41:40 +00:00
o . comment = U_COPYRIGHT_STRING ;
2006-02-24 19:47:47 +00:00
} else if ( options [ COMMENT ] . doesOccur ) {
o . comment = options [ COMMENT ] . value ;
2002-03-15 23:41:40 +00:00
}
2006-02-24 19:47:47 +00:00
if ( options [ DESTDIR ] . doesOccur ) {
o . targetDir = options [ DESTDIR ] . value ;
2002-03-15 23:41:40 +00:00
} else {
2002-07-31 00:50:42 +00:00
o . targetDir = " . " ; /* cwd */
2000-06-14 00:50:58 +00:00
}
2006-02-24 19:47:47 +00:00
o . clean = options [ CLEAN ] . doesOccur ;
o . nooutput = options [ NOOUTPUT ] . doesOccur ;
o . rebuild = options [ REBUILD ] . doesOccur ;
2003-07-18 00:46:04 +00:00
2006-02-24 19:47:47 +00:00
if ( options [ TEMPDIR ] . doesOccur ) {
o . tmpDir = options [ TEMPDIR ] . value ;
2002-03-15 23:41:40 +00:00
} else {
o . tmpDir = o . targetDir ;
}
2006-02-24 19:47:47 +00:00
if ( options [ INSTALL ] . doesOccur ) {
o . install = options [ INSTALL ] . value ;
2002-03-15 23:41:40 +00:00
}
2006-02-24 19:47:47 +00:00
if ( options [ SOURCEDIR ] . doesOccur ) {
o . srcDir = options [ SOURCEDIR ] . value ;
2002-03-15 23:41:40 +00:00
} else {
o . srcDir = " . " ;
}
2006-02-24 19:47:47 +00:00
if ( options [ ENTRYPOINT ] . doesOccur ) {
o . entryName = options [ ENTRYPOINT ] . value ;
2002-03-15 23:41:40 +00:00
} else {
2002-03-16 21:16:02 +00:00
o . entryName = o . cShortName ;
2002-03-15 23:41:40 +00:00
}
/* OK options are set up. Now the file lists. */
tail = NULL ;
for ( i = 1 ; i < argc ; i + + ) {
if ( ! uprv_strcmp ( argv [ i ] , " - " ) ) {
/* stdin */
if ( o . hadStdin = = TRUE ) {
fprintf ( stderr , " Error: can't specify '-' twice! \n "
" Run '%s --help' for help. \n " , progname ) ;
return 1 ;
}
o . hadStdin = TRUE ;
}
o . fileListFiles = pkg_appendToList ( o . fileListFiles , & tail , uprv_strdup ( argv [ i ] ) ) ;
}
/* load the files */
loadLists ( & o , & status ) ;
if ( U_FAILURE ( status ) ) {
fprintf ( stderr , " error loading input file lists: %s \n " , u_errorName ( status ) ) ;
return 2 ;
}
/* Makefile pathname */
uprv_strcpy ( tmp , o . tmpDir ) ;
2005-03-11 16:08:37 +00:00
# ifdef U_MAKE_IS_NMAKE
2002-03-15 23:41:40 +00:00
uprv_strcat ( tmp , U_FILE_SEP_STRING ) ;
2005-03-11 16:08:37 +00:00
# else
uprv_strcat ( tmp , U_FILE_ALT_SEP_STRING ) ;
# endif
2002-03-15 23:41:40 +00:00
uprv_strcat ( tmp , o . shortName ) ;
uprv_strcat ( tmp , " _ " ) ;
uprv_strcat ( tmp , o . mode ) ;
uprv_strcat ( tmp , " .mak " ) ; /* MAY NEED TO CHANGE PER PLATFORM */
o . makeFile = uprv_strdup ( tmp ) ;
out = T_FileStream_open ( o . makeFile , " w " ) ;
if ( out ) {
pkg_mak_writeHeader ( out , & o ) ; /* need to take status */
o . fcn ( & o , out , & status ) ;
pkg_mak_writeFooter ( out , & o ) ;
T_FileStream_close ( out ) ;
} else {
fprintf ( stderr , " warning: couldn't create %s, will use existing file if any \n " , o . makeFile ) ;
/*status = U_FILE_ACCESS_ERROR;*/
}
if ( U_FAILURE ( status ) ) {
fprintf ( stderr , " Error creating makefile [%s]: %s \n " , o . mode ,
2000-06-14 00:50:58 +00:00
u_errorName ( status ) ) ;
2002-03-15 23:41:40 +00:00
return 1 ;
}
2000-06-14 00:50:58 +00:00
2002-03-15 23:41:40 +00:00
if ( o . nooutput = = TRUE ) {
return 0 ; /* nothing to do. */
}
2001-03-21 23:22:16 +00:00
2002-03-15 23:41:40 +00:00
return executeMakefile ( & o ) ;
2000-09-30 02:35:31 +00:00
}
/* POSIX - execute makefile */
static int executeMakefile ( const UPKGOptions * o )
{
2002-03-15 23:41:40 +00:00
char cmd [ 1024 ] ;
/*char pwd[1024];*/
const char * make ;
int rc ;
2001-03-21 23:22:16 +00:00
2002-03-15 23:41:40 +00:00
make = getenv ( " MAKE " ) ;
2000-06-14 00:50:58 +00:00
2002-03-15 23:41:40 +00:00
if ( ! make | | ! make [ 0 ] ) {
make = U_MAKE ;
}
2000-06-14 00:50:58 +00:00
2002-03-15 23:41:40 +00:00
/*getcwd(pwd, 1024);*/
2005-02-17 00:19:44 +00:00
# ifdef U_WINDOWS
2002-03-15 23:41:40 +00:00
sprintf ( cmd , " %s %s%s -f \" %s \" %s %s %s %s " ,
make ,
o - > install ? " INSTALLTO= " : " " ,
o - > install ? o - > install : " " ,
o - > makeFile ,
o - > clean ? " clean " : " " ,
o - > rebuild ? " rebuild " : " " ,
o - > install ? " install " : " " ,
o - > makeArgs ) ;
2005-07-18 21:43:48 +00:00
# elif defined(OS400)
2005-03-18 19:54:21 +00:00
sprintf ( cmd , " CALL GNU/GMAKE PARM(%s%s%s '-f' '%s' %s %s %s %s%s%s) " ,
2002-03-15 23:41:40 +00:00
o - > install ? " 'INSTALLTO= " : " " ,
o - > install ? o - > install : " " ,
o - > install ? " ' " : " " ,
o - > makeFile ,
o - > clean ? " 'clean' " : " " ,
o - > rebuild ? " 'rebuild' " : " " ,
o - > install ? " 'install' " : " " ,
2005-03-19 01:42:01 +00:00
o - > makeArgs & & * o - > makeArgs ? " ' " : " " ,
2005-04-08 00:04:08 +00:00
o - > makeArgs & & * o - > makeArgs ? o - > makeArgs : " " ,
2005-03-19 01:42:01 +00:00
o - > makeArgs & & * o - > makeArgs ? " ' " : " " ) ;
2000-08-08 23:20:37 +00:00
# else
2002-03-15 23:41:40 +00:00
sprintf ( cmd , " %s %s%s -f %s %s %s %s %s " ,
make ,
o - > install ? " INSTALLTO= " : " " ,
o - > install ? o - > install : " " ,
o - > makeFile ,
o - > clean ? " clean " : " " ,
o - > rebuild ? " rebuild " : " " ,
o - > install ? " install " : " " ,
o - > makeArgs ) ;
2000-08-08 23:20:37 +00:00
# endif
2002-03-15 23:41:40 +00:00
if ( o - > verbose ) {
puts ( cmd ) ;
}
2000-06-14 00:50:58 +00:00
2002-03-15 23:41:40 +00:00
rc = system ( cmd ) ;
2001-03-21 23:22:16 +00:00
2002-03-15 23:41:40 +00:00
if ( rc < 0 ) {
fprintf ( stderr , " # Failed, rc=%d \n " , rc ) ;
}
2002-03-16 21:16:02 +00:00
2002-03-15 23:41:40 +00:00
return rc < 128 ? rc : ( rc > > 8 ) ;
2000-06-14 00:50:58 +00:00
}
2000-09-30 02:35:31 +00:00
2000-06-14 00:50:58 +00:00
static void loadLists ( UPKGOptions * o , UErrorCode * status )
{
2003-05-03 00:44:47 +00:00
CharList * l , * tail = NULL , * tail2 = NULL ;
FileStream * in ;
char line [ 16384 ] ;
char * linePtr , * lineNext ;
const uint32_t lineMax = 16300 ;
2004-04-14 20:08:16 +00:00
char tmp [ 1024 ] ;
2003-05-03 00:44:47 +00:00
char * s ;
2004-04-14 20:08:16 +00:00
int32_t ln = 0 ; /* line number */
2003-05-03 00:44:47 +00:00
for ( l = o - > fileListFiles ; l ; l = l - > next ) {
if ( o - > verbose ) {
fprintf ( stdout , " # Reading %s.. \n " , l - > str ) ;
2002-03-15 23:41:40 +00:00
}
2003-05-03 00:44:47 +00:00
/* TODO: stdin */
2004-04-14 20:08:16 +00:00
in = T_FileStream_open ( l - > str , " r " ) ; /* open files list */
2003-05-03 00:44:47 +00:00
if ( ! in ) {
fprintf ( stderr , " Error opening <%s>. \n " , l - > str ) ;
* status = U_FILE_ACCESS_ERROR ;
return ;
2002-07-31 20:28:32 +00:00
}
2004-04-14 20:08:16 +00:00
while ( T_FileStream_readLine ( in , line , sizeof ( line ) ) ! = NULL ) { /* for each line */
2006-02-24 19:47:47 +00:00
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 ) ;
2003-05-03 00:44:47 +00:00
}
2006-02-24 19:47:47 +00:00
/* remove spaces at the beginning */
linePtr = line ;
while ( isspace ( * linePtr ) ) {
linePtr + + ;
2003-05-03 00:44:47 +00:00
}
2006-02-24 19:47:47 +00:00
s = linePtr ;
/* remove trailing newline characters */
while ( * s ! = 0 ) {
if ( * s = = ' \r ' | | * s = = ' \n ' ) {
* s = 0 ;
break ;
}
2003-05-03 00:44:47 +00:00
+ + s ;
2002-03-15 23:41:40 +00:00
}
2006-02-24 19:47:47 +00:00
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 + + ;
}
}
2003-05-03 00:44:47 +00:00
} else {
2006-02-24 19:47:47 +00:00
lineNext = uprv_strchr ( linePtr , ' ' ) ;
if ( lineNext ) {
* lineNext = 0 ; /* terminate at space */
lineNext + + ;
2003-05-03 00:44:47 +00:00
}
}
2006-02-24 19:47:47 +00:00
/* 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 ) ) ;
2006-08-14 22:59:10 +00:00
if ( uprv_pathIsAbsolute ( s ) ) {
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 ) ;
}
2004-04-14 20:08:16 +00:00
uprv_strcpy ( tmp , o - > srcDir ) ;
uprv_strcat ( tmp , o - > srcDir [ uprv_strlen ( o - > srcDir ) - 1 ] = = U_FILE_SEP_CHAR ? " " : U_FILE_SEP_STRING ) ;
uprv_strcat ( tmp , s ) ;
o - > filePaths = pkg_appendToList ( o - > filePaths , & tail2 , uprv_strdup ( tmp ) ) ;
2006-02-24 19:47:47 +00:00
linePtr = lineNext ;
} /* for each entry on line */
2004-04-14 20:08:16 +00:00
} /* for each line */
2003-05-03 00:44:47 +00:00
T_FileStream_close ( in ) ;
2004-04-14 20:08:16 +00:00
} /* for each file list file */
2000-06-14 00:50:58 +00:00
}
2002-05-10 20:31:01 +00:00
/* Try calling icu-config directly to get information */
2004-01-06 21:52:08 +00:00
static void fillInMakefileFromICUConfig ( UOption * option )
2002-05-10 20:31:01 +00:00
{
2002-05-29 22:05:20 +00:00
# if U_HAVE_POPEN
2003-09-20 19:27:38 +00:00
FILE * p ;
size_t n ;
static char buf [ 512 ] = " " ;
static const char cmd [ ] = " icu-config --incfile " ;
if ( options [ 5 ] . doesOccur )
{
/* informational */
fprintf ( stderr , " %s: No -O option found, trying '%s'. \n " , progname , cmd ) ;
}
p = popen ( cmd , " r " ) ;
if ( p = = NULL )
{
fprintf ( stderr , " %s: icu-config: No icu-config found. (fix PATH or use -O option) \n " , progname ) ;
return ;
}
n = fread ( buf , 1 , 511 , p ) ;
pclose ( p ) ;
if ( n < = 0 )
{
fprintf ( stderr , " %s: icu-config: Could not read from icu-config. (fix PATH or use -O option) \n " , progname ) ;
return ;
}
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 ;
}
if ( options [ 5 ] . doesOccur )
{
/* informational */
fprintf ( stderr , " %s: icu-config: using '-O %s' \n " , progname , buf ) ;
}
option - > value = buf ;
option - > doesOccur = TRUE ;
2002-05-29 22:05:20 +00:00
# else /* ! U_HAVE_POPEN */
2005-02-17 00:19:44 +00:00
# ifdef U_WINDOWS
2003-09-22 01:05:13 +00:00
char pathbuffer [ _MAX_PATH ] = { 0 } ;
char * fullEXEpath = NULL ;
char * pathstuff = NULL ;
if ( strchr ( progname , U_FILE_SEP_CHAR ) ! = NULL | | strchr ( progname , U_FILE_ALT_SEP_CHAR ) ! = NULL ) {
/* pkgdata was executed with relative path */
fullEXEpath = _fullpath ( pathbuffer , progname , sizeof ( pathbuffer ) ) ;
pathstuff = ( char * ) options [ 1 ] . value ;
if ( fullEXEpath ) {
pathstuff = strrchr ( fullEXEpath , U_FILE_SEP_CHAR ) ;
if ( pathstuff ) {
pathstuff [ 1 ] = 0 ;
uprv_memmove ( fullEXEpath + 2 , fullEXEpath , uprv_strlen ( fullEXEpath ) + 1 ) ;
fullEXEpath [ 0 ] = PKGDATA_DERIVED_PATH ;
fullEXEpath [ 1 ] = ' : ' ;
option - > value = uprv_strdup ( fullEXEpath ) ;
option - > doesOccur = TRUE ;
}
}
}
else {
/* pkgdata was executed from the path */
/* Search for file in PATH environment variable: */
_searchenv ( " pkgdata.exe " , " PATH " , pathbuffer ) ;
if ( * pathbuffer ! = ' \0 ' ) {
fullEXEpath = pathbuffer ;
pathstuff = strrchr ( pathbuffer , U_FILE_SEP_CHAR ) ;
if ( pathstuff ) {
pathstuff [ 1 ] = 0 ;
uprv_memmove ( fullEXEpath + 2 , fullEXEpath , uprv_strlen ( fullEXEpath ) + 1 ) ;
fullEXEpath [ 0 ] = PKGDATA_DERIVED_PATH ;
fullEXEpath [ 1 ] = ' : ' ;
option - > value = uprv_strdup ( fullEXEpath ) ;
option - > doesOccur = TRUE ;
}
2003-09-20 19:27:38 +00:00
}
}
/* else can't determine the path */
# endif
/* no popen available */
/* Put other OS specific ways to search for the Makefile.inc type
information or else fail . . */
2002-05-29 22:05:20 +00:00
# endif
2002-05-10 20:31:01 +00:00
}