/* echo this is a rexx script! cancel & quit & exit */ /* $Id: $ */ /** @file * * LIBC Development Environment Setup Script. * * * Copyright (c) 1999-2007 knut st. osmundsen * * * This file is part of kLIBC. * * kLIBC is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * kLIBC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with kLIBC; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * Setup the usual stuff... */ Address CMD '@echo off'; signal on novalue name NoValueHandler if (RxFuncQuery('SysLoadFuncs') = 1) then do call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'; call SysLoadFuncs; end /* * Apply CMD.EXE workaround. */ call FixCMDEnv; /* * Parse argument. */ fRm = 0; sPathGcc = ''; sPathUnix = EnvGet('UNIXROOT'); sPathkBuild = EnvGet('KBUILD_PATH'); if sPathkBuild ='' then sPathkBuild = EnvGet('PATH_KBUILD'); fWithBuiltStuff = 1; fUseBuildEnv = 1; sBuildType = 'debug'; sBuildTarget = 'os2'; sBuildArch = 'x86'; parse arg sArgs do i = 1 to words(sArgs) /* extract word */ sArg = word(sArgs, i) /* */ if (left(sArg, 1) = '/' | (left(sArg, 1) = '-')) then do sArg = strip(strip(sArg, 'L', '/'), 'L', '-'); select when (sArg = 'gcc') then do if i = words(sArgs) then do say 'syntax error: '''sArg''' is missing the path.' exit(12); end i = i + 1; sPathGcc = word(sArgs, i); end when (sArg = 'unixroot') then do if i = words(sArgs) then do say 'syntax error: '''sArg''' is missing the path.' exit(12); end i = i + 1; sPathUnix = word(sArgs, i); end when (sArg = 'kbuild' | sArg = 'kBuild') then do if i = words(sArgs) then do say 'syntax error: '''sArg''' is missing the path.' exit(12); end i = i + 1; sPathkBuild = word(sArgs, i); end when (sArg = 'uninstall') then fRM = 1; when (sArg = 'install') then fRM = 0; otherwise do call syntax; exit(12); end end end else do sBuildType = ToLower(sArg); if (sBuildType <> 'release' & sBuildType <> 'debug') then do say 'syntax error: Invalid build type '''sBuildType'''. valid types are: release and debug' exit(12); end end end /* * Assuming this script is in the root directory, we can determing * the abs path to it by using the 'parse source' feature in rexx. */ parse source . . sSrc sPathRoot = ToDosSlash(FixPath(filespec('drive', sSrc) || strip(filespec('path', sSrc), 'T', '\'))); sPathRootF = ToUnixSlash(sPathRoot); if (substr(sPathRootF, 1, 2) = '//') then do say 'error: script invoked with UNC path. that won''t work.' exit(12); end /* * Figure where the output directory is. * (kBuild actually decides this, so kee it in sync.) */ sPathOut = sPathRoot'\out\'sBuildTarget'.'sBuildArch'\'sBuildType sPathOutF = sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sBuildType /* * Use out/.../dist as UNIXROOT if not specified or in the env. */ if (sPathUnix = '') then sPathUnix = sPathOut'\dist'; say 'info: unix root at '''sPathUnix'''.'; sPathUnix = ToDosSlash(FixPath(sPathUnix)); sPathUnixF = ToUnixSlash(sPathUnix); sPathUnixFD= ToUnixSlash(filespec('path', sPathUnix)||filespec('name', sPathUnix)); /* * Check for kBuild. */ if (sPathkBuild = '') then sPathkBuild = sPathRoot'\kBuild'; sPathkBuild = ToDosSlash(FixPath(sPathkBuild)); sPathkBuildF = ToUnixSlash(sPathkBuild); if (\FileExists(sPathkBuild'\footer.kmk')) then do say 'fatal error: cannot find a kBuild valid installation!'; say 'check the build instructions (web) for how to get and install kBuild!'; exit(8); end /* * Check the gcc path. */ if (FileExists(sPathGcc'/usr/bin/g++.exe')) then sPathGcc = sPathGcc'/usr'; sPathGcc = FixPath(sPathGcc); if (\FileExists(sPathGcc'/bin/g++.exe')) then do say 'fatal error: cannot find g++.exe at the specific gcc location: 'sPathGcc; say 'Use the --gcc option to point to a proper gcc installation.' exit(8); end /* * Setup the environment. */ /* cleanup */ asBuildTypes.0 = 2; asBuildTypes.1 = 'debug'; asBuildTypes.2 = 'release'; asStages.0 = 2 asStages.1 = 'stage1' asStages.2 = 'stage2' do i = 1 to asBuildTypes.0 sType = asBuildTypes.i; call EnvAddFront 1, 'PATH', sPathRoot'\out\'sBuildTarget'.'sBuildArch'\'sType'\dist\bin;' call EnvAddFront 1, 'PATH', sPathRoot'\out\'sBuildTarget'.'sBuildArch'\'sType'\dist\usr\omfhackbin;' call EnvAddFront 1, 'PATH', sPathRoot'\out\'sBuildTarget'.'sBuildArch'\'sType'\dist\usr\bin;' call EnvAddFront 1, 'PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/bin;' call EnvAddFront 1, 'PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/usr/bin;' call EnvAddFront 1, 'C_INCLUDE_PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/usr/include;' call EnvAddFront 1, 'CPLUS_INCLUDE_PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/usr/include;' call EnvAddFront 1, 'COBJ_INCLUDE_PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/usr/include;' call EnvAddFront 1, 'LIBRARY_PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/lib;' call EnvAddFront 1, 'LIBRARY_PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/usr/lib;' call EnvAddFront 1, 'LIBRARY_PATH', sPathRootF'/out/'sBuildTarget'.'sBuildArch'/'sType'/dist/usr/lib/gcc-lib/i386-pc-os2-emx/3.3.5;' do j = 1 to asStages.0 call EnvAddFront 1,'BEGINLIBPATH', sPathRoot'\out\'sBuildTarget'.'sBuildArch'\'sType'\obj\gcc\gcc\'asStages.j';' end call EnvAddFront 1, 'BEGINLIBPATH', sPathRoot'\out\'sBuildTarget'.'sBuildArch'\'sType'\dist\lib;' call EnvAddFront 1, 'BEGINLIBPATH', sPathRoot'\out\'sBuildTarget'.'sBuildArch'\'sType'\dist\usr\lib;' end if (fUseBuildEnv) then do 'call BuildEnv.cmd unixõ vac365õ vac308õ toolkit452õ toolkit40õ emxõ emxpgccõ gcc302õ gcc303õ gcc321õ gcc322õ gcc335õ' call EnvAddFront 1, 'PATH', '.;' /* the sucker gets removed by 'buildenv toolkit40õ' */ end /* unset some varible which may f**k up. */ call EnvSet 1, 'AC_PREFIX' call EnvSet 1, 'AC_MACRODIR' call EnvSet 1, 'CC', '' call EnvSet 1, 'CFLAGS', '' call EnvSet 1, 'CXX', '' call EnvSet 1, 'CXXFLAGS', '' call EnvSet 1, 'LD', '' call EnvSet 1, 'LDFLAGS', '' call EnvSet 1, 'GCCLOAD', '' call EnvSet 1, 'PERL5LIB', '' call EnvSet 1, 'PERL5LOAD', '' call EnvSet 1, 'TPERL', '' call EnvSet 1, 'BISON_HAIRY', '' call EnvSet 1, 'BISON_SIMPLE', '' call EnvSet 1, 'EMXSHELL', '' /* messes up stuff */ if (EnvGet('LIBC_HOOK_DLLS') <> '') then do say 'warning: removing LIBC_HOOK_DLLS="'||EnvGet('LIBC_HOOK_DLLS')||'" because it usually crashes on fork (perl bootstrap crash).' call EnvSet 1, 'LIBC_HOOK_DLLS', '' end /* /* bird basics */ if (fUseBuildEnv & \fRm) then 'call BuildEnv.cmd cvs~ emx~ ';/*svn~'*/*/ /* We do not want any influence from the emx, that's only runtime stuff. */ call EnvSet 1, 'LDPATH' call EnvSet 1, 'LIBRARY_PATH' call EnvSet 1, 'C_INCLUDE_PATH' call EnvSet 1, 'CPLUS_INCLUDE_PATH' call EnvSet 1, 'COBJ_INCLUDE_PATH' /* icsdebug */ if (fileExists(sPathUnix'\opt\icsdebug\bin\icsdebug.exe')) then do call EnvAddFront fRm, 'PATH', sPathUnix'\opt\icsdebug\bin;'; call EnvAddFront fRm, 'DPATH', sPathUnix'\opt\icsdebug\help;'; call EnvAddFront fRm, 'HELP', sPathUnix'\opt\icsdebug\help;'; call EnvAddFront fRm, 'BEGINLIBPATH', sPathUnix'\opt\icsdebug\dll;'; call EnvAddFront fRm, 'LOCPATH', sPathUnix'\opt\icsdebug\locale;'; end /* idebug */ if (fileExists(sPathUnix'\opt\idebug\bin\idebug.exe')) then do call EnvAddFront fRm, 'PATH', sPathUnix'\opt\idebug\bin;'; call EnvAddFront fRm, 'DPATH', sPathUnix'\opt\idebug\help;'; call EnvAddFront fRm, 'HELP', sPathUnix'\opt\idebug\help;'; call EnvAddFront fRm, 'BEGINLIBPATH', sPathUnix'\opt\idebug\dll;'; call EnvAddFront fRm, 'NLSPATH', sPathUnix'\opt\icsdebug\msg\%N;'; end /* unixroot (assumes perl, tcl and stuff...) */ call EnvSet fRm, 'UNIXROOT', sPathUnixF call EnvAddFront fRm, 'PATH', sPathUnixF'/usr/local/bin;' call EnvAddFront fRm, 'PATH', sPathUnix'\usr\local\bin;' call EnvAddFront fRm, 'PATH', sPathUnixF'/usr/bin;' call EnvAddFront fRm, 'PATH', sPathUnix'\usr\bin;' call EnvAddFront fRm, 'PATH', sPathUnixF'/bin;' call EnvAddFront fRm, 'PATH', sPathUnix'\bin;' call EnvAddFront fRm, 'BEGINLIBPATH', sPathUnix'\lib;'sPathUnix'\usr\lib;'sPathUnix'\usr\local\lib;' call EnvAddFront fRm, 'C_INCLUDE_PATH', sPathUnixF'/usr/include;'sPathUnixF'/usr/local/include;' call EnvAddFront fRm, 'CPLUS_INCLUDE_PATH', sPathUnixF'/usr/include;'sPathUnixF'/usr/local/include;' call EnvAddFront fRm, 'OBJC_INCLUDE_PATH', sPathUnixF'/usr/include;'sPathUnixF'/usr/local/include;' call EnvAddFront fRm, 'LIBRARY_PATH', sPathUnixF'/lib;'sPathUnixF'/usr/lib;'sPathUnixF'/usr/local/lib;' call EnvSet fRm, 'PATH_SEPARATOR', ';' sShell = ''; if (sShell = '' & FileExists(sPathUnixF'/bin/ash.exe')) then sShell = sPathUnixF'/bin/ash.exe'; if (sShell = '' & FileExists(sPathUnixF'/bin/sh.exe')) then sShell = sPathUnixF'/bin/sh.exe'; if (sShell = '' & FileExists(sPathUnixF'/bin/bash.exe')) then sShell = sPathUnixF'/bin/bash.exe'; if (sShell = '') then sShell = sPathkBuildF'/bin/os2.x86/kmk_ash.exe'; call EnvSet fRm, 'CONFIG_SHELL', sShell call EnvSet fRm, 'MAKESHELL', sShell call EnvSet fRm, 'SHELL', sShell call EnvSet fRM, 'PERLLIB_PREFIX', 'L:/Perl/lib;'sPathUnixF'/usr/lib/perl5' /*call EnvSet fRM, 'PERL_SH_DIR', sPathUnixF'/bin' */ call EnvSet fRM, 'PERL_BADLANG', '0' call EnvSet fRM, 'TCL_LIBRARY', sPathUnixF'/usr/lib/tcl8.0' /* unixroot: must have all the temp variables with unix slashes. */ if (\fRm) then do sTmpF = ToUnixSlash(FixPath(EnvGet('TMP'))); if (sTmpF = '') then sTmpF = sPathUnixF'/tmp'; if (\DirExists(sTmpF)) then say 'warning: TMP='''sTmpF''' doesn''t exist!'; call EnvSet fRM, 'TMP', sTmpF; call EnvSet fRM, 'TEMP', sTmpF; call EnvSet fRM, 'TMPDIR', sTmpF; if ( pos(filespec('drive', sTmpF), SysDriveMap(filespec('drive', sTmpF), "REMOTE")) > 0, & word(SysDriveInfo(filespec('drive', sTmpF)), 4) = 'RAMDISK') then do say 'warning: detected RAMFS, setting TMPDIR to ''.'' to make sure yacc will work.' call EnvSet fRM, 'TMPDIR', '.'; end end /* unixroot: hostname */ sHostName = EnvGet('HOSTNAME'); if (sHostName = '') then do say 'warning: hostname not set. using ''localhost'' as hostname.'; sHostName = 'localhost'; call EnvSet fRm, 'HOSTNAME', sHostName; end /* unixroot: there must a user and home directory. */ if (EnvGet('USER') = '') then call EnvSet fRm, 'USER', EnvGet('USERNAME'); if (EnvGet('USER') = '') then call EnvSet fRm, 'USER', EnvGet('LOGNAME'); if (EnvGet('USER') = '') then call EnvSet fRm, 'USER', sHostName; if (EnvGet('USERNAME') = '') then call EnvSet fRm, 'USERNAME', EnvGet('USER'); if (EnvGet('LOGNAME') = '') then call EnvSet fRm, 'LOGNAME', EnvGet('USER'); if (EnvGet('HOME') = '') then call EnvSet fRm, 'HOME', ToUnixSlash(EnvGet('TMP')); /* unixroot: libtool */ call EnvSet fRm, 'LT_OS2_DLL_PREFIX', 'k' call EnvSet 1, 'LT_OS2_DLL_MAPPED', '' /* kBuild. */ call EnvSet fRm, 'PATH_KBUILD', sPathkBuildF call EnvAddFront fRm, 'PATH', sPathkBuild'\bin\os2.x86;' call EnvAddFront fRm, 'BEGINLIBPATH', sPathkBuild'\bin\os2.x86;' call EnvSet fRm, 'BUILD_TYPE', sBuildType call EnvSet fRm, 'BUILD_TARGET', sBuildTarget call EnvSet fRm, 'BUILD_TARGET_ARCH', 'x86' call EnvSet fRm, 'BUILD_TARGET_CPU', 'i386' call EnvSet fRm, 'BUILD_PLATFORM', sBuildTarget call EnvSet fRm, 'BUILD_PLATFORM_ARCH','x86' call EnvSet fRm, 'BUILD_PLATFORM_CPU', 'i386' /* Workaround for make handle leak. */ call EnvSet fRm, 'EMXOPT', '-c -n -h1024'; /* GCC */ call GCC3xx 'gcc335', fRm, sPathGcc /* The built stuff? */ if (fWithBuiltStuff) then do call EnvSet fRm, 'PATH_BUILTUNIX', sPathOutF'/dist' call EnvAddFront fRm, 'PATH', sPathOutF'/dist/usr/bin;' call EnvAddFront fRm, 'PATH', sPathOut'\dist\usr\bin;' call EnvAddFront fRm, 'PATH', sPathOutF'/dist/bin;' call EnvAddFront fRm, 'PATH', sPathOut'\dist\bin;' call EnvAddFront fRm, 'PATH', sPathOut'\dist\usr\omfhackbin;' /* remove me! */ call EnvAddFront fRm, 'BEGINLIBPATH', sPathOut'\dist\usr\lib;' call EnvAddFront fRm, 'C_INCLUDE_PATH', sPathOutF'/dist/usr/include;' call EnvAddFront fRm, 'CPLUS_INCLUDE_PATH', sPathOutF'/dist/usr/include;' call EnvAddFront fRm, 'OBJC_INCLUDE_PATH', sPathOutF'/dist/usr/include;' call EnvAddFront fRm, 'LIBRARY_PATH', sPathOutF'/dist/usr/lib;' call EnvAddFront fRm, 'LIBRARY_PATH', sPathOutF'/dist/usr/lib/gcc-lib/i386-pc-os2-emx/3.3.5;' end /* fix LIBRARY_PATH (gcc configure is kind of picky about this). */ if (\fRm) then do sTmp = EnvGet('LIBRARY_PATH'); iPos = pos(';;', sTmp); do while (iPos > 0) sTmp = left(sTmp, iPos - 1)||substr(sTmp, iPos+1); iPos = pos(';;', sTmp); end sTmp = strip(sTmp, 'B', ';'); call EnvSet fRm, 'LIBRARY_PATH', sTmp; drop sTmp; end exit(rc); /******************************************************************************* * Procedure Section * *******************************************************************************/ /** * Give the script syntax */ syntax: procedure say 'syntax: env.cmd [options] [mode]' say '' say 'Mode:' say ' The build mode, debug or release. Default it debug.' say '' say 'Options:' say ' --gcc ' say ' --unixroot ' say ' --kBuild ' say '' return 0; /** * No value handler */ NoValueHandler: say 'NoValueHandler: line 'SIGL; exit(16); /** * Add sToAdd in front of sEnvVar. * Note: sToAdd now is allowed to be alist! * * Known features: Don't remove sToAdd from original value if sToAdd * is at the end and don't end with a ';'. */ EnvAddFront: procedure parse arg fRM, sEnvVar, sToAdd, sSeparator /* sets default separator if not specified. */ if (sSeparator = '') then sSeparator = ';'; /* checks that sToAdd ends with an ';'. Adds one if not. */ if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then sToAdd = sToAdd || sSeparator; /* check and evt. remove ';' at start of sToAdd */ if (substr(sToAdd, 1, 1) = ';') then sToAdd = substr(sToAdd, 2); /* loop thru sToAdd */ rc = 0; i = length(sToAdd); do while i > 1 & rc = 0 j = lastpos(sSeparator, sToAdd, i-1); rc = EnvAddFront2(fRM, sEnvVar, substr(sToAdd, j+1, i - j), sSeparator); i = j; end return rc; /** * Add sToAdd in front of sEnvVar. * * Known features: Don't remove sToAdd from original value if sToAdd * is at the end and don't end with a ';'. */ EnvAddFront2: procedure parse arg fRM, sEnvVar, sToAdd, sSeparator /* sets default separator if not specified. */ if (sSeparator = '') then sSeparator = ';'; /* checks that sToAdd ends with a separator. Adds one if not. */ if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then sToAdd = sToAdd || sSeparator; /* check and evt. remove the separator at start of sToAdd */ if (substr(sToAdd, 1, 1) = sSeparator) then sToAdd = substr(sToAdd, 2); /* Get original variable value */ sOrgEnvVar = EnvGet(sEnvVar); /* Remove previously sToAdd if exists. (Changing sOrgEnvVar). */ i = pos(translate(sToAdd), translate(sOrgEnvVar)); if (i > 0) then sOrgEnvVar = substr(sOrgEnvVar, 1, i-1) || substr(sOrgEnvVar, i + length(sToAdd)); /* set environment */ if (fRM) then return EnvSet(0, sEnvVar, sOrgEnvVar); return EnvSet(0, sEnvVar, sToAdd||sOrgEnvVar); /** * Add sToAdd as the end of sEnvVar. * Note: sToAdd now is allowed to be alist! * * Known features: Don't remove sToAdd from original value if sToAdd * is at the end and don't end with a ';'. */ EnvAddEnd: procedure parse arg fRM, sEnvVar, sToAdd, sSeparator /* sets default separator if not specified. */ if (sSeparator = '') then sSeparator = ';'; /* checks that sToAdd ends with a separator. Adds one if not. */ if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then sToAdd = sToAdd || sSeparator; /* check and evt. remove ';' at start of sToAdd */ if (substr(sToAdd, 1, 1) = sSeparator) then sToAdd = substr(sToAdd, 2); /* loop thru sToAdd */ rc = 0; i = length(sToAdd); do while i > 1 & rc = 0 j = lastpos(sSeparator, sToAdd, i-1); rc = EnvAddEnd2(fRM, sEnvVar, substr(sToAdd, j+1, i - j), sSeparator); i = j; end return rc; /** * Add sToAdd as the end of sEnvVar. * * Known features: Don't remove sToAdd from original value if sToAdd * is at the end and don't end with a ';'. */ EnvAddEnd2: procedure parse arg fRM, sEnvVar, sToAdd, sSeparator /* sets default separator if not specified. */ if (sSeparator = '') then sSeparator = ';'; /* checks that sToAdd ends with a separator. Adds one if not. */ if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then sToAdd = sToAdd || sSeparator; /* check and evt. remove separator at start of sToAdd */ if (substr(sToAdd, 1, 1) = sSeparator) then sToAdd = substr(sToAdd, 2); /* Get original variable value */ sOrgEnvVar = EnvGet(sEnvVar); if (sOrgEnvVar <> '') then do /* Remove previously sToAdd if exists. (Changing sOrgEnvVar). */ i = pos(translate(sToAdd), translate(sOrgEnvVar)); if (i > 0) then sOrgEnvVar = substr(sOrgEnvVar, 1, i-1) || substr(sOrgEnvVar, i + length(sToAdd)); /* checks that sOrgEnvVar ends with a separator. Adds one if not. */ if (sOrgEnvVar = '') then if (right(sOrgEnvVar,1) <> sSeparator) then sOrgEnvVar = sOrgEnvVar || sSeparator; end /* set environment */ if (fRM) then return EnvSet(0, sEnvVar, sOrgEnvVar); return EnvSet(0, sEnvVar, sOrgEnvVar||sToAdd); /** * Sets sEnvVar to sValue. */ EnvSet: procedure parse arg fRM, sEnvVar, sValue /* if we're to remove this, make valuestring empty! */ if (fRM) then sValue = ''; sEnvVar = translate(sEnvVar); /* * Begin/EndLibpath fix: * We'll have to set internal these using both commandline 'SET' * and internal VALUE in order to export it and to be able to * get it (with EnvGet) again. */ if ((sEnvVar = 'BEGINLIBPATH') | (sEnvVar = 'ENDLIBPATH')) then do if (length(sValue) >= 1024) then say 'Warning: 'sEnvVar' is too long,' length(sValue)' char.'; return SysSetExtLibPath(sValue, substr(sEnvVar, 1, 1)); end if (length(sValue) >= 1024) then do say 'Warning: 'sEnvVar' is too long,' length(sValue)' char.'; say ' This may make CMD.EXE unstable after a SET operation to print the environment.'; end sRc = VALUE(sEnvVar, sValue, 'OS2ENVIRONMENT'); return 0; /** * Gets the value of sEnvVar. */ EnvGet: procedure parse arg sEnvVar if ((translate(sEnvVar) = 'BEGINLIBPATH') | (translate(sEnvVar) = 'ENDLIBPATH')) then return SysQueryExtLibPath(substr(sEnvVar, 1, 1)); return value(sEnvVar,, 'OS2ENVIRONMENT'); /** * Checks if a file exists. * @param sFile Name of the file to look for. * @param sComplain Complaint text. Complain if non empty and not found. * @returns TRUE if file exists. * FALSE if file doesn't exists. */ FileExists: procedure parse arg sFile, sComplain rc = stream(sFile, 'c', 'query exist'); if ((rc = '') & (sComplain <> '')) then say sComplain ''''sFile'''.'; return rc <> ''; /** * Checks if a directory exists. * @param sDir Name of the directory to look for. * @param sComplain Complaint text. Complain if non empty and not found. * @returns TRUE if file exists. * FALSE if file doesn't exists. */ DirExists: procedure parse arg sDir, sComplain rc = SysFileTree(sDir, 'asDirs', 'DO'); if (rc = 0 & asDirs.0 = 1) then rc = 1; else rc = 0; if (rc = 0 & sComplain <> '') then say sComplain ''''sDir'''.'; drop asDirs.; return rc; /** * GCC 3.3.x. */ GCC3xx: procedure expose aCfg. aPath. sPathFile sPathUnix sPathUnixF parse arg sToolId, fRM, sPathGcc sGCCBack = ToDosSlash(sPathGcc); sGCCForw = ToUnixSlash(sPathGcc); chMajor = '3'; chMinor = left(right(sToolId, 2), 1); chRel = right(sToolId, 1); sVer = chMajor'.'chMinor'.'chRel call EnvSet fRM, 'PATH_IGCC', sGCCBack; call EnvAddFront fRM, 'BEGINLIBPATH', sGCCBack'\lib;' call EnvAddFront fRM, 'PATH', sGCCForw'/bin;'sGCCBack'\bin;' call EnvAddFront fRM, 'C_INCLUDE_PATH', sGCCForw'/include' call EnvAddFront fRM, 'LIBRARY_PATH', sGCCForw'/lib/gcc-lib/i386-pc-os2-emx/'sVer';'sGCCForw'/lib;' call EnvAddFront fRm, 'CPLUS_INCLUDE_PATH', sGCCForw'/include;' call EnvAddFront fRm, 'CPLUS_INCLUDE_PATH', sGCCForw'/include/c++/'sVer'/backward;' call EnvAddFront fRm, 'CPLUS_INCLUDE_PATH', sGCCForw'/include/c++/'sVer'/i386-pc-os2-emx;' call EnvAddFront fRm, 'CPLUS_INCLUDE_PATH', sGCCForw'/include/c++/'sVer';' call EnvSet fRM, 'PROTODIR', sGCCForw'/include/cpp/gen' call EnvSet fRM, 'OBJC_INCLUDE_PATH', sGCCForw'/include' if (1) then do say 'info: Using wl.exe as OMF linker.'; call EnvSet fRM, 'EMXOMFLD_TYPE', 'WLINK' call EnvSet fRM, 'EMXOMFLD_LINKER', 'wl.exe' end else do say 'info: Using ilink.exe (v5) as OMF linker.'; call EnvSet fRM, 'EMXOMFLD_TYPE', 'VAC365' call EnvSet fRM, 'EMXOMFLD_LINKER', 'ilink.exe' end return 0; /** * Workaround for bug in CMD.EXE. * It messes up when REXX have expanded the environment. */ FixCMDEnv: procedure /* force environment expansion by setting a lot of variables and freeing them. * ~6600 (bytes) */ do i = 1 to 100 Address CMD '@set dummyenvvar'||i'=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; end do i = 1 to 100 Address CMD '@set dummyenvvar'||i'='; end return 0; /** * Fixes the casing of a path. * Returns a DOS path. */ FixPath: procedure parse arg sPath sPath = ToDosSlash(sPath); sDrv = translate(strip(filespec('drive', sPath))); if (sDrv = '' & left(sPath, 2) = '\\') then sDrv = '\\' || translate(word(strip(translate(sPath, ' ', '\')), 1)); sPath = substr(sPath, length(sDrv) + 1); if (sPath = '\' | sPath = '/') then return sDrv||sPath; /* split the path into words and take them on one by one. */ sPath = strip(translate(sPath, ' ', '\/')); sNewPath = sDrv; do i = 1 to words(sPath) sCur = word(sPath, i); sTmp = sNewPath'\'sCur; rc = SysFileTree(sTmp'?', 'asEntries', 'BO'); if (rc = 0) then do do j = 1 to asEntries.0 sName = filespec('name', asEntries.j); if (ToLower(sName) = ToLower(sCur)) then do sTmp = asEntries.j; leave end end drop asEntries.; end sNewPath = sTmp; end return sNewPath; /** * Translate a string to lower case. */ ToLower: procedure parse arg sString return translate(sString, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); /** * Translate a path to unix slashes. */ ToUnixSlash: procedure parse arg sPath return translate(sPath, '/', '\'); /** * Translate a path to dos slashes. */ ToDosSlash: procedure parse arg sPath return translate(sPath, '\', '/');