Question

I'm using the GnuWin32 project, and created a makefile to manage the compiling of some code. In the command line I run:

set PYUIC=python "E:\PortableApps\Portable Python 2.7.3.1\App\Lib\site-packages\PyQt4\uic\pyuic.py"

my make file contains the following:

UIC := %pyuic%
HELP_VIEW := less

vpath %.ui ./ui
vpath %.py ./py

.PHONY: help

help:
    ${HELP_VIEW} help

%.py: %.ui
    ${UIC} -o ./py/$@ $^

print_%:
    @echo $* = ${$*}

when I run make print_UIC I get:

UIC = python "E:\PortableApps\Portable Python 2.7.3.1\App\Lib\site-packages\PyQt4\uic\pyuic.py"

but when I run 'make main.py' I get:

%pyuic% -o ./py/main.py ./ui/main.ui
process_begin: CreateProcess(NULL, %pyuic% -o ./py/main.py ./ui/main.ui, ...) fa
iled.
make (e=2): The system cannot find the file specified.
make: *** [main.py] Error 2

when I run %pyuic% -o ./py/main.py ./ui/main.ui it runs with no problems, and result is as expected.

What's wrong?

Was it helpful?

Solution

GNU make doesn't support Windows-style environment variables, like %pyuic%. Your first example works because it's invoking the Windows "shell", and that shell is expanding this value for you. In your second example GNU make is trying to directly invoke the command. This could be considered a bug in GNU make: probably if make sees a % in a rule on Windows it should always use the Windows shell.

Anyway, you should use GNU make's variable syntax; GNU make will import all environment variables when it starts up, so you can refer to them as make variables. This is much more portable, since obviously %pyuic% will not work at all on anything but Windows:

UIC := $(pyuic)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top