From 19f3c8ba604cf9485eee9acd657ae000e6e35c06 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Wed, 3 Nov 2021 17:43:11 +0100 Subject: [PATCH] easier to maintain support for arch independent modules (without lib) --- App/tools/driver.makefile | 2 +- require.c | 190 +++++++++++++++++++++----------------- 2 files changed, 107 insertions(+), 85 deletions(-) diff --git a/App/tools/driver.makefile b/App/tools/driver.makefile index 22a9b4e..2d6ccee 100644 --- a/App/tools/driver.makefile +++ b/App/tools/driver.makefile @@ -919,7 +919,7 @@ ifeq (${OS_CLASS},WIN32) # .lib for WIN32 is also required for linking INSTALL_LIBS += $(addprefix ${INSTALL_LIB}/,${LIB_PREFIX}${PRJ}${LIB_SUFFIX}) endif endif -INSTALL_DEPS = ${DEPFILE:%=${INSTALL_LIB}/%} +INSTALL_DEPS = ${DEPFILE:%=$(if ${MODULELIB},${INSTALL_LIB},${INSTALL_REV})/%} INSTALL_DBDS = ${MODULEDBD:%=${INSTALL_DBD}/%} INSTALL_HDRS = $(addprefix ${INSTALL_INCLUDE}/,$(call os_include_dir,${HDRS},${OS_CLASS})) INSTALL_DBS = $(addprefix ${INSTALL_DB}/,$(notdir ${TEMPLS})) diff --git a/require.c b/require.c index be17217..b4cb095 100644 --- a/require.c +++ b/require.c @@ -1302,7 +1302,7 @@ static int require_priv(const char* module, const char* version, const char* arg const char *end; int releasediroffs; - int libdiroffs; + int libdiroffs = 0; int extoffs; char* founddir = NULL; char* symbolname; @@ -1457,22 +1457,34 @@ static int require_priv(const char* module, const char* version, const char* arg case EXACT: /* exact match found */ case MATCH: /* all given numbers match. */ { + /* filename = "/[dirlen]/[modulediroffs]" */ + /* Add our EPICS version */ + snprintf(filename+modulediroffs, sizeof(filename)-modulediroffs, "%s/R%s/%n", + currentFilename, epicsRelease, &releasediroffs); + releasediroffs += modulediroffs; + /* filename = "/[dirlen]/[modulediroffs]/R/[releasediroffs]" */ + someArchFound = 1; if (requireDebug) printf("require: %s %s may match %s\n", module, currentFilename, version); - /* Check if it has our EPICS version and architecture. */ - /* Even if it has no library, at least it has a dep file in the lib dir */ - - /* filename = "/[dirlen]/[modulediroffs]" */ - if (!TRY_FILE(modulediroffs, "%s/R%s/" LIBDIR "/%s/", - currentFilename, epicsRelease, targetArch)) - /* filename = "/[dirlen]/[modulediroffs]/R/lib//" */ + /* Check if it is an architecture independent module without lib dir */ + if (!TRY_FILE(releasediroffs, LIBDIR "/")) { if (requireDebug) - printf("require: %s %s has no support for %s %s\n", + printf("require: %s %s is architecture independent for R%s \n", + module, currentFilename, epicsRelease); + } + else + + /* Else check if it has our architecture. */ + if (!TRY_FILE(releasediroffs, LIBDIR "/%s/", targetArch)) + /* filename = "/[dirlen]/[modulediroffs]/R/[releasediroffs]lib//" */ + { + if (requireDebug) + printf("require: %s %s has no support for R%s %s\n", module, currentFilename, epicsRelease, targetArch); continue; } @@ -1489,7 +1501,7 @@ static int require_priv(const char* module, const char* version, const char* arg /* Is it higher than the one we found before? */ if (requireDebug) - printf("require: %s %s support for %s %s found, compare against previously found %s\n", + printf("require: %s %s support for R%s %s found, compare against previously found %s\n", module, currentFilename, epicsRelease, targetArch, found); if (!found || compareVersions(currentFilename, found, exactnessLevel) == HIGHER) { @@ -1587,99 +1599,109 @@ static int require_priv(const char* module, const char* version, const char* arg printf("require: looking for dependency file\n"); if (!TRY_FILE(0, "%s/R%s/%n" LIBDIR "/%s/%n%s.dep", - founddir, epicsRelease, &releasediroffs, targetArch, &libdiroffs, module)) - /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/module.dep" */ + founddir, epicsRelease, &releasediroffs, targetArch, &libdiroffs, module) && + /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/.dep" */ + !TRY_FILE(releasediroffs, "%n%s.dep", &libdiroffs, module)) + /* filename = "/[dirlen]//R/[releasediroffs]/.dep" */ { fprintf(stderr, "Dependency file %s not found\n", filename); } else { checkdep: - /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/module.dep" */ - /* or (old) "/[dirlen]][releasediroffs][libdiroffs](-)?.dep" */ + /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/.dep" */ + /* or "/[dirlen]//R/[releasediroffs]/.dep" */ + /* or (old) "/[dirlen][releasediroffs][libdiroffs](-)?.dep" */ if (handleDependencies(module, filename) == -1) return -1; } - if (requireDebug) - printf("require: looking for library file\n"); - - if (!(TRY_FILE(libdiroffs, PREFIX "%s" INFIX "%s%n" EXT, module, versionstr, &extoffs) - #ifdef vxWorks - /* try without extension */ - || (filename[libdiroffs + extoffs] = 0, fileExists(filename)) - #endif - )) - /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/PREFIXINFIX[extoffs](EXT)?" */ - /* or (old) "/[dirlen][releasediroffs][libdiroffs]PREFIXINFIX(-)?[extoffs](EXT)?" */ + if (!libdiroffs) { - printf("Module %s has no library\n", module); + printf("Module %s is architecture independent\n", module); } else { -loadlib: - /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/PREFIXINFIX[extoffs]EXT" */ - /* or (old) "/[dirlen][releasediroffs][libdiroffs]PREFIXINFIX(-)?[extoffs]EXT" */ - printf("Loading library %s\n", filename); - if ((libhandle = loadlib(filename)) == NULL) - return -1; - - /* now check what version we really got (with compiled-in version number) */ - if (asprintf (&symbolname, "_%sLibRelease", module) < 0) - return errno; - - found = (const char*) getAddress(libhandle, symbolname); - free(symbolname); - printf("Loaded %s version %s\n", module, found); - - /* check what we got */ if (requireDebug) - printf("require: compare requested version %s with loaded version %s\n", version, found); - if (compareVersions(found, version, exactnessLevel) == MISMATCH) + printf("require: looking for library file in %.*s\n", libdiroffs, filename); + + if (!(TRY_FILE(libdiroffs, PREFIX "%s" INFIX "%s%n" EXT, module, versionstr, &extoffs) + #ifdef vxWorks + /* try without extension */ + || (filename[libdiroffs + extoffs] = 0, fileExists(filename)) + #endif + )) + /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/PREFIXINFIX[extoffs](EXT)?" */ + /* or (old) "/[dirlen][releasediroffs][libdiroffs]PREFIXINFIX(-)?[extoffs](EXT)?" */ { - fprintf(stderr, "Requested %s version %s not available, found only %s.\n", - module, version, found); - return -1; - } - - /* load dbd file */ - if (TRY_NONEMPTY_FILE(releasediroffs, "dbd/%s%s.dbd", module, versionstr) || - TRY_NONEMPTY_FILE(releasediroffs, "%s%s.dbd", module, versionstr) || - TRY_NONEMPTY_FILE(releasediroffs, "../dbd/%s%s.dbd", module, versionstr) || - TRY_NONEMPTY_FILE(releasediroffs, "../%s%s.dbd", module, versionstr) || - TRY_NONEMPTY_FILE(releasediroffs, "../../dbd/%s.dbd", module)) /* org EPICSbase */ - { - printf("Loading dbd file %s\n", filename); - if (dbLoadDatabase(filename, NULL, NULL) != 0) - { - fprintf (stderr, "Error loading %s\n", filename); - return -1; - } - - #ifndef EPICS_3_13 - /* when dbd is loaded call register function */ - if (asprintf(&symbolname, "%s_registerRecordDeviceDriver", module) < 0) - return errno; - - printf ("Calling function %s\n", symbolname); - #ifdef vxWorks - { - FUNCPTR f = (FUNCPTR) getAddress(NULL, symbolname); - if (f) - f(pdbbase); - else - fprintf (stderr, "require: can't find %s function\n", symbolname); - } - #else /* !vxWorks */ - iocshCmd(symbolname); - #endif /* !vxWorks */ - free(symbolname); - #endif /* !EPICS_3_13 */ + printf("Module %s has no library\n", module); } else { - /* no dbd file, but that might be OK */ - printf("%s has no dbd file\n", module); +loadlib: + /* filename = "/[dirlen]//R/[releasediroffs]/lib//[libdiroffs]/PREFIXINFIX[extoffs]EXT" */ + /* or (old) "/[dirlen][releasediroffs][libdiroffs]PREFIXINFIX(-)?[extoffs]EXT" */ + printf("Loading library %s\n", filename); + if ((libhandle = loadlib(filename)) == NULL) + return -1; + + /* now check what version we really got (with compiled-in version number) */ + if (asprintf (&symbolname, "_%sLibRelease", module) < 0) + return errno; + + found = (const char*) getAddress(libhandle, symbolname); + free(symbolname); + printf("Loaded %s version %s\n", module, found); + + /* check what we got */ + if (requireDebug) + printf("require: compare requested version %s with loaded version %s\n", version, found); + if (compareVersions(found, version, exactnessLevel) == MISMATCH) + { + fprintf(stderr, "Requested %s version %s not available, found only %s.\n", + module, version, found); + return -1; + } + + /* load dbd file */ + if (TRY_NONEMPTY_FILE(releasediroffs, "dbd/%s%s.dbd", module, versionstr) || + TRY_NONEMPTY_FILE(releasediroffs, "%s%s.dbd", module, versionstr) || + TRY_NONEMPTY_FILE(releasediroffs, "../dbd/%s%s.dbd", module, versionstr) || + TRY_NONEMPTY_FILE(releasediroffs, "../%s%s.dbd", module, versionstr) || + TRY_NONEMPTY_FILE(releasediroffs, "../../dbd/%s.dbd", module)) /* org EPICSbase */ + { + printf("Loading dbd file %s\n", filename); + if (dbLoadDatabase(filename, NULL, NULL) != 0) + { + fprintf (stderr, "Error loading %s\n", filename); + return -1; + } + + #ifndef EPICS_3_13 + /* when dbd is loaded call register function */ + if (asprintf(&symbolname, "%s_registerRecordDeviceDriver", module) < 0) + return errno; + + printf ("Calling function %s\n", symbolname); + #ifdef vxWorks + { + FUNCPTR f = (FUNCPTR) getAddress(NULL, symbolname); + if (f) + f(pdbbase); + else + fprintf (stderr, "require: can't find %s function\n", symbolname); + } + #else /* !vxWorks */ + iocshCmd(symbolname); + #endif /* !vxWorks */ + free(symbolname); + #endif /* !EPICS_3_13 */ + } + else + { + /* no dbd file, but that might be OK */ + printf("%s has no dbd file\n", module); + } } } /* register module with path */