ICU-1895 have pkgdata handle "." temp and target paths better (don't generate the form './' )

X-SVN-Rev: 8592
This commit is contained in:
Steven R. Loomis 2002-05-10 20:31:01 +00:00
parent 9a84368217
commit e8462860d1
4 changed files with 115 additions and 19 deletions

View file

@ -36,6 +36,7 @@ pkg_mak_writeHeader(FileStream *f, const UPKGOptions *o)
"CNAME=%s\n"
"TARGETDIR=%s\n"
"TEMP_DIR=%s\n"
"srcdir=$(TEMP_DIR)\n"
"MODE=%s\n"
"MAKEFILE=%s\n"
"ENTRYPOINT=%s\n"
@ -51,6 +52,26 @@ pkg_mak_writeHeader(FileStream *f, const UPKGOptions *o)
o->options);
T_FileStream_writeLine(f, linebuf);
/* TEMP_PATH and TARG_PATH will be empty if the respective dir is . */
/* Avoid //'s and .'s which confuse make ! */
if(!strcmp(o->tmpDir,"."))
{
T_FileStream_writeLine(f, "TEMP_PATH=\n");
}
else
{
T_FileStream_writeLine(f, "TEMP_PATH=$(TEMP_DIR)/\n");
}
if(!strcmp(o->targetDir,"."))
{
T_FileStream_writeLine(f, "TARG_PATH=\n");
}
else
{
T_FileStream_writeLine(f, "TARG_PATH=$(TARGETDIR)/\n");
}
sprintf(linebuf, "## List files [%d] containing data files to process (note: - means stdin)\n"
"LISTFILES= ",
pkg_countCharList(o->fileListFiles));

View file

@ -194,7 +194,9 @@ Specify options for the builder. The builder is used internally by
to generate the correct packaged file. Such options include, but are
not limited to, setting variables used by
.BR make (1)
during the build of the packaged file.
during the build of the packaged file. Note: If
.BR icu-config
is available, then this option is not needed.
.TP
.BI "\-p\fP, \fB\-\-name" " name"
Set the packaged file name to

View file

@ -27,6 +27,10 @@
#include "unewdata.h"
#include "uoptions.h"
#ifndef WIN32
#include <unistd.h> /* for popen */
#endif
U_CDECL_BEGIN
#include "pkgtypes.h"
#include "makefile.h"
@ -35,6 +39,8 @@ U_CDECL_END
static int executeMakefile(const UPKGOptions *o);
static void loadLists(UPKGOptions *o, UErrorCode *status);
static void fillInMakefileFromICUConfig(UOption *option);
/* This sets the modes that are available */
static struct
{
@ -83,7 +89,7 @@ const char options_help[][160]={
#ifdef WIN32
"R:icupath for release version or D:icupath for debug version, where icupath is the directory where ICU is located",
#else
"Specify options for the builder",
"Specify options for the builder. (Autdetected if icu-config is available)",
#endif
"Specify the mode of building (see below; default: common)",
"This usage text",
@ -103,12 +109,13 @@ const char options_help[][160]={
"Pass the next argument to make(1)"
};
const char *progname = "PKGDATA";
int
main(int argc, char* argv[]) {
FileStream *out;
UPKGOptions o;
CharList *tail;
const char *progname;
UBool needsHelp = FALSE;
UErrorCode status = U_ZERO_ERROR;
char tmp[1024];
@ -140,10 +147,23 @@ main(int argc, char* argv[]) {
fprintf(stderr, "Run '%s --help' for help.\n", progname);
return 1;
}
if(! (options[0].doesOccur && options[1].doesOccur) ) {
fprintf(stderr, " required parameters are missing: -p and -O are required \n");
fprintf(stderr, "Run '%s --help' for help.\n", progname);
return 1;
if(!options[1].doesOccur) {
/* Try to fill in from icu-config or equivalent */
fillInMakefileFromICUConfig(&options[1]);
}
if(!options[1].doesOccur) {
fprintf(stderr, " required parameter is missing: -O is required \n");
fprintf(stderr, "Run '%s --help' for help.\n", progname);
return 1;
}
if(!options[0].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) {
@ -467,3 +487,56 @@ static void loadLists(UPKGOptions *o, UErrorCode *status)
}
#ifndef WIN32
/* Try calling icu-config directly to get information */
void fillInMakefileFromICUConfig(UOption *option)
{
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");
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;
}
#endif

View file

@ -142,10 +142,10 @@ writeObjRules(UPKGOptions *o, FileStream *makefile, CharList **objects)
sprintf(stanza, "$(INVOKE) $(GENCCODE) -n $(ENTRYPOINT) -d $(TEMP_DIR) $<");
commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
sprintf(stanza, "$(COMPILE.c) -o $@ $(TEMP_DIR)/%s", cfile);
sprintf(stanza, "$(COMPILE.c) -o $@ $(TEMP_PATH)%s", cfile);
commands = pkg_appendToList(commands, NULL, uprv_strdup(stanza));
sprintf(stanza, "$(TEMP_DIR)/%s", tmp);
sprintf(stanza, "$(TEMP_PATH)%s", tmp);
pkg_mak_writeStanza(makefile, o, stanza, parents, commands);
pkg_deleteList(parents);
@ -208,7 +208,7 @@ void pkg_mode_static(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
T_FileStream_writeLine(makefile, "LIB_TARGET=$(TARGET)\n");
uprv_strcpy(tmp, "all: $(TARGETDIR)/$(LIB_TARGET)");
uprv_strcpy(tmp, "all: $(TARG_PATH)$(LIB_TARGET)");
uprv_strcat(tmp, "\n\n");
T_FileStream_writeLine(makefile, tmp);
@ -233,16 +233,16 @@ void pkg_mode_static(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
"\tdone;\n\n");
}
sprintf(tmp,"$(TEMP_DIR)/$(NAME)_dat.$(STATIC_O) : $(TEMP_DIR)/$(NAME)_dat.c\n"
sprintf(tmp,"$(TEMP_PATH)$(NAME)_dat.$(STATIC_O) : $(TEMP_PATH)$(NAME)_dat.c\n"
"\t$(COMPILE.c) -o $@ $<\n\n");
T_FileStream_writeLine(makefile, tmp);
T_FileStream_writeLine(makefile, "# 'TOCOBJ' contains C Table of Contents objects [if any]\n");
sprintf(tmp, "$(TEMP_DIR)/$(NAME)_dat.c: $(CMNLIST)\n"
sprintf(tmp, "$(TEMP_PATH)$(NAME)_dat.c: $(CMNLIST)\n"
"\t$(INVOKE) $(GENCMN) -e $(ENTRYPOINT) -n $(NAME) -S -d $(TEMP_DIR) 0 $(CMNLIST)\n\n");
T_FileStream_writeLine(makefile, tmp);
sprintf(tmp, "TOCOBJ= $(NAME)_dat%s \n\n", OBJ_SUFFIX);
T_FileStream_writeLine(makefile, tmp);
sprintf(tmp, "TOCSYM= $(ENTRYPOINT)_dat \n\n"); /* entrypoint not always shortname! */
@ -252,21 +252,21 @@ void pkg_mode_static(UPKGOptions *o, FileStream *makefile, UErrorCode *status)
pkg_writeCharListWrap(makefile, objects, " ", " \\\n",0);
T_FileStream_writeLine(makefile, "\n\n");
T_FileStream_writeLine(makefile, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_DIR)/%)\n\n");
T_FileStream_writeLine(makefile, "OBJECTS=$(BASE_OBJECTS:%=$(TEMP_PATH)%)\n\n");
T_FileStream_writeLine(makefile,"$(TEMP_DIR)/%.$(STATIC_O): $(TEMP_DIR)/%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
T_FileStream_writeLine(makefile,"$(TEMP_PATH)%.$(STATIC_O): $(TEMP_PATH)%.c\n\t $(COMPILE.c) -o $@ $<\n\n");
T_FileStream_writeLine(makefile, "$(TARGETDIR)/$(LIB_TARGET):$(TARGETDIR)/$(LIB_TARGET)($(OBJECTS)) $(LISTFILES)\n"
T_FileStream_writeLine(makefile, "$(TARG_PATH)$(LIB_TARGET):$(TARG_PATH)$(LIB_TARGET)($(OBJECTS)) $(LISTFILES)\n"
"\t$(RANLIB) $@\n\n");
T_FileStream_writeLine(makefile, "CLEANFILES= $(CMNLIST) $(OBJECTS) $(TARGETDIR)/$(LIB_TARGET) $(TARGETDIR)/$(MIDDLE_STATIC_LIB_TARGET) $(TARGETDIR)/$(TARGET)\n\nclean:\n\t-$(RMV) $(CLEANFILES) $(MAKEFILE)");
T_FileStream_writeLine(makefile, "CLEANFILES= $(CMNLIST) $(OBJECTS) $(TARG_PATH)$(LIB_TARGET) $(TARG_PATH)$(MIDDLE_STATIC_LIB_TARGET) $(TARG_PATH)$(TARGET)\n\nclean:\n\t-$(RMV) $(CLEANFILES) $(MAKEFILE)");
T_FileStream_writeLine(makefile, "\n\n");
T_FileStream_writeLine(makefile, "# static mode shouldn't need to be installed, but we will install the header and static library for them.\n");
T_FileStream_writeLine(makefile, "install: $(TARGETDIR)/$(LIB_TARGET)\n"
"\t$(INSTALL-L) $(TARGETDIR)/$(LIB_TARGET) $(INSTALLTO)/$(LIB_TARGET)\n");
T_FileStream_writeLine(makefile, "install: $(TARG_PATH)$(LIB_TARGET)\n"
"\t$(INSTALL-L) $(TARG_PATH)$(LIB_TARGET) $(INSTALLTO)/$(LIB_TARGET)\n");
if (o->version) {
T_FileStream_writeLine(makefile, "\tcd $(INSTALLTO) && $(RM) $(MIDDLE_STATIC_LIB_TARGET) && ln -s $(LIB_TARGET) $(MIDDLE_STATIC_LIB_TARGET)\n\tcd $(INSTALLTO) && $(RM) $(STATIC_LIB_TARGET) && ln -s $(LIB_TARGET) $(STATIC_LIB_TARGET)\n");
}