Search code examples
pythonwindowsmakefile

Why doesn't makefile work and how to fix it?


there is such a makefile

define HELPBODY
Available commands:

    make help       - this thing.

    make init       - install python dependancies
    make test       - run tests and coverage
    make pylint     - code analysis
    make build      - pylint + test
    make docs       - generate html docs using sphinx

    make dist       - build source distribution
    mage register   - register in pypi
    make upload     - upload to pypi

    make pb_fetch   - fetch protobufs from SteamRE
    make pb_compile - compile with protoc
    make pb_clear   - removes *.proto
    make pb_update  - pb_fetch + pb_compile

endef

export HELPBODY
help:
    @echo "$$HELPBODY"

init:
    pip install -r requirements.txt

test:
    coverage erase
    PYTHONHASHSEED=0 nosetests --verbosity 1 --with-coverage --cover-package=dota2

pylint:
    pylint -r n -f colorized dota2 || true

build: pylint test docs

.FORCE:
docs: .FORCE
    $(MAKE) -C docs html

clean:
    rm -rf dist dota2.egg-info dota2/*.pyc

dist: clean
    python setup.py sdist

register:
    python setup.py register -r pypi

upload: dist register
    twine upload -r pypi dist/*

pb_fetch:
    wget -nv --backups=1 --show-progress -P ./protobufs/ -i protobuf_list.txt
    rm -f ./protobufs/*.1
    sed -i '1s/^/syntax = "proto2"\;\npackage dota\;\n/' protobufs/*.proto
    sed -i 's/\(optional\|repeated\) \.\([A-Z]\)/\1 dota.\2/' protobufs/*.proto
    sed -i 's/cc_generic_services/py_generic_services/' protobufs/*.proto
    sed -i 's/ = 6000/ = 7000/' protobufs/steammessages.proto  # extentions hack

pb_compile:
    for filepath in `ls ./protobufs/*.proto`; do \
        protoc3 --python_out ./dota2/protobufs/ --proto_path=./protobufs "$$filepath"; \
    done;
    sed -i '/^import sys/! s/^import /import dota2.protobufs./' dota2/protobufs/*_pb2.py

pb_clear:
    rm -f ./protobufs/*.proto ./dota2/protobufs/*_pb2.py

gen_enums:
    python gen_enum_from_protos.py > dota2/proto_enums.py

pb_update: pb_fetch pb_compile gen_enums

when entering make pb_compile it gives this error

MAKE Version 5.43  Copyright (c) 1987, 2019 Embarcadero Technologies, Inc.
Error makefile 2: Command syntax error
Error makefile 22: Command syntax error
Error makefile 24: Command syntax error
Error makefile 40: Colon expected
*** 4 errors during make ***

I removed all the unnecessary things and it worked out

pb_compile:
    for filepath in `ls ./protobufs/*.proto`; do \
        protoc3 --python_out ./dota2/protobufs/ --proto_path=./protobufs "$$filepath"; \
    done;
    sed -i '/^import sys/! s/^import /import dota2.protobufs./' dota2/protobufs/*_pb2.py

now error

MAKE Version 5.43 Copyright (c) 1987, 2019 Embarcadero Technologies, Inc.
for filepath in `ls ./protobufs/*.proto`; do protoc3 --python_out ./dota2/protobufs/ --proto_path=./protobufs "$filepath"; done;
Unexpected occurrence: filepath.

** error 1 ** deleting pb_compile

renamed the filepath variable but that didn't help I have no idea how to fix this


Solution

  • Why doesn't makefile work

    You are using a makefile intended specifically for GNU make running in a POSIX environment with a POSIX shell, but you are using Embarcadero make in a Windows environment.

    From its docs, Embarcadero's make is similar to a POSIX make, but not fully conformant. Furthermore, it does not appear to provide any of GNU's make extensions. Moreover, the recipes in the makefile are intended for execution by a POSIX shell, not by Windows PowerShell or cmd.exe.

    and how to fix it?

    The makefile you are trying to use seems to be altogether unsuitable for your environment as it now stands. There is no simple fix. The primary options appear to be:

    • rewrite the makefile from the ground up for Embarcadero make running in your Windows environment, OR

    • Install and use GNU make and POSIX style environment, such as MinGW-w64 / MSYS2.