Ticket #110: gccenv.cmd.452

File gccenv.cmd.452, 11.6 KB (added by Dmitry A. Kuminov, 13 years ago)

A fresh gccenv.cmd suitable for GCC 4.5.2

Line 
1/* $Id: gccenv.cmd 3376 2007-06-05 21:05:46Z bird $
2 *
3 * GCC environment script.
4 *
5 * Copyright (c) 2003 InnoTek Systemberatung GmbH
6 * Author: knut st. osmundsen <bird-srcspam@anduin.net>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with This program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 *
23 */
24
25/*
26 * Typical init.
27 */
28signal on novalue name NoValueHandler
29if (RxFuncQuery('SysLoadFuncs') = 1) then
30do
31    call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs';
32    call SysLoadFuncs;
33end
34call FixCMDEnv
35
36/*
37 * Parse any args.
38 */
39parse arg sPath sLinker sDummy
40if (sPath = '') then
41do
42    /* Default is that this script resides in /usr/bin/. */
43    parse source . . sSrc
44    sPath = filespec('drive', sSrc)||strip(filespec('path', strip(filespec('path', sSrc), 'T', '\')), 'T', '\');
45end
46
47sLinker = translate(sLinker);
48if (sLinker <> '' & sLinker <> 'VAC308' & sLinker <> 'VAC365' & sLinker <> 'LINK386' & sLinker <> 'WLINK') then
49do
50    say 'Syntax error: Invalid linker '''sLinker''' specified.';
51    say ''
52    call Usage;
53    exit 8;
54end
55
56
57/*
58 * Do work.
59 */
60call GCC322plus sPath, 'gcc452', 0, sLinker;
61exit 0;
62
63
64/**
65 * Display usage info for script.
66 */
67Usage: procedure
68    say 'syntax: gccenv.cmd [gcc-usr-path [linker]]';
69    say ''
70    say '[gcc-usr-path] is the path to the /usr directory of the gcc distro.'
71    say 'If [gcc-usr-path] isn''t specified, the script assumes it''s located'
72    say 'in /usr/bin of the gcc distro and deducts the path based on that.'
73    say ''
74    say '[linker] is the EMXOMFLD_TYPE as described by emxomfld.exe usage. It''s'
75    say 'thus either LINK386, VAC308 or VAC365.'
76    say ''
77    say 'Copyright (c) 2003 InnoTek Systemberatung GmbH'
78    say ''
79return 0;
80
81
82
83/**
84 * Innotek GCC 3.2.x and higher - this environment is EMX RT free.
85 * @param   sPath       The path of the /usr directory in the GCC distro.
86 * @param   sToolId     Tool identificator. gcc335
87 * @param   fRM         If set we'll remove the environment setup.
88 *                      If clear we'll install it.
89 * @param   sLinker     Which linker to use. If blank use emxomfld default linker.
90 */
91GCC322plus: procedure
92    parse arg sPath, sToolId, fRM, sLinker
93
94    /*
95     * EMX/GCC main directory.
96     */
97
98    /* parse out the version / constants */
99    chMajor     = '4';
100    chMinor     = '5';
101    chRel       = '2';
102    sVer        = chMajor'.'chMinor'.'chRel
103    sVerShrt    = chMajor||chMinor||chRel;
104    sTrgt       = 'i386-pc-os2-emx'
105    chNewMajor  = left(right(sToolId, 3), 1);
106    chNewMinor  = left(right(sToolId, 2), 1);
107    chNewRel    = right(sToolId, 1);
108    sNewVer     = chNewMajor'.'chNewMinor'.'chNewRel;
109    sNewDir     = 'local'||chNewMajor||chNewMinor||chNewRel;
110
111    sGCCBack    = translate(sPath, '\', '/');
112    sGCCForw    = translate(sPath, '/', '\');
113   
114    if (stream(sGCCBack'\bin\gcc.exe', 'c', 'query exist') = '' &,
115        stream(sGCCBack'\'sNewDir'\bin\gcc.exe', 'c', 'query exist') = '') then
116    do
117        say 'Error: cannot find gcc.exe in '''sGCCBack'\bin'' or in '''sGCCBack'\'sNewDir'\bin''!';
118        say ''
119        call Usage;
120        exit 8;
121    end
122   
123    call EnvSet      fRM, 'PATH_EMXPGCC',   sGCCBack;
124    call EnvSet      fRM, 'CCENV',          'EMX'
125    call EnvSet      fRM, 'BUILD_ENV',      'EMX'
126    call EnvSet      fRM, 'BUILD_PLATFORM', 'OS2'
127
128    call EnvAddFront fRM, 'BEGINLIBPATH',       sGCCBack'\lib;'
129    call EnvAddFront fRM, 'BEGINLIBPATH',       sGCCBack'\'sNewDir'\lib;'
130    call EnvAddFront fRM, 'DPATH',              sGCCBack'\lib;'
131    call EnvAddFront fRM, 'DPATH',              sGCCBack'\'sNewDir'\lib;'
132    /*call EnvAddFront fRM, 'HELP',               sGCCBack'\lib;'*/
133    call EnvAddFront fRM, 'PATH',               sGCCBack'\bin;'
134    call EnvAddFront fRM, 'PATH',               sGCCBack'\'sNewDir'\bin;'
135    call EnvAddFront fRM, 'PATH',               sGCCBack'\'sNewDir'\libexec\gcc\'sTrgt'\'sNewVer';'
136    /*call EnvAddFront fRM, 'DPATH',              sGCCBack'\book;'
137    call EnvAddFront fRM, 'BOOKSHELF',          sGCCBack'\book;'
138    call EnvAddFront fRM, 'HELP',               sGCCBack'\help;' */
139    call EnvAddFront fRM, 'C_INCLUDE_PATH',     sGCCForw'/include;'
140    call EnvAddFront fRM, 'C_INCLUDE_PATH',     sGCCForw'/'sNewDir'/include;'
141    call EnvAddFront fRM, 'C_INCLUDE_PATH',     sGCCForw'/'sNewDir'/lib/gcc/'sTrgt'/'sNewVer'/include;'
142    call EnvAddFront fRM, 'CPLUS_INCLUDE_PATH', sGCCForw'/include;'
143    call EnvAddFront fRM, 'CPLUS_INCLUDE_PATH', sGCCForw'/'sNewDir'/include;'
144    call EnvAddFront fRM, 'CPLUS_INCLUDE_PATH', sGCCForw'/'sNewDir'/include/c++/'sNewVer'/backward;'
145    call EnvAddFront fRM, 'CPLUS_INCLUDE_PATH', sGCCForw'/'sNewDir'/include/c++/'sNewVer'/'sTrgt';'
146    call EnvAddFront fRM, 'CPLUS_INCLUDE_PATH', sGCCForw'/'sNewDir'/include/c++/'sNewVer';'
147    call EnvAddFront fRM, 'LIBRARY_PATH',       sGCCForw'/lib;'
148    call EnvAddFront fRM, 'LIBRARY_PATH',       sGCCForw'/'sNewDir'/lib;'
149    call EnvAddFront fRM, 'LIBRARY_PATH',       sGCCForw'/'sNewDir'/lib/gcc/'sTrgt'/'sNewVer';'
150    call EnvAddFront fRM, 'INFOPATH',           sGCCForw'/info;'
151    call EnvAddFront fRM, 'INFOPATH',           sGCCForw'/'sNewDir'/info;'
152    /* is this used? */
153    call EnvSet      fRM, 'PROTODIR',           sGCCForw'/include/c++/gen'
154
155    /* use wlink? */
156    if (sLinker = 'WLINK') then
157    do
158        call EnvSet  fRM, 'EMXOMFLD_TYPE',      'WLINK';
159        call EnvSet  fRM, 'EMXOMFLD_LINKER',    'wl.exe';
160        /* call EnvSet  fRM, 'EMXOMFLD_LINKER',    'wl.exe'; - comment this in if you use an official OpenWatcom wlink. */
161    end
162
163    /* use link386? */
164    if (sLinker = 'LINK386') then
165    do
166        call EnvSet  fRM, 'EMXOMFLD_TYPE',      'LINK386';
167        call EnvSet  fRM, 'EMXOMFLD_LINKER',    'link386.exe';
168    end
169
170    /* use vac308? */
171    if (sLinker = 'VAC308') then
172    do
173        call EnvSet  fRM, 'EMXOMFLD_TYPE',      'VAC308';
174        call EnvSet  fRM, 'EMXOMFLD_LINKER',    'ilink.exe';
175    end
176
177    /* use default or VAC365? */
178    if (sLinker = '' | sLinker = 'VAC365') then
179    do
180        call EnvSet  1, 'EMXOMFLD_TYPE';
181        call EnvSet  1, 'EMXOMFLD_LINKER';
182    end
183
184return 0;
185
186
187/**
188 * Add sToAdd in front of sEnvVar. sToAdd may be a list.
189 *
190 * See EnvAddFrontOrBack for details.
191 */
192EnvAddFront: procedure
193    parse arg fRM, sEnvVar, sToAdd, sSeparator
194return EnvAddFrontOrBack(1, fRM, sEnvVar, sToAdd, sSeparator);
195
196
197/**
198 * Add sToAdd in front of sEnvVar. sToAdd may be a list.
199 *
200 * See EnvAddFrontOrBack for details.
201 */
202EnvAddEnd: procedure
203    parse arg fRM, sEnvVar, sToAdd, sSeparator
204return EnvAddFrontOrBack(0, fRM, sEnvVar, sToAdd, sSeparator);
205
206
207/**
208 * Add sToAdd in front or at the end of sEnvVar. sToAdd may be a list.
209 *
210 * Note: This function will remove leading and trailing semicolons, as well
211 * as duplcate semicolons somewhere in the middle. See
212 *
213 *   http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Environment-Variables.html
214 *
215 * (CPLUS_INCLUDE_PATH and friends) for the explaination why it is necessary to
216 * do. If you want to specifially mean the current working directory, use "."
217 * instead of an empty path element.
218 */
219EnvAddFrontOrBack: procedure
220    parse arg fFront, fRM, sEnvVar, sToAdd, sSeparator
221
222    /* sets default separator if not specified. */
223    if (sSeparator = '') then sSeparator = ';';
224
225    /* get rid of extra ';' */
226    sToAdd = strip(sToAdd,, sSeparator);
227    sToAddClean = ''
228    do i = 1 to length(sToAdd)
229        ch = substr(sToAdd, i, 1);
230        if (ch == sSeparator & right(sToAddClean, 1) == sSeparator) then
231            iterate
232        sToAddClean = sToAddClean||ch
233    end
234
235    /* Get original variable value */
236    sOrgEnvVar = EnvGet(sEnvVar);
237
238    /* loop thru sToAddClean */
239    rc = 0;
240    i = length(sToAddClean);
241    do while (i > 0 & rc = 0)
242        j = lastpos(sSeparator, sToAddClean, i);
243        sOne = substr(sToAddClean, j+1, i - j);
244        cbOne = length(sOne);
245        /* Remove previous sOne if exists. (Changing sOrgEnvVar). */
246        s1 = 1;
247        do while (s1 <= length(sOrgEnvVar))
248            s2 = pos(sSeparator, sOrgEnvVar, s1);
249            if (s2 == 0) then
250                s2 = length(sOrgEnvVar) + 1;
251            if (translate(substr(sOrgEnvVar, s1, s2 - s1)) == translate(sOne)) then do
252                sOrgEnvVar = delstr(sOrgEnvVar, s1, s2 - s1 + 1 /*+sep*/);
253                s1 = s1 + 1;
254            end
255            else do
256                s1 = s2 + 1;
257            end
258        end
259        sOrgEnvVar = strip(sOrgEnvVar,, sSeparator);
260
261        i = j - 1;
262    end
263
264    /* set environment */
265    if (fRM) then
266        return EnvSet(0, sEnvVar, sOrgEnvVar);
267
268    /* add sToAddClean in necessary mode */
269    if (fFront) then
270    do
271        if (sOrgEnvVar \== '' & left(sOrgEnvVar, 1) \== sSeparator) then
272            sOrgEnvVar = sSeparator||sOrgEnvVar;
273        sOrgEnvVar = sToAddClean||sOrgEnvVar;
274    end
275    else
276    do
277        if (sOrgEnvVar \== '' & right(sOrgEnvVar, 1) \== sSeparator) then
278            sOrgEnvVar = sOrgEnvVar||sSeparator;
279        sOrgEnvVar = sOrgEnvVar||sToAddClean;
280    end
281
282return EnvSet(0, sEnvVar, sOrgEnvVar);
283
284
285/**
286 * Sets sEnvVar to sValue.
287 */
288EnvSet: procedure
289    parse arg fRM, sEnvVar, sValue
290
291    /* if we're to remove this, make valuestring empty! */
292    if (fRM) then
293        sValue = '';
294    sEnvVar = translate(sEnvVar);
295
296    /*
297     * Begin/EndLibpath fix:
298     *      We'll have to set internal these using both commandline 'SET'
299     *      and internal VALUE in order to export it and to be able to
300     *      get it (with EnvGet) again.
301     */
302    if ((sEnvVar = 'BEGINLIBPATH') | (sEnvVar = 'ENDLIBPATH')) then
303    do
304        if (length(sValue) >= 1024) then
305            say 'Warning: 'sEnvVar' is too long,' length(sValue)' char.';
306        return SysSetExtLibPath(sValue, substr(sEnvVar, 1, 1));
307    end
308
309    if (length(sValue) >= 1024) then
310    do
311        say 'Warning: 'sEnvVar' is too long,' length(sValue)' char.';
312        say '    This may make CMD.EXE unstable after a SET operation to print the environment.';
313    end
314    sRc = VALUE(sEnvVar, sValue, 'OS2ENVIRONMENT');
315return 0;
316
317/**
318 * Gets the value of sEnvVar.
319 */
320EnvGet: procedure
321    parse arg sEnvVar
322    if ((translate(sEnvVar) = 'BEGINLIBPATH') | (translate(sEnvVar) = 'ENDLIBPATH')) then
323        return SysQueryExtLibPath(substr(sEnvVar, 1, 1));
324return value(sEnvVar,, 'OS2ENVIRONMENT');
325
326
327/**
328 *  Workaround for bug in CMD.EXE.
329 *  It messes up when REXX have expanded the environment.
330 */
331FixCMDEnv: procedure
332    /* check for 4OS2 first */
333    Address CMD '@set 4os2test_env=%@eval[2 + 2]';
334    if (value('4os2test_env',, 'OS2ENVIRONMENT') = '4') then
335        return 0;
336
337    /* force environment expansion by setting a lot of variables and freeing them. */
338    do i = 1 to 100
339        Address CMD '@set dummyenvvar'||i'=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
340    end
341    do i = 1 to 100
342        Address CMD '@set dummyenvvar'||i'=';
343    end
344return 0;
345