Copyright (C) 2002-2020 Arnaud BERTRAND
web-site: http://apvsys.sourceforge.net
The ap-environment file is a kind of setup script executed before each command related to a tool or version of a tool. This file can be written in C, perl, sh, csh, bash, ksh or tcsh and must be located in the root directory of the tool/version: $APVSYS_ROOT/OsName/vOsVersion/ToolName/vToolVersion/ap-environment.xx
Warning: The extension of ap-environment.xx determines which interpreter will start according to the following list.
so -> C compiled code
pl -> perl
sh -> sh
csh -> csh
bash -> bash
ksh -> ksh
tcsh -> tcsh
The priority order is the order above with .so having greatest priority but it would be very strange to require 2 ap-environment.xx files for the same version of a tool!
Some variables and functions are available for use in these scripts:
TOOLPATH : This variable is set to $APVSYS_ROOT/OsName/vOsVersion for example: /ap/apvroot/SunOS/v5.8
CHOSENTOOL : This variable is set to Toolname/vToolVersion for example gcc/v2.95.3 and will be used in combination with TOOLPATH to reference the root of the tool of the command currently executed. (see examples)
APVSYS_TARGET : this variable contains the command ( not the full path ) to be executed.
APVSYS_LICENSE_CMD : this variable can be set to a dedicated command which displays the license status. If the tool is using flexlm and the LM_LICENSE_FILE is defined in the ap-environment file, the command lmstat -a is assumed (if APVSYS_LICENSE_CMD is not defined).
APVSYS_PREFIXCMD : this variable can be set to any string that will prefix the started command. The content of the variable is concatenated to the command without any space character. This is typically interresting for commands like "sudo". E.g. setting APVSYS_PREFIXCMD variable to "/usr/bin/sudo flexadm " will allow commands to be started as different user.
NOTE: this variable can only be set in an ap-environment file (it is unset before reading ap-environment file).
of course, the syntax of these commands depends on the language used. Please read the syntax section.
loadenv : This function allows the apvsys administrator to define dependencies between tools, for example when a tool must use a library defined in another tool. This function specifies the name of the tool and can optionally specify a version.
e.g. : loadenv("gcc","v2.95.3") or loadenv("gcc","default") or loadenv("gcc").
uniquify_env : used to uniquify the fields of an environment variable.
prepend_env : put a new value at the beginning of an existing variable AND uniquifies this variable.
append_env : put a new value at the end of an existing variable AND uniquifies this variable.
To show the syntax, an example will be shown for each language:
This file is the only one which has to be compiled. It comes from ap-environment.c and must contains the function int apenvironment(int argc, char** argv). This functions must return 1 if successful. To compile ap-environment.c, the script apv-envCompile MUST be used. Here is an example:
int apenvironment(int argc, char **argv) {
printf("--- C environment setting ---\n");
loadenv("apv-child1",0,argc,argv);
loadenv("apv-child2","v2.0",argc,argv);
set_env("APVEXAMPLE","C tested");
set_env("APVUNIQ","c:ca:cb:ca:ca:c:cc");
uniquify_env(getenv("APVUNIQ"));
set_env("APVAPPEND","first:set");
set_env("APVPREPEND","first:set");
append_env("APVAPPEND", "second:set");
prepend_env("APVPREPEND", "second:set");
printf("--- END C environment setting ---\n");
return 1;
}
IMPORTANT NOTE: loadenv must contains 4 arguments and the last two arguments are argc, argv.
print "--- perl environment setting ---\n";
&loadenv("apv-child1");
&loadenv("apv-child2", "v2.0");
$ENV{APVEXAMPLE}="perl tested";
$ENV{APVUNIQ}=&uniquify_env("pl:pla:plb:pla:pla:pl:plc");
$ENV{APVAPPEND}="first:set";
$ENV{APVPREPEND}="first:set";
&append_env("APVAPPEND", "second:set");
&prepend_env("APVPREPEND", "second:set");
print "--- END perl environment setting ---\n";
echo "--- sh environment setting ---"
loadenv "apv-child1"
loadenv "apv-child2" "v2.0"
APVEXAMPLE="sh tested"
APVUNIQ=`uniquify_env "sh:sha:shb:sha:sha:sh:shc"`
APVAPPEND="first:set"
APVPREPEND="first:set"
append_env APVAPPEND "second:set"
prepend_env APVPREPEND "second:set"
export APVUNIQ
export APVEXAMPLE
echo "--- END sh environment setting ---"
echo "--- csh environment setting ---"
loadenv "apv-child1"
loadenv "apv-child2" "v2.0"
setenv APVEXAMPLE "csh tested"
setenv APVUNIQ `uniquify_env "csh:csha:cshb:csha:csha:csh:cshc"`
setenv APVAPPEND "first:set"
setenv APVPREPEND "first:set"
append_env APVAPPEND "second:set"
prepend_env APVPREPEND "second:set"
echo "--- END csh environment setting ---"