Search code examples
pythonmakefilebuildpython-2.xgnuwin32

Gnuwin32: makefile on windows "The syntax of the command is incorrect."


I'm trying to call make to compile my code but I keep getting this error:

C:\Users\lovel\Anaconda3\S4>make
mkdir -p build
mkdir -p build / S4k
The syntax of the command is incorrect.
make: *** [objdir] Error 1

Here's part of my makefile code in python:

objdir:
    mkdir -p $(OBJDIR)
    mkdir -p $(OBJDIR) / S4k
    mkdir -p $(OBJDIR) / modules

S4_LIBOBJS = \
    $(OBJDIR)/S4k/S4.o \
    $(OBJDIR)/S4k/rcwa.o \
    $(OBJDIR)/S4k/fmm_common.o \
    $(OBJDIR)/S4k/fmm_FFT.o \
    $(OBJDIR)/S4k/fmm_kottke.o \
    $(OBJDIR)/S4k/fmm_closed.o \
    $(OBJDIR)/S4k/fmm_PolBasisNV.o \
    $(OBJDIR)/S4k/fmm_PolBasisVL.o \
    $(OBJDIR)/S4k/fmm_PolBasisJones.o \
    $(OBJDIR)/S4k/fmm_experimental.o \
    $(OBJDIR)/S4k/fft_iface.o \
    $(OBJDIR)/S4k/pattern.o \
    $(OBJDIR)/S4k/intersection.o \
    $(OBJDIR)/S4k/predicates.o \
    $(OBJDIR)/S4k/numalloc.o \
    $(OBJDIR)/S4k/gsel.o \
    $(OBJDIR)/S4k/sort.o \
    $(OBJDIR)/S4k/kiss_fft.o \
    $(OBJDIR)/S4k/kiss_fftnd.o \
    $(OBJDIR)/S4k/SpectrumSampler.o \
    $(OBJDIR)/S4k/cubature.o \
    $(OBJDIR)/S4k/Interpolator.o \
    $(OBJDIR)/S4k/convert.o`

I'm working on Windows. I changed the '/' to '\' and it didn't work, I also added '\' in the end did not work either.


Solution

  • you must remove the spacing around the slashes or argument parsing believes that there are more than 1 argument (and you can also forget about creating $(OBJDIR) because -p option creates all non-existing dirs to the target dir:

    Unix/Linux compliant should be:

    objdir:
        mkdir -p $(OBJDIR)/S4k
        mkdir -p $(OBJDIR)/modules
    

    Note that when using Windows mkdir command, the -p option should be dropped (windows version does that by default and that option isn't recognized). Given the message you're getting, you're probably running the windows version so it should be:

    objdir:
        mkdir $(OBJDIR)\S4k
        mkdir $(OBJDIR)\modules
    

    (slashes are not accepted by Windows mkdir command so $(OBJDIR) should be built with backslashes as well)

    slashes are used for command switches in basic commands like mkdir, or else you have to quote the paths

    objdir:
        mkdir "$(OBJDIR)/S4k"
        mkdir "$(OBJDIR)/modules"
    

    (as you see it's rather difficult to have a portable makefile from Linux to Windows unless you're running it within MSYS shell where mkdir is the MSYS one, and keep in mind that there are native & MSYS versions of the make command too, I got caught once: How to force make to use bash as a shell on Windows/MSYS2)