I have problems with using pkg-config in a Makefile, while running in sudo mode. I need to have PKG_CONFIG_PATH set for pkg-config to find geany.pc file that is held in /usr/local/lib/pkgconfig.If I run:$ echo $PKG_CONFIG_PATH/usr/local/lib/pkgconfigIf I run with sudo:$ sudo echo $PKG_CONFIG_PATH/usr/local/lib/pkgconfigSo I try running my Makefile that looks like this:PLUGIN_DIR=`pkg-config --variable=libdir geany`/geanyall: pyflakes.o    gcc pyflakes.o -o geanypyflakes.so -shared `pkg-config --libs geany`pyflakes.o: pyflakes.c    gcc -Wall -c pyflakes.c -fPIC `pkg-config --cflags geany` install:    echo ${PKG_CONFIG_PATH}    cp geanypyflakes.so ${PLUGIN_DIR} --verboseclean:    rm geanypyflakes.so pyflakes.osudo make installand I get following ouput:echo cp geanypyflakes.so `pkg-config --variable=libdir geany`/geany --verbose`geanypyflakes.so' -> `/geany'Why suddenly PKG_CONFIG_PATH is not set? I can run sudo -E and then it works, but I would like to understand why it suddenly is not working.EDITRunning export before didn't help:$ export PKG_CONFIG_PATH='/usr/local/lib/pkconfig' && sudo make installecho cp geanypyflakes.so `pkg-config --variable=libdir geany`/geany --verbose`geanypyflakes.so' -> `/geany'
When running sudo make install environment variables are not passed
sudo;make
Thesudo echo $PKG_CONFIG_PATHcommand is not doing what you expect. The shell variable is expanded on the commandline before sudo is run. Try using single quotes around $PKG_CONFIG_PATH to stop the expansion on the sudo commandline and you will stop the shell expansion before sudo runsrichm@royalcounty:~$ export PKG_CONFIG_PATH=hellorichm@royalcounty:~$ sudo echo $PKG_CONFIG_PATHhellorichm@royalcounty:~$ sudo echo '$PKG_CONFIG_PATH'$PKG_CONFIG_PATHIn actual fact your original command is wrong because the echo inside sudo will do no variable expansion. You can force that by running the shell explicitlyrichm@royalcounty:~$ sudo -E echo '$PKG_CONFIG_PATH'$PKG_CONFIG_PATHrichm@royalcounty:~$ sudo sh -c 'echo $PKG_CONFIG_PATH'richm@royalcounty:~$ sudo -E sh -c 'echo $PKG_CONFIG_PATH'helloThat demonstrates why your sudo make install does not work without the -E argument to sudo