3

I'm trying to create a Makefile that works on both Windows and Linux. Running make clean generates the following error:

process_begin: CreateProcess(NULL, rmdir /s /q D:\Documents\Programming\project\bin, ...) failed.
make: Makefile:13: pipe: No such file or directory
process_begin: CreateProcess(NULL, rmdir /s /q D:\Documents\Programming\project\obj, ...) failed.
make: Makefile:15: pipe: No such file or directory

The relevant parts of the Makefile are:

BIN_DIR=bin
OBJ_DIR=obj
SRC_DIR=src

ifeq ($(OS),Windows_NT)
    RMDIR=$(shell rmdir /s /q $(subst /,\,$(abspath $1)))
else
    RMDIR=$(shell rm -rf $(abspath $1))
endif

clean:
    @echo "RM $(BIN_DIR)"
    @$(call RMDIR,$(BIN_DIR))
    @echo "RM $(OBJ_DIR)"
    @$(call RMDIR,$(OBJ_DIR))
    @echo "Done!"

.PHONY: clean

The project structure looks like this:

├─bin
├─obj
├─src
└─Makefile
CredixYt
  • 33
  • 4
  • I am not familiar with how windows behaves if you try to remove a directory that does not exists, in linux, on the other hand, by adding `-f` basically you are silencing the diagnostic. Perhaps it is worth to try something like what is mentioned here: https://stackoverflow.com/a/14502670/4868875 – Berthin Jan 24 '21 at 22:24
  • This should not happen on a recent version of make. Please show your `make --version` output for Windows `make`. – raspy Jan 24 '21 at 22:27
  • 1
    First, please remove all the `@` in your recipes, then show the output make prints. Adding `@` when your makefile doesn't work is like trying to debug your problem blindfolded. Second, why are you using `$(shell ...)` here from inside a recipe? That's almost always wrong. Why not just say `RMDIR = rmdir /s ...` without the `$(shell ...)`? – MadScientist Jan 25 '21 at 13:23

0 Answers0