Changeset 357


Ignore:
Timestamp:
Nov 28, 2009, 8:49:40 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Make the Qt library portable on OS/2 by replacing hard-coded paths with paths relative to the QtCore DLL (or the application executable if Qt is built as a static library). Add two new locations to search for qt.conf/qtsys.conf for providing more portability and easier system integration. See #78 for more details.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.cmd

    r315 r357  
    299299    G.CFG_GRAPHICS_SYSTEM = "default"
    300300
    301     /* initalize variables used for installation */
     301    /* variables used for locating installed Qt components */
    302302    G.QT_INSTALL_PREFIX = ""
    303303    G.QT_INSTALL_DOCS = ""
     
    545545    /* prefix */
    546546    if (G.QT_INSTALL_PREFIX == "") then
    547         G.QT_INSTALL_PREFIX = G.OutPath
     547        G.QT_INSTALL_PREFIX = "."
    548548    /* docs */
    549549    if (G.QT_INSTALL_DOCS == "") then
    550         G.QT_INSTALL_DOCS = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\docs"
     550        G.QT_INSTALL_DOCS = "doc"
    551551    /* headers */
    552552    if (G.QT_INSTALL_HEADERS == "") then
    553         G.QT_INSTALL_HEADERS = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\include"
     553        G.QT_INSTALL_HEADERS = "include"
    554554    /* libs */
    555555    if (G.QT_INSTALL_LIBS == "") then
    556         G.QT_INSTALL_LIBS = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\lib"
     556        G.QT_INSTALL_LIBS = "lib"
    557557    /* bins */
    558558    if (G.QT_INSTALL_BINS == "") then
    559         G.QT_INSTALL_BINS = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\bin"
     559        G.QT_INSTALL_BINS = "bin"
    560560    /* plugins */
    561561    if (G.QT_INSTALL_PLUGINS == "") then
    562         G.QT_INSTALL_PLUGINS = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\plugins"
     562        G.QT_INSTALL_PLUGINS = "plugins"
    563563    /* data */
    564564    if (G.QT_INSTALL_DATA == "") then
    565         G.QT_INSTALL_DATA = FixDirNoSlash(G.QT_INSTALL_PREFIX)
     565        G.QT_INSTALL_DATA = "."
    566566    /* translations */
    567567    if (G.QT_INSTALL_TRANSLATIONS == "") then
    568         G.QT_INSTALL_TRANSLATIONS = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\translations"
     568        G.QT_INSTALL_TRANSLATIONS = "translations"
    569569    /* settings */
    570570    if (G.QT_INSTALL_SETTINGS == "") then
    571         G.QT_INSTALL_SETTINGS = SysBootDrive()"\OS2\xdg"
     571        G.QT_INSTALL_SETTINGS = "$(ETC)\qt"
    572572    /* examples */
    573573    if (G.QT_INSTALL_EXAMPLES == "") then
    574         G.QT_INSTALL_EXAMPLES = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\examples"
     574        G.QT_INSTALL_EXAMPLES = "examples"
    575575    /* demos */
    576576    if (G.QT_INSTALL_DEMOS == "") then
    577         G.QT_INSTALL_DEMOS = FixDirNoSlash(G.QT_INSTALL_PREFIX)"\demos"
     577        G.QT_INSTALL_DEMOS = "demos"
    578578
    579579    /*--------------------------------------------------------------------------
     
    634634    --------------------------------------------------------------------------*/
    635635
    636     if (\DirExists(G.OutPath"\src\corelib\global")) then
    637         call MakeDir G.OutPath"\src\corelib\global"
     636    call MakeDir G.OutPath"\src\corelib\global"
    638637
    639638    qconfig_cpp = G.OutPath"\src\corelib\global\qconfig.cpp"
     
    641640    config_cpp_str =,
    642641'/* License Info */'G.EOL||,
    643 'static const char qt_configure_licensee_str          [260 + 12] = "qt_lcnsuser='CPPPath(MaxLen(G.Licensee,259))'";'G.EOL||,
    644 'static const char qt_configure_licensed_products_str [260 + 12] = "qt_lcnsprod='CPPPath(MaxLen(G.Edition,259))'";'G.EOL||,
    645 '/* Installation Info */'G.EOL||,
    646 'static const char qt_configure_prefix_path_str       [260 + 12] = "qt_prfxpath='CPPPath(MaxLen(G.QT_INSTALL_PREFIX,259))'";'G.EOL||,
    647 'static const char qt_configure_documentation_path_str[260 + 12] = "qt_docspath='CPPPath(MaxLen(G.QT_INSTALL_DOCS,259))'";'G.EOL||,
    648 'static const char qt_configure_headers_path_str      [260 + 12] = "qt_hdrspath='CPPPath(MaxLen(G.QT_INSTALL_HEADERS,259))'";'G.EOL||,
    649 'static const char qt_configure_libraries_path_str    [260 + 12] = "qt_libspath='CPPPath(MaxLen(G.QT_INSTALL_LIBS,259))'";'G.EOL||,
    650 'static const char qt_configure_binaries_path_str     [260 + 12] = "qt_binspath='CPPPath(MaxLen(G.QT_INSTALL_BINS,259))'";'G.EOL||,
    651 'static const char qt_configure_plugins_path_str      [260 + 12] = "qt_plugpath='CPPPath(MaxLen(G.QT_INSTALL_PLUGINS,259))'";'G.EOL||,
    652 'static const char qt_configure_data_path_str         [260 + 12] = "qt_datapath='CPPPath(MaxLen(G.QT_INSTALL_DATA,259))'";'G.EOL||,
    653 'static const char qt_configure_translations_path_str [260 + 12] = "qt_trnspath='CPPPath(MaxLen(G.QT_INSTALL_TRANSLATIONS,259))'";'G.EOL||,
    654 'static const char qt_configure_settings_path_str     [260 + 12] = "qt_stngpath='CPPPath(MaxLen(G.QT_INSTALL_SETTINGS,259))'";'G.EOL||,
    655 'static const char qt_configure_examples_path_str     [260 + 12] = "qt_xmplpath='CPPPath(MaxLen(G.QT_INSTALL_EXAMPLES,259))'";'G.EOL||,
    656 'static const char qt_configure_demos_path_str        [260 + 12] = "qt_demopath='CPPPath(MaxLen(G.QT_INSTALL_DEMOS,259))'";'G.EOL||,
    657 '/* strlen( "qt_lcnsxxxx" ) == 12 */'G.EOL||,
    658 '#define QT_CONFIGURE_LICENSEE qt_configure_licensee_str + 12;'G.EOL||,
    659 '#define QT_CONFIGURE_LICENSED_PRODUCTS qt_configure_licensed_products_str + 12;'G.EOL||,
    660 '#define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12;'G.EOL||,
    661 '#define QT_CONFIGURE_DOCUMENTATION_PATH qt_configure_documentation_path_str + 12;'G.EOL||,
    662 '#define QT_CONFIGURE_HEADERS_PATH qt_configure_headers_path_str + 12;'G.EOL||,
    663 '#define QT_CONFIGURE_LIBRARIES_PATH qt_configure_libraries_path_str + 12;'G.EOL||,
    664 '#define QT_CONFIGURE_BINARIES_PATH qt_configure_binaries_path_str + 12;'G.EOL||,
    665 '#define QT_CONFIGURE_PLUGINS_PATH qt_configure_plugins_path_str + 12;'G.EOL||,
    666 '#define QT_CONFIGURE_DATA_PATH qt_configure_data_path_str + 12;'G.EOL||,
    667 '#define QT_CONFIGURE_TRANSLATIONS_PATH qt_configure_translations_path_str + 12;'G.EOL||,
    668 '#define QT_CONFIGURE_SETTINGS_PATH qt_configure_settings_path_str + 12;'G.EOL||,
    669 '#define QT_CONFIGURE_EXAMPLES_PATH qt_configure_examples_path_str + 12;'G.EOL||,
    670 '#define QT_CONFIGURE_DEMOS_PATH qt_configure_demos_path_str + 12;'G.EOL||,
     642'#define QT_CONFIGURE_LICENSEE "'CPPPath(MaxLen(G.Licensee,259))'"'G.EOL||,
     643'#define QT_CONFIGURE_LICENSED_PRODUCTS "'CPPPath(MaxLen(G.Edition,259))'"'G.EOL||,
     644'/* Installation Info */'G.EOL
     645
     646    if (G.QT_INSTALL_PREFIX == ".") then
     647        /* make the prefix path be the directory where the module containing
     648         * core Qt classes (in particular, QLibraryInfo) resides. Normally, it
     649         * will be the path to QtCore4.DLL which is useful for separate Qt runtime
     650         * distros that will have all components along in the same directory */
     651        config_cpp_str = config_cpp_str||,
     652'#define QT_CONFIGURE_PREFIX_PATH qt_module_path()'G.EOL
     653    else
     654        config_cpp_str = config_cpp_str||,
     655'#define QT_CONFIGURE_PREFIX_PATH "'CPPPath(G.QT_INSTALL_PREFIX)'"'G.EOL
     656
     657    config_cpp_str = config_cpp_str||,
     658'#define QT_CONFIGURE_DOCUMENTATION_PATH "'CPPPath(G.QT_INSTALL_DOCS)'"'G.EOL||,
     659'#define QT_CONFIGURE_HEADERS_PATH "'CPPPath(G.QT_INSTALL_HEADERS)'"'G.EOL||,
     660'#define QT_CONFIGURE_LIBRARIES_PATH "'CPPPath(G.QT_INSTALL_LIBS)'"'G.EOL||,
     661'#define QT_CONFIGURE_BINARIES_PATH "'CPPPath(G.QT_INSTALL_BINS)'"'G.EOL||,
     662'#define QT_CONFIGURE_PLUGINS_PATH "'CPPPath(G.QT_INSTALL_PLUGINS)'"'G.EOL||,
     663'#define QT_CONFIGURE_DATA_PATH "'CPPPath(G.QT_INSTALL_DATA)'"'G.EOL||,
     664'#define QT_CONFIGURE_TRANSLATIONS_PATH "'CPPPath(G.QT_INSTALL_TRANSLATIONS)'"'G.EOL||,
     665'#define QT_CONFIGURE_SETTINGS_PATH "'CPPPath(G.QT_INSTALL_SETTINGS)'"'G.EOL||,
     666'#define QT_CONFIGURE_EXAMPLES_PATH "'CPPPath(G.QT_INSTALL_EXAMPLES)'"'G.EOL||,
     667'#define QT_CONFIGURE_DEMOS_PATH "'CPPPath(G.QT_INSTALL_DEMOS)'"'G.EOL||,
    671668G.EOL
    672669
     
    679676        call charout qconfig_cpp
    680677    end
     678
     679    /* create qt.conf in the bin\ subdirectory with the correct paths to the
     680     * Qt components we will build. This is necessary because the default paths
     681     * in qconfig.cpp generated above will be relative to QtCore4.DLL while in
     682     * the development environment they need to be relative to the output tree
     683     * of the Qt library */
     684    call MakeDir G.OutPath"\bin"
     685    qt_conf = G.OutPath"\bin\qt.conf"
     686    call charout qt_conf, '[Paths]'G.EOL'Prefix = ..'G.EOL
     687    call charout qt_conf
    681688
    682689    /*--------------------------------------------------------------------------
     
    18291836
    18301837MakeDir: procedure expose (Globals)
    1831     /* @todo teach it to create all non-existing intermediate dirs */
    18321838    parse arg aDir
    1833     rc = SysMkDir(aDir)
    1834     if (rc \= 0) then do
    1835         call SayErr 'FATAL: Could not create directory '''aDir'''!'
    1836         call SayErr 'SysMkDir returned 'rc
    1837         call Done 1
     1839    aDir = translate(aDir, '\', '/')
     1840    curdir = directory()
     1841    base = aDir
     1842    todo.0 = 0
     1843    do while 1
     1844        d = directory(base)
     1845        if (d \== '') then
     1846            leave
     1847        i = todo.0 + 1
     1848        todo.i = filespec('N', base)
     1849        todo.0 = i
     1850        drv = filespec('D', base)
     1851        path = filespec('P', base)
     1852        if (path == '\' | path == '') then do
     1853            base = drv||path
     1854            leave
     1855        end
     1856        base = drv||strip(path, 'T', '\')
     1857    end
     1858    call directory curdir
     1859    do i = todo.0 to 1 by -1
     1860        if (i < todo.0 | (base \== '' & right(base,1) \== '\' &,
     1861                                        right(base,1) \== ':')) then
     1862            base = base'\'
     1863        base = base||todo.i
     1864        rc = SysMkDir(base)
     1865        if (rc \= 0) then do
     1866            call SayErr 'FATAL: Could not create directory '''base'''!'
     1867            call SayErr 'SysMkDir returned 'rc
     1868            call Done 1
     1869        end
    18381870    end
    18391871    return
     
    22382270
    22392271/**
    2240  *  Returns the name of the temporary directory.
     2272 *  Returns the absolute path to the temporary directory.
    22412273 *  The returned value doesn't end with a slash.
    22422274 */
  • trunk/doc/src/qt-conf.qdoc

    r2 r357  
    5858    libraries look elsewhere.
    5959
     60        Note that on OS/2, the libraries do not use the hard-coded paths
     61        by default. Instead, they look for plugins and other components in a
     62        directory that contains the QtCore DLL library (or the application
     63        executable if Qt is built as a static library). This behavior may
     64        also be overridden using the \c qt.conf file.
     65   
    6066    QLibraryInfo will load \c qt.conf from one of the following locations:
    6167
     
    7278    \endlist
    7379
     80    On OS/2, if neither of the above locations contains \c qt.conf,
     81    QLibraryInfo will additionally try the following two locations:
     82
     83    \list 1
     84
     85    \o \c qt.conf in the directory containing the QtCore DLL library
     86    (or the application executable if Qt is built as a static library)
     87
     88    \o \c %ETC%\qt\qtsys.conf
     89   
     90    \endlist
     91   
    7492    The \c qt.conf file is an INI text file, as described in the \l
    7593    {QSettings::Format}{QSettings} documentation. The file should have
     
    106124    need to be placed in specific sub-directories under the
    107125    \c{plugins} directory (see \l{How to Create Qt Plugins} for
    108     details).
    109 
     126    details). On OS/2, the \c Prefix is always relative to the directory
     127    where \c qt.conf or \c qtsys.conf is loaded from.
     128   
    110129    For example, a \c qt.conf file could contain the following:
    111130
  • trunk/src/corelib/global/qlibraryinfo.cpp

    r2 r357  
    4141
    4242#include "qdir.h"
    43 #include "qfile.h"   
     43#include "qfile.h"
    4444#include "qconfig.h"
    4545#include "qsettings.h"
     
    5858#  include "private/qcore_mac_p.h"
    5959#endif
     60
     61#ifdef Q_OS_OS2
     62
     63#include "qt_os2.h"
     64
     65static const char *qt_module_path()
     66{
     67    static char path[CCHMAXPATH] = {'\0'};
     68    if (!path[0]) {
     69        HMODULE hmod;
     70        ULONG objNum, offset;
     71        DosQueryModFromEIP(&hmod, &objNum, sizeof(path), path, &offset,
     72                           (ULONG)qt_module_path);
     73        DosQueryModuleName(hmod, sizeof(path), path);
     74        char *slash = strrchr(path, '\\');
     75        if (slash)
     76            *slash = '\0';
     77    }
     78    return path;
     79}
     80
     81#endif // Q_OS_OS2
    6082
    6183#include "qconfig.cpp"
     
    137159                qtconfig = pwd.filePath(QLatin1String("qt.conf"));
    138160            }
     161#ifdef Q_OS_OS2
     162    if (!QFile::exists(qtconfig)) {
     163        // search in the directory that contains the DLL or EXE where this
     164        // code is located (e.g. QtCore.dll or app.exe if Qt is a static lib)
     165        qtconfig = QString::fromLocal8Bit(qt_module_path());
     166        qtconfig = QDir::fromNativeSeparators(qtconfig) +
     167                   QLatin1String("/qt.conf");
     168        qtconfig = QDir::cleanPath(qtconfig);
     169
     170        if (!QFile::exists(qtconfig)) {
     171            // search in the system-wide location
     172            qtconfig = QString::fromLocal8Bit(qgetenv("ETC"));
     173            if (qtconfig.isEmpty())
     174                qtconfig = QDir::rootPath();
     175            qtconfig = QDir::fromNativeSeparators(qtconfig) +
     176                       QLatin1String("/qt/qtsys.conf");
     177            qtconfig = QDir::cleanPath(qtconfig);
     178        }
     179    }
     180#endif
    139181    }
    140182#endif
     
    296338        }
    297339
    298         if (path)
     340        if (path) {
    299341            ret = QString::fromLocal8Bit(path);
     342#ifdef Q_OS_OS2
     343            // expand environment variables in the form $(ENVVAR)
     344            int rep;
     345            QRegExp reg_var(QLatin1String("\\$\\(.*\\)"));
     346            reg_var.setMinimal(true);
     347            while((rep = reg_var.indexIn(ret)) != -1) {
     348                ret.replace(rep, reg_var.matchedLength(),
     349                            QString::fromLocal8Bit(qgetenv(ret.mid(rep + 2,
     350                                reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
     351            }
     352#endif
     353        }
    300354    } else {
    301355        QString key;
     
    431485            // we make the prefix path absolute to the executable's directory
    432486#ifdef QT_BUILD_QMAKE
    433             return QFileInfo(qmake_libraryInfoFile()).absolutePath();
     487            QFileInfo fi(qmake_libraryInfoFile());
     488            return QDir::cleanPath(QDir(fi.absolutePath()).absoluteFilePath(ret));
    434489#else
     490#ifdef Q_OS_OS2
     491            QSettings *config = QLibraryInfoPrivate::configuration();
     492            if (config) {
     493                // if we read paths from qt[sys].conf, the Prefix is relative to
     494                // the directory we load qt[sys].conf from
     495                QFileInfo fi(config->fileName());
     496                return QDir::cleanPath(QDir(fi.absolutePath()).absoluteFilePath(ret));
     497            }
     498            else
     499#endif
    435500            if (QCoreApplication::instance()) {
    436501#ifdef Q_OS_MAC
     
    444509                }
    445510#endif
    446                 return QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(ret);
     511                return QDir::cleanPath(QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(ret));
    447512            } else {
    448513                return QDir::current().absoluteFilePath(ret);
     
    451516        } else {
    452517            // we make any other path absolute to the prefix directory
    453             return QDir(location(PrefixPath)).absoluteFilePath(ret);
     518            return QDir::cleanPath(QDir(location(PrefixPath)).absoluteFilePath(ret));
    454519        }
    455520    }
    456     return ret;
     521    return QDir::cleanPath(ret);
    457522}
    458523
Note: See TracChangeset for help on using the changeset viewer.