Is it possible to add to .gitignore rules depends on environment variables?
for example
if -e $(ENV_VAR) \"AAA\"
!liba.so
else
liba.so
The answer is no. Gitignore rules are static. You can turn around it by dynamically creating your .gitignore file. So, you will also have dynamically created static rules.
This can be easily done within the application building system such a Makefile. The .gitignore file can rebuilt each time the project is built.
Example Makefile:
all: my_app .gitignore
.gitignore: some deps
cp my_static_gitignore_rules .gitignore
echo 'dynamically_created_rule1' >> .gitignore
echo 'dynamically_created_rule2' >> .gitignore
my_app: my_app.c
...