~ubuntu-branches/ubuntu/gutsy/icu/gutsy

« back to all changes in this revision

Viewing changes to source/tools/pkgdata/pkgdata.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2005-05-21 22:44:31 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: package-import@ubuntu.com-20050521224431-r7rktfhnu1n4tf1g
Tags: 2.1-2.1
Rename icu-doc to icu21-doc. icu-doc is built by the icu28 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
/* This sets the modes that are available */
39
39
static struct
40
40
{
41
 
  const char *name, *alt_name;
42
 
  UPKGMODE   *fcn;
43
 
  const char *desc;
 
41
    const char *name, *alt_name;
 
42
    UPKGMODE   *fcn;
 
43
    const char *desc;
44
44
} modes[] =
45
45
{
46
 
  { "files", 0, pkg_mode_files, "Uses raw data files (no effect). Installation copies all files to the target location." },
 
46
    { "files", 0, pkg_mode_files, "Uses raw data files (no effect). Installation copies all files to the target location." },
47
47
#ifdef WIN32
48
 
  { "dll",    "library", pkg_mode_windows,    "Generates one common data file and one shared library, <package>.dll"},
49
 
  { "common", "archive", pkg_mode_windows,    "Generates just the common file, <package>.dat"}
 
48
    { "dll",    "library", pkg_mode_windows,    "Generates one common data file and one shared library, <package>.dll"},
 
49
    { "common", "archive", pkg_mode_windows,    "Generates just the common file, <package>.dat"},
 
50
    { "static", "static",  pkg_mode_windows,    "Generates one statically linked library, " LIB_PREFIX "<package>" UDATA_LIB_SUFFIX }
50
51
#else /*#ifdef WIN32*/
51
52
#ifdef UDATA_SO_SUFFIX
52
 
  { "dll",    "library", pkg_mode_dll,    "Generates one shared library, <package>" UDATA_SO_SUFFIX },
 
53
    { "dll",    "library", pkg_mode_dll,    "Generates one shared library, <package>" UDATA_SO_SUFFIX },
53
54
#endif
54
 
  { "common", "archive", pkg_mode_common, "Generates one common data file, <package>.dat" },
55
 
  { "static", "static",  pkg_mode_static, "Generates one statically linked library, " LIB_PREFIX "<package>" UDATA_LIB_SUFFIX }
 
55
    { "common", "archive", pkg_mode_common, "Generates one common data file, <package>.dat" },
 
56
    { "static", "static",  pkg_mode_static, "Generates one statically linked library, " LIB_PREFIX "<package>" UDATA_LIB_SUFFIX }
56
57
#endif /*#ifdef WIN32*/
57
58
};
58
59
 
59
60
static UOption options[]={
60
 
/*00*/    UOPTION_DEF( "name",    'p', UOPT_REQUIRES_ARG),
61
 
/*01*/    UOPTION_DEF( "bldopt",  'O', UOPT_REQUIRES_ARG), /* on Win32 it is release or debug */
62
 
/*02*/    UOPTION_DEF( "mode",    'm', UOPT_REQUIRES_ARG),
63
 
/*03*/    UOPTION_HELP_H,                                   /* -h */
64
 
/*04*/    UOPTION_HELP_QUESTION_MARK,                       /* -? */
65
 
/*05*/    UOPTION_VERBOSE,                                  /* -v */
66
 
/*06*/    UOPTION_COPYRIGHT,                                /* -c */
67
 
/*07*/    UOPTION_DEF( "comment", 'C', UOPT_REQUIRES_ARG),
68
 
/*08*/    UOPTION_DESTDIR,                                  /* -d */
69
 
/*09*/    UOPTION_DEF( "clean",   'k', UOPT_NO_ARG),
70
 
/*10*/    UOPTION_DEF( "nooutput",'n', UOPT_NO_ARG),
71
 
/*11*/    UOPTION_DEF( "rebuild", 'F', UOPT_NO_ARG),
72
 
/*12*/    UOPTION_DEF( "tempdir", 'T', UOPT_REQUIRES_ARG),
73
 
/*13*/    UOPTION_DEF( "install", 'I', UOPT_REQUIRES_ARG),
74
 
/*14*/    UOPTION_SOURCEDIR ,
75
 
/*15*/    UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG),
76
 
/*16*/    UOPTION_DEF( "revision", 'r', UOPT_REQUIRES_ARG),
77
 
/*17*/    UOPTION_DEF( 0, 'M', UOPT_REQUIRES_ARG)
 
61
    /*00*/    UOPTION_DEF( "name",    'p', UOPT_REQUIRES_ARG),
 
62
    /*01*/    UOPTION_DEF( "bldopt",  'O', UOPT_REQUIRES_ARG), /* on Win32 it is release or debug */
 
63
    /*02*/    UOPTION_DEF( "mode",    'm', UOPT_REQUIRES_ARG),
 
64
    /*03*/    UOPTION_HELP_H,                                   /* -h */
 
65
    /*04*/    UOPTION_HELP_QUESTION_MARK,                       /* -? */
 
66
    /*05*/    UOPTION_VERBOSE,                                  /* -v */
 
67
    /*06*/    UOPTION_COPYRIGHT,                                /* -c */
 
68
    /*07*/    UOPTION_DEF( "comment", 'C', UOPT_REQUIRES_ARG),
 
69
    /*08*/    UOPTION_DESTDIR,                                  /* -d */
 
70
    /*09*/    UOPTION_DEF( "clean",   'k', UOPT_NO_ARG),
 
71
    /*10*/    UOPTION_DEF( "nooutput",'n', UOPT_NO_ARG),
 
72
    /*11*/    UOPTION_DEF( "rebuild", 'F', UOPT_NO_ARG),
 
73
    /*12*/    UOPTION_DEF( "tempdir", 'T', UOPT_REQUIRES_ARG),
 
74
    /*13*/    UOPTION_DEF( "install", 'I', UOPT_REQUIRES_ARG),
 
75
    /*14*/    UOPTION_SOURCEDIR ,
 
76
    /*15*/    UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG),
 
77
    /*16*/    UOPTION_DEF( "revision", 'r', UOPT_REQUIRES_ARG),
 
78
    /*17*/    UOPTION_DEF( 0, 'M', UOPT_REQUIRES_ARG)
78
79
};
79
80
 
80
81
const char options_help[][160]={
81
 
  "Set the data name",
 
82
    "Set the data name",
82
83
#ifdef WIN32
83
 
      "R:icupath for release version or D:icupath for debug version, where icupath is the directory where ICU is located",
 
84
    "R:icupath for release version or D:icupath for debug version, where icupath is the directory where ICU is located",
84
85
#else
85
 
      "Specify options for the builder",
 
86
    "Specify options for the builder",
86
87
#endif
87
 
  "Specify the mode of building (see below; default: common)",
88
 
  "This usage text",
89
 
  "This usage text",
90
 
  "Make the output verbose",
91
 
  "Use the standard ICU copyright",
92
 
  "Use a custom comment (instead of the copyright)",
93
 
  "Specify the destination directory for files",
94
 
  "Clean out generated & temporary files",
95
 
  "Suppress output of data, just list files to be created",
96
 
  "Force rebuilding of all data",
97
 
  "Specify temporary dir (default: output dir)",
98
 
  "Install the data (specify target)",
99
 
  "Specify a custom source directory",
100
 
  "Specify a custom entrypoint name (default: short name)",
101
 
  "Specify a version when packaging in DLL mode",
102
 
  "Pass the next argument to make(1)"
 
88
    "Specify the mode of building (see below; default: common)",
 
89
    "This usage text",
 
90
    "This usage text",
 
91
    "Make the output verbose",
 
92
    "Use the standard ICU copyright",
 
93
    "Use a custom comment (instead of the copyright)",
 
94
    "Specify the destination directory for files",
 
95
    "Clean out generated & temporary files",
 
96
    "Suppress output of data, just list files to be created",
 
97
    "Force rebuilding of all data",
 
98
    "Specify temporary dir (default: output dir)",
 
99
    "Install the data (specify target)",
 
100
    "Specify a custom source directory",
 
101
    "Specify a custom entrypoint name (default: short name)",
 
102
    "Specify a version when packaging in DLL or static mode",
 
103
    "Pass the next argument to make(1)"
103
104
};
104
105
 
105
106
int
106
107
main(int argc, char* argv[]) {
107
 
  FileStream  *out;
108
 
  UPKGOptions  o;
109
 
  CharList    *tail;
110
 
  const char  *progname;
111
 
  UBool        needsHelp = FALSE;
112
 
  UErrorCode   status = U_ZERO_ERROR;
113
 
  char         tmp[1024];
114
 
  int32_t i;
115
 
 
116
 
  progname = argv[0];
117
 
 
118
 
  options[2].value = "common";
119
 
  options[17].value = "";
120
 
 
121
 
  /* read command line options */
122
 
  argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
123
 
 
124
 
  /* error handling, printing usage message */
125
 
  /* I've decided to simply print an error and quit. This tool has too
126
 
     many options to just display them all of the time. */
127
 
 
128
 
  if(options[3].doesOccur || options[4].doesOccur) {
129
 
    needsHelp = TRUE;
130
 
  }
131
 
  else {
132
 
    if(!needsHelp && argc<0) {
133
 
      fprintf(stderr,
134
 
              "%s: error in command line argument \"%s\"\n",
135
 
              progname,
136
 
              argv[-argc]);
137
 
      fprintf(stderr, "Run '%s --help' for help.\n", progname);
138
 
      return 1;
139
 
    }
140
 
    if(! (options[0].doesOccur && options[1].doesOccur) ) {
141
 
      fprintf(stderr, " required parameters are missing: -p and -O are required \n");
142
 
      fprintf(stderr, "Run '%s --help' for help.\n", progname);
143
 
      return 1;
144
 
    }
145
 
 
146
 
    if(argc == 1) {
147
 
      fprintf(stderr,
148
 
              "No input files specified.\n"
149
 
              "Run '%s --help' for help.\n", progname);
150
 
      return 1;
151
 
    }
152
 
  }   /* end !needsHelp */
153
 
 
154
 
  if(argc<0 || needsHelp  ) {
155
 
    fprintf(stderr,
 
108
    FileStream  *out;
 
109
    UPKGOptions  o;
 
110
    CharList    *tail;
 
111
    const char  *progname;
 
112
    UBool        needsHelp = FALSE;
 
113
    UErrorCode   status = U_ZERO_ERROR;
 
114
    char         tmp[1024];
 
115
    int32_t i;
 
116
 
 
117
    U_MAIN_INIT_ARGS(argc, argv);
 
118
 
 
119
    progname = argv[0];
 
120
 
 
121
    options[2].value = "common";
 
122
    options[17].value = "";
 
123
 
 
124
    /* read command line options */
 
125
    argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
 
126
 
 
127
    /* error handling, printing usage message */
 
128
    /* I've decided to simply print an error and quit. This tool has too
 
129
    many options to just display them all of the time. */
 
130
 
 
131
    if(options[3].doesOccur || options[4].doesOccur) {
 
132
        needsHelp = TRUE;
 
133
    }
 
134
    else {
 
135
        if(!needsHelp && argc<0) {
 
136
            fprintf(stderr,
 
137
                "%s: error in command line argument \"%s\"\n",
 
138
                progname,
 
139
                argv[-argc]);
 
140
            fprintf(stderr, "Run '%s --help' for help.\n", progname);
 
141
            return 1;
 
142
        }
 
143
        if(! (options[0].doesOccur && options[1].doesOccur) ) {
 
144
            fprintf(stderr, " required parameters are missing: -p and -O are required \n");
 
145
            fprintf(stderr, "Run '%s --help' for help.\n", progname);
 
146
            return 1;
 
147
        }
 
148
 
 
149
        if(argc == 1) {
 
150
            fprintf(stderr,
 
151
                "No input files specified.\n"
 
152
                "Run '%s --help' for help.\n", progname);
 
153
            return 1;
 
154
        }
 
155
    }   /* end !needsHelp */
 
156
 
 
157
    if(argc<0 || needsHelp  ) {
 
158
        fprintf(stderr,
156
159
            "usage: %s [-options] [-] [packageFile] \n"
157
160
            "\tProduce packaged ICU data from the given list(s) of files.\n"
158
161
            "\t'-' by itself means to read from stdin.\n"
159
162
            "\tpackageFile is a text file containing the list of files to package.\n",
160
163
            progname);
161
164
 
162
 
    fprintf(stderr, "\n options:\n");
163
 
    for(i=0;i<(sizeof(options)/sizeof(options[0]));i++) {
164
 
      fprintf(stderr, "%-5s -%c %s%-10s  %s\n",
165
 
              (i<2?"[REQ]":""),
166
 
              options[i].shortName,
167
 
              options[i].longName ? "or --" : "     ",
168
 
              options[i].longName ? options[i].longName : "",
169
 
              options_help[i]);
170
 
    }
171
 
 
172
 
    fprintf(stderr, "modes: (-m option)\n");
173
 
    for(i=0;i<(sizeof(modes)/sizeof(modes[0]));i++) {
174
 
      fprintf(stderr, "   %-9s ", modes[i].name);
175
 
      if (modes[i].alt_name) {
176
 
        fprintf(stderr, "/ %-9s", modes[i].alt_name);
177
 
      } else {
178
 
        fprintf(stderr, "           ");
179
 
      }
180
 
      fprintf(stderr, "  %s\n", modes[i].desc);
181
 
    }
182
 
    return 1;
183
 
  }
184
 
 
185
 
  /* OK, fill in the options struct */
186
 
  uprv_memset(&o, 0, sizeof(o));
187
 
 
188
 
  o.mode      = options[2].value;
189
 
  o.version   = options[16].doesOccur ? options[16].value : 0;
190
 
  o.makeArgs  = options[17].value;
191
 
 
192
 
  o.fcn = NULL;
193
 
 
194
 
  for(i=0;i<sizeof(modes)/sizeof(modes[0]);i++) {
195
 
    if(!uprv_strcmp(modes[i].name, o.mode)) {
196
 
      o.fcn = modes[i].fcn;
197
 
      break;
198
 
    } else if (modes[i].alt_name && !uprv_strcmp(modes[i].alt_name, o.mode)) {
199
 
      o.mode = modes[i].name;
200
 
      o.fcn = modes[i].fcn;
201
 
      break;
202
 
    }
203
 
  }
204
 
 
205
 
  if(o.fcn == NULL) {
206
 
    fprintf(stderr, "Error: invalid mode '%s' specified. Run '%s --help' to list valid modes.\n", o.mode, progname);
207
 
    return 1;
208
 
  }
209
 
 
210
 
  o.shortName = options[0].value;
 
165
        fprintf(stderr, "\n options:\n");
 
166
        for(i=0;i<(sizeof(options)/sizeof(options[0]));i++) {
 
167
            fprintf(stderr, "%-5s -%c %s%-10s  %s\n",
 
168
                (i<2?"[REQ]":""),
 
169
                options[i].shortName,
 
170
                options[i].longName ? "or --" : "     ",
 
171
                options[i].longName ? options[i].longName : "",
 
172
                options_help[i]);
 
173
        }
 
174
 
 
175
        fprintf(stderr, "modes: (-m option)\n");
 
176
        for(i=0;i<(sizeof(modes)/sizeof(modes[0]));i++) {
 
177
            fprintf(stderr, "   %-9s ", modes[i].name);
 
178
            if (modes[i].alt_name) {
 
179
                fprintf(stderr, "/ %-9s", modes[i].alt_name);
 
180
            } else {
 
181
                fprintf(stderr, "           ");
 
182
            }
 
183
            fprintf(stderr, "  %s\n", modes[i].desc);
 
184
        }
 
185
        return 1;
 
186
    }
 
187
 
 
188
    /* OK, fill in the options struct */
 
189
    uprv_memset(&o, 0, sizeof(o));
 
190
 
 
191
    o.mode      = options[2].value;
 
192
    o.version   = options[16].doesOccur ? options[16].value : 0;
 
193
    o.makeArgs  = options[17].value;
 
194
 
 
195
    o.fcn = NULL;
 
196
 
 
197
    for(i=0;i<sizeof(modes)/sizeof(modes[0]);i++) {
 
198
        if(!uprv_strcmp(modes[i].name, o.mode)) {
 
199
            o.fcn = modes[i].fcn;
 
200
            break;
 
201
        } else if (modes[i].alt_name && !uprv_strcmp(modes[i].alt_name, o.mode)) {
 
202
            o.mode = modes[i].name;
 
203
            o.fcn = modes[i].fcn;
 
204
            break;
 
205
        }
 
206
    }
 
207
 
 
208
    if(o.fcn == NULL) {
 
209
        fprintf(stderr, "Error: invalid mode '%s' specified. Run '%s --help' to list valid modes.\n", o.mode, progname);
 
210
        return 1;
 
211
    }
 
212
 
 
213
    o.shortName = options[0].value;
 
214
    /**/ {
 
215
        int len = uprv_strlen(o.shortName);
 
216
        char *csname, *cp;
 
217
        const char *sp;
 
218
 
 
219
        cp = csname = (char *) uprv_malloc((len + 1 + 1) * sizeof(*o.cShortName));
 
220
        if (*(sp = o.shortName)) {
 
221
            *cp++ = isalpha(*sp) ? * sp : '_';
 
222
            for (++sp; *sp; ++sp) {
 
223
                *cp++ = isalnum(*sp) ? *sp : '_';
 
224
            }
 
225
        }
 
226
        *cp = 0;
 
227
 
 
228
        o.cShortName = csname;
 
229
    }
 
230
 
211
231
#ifdef WIN32 /* format is R:pathtoICU or D:pathtoICU */
212
 
  {
213
 
      char *pathstuff = (char *)options[1].value;
214
 
      if(options[1].value[uprv_strlen(options[1].value)-1] == '\\') {
215
 
        pathstuff[uprv_strlen(options[1].value)-1] = '\0';
216
 
      }
217
 
      if(*pathstuff == 'R' || *pathstuff == 'D') {
218
 
          o.options = pathstuff;
219
 
          pathstuff++;
220
 
          if(*pathstuff == ':') {
221
 
              *pathstuff = '\0';
222
 
              pathstuff++;
223
 
          } else {
 
232
    {
 
233
        char *pathstuff = (char *)options[1].value;
 
234
        if(options[1].value[uprv_strlen(options[1].value)-1] == '\\') {
 
235
            pathstuff[uprv_strlen(options[1].value)-1] = '\0';
 
236
        }
 
237
        if(*pathstuff == 'R' || *pathstuff == 'D') {
 
238
            o.options = pathstuff;
 
239
            pathstuff++;
 
240
            if(*pathstuff == ':') {
 
241
                *pathstuff = '\0';
 
242
                pathstuff++;
 
243
            } else {
 
244
                fprintf(stderr, "Error: invalid windows build mode, should be R (release) or D (debug).\n", o.mode, progname);
 
245
                return 1;
 
246
            }
 
247
        } else {
224
248
            fprintf(stderr, "Error: invalid windows build mode, should be R (release) or D (debug).\n", o.mode, progname);
225
249
            return 1;
226
 
          }
227
 
      } else {
228
 
        fprintf(stderr, "Error: invalid windows build mode, should be R (release) or D (debug).\n", o.mode, progname);
229
 
        return 1;
230
 
      }
231
 
      o.icuroot = pathstuff;
232
 
  }
 
250
        }
 
251
        o.icuroot = pathstuff;
 
252
    }
233
253
#else /* on UNIX, we'll just include the file... */
234
 
  o.options   = options[1].value;
 
254
    o.options   = options[1].value;
235
255
#endif
236
 
  o.verbose   = options[5].doesOccur;
237
 
  if(options[6].doesOccur) {
238
 
    o.comment = U_COPYRIGHT_STRING;
239
 
  } else if (options[7].doesOccur) {
240
 
    o.comment = options[7].value;
241
 
  }
242
 
 
243
 
  if( options[8].doesOccur ) {
244
 
    o.targetDir = options[8].value;
245
 
  } else {
246
 
    o.targetDir = "";  /* cwd */
247
 
  }
248
 
 
249
 
  o.clean     = options[9].doesOccur;
250
 
  o.nooutput  = options[10].doesOccur;
251
 
  o.rebuild   = options[11].doesOccur;
252
 
 
253
 
  if( options[12].doesOccur ) {
254
 
    o.tmpDir    = options[12].value;
255
 
  } else {
256
 
    o.tmpDir    = o.targetDir;
257
 
  }
258
 
 
259
 
  if( options[13].doesOccur ) {
260
 
    o.install  = options[13].value;
261
 
  }
262
 
 
263
 
  if( options[14].doesOccur ) {
264
 
    o.srcDir   = options[14].value;
265
 
  } else {
266
 
    o.srcDir   = ".";
267
 
  }
268
 
 
269
 
  if( options[15].doesOccur ) {
270
 
    o.entryName = options[15].value;
271
 
  } else {
272
 
    o.entryName = o.shortName;
273
 
  }
274
 
 
275
 
  /* OK options are set up. Now the file lists. */
276
 
  tail = NULL;
277
 
  for( i=1; i<argc; i++) {
278
 
    if ( !uprv_strcmp(argv[i] , "-") ) {
279
 
      /* stdin */
280
 
      if( o.hadStdin == TRUE ) {
281
 
        fprintf(stderr, "Error: can't specify '-' twice!\n"
282
 
                        "Run '%s --help' for help.\n", progname);
283
 
        return 1;
284
 
      }
285
 
      o.hadStdin = TRUE;
286
 
    }
287
 
 
288
 
    o.fileListFiles = pkg_appendToList(o.fileListFiles, &tail, uprv_strdup(argv[i]));
289
 
  }
290
 
 
291
 
  /* load the files */
292
 
  loadLists(&o, &status);
293
 
  if( U_FAILURE(status) ) {
294
 
    fprintf(stderr, "error loading input file lists: %s\n", u_errorName(status));
295
 
    return 2;
296
 
  }
297
 
 
298
 
  /* Makefile pathname */
299
 
  uprv_strcpy(tmp, o.tmpDir);
300
 
  uprv_strcat(tmp, U_FILE_SEP_STRING);
301
 
  uprv_strcat(tmp, o.shortName);
302
 
  uprv_strcat(tmp, "_");
303
 
  uprv_strcat(tmp, o.mode);
304
 
  uprv_strcat(tmp, ".mak");  /* MAY NEED TO CHANGE PER PLATFORM */
305
 
 
306
 
  o.makeFile = uprv_strdup(tmp);
307
 
 
308
 
  out = T_FileStream_open(o.makeFile, "w");
309
 
  if (out) {
310
 
      pkg_mak_writeHeader(out, &o); /* need to take status */
311
 
      o.fcn(&o, out, &status);
312
 
      pkg_mak_writeFooter(out, &o);
313
 
      T_FileStream_close(out);
314
 
  } else {
315
 
      fprintf(stderr, "warning: couldn't create %s, will use existing file if any\n", o.makeFile);
316
 
      /*status = U_FILE_ACCESS_ERROR;*/
317
 
  }
318
 
 
319
 
  if(U_FAILURE(status)) {
320
 
    fprintf(stderr, "Error creating makefile [%s]: %s\n", o.mode,
 
256
    o.verbose   = options[5].doesOccur;
 
257
    if(options[6].doesOccur) {
 
258
        o.comment = U_COPYRIGHT_STRING;
 
259
    } else if (options[7].doesOccur) {
 
260
        o.comment = options[7].value;
 
261
    }
 
262
 
 
263
    if( options[8].doesOccur ) {
 
264
        o.targetDir = options[8].value;
 
265
    } else {
 
266
        o.targetDir = "";  /* cwd */
 
267
    }
 
268
 
 
269
    o.clean     = options[9].doesOccur;
 
270
    o.nooutput  = options[10].doesOccur;
 
271
    o.rebuild   = options[11].doesOccur;
 
272
 
 
273
    if( options[12].doesOccur ) {
 
274
        o.tmpDir    = options[12].value;
 
275
    } else {
 
276
        o.tmpDir    = o.targetDir;
 
277
    }
 
278
 
 
279
    if( options[13].doesOccur ) {
 
280
        o.install  = options[13].value;
 
281
    }
 
282
 
 
283
    if( options[14].doesOccur ) {
 
284
        o.srcDir   = options[14].value;
 
285
    } else {
 
286
        o.srcDir   = ".";
 
287
    }
 
288
 
 
289
    if( options[15].doesOccur ) {
 
290
        o.entryName = options[15].value;
 
291
    } else {
 
292
        o.entryName = o.cShortName;
 
293
    }
 
294
 
 
295
    /* OK options are set up. Now the file lists. */
 
296
    tail = NULL;
 
297
    for( i=1; i<argc; i++) {
 
298
        if ( !uprv_strcmp(argv[i] , "-") ) {
 
299
            /* stdin */
 
300
            if( o.hadStdin == TRUE ) {
 
301
                fprintf(stderr, "Error: can't specify '-' twice!\n"
 
302
                    "Run '%s --help' for help.\n", progname);
 
303
                return 1;
 
304
            }
 
305
            o.hadStdin = TRUE;
 
306
        }
 
307
 
 
308
        o.fileListFiles = pkg_appendToList(o.fileListFiles, &tail, uprv_strdup(argv[i]));
 
309
    }
 
310
 
 
311
    /* load the files */
 
312
    loadLists(&o, &status);
 
313
    if( U_FAILURE(status) ) {
 
314
        fprintf(stderr, "error loading input file lists: %s\n", u_errorName(status));
 
315
        return 2;
 
316
    }
 
317
 
 
318
    /* Makefile pathname */
 
319
    uprv_strcpy(tmp, o.tmpDir);
 
320
    uprv_strcat(tmp, U_FILE_SEP_STRING);
 
321
    uprv_strcat(tmp, o.shortName);
 
322
    uprv_strcat(tmp, "_");
 
323
    uprv_strcat(tmp, o.mode);
 
324
    uprv_strcat(tmp, ".mak");  /* MAY NEED TO CHANGE PER PLATFORM */
 
325
 
 
326
    o.makeFile = uprv_strdup(tmp);
 
327
 
 
328
    out = T_FileStream_open(o.makeFile, "w");
 
329
    if (out) {
 
330
        pkg_mak_writeHeader(out, &o); /* need to take status */
 
331
        o.fcn(&o, out, &status);
 
332
        pkg_mak_writeFooter(out, &o);
 
333
        T_FileStream_close(out);
 
334
    } else {
 
335
        fprintf(stderr, "warning: couldn't create %s, will use existing file if any\n", o.makeFile);
 
336
        /*status = U_FILE_ACCESS_ERROR;*/
 
337
    }
 
338
 
 
339
    if(U_FAILURE(status)) {
 
340
        fprintf(stderr, "Error creating makefile [%s]: %s\n", o.mode,
321
341
            u_errorName(status));
322
 
    return 1;
323
 
  }
324
 
 
325
 
  if(o.nooutput == TRUE) {
326
 
    return 0; /* nothing to do. */
327
 
  }
328
 
 
329
 
  return executeMakefile(&o);
 
342
        return 1;
 
343
    }
 
344
 
 
345
    if(o.nooutput == TRUE) {
 
346
        return 0; /* nothing to do. */
 
347
    }
 
348
 
 
349
    return executeMakefile(&o);
330
350
}
331
351
 
332
352
/* POSIX - execute makefile */
333
353
static int executeMakefile(const UPKGOptions *o)
334
354
{
335
 
  char cmd[1024];
336
 
  /*char pwd[1024];*/
337
 
  const char *make;
338
 
  int rc;
339
 
 
340
 
  make = getenv("MAKE");
341
 
 
342
 
  if(!make || !make[0]) {
343
 
    make = U_MAKE;
344
 
  }
345
 
 
346
 
  /*getcwd(pwd, 1024);*/
 
355
    char cmd[1024];
 
356
    /*char pwd[1024];*/
 
357
    const char *make;
 
358
    int rc;
 
359
 
 
360
    make = getenv("MAKE");
 
361
 
 
362
    if(!make || !make[0]) {
 
363
        make = U_MAKE;
 
364
    }
 
365
 
 
366
    /*getcwd(pwd, 1024);*/
347
367
#ifdef WIN32
348
 
  sprintf(cmd, "%s %s%s -f \"%s\" %s %s %s %s",
349
 
          make,
350
 
          o->install ? "INSTALLTO=" : "",
351
 
          o->install ? o->install    : "",
352
 
          o->makeFile,
353
 
          o->clean   ? "clean"      : "",
354
 
          o->rebuild ? "rebuild"    : "",
355
 
          o->install ? "install"    : "",
356
 
          o->makeArgs);
 
368
    sprintf(cmd, "%s %s%s -f \"%s\" %s %s %s %s",
 
369
        make,
 
370
        o->install ? "INSTALLTO=" : "",
 
371
        o->install ? o->install    : "",
 
372
        o->makeFile,
 
373
        o->clean   ? "clean"      : "",
 
374
        o->rebuild ? "rebuild"    : "",
 
375
        o->install ? "install"    : "",
 
376
        o->makeArgs);
357
377
#elif OS400
358
 
  sprintf(cmd, "CALL GNU/GMAKE PARM(%s%s%s '-f' '%s' %s %s %s %s)",
359
 
          o->install ? "'INSTALLTO=" : "",
360
 
          o->install ? o->install    : "",
361
 
          o->install ? "'"           : "",
362
 
          o->makeFile,
363
 
          o->clean   ? "'clean'"     : "",
364
 
          o->rebuild ? "'rebuild'"   : "",
365
 
          o->install ? "'install'"   : "",
366
 
          o->makeArgs);
 
378
    sprintf(cmd, "CALL GNU/GMAKE PARM(%s%s%s '-f' '%s' %s %s %s %s)",
 
379
        o->install ? "'INSTALLTO=" : "",
 
380
        o->install ? o->install    : "",
 
381
        o->install ? "'"           : "",
 
382
        o->makeFile,
 
383
        o->clean   ? "'clean'"     : "",
 
384
        o->rebuild ? "'rebuild'"   : "",
 
385
        o->install ? "'install'"   : "",
 
386
        o->makeArgs);
367
387
#else
368
 
  sprintf(cmd, "%s %s%s -f %s %s %s %s %s",
369
 
          make,
370
 
          o->install ? "INSTALLTO=" : "",
371
 
          o->install ? o->install    : "",
372
 
          o->makeFile,
373
 
          o->clean   ? "clean"      : "",
374
 
          o->rebuild ? "rebuild"    : "",
375
 
          o->install ? "install"    : "",
376
 
          o->makeArgs);
 
388
    sprintf(cmd, "%s %s%s -f %s %s %s %s %s",
 
389
        make,
 
390
        o->install ? "INSTALLTO=" : "",
 
391
        o->install ? o->install    : "",
 
392
        o->makeFile,
 
393
        o->clean   ? "clean"      : "",
 
394
        o->rebuild ? "rebuild"    : "",
 
395
        o->install ? "install"    : "",
 
396
        o->makeArgs);
377
397
#endif
378
 
  if(o->verbose) {
379
 
    puts(cmd);
380
 
  }
381
 
 
382
 
  rc = system(cmd);
383
 
 
384
 
  if(rc < 0) {
385
 
    fprintf(stderr, "# Failed, rc=%d\n", rc);
386
 
  }
387
 
  return rc < 128 ? rc : (rc >> 8);
 
398
    if(o->verbose) {
 
399
        puts(cmd);
 
400
    }
 
401
 
 
402
    rc = system(cmd);
 
403
 
 
404
    if(rc < 0) {
 
405
        fprintf(stderr, "# Failed, rc=%d\n", rc);
 
406
    }
 
407
 
 
408
    return rc < 128 ? rc : (rc >> 8);
388
409
}
389
410
 
390
411
 
391
412
static void loadLists(UPKGOptions *o, UErrorCode *status)
392
413
{
393
 
  CharList   *l, *tail = NULL, *tail2 = NULL;
394
 
  FileStream *in;
395
 
  char        line[2048];
396
 
  char        tmp[1024];
397
 
  const char* baseName;
398
 
  char       *s;
399
 
 
400
 
  for(l = o->fileListFiles; l; l = l->next) {
401
 
    if(o->verbose) {
402
 
      fprintf(stdout, "# Reading %s..\n", l->str);
403
 
    }
404
 
 
405
 
    /* TODO: stdin */
406
 
    in = T_FileStream_open(l->str, "r");
407
 
 
408
 
    if(!in) {
409
 
      fprintf(stderr, "Error opening <%s>.\n", l->str);
410
 
      *status = U_FILE_ACCESS_ERROR;
411
 
      return;
412
 
    }
413
 
 
414
 
    while(T_FileStream_readLine(in, line, sizeof(line))!=NULL) {
415
 
      /* remove trailing newline characters */
416
 
      s=line;
417
 
      while(*s!=0) {
418
 
        if(*s=='\r' || *s=='\n') {
419
 
          *s=0;
420
 
          break;
421
 
        }
422
 
        ++s;
423
 
      }
424
 
      if((*line == 0) || (*line == '#')) {
425
 
        continue; /* comment or empty line */
426
 
      }
427
 
 
428
 
      /* add the file */
429
 
      s = (char*)getLongPathname(line);
430
 
 
431
 
      baseName = findBasename(s);
432
 
 
433
 
      o->files = pkg_appendToList(o->files, &tail, uprv_strdup(baseName));
434
 
 
435
 
      if(s != baseName) { /* s was something long, so we leave it as it is */
436
 
        o->filePaths = pkg_appendToList(o->filePaths, &tail2, uprv_strdup(s));
437
 
      } else { /* s was just a basename, we want to prepend source dir*/
438
 
          uprv_strcpy(tmp, o->srcDir);
439
 
          uprv_strcat(tmp, o->srcDir[uprv_strlen(o->srcDir)-1]==U_FILE_SEP_CHAR?"":U_FILE_SEP_STRING);
440
 
          uprv_strcat(tmp, s);
441
 
          o->filePaths = pkg_appendToList(o->filePaths, &tail2, uprv_strdup(tmp));
442
 
      }
443
 
    }
444
 
 
445
 
    T_FileStream_close(in);
446
 
  }
 
414
    CharList   *l, *tail = NULL, *tail2 = NULL;
 
415
    FileStream *in;
 
416
    char        line[2048];
 
417
    char        tmp[1024];
 
418
    const char* baseName;
 
419
    char       *s;
 
420
 
 
421
    for(l = o->fileListFiles; l; l = l->next) {
 
422
        if(o->verbose) {
 
423
            fprintf(stdout, "# Reading %s..\n", l->str);
 
424
        }
 
425
        /* TODO: stdin */
 
426
        in = T_FileStream_open(l->str, "r");
 
427
 
 
428
        if(!in) {
 
429
            fprintf(stderr, "Error opening <%s>.\n", l->str);
 
430
            *status = U_FILE_ACCESS_ERROR;
 
431
            return;
 
432
        }
 
433
 
 
434
        while(T_FileStream_readLine(in, line, sizeof(line))!=NULL) {
 
435
            /* remove trailing newline characters */
 
436
            s=line;
 
437
            while(*s!=0) {
 
438
                if(*s=='\r' || *s=='\n') {
 
439
                    *s=0;
 
440
                    break;
 
441
                }
 
442
                ++s;
 
443
            }
 
444
            if((*line == 0) || (*line == '#')) {
 
445
                continue; /* comment or empty line */
 
446
            }
 
447
 
 
448
            /* add the file */
 
449
            s = (char*)getLongPathname(line);
 
450
 
 
451
            baseName = findBasename(s);
 
452
 
 
453
            o->files = pkg_appendToList(o->files, &tail, uprv_strdup(baseName));
 
454
 
 
455
            if(s != baseName) { /* s was something long, so we leave it as it is */
 
456
                o->filePaths = pkg_appendToList(o->filePaths, &tail2, uprv_strdup(s));
 
457
            } else { /* s was just a basename, we want to prepend source dir*/
 
458
                uprv_strcpy(tmp, o->srcDir);
 
459
                uprv_strcat(tmp, o->srcDir[uprv_strlen(o->srcDir)-1]==U_FILE_SEP_CHAR?"":U_FILE_SEP_STRING);
 
460
                uprv_strcat(tmp, s);
 
461
                o->filePaths = pkg_appendToList(o->filePaths, &tail2, uprv_strdup(tmp));
 
462
            }
 
463
        }
 
464
 
 
465
        T_FileStream_close(in);
 
466
    }
447
467
}
448
468
 
449
469