Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clean is not working with generated files #1650

Closed
aryan-11825114 opened this issue Jun 15, 2021 · 9 comments · Fixed by #1763
Closed

Make clean is not working with generated files #1650

aryan-11825114 opened this issue Jun 15, 2021 · 9 comments · Fixed by #1763
Labels

Comments

@aryan-11825114
Copy link

What seems to be the problem?
I have a simple premake5 file that creates makefiles for a small project of mine. When I run premake5 gmake2 all makefiles are created successfully and I can call make to compile to an executable and run it.
The problem is when I try to call make clean, I get an error saying: The directory name is invalid. and make: *** [clean] Error 267

What did you expect to happen?
Build directory should have been cleaned

What have you tried so far?
I've narrowed it down to one line in the makefile which should remove all the object files, but causes an error and stops any more files from being removed.

$(SILENT) if exist $(subst /,\\,$(GENERATED)) rmdir /s /q $(subst /,\\,$(GENERATED))

This is the line that is causing the error. Removing it fixes the problem but causes my bin/obj folder to remain.

How can we reproduce this?
Calling make clean gives this error.

What version of Premake are you using?
premake5 (Premake Build Script Generator) 5.0.0-alpha16.

Anything else we should know?
This issue is based on https://stackoverflow.com/questions/64414270/make-clean-is-not-working-when-using-premake5
though this problem occurs with me too.

@samsinsane
Copy link
Member

How can we reproduce this?
Calling make clean gives this error.

I built the alpha16 source, and did this against the Premake project. It works fine.

In the other issue you opened for this, I requested that you fill in the template as requested, this is one of those cases where you need to help us, help you.

The template states:

Please provide a minimal, reproducible example we can use to replicate the problem in our own development environments. Use code blocks to format code and console output nicely.

@aryan-11825114
Copy link
Author

I'm sorry for the poor explanation. I'm super new to this.
I'm using MinGW-w64 for windows downloaded from https://winlibs.com
Just by running the command after building the project
mingw32-make clean

This error occures

The directory name is invalid.
mingw32-make[1]: *** [Makefile:101: clean] Error 267
mingw32-make: *** [makefile:42: clean] Error 2

and this error and this seems to only happenes when I have only one cpp file in my project.
This was not the problem in premake5 (Premake Build Script Generator) 5.0.0-alpha14

@starkos
Copy link
Member

starkos commented Jun 21, 2021

@samsinsane Is asking for you to a) put together a simple Premake script which we can run to recreate the error that you're seeing, and b) share it with us as part of the issue. The link they shared provides some guidance what what a simple example should look like. (Hint: don't just dump a .zip of your entire project on us.)

Like @samsinsane I can run make clean against any of my Premake-generated projects and I do not get this error, so it is something specific to your project.

@aryan-11825114
Copy link
Author

Ok, here is a simple project that reproduces the error for me

|-- Build/
|   |-- premake5.exe
|
|-- Source/
|   |-- Main.cpp
|-- premake5.lua

Main.cpp

#include <iostream>

int main()
{
	std::cout << "Hello World!\n";
}

premake5.lua

workspace "Project-Workspace"
	configurations
	{
		"Debug",
		"Release"
	}

project "Project"
	kind "ConsoleApp"
	language "C++"
	targetdir "Binaries/%{cfg.buildcfg}/%{prj.name}"
	objdir "Binaries/%{cfg.buildcfg}/%{prj.name}/Objects"

	files
	{
		"Source/Main.cpp"
	}

	filter "configurations:Debug"	
		symbols "on"
		runtime "Debug"

	filter "configurations:Release"
		runtime "Release"
		optimize "on"

then I run

Build\premake5.exe gmake2
mingw32-make

The project files are generated and builds just fine, but after that if I run

mingw32-make clean

it results in an error saying

Cleaning Project
The directory name is invalid.
mingw32-make[1]: *** [Project.make:99: clean] Error 267
mingw32-make: *** [makefile:34: clean] Error 2

@nickclark2016
Copy link
Member

Would you happen to have spaces in the path?

@aryan-11825114
Copy link
Author

No, but I think I know what might be the problem.
When the Project.make is generated Main.o is added to GENERATED

GENERATED += $(OBJDIR)/Main.o

and upon cleaning the project, this line

$(SILENT) if exist $(subst /,\\,$(GENERATED)) rmdir /s /q $(subst /,\\,$(GENERATED))

expands to

rmdir /s /q Binaries\Debug\Project\Objects\Main.o

this will not work as rmdir is used to remove a directory not a file

Project.make

# Alternative GNU Make project makefile autogenerated by Premake

ifndef config
  config=debug
endif

ifndef verbose
  SILENT = @
endif

.PHONY: clean prebuild

SHELLTYPE := posix
ifeq (.exe,$(findstring .exe,$(ComSpec)))
	SHELLTYPE := msdos
endif

# Configurations
# #############################################

RESCOMP = windres
DEFINES +=
INCLUDES +=
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef

ifeq ($(config),debug)
TARGETDIR = Binaries/Debug/Project
TARGET = $(TARGETDIR)/Project.exe
OBJDIR = Binaries/Debug/Project/Objects
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
ALL_LDFLAGS += $(LDFLAGS)

else ifeq ($(config),release)
TARGETDIR = Binaries/Release/Project
TARGET = $(TARGETDIR)/Project.exe
OBJDIR = Binaries/Release/Project/Objects
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2
ALL_LDFLAGS += $(LDFLAGS) -s

endif

# Per File Configurations
# #############################################


# File sets
# #############################################

GENERATED :=
OBJECTS :=

GENERATED += $(OBJDIR)/Main.o
OBJECTS += $(OBJDIR)/Main.o

# Rules
# #############################################

all: $(TARGET)
	@:

$(TARGET): $(GENERATED) $(OBJECTS) $(LDDEPS) | $(TARGETDIR)
	$(PRELINKCMDS)
	@echo Linking Project
	$(SILENT) $(LINKCMD)
	$(POSTBUILDCMDS)

$(TARGETDIR):
	@echo Creating $(TARGETDIR)
ifeq (posix,$(SHELLTYPE))
	$(SILENT) mkdir -p $(TARGETDIR)
else
	$(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
endif

$(OBJDIR):
	@echo Creating $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
	$(SILENT) mkdir -p $(OBJDIR)
else
	$(SILENT) mkdir $(subst /,\\,$(OBJDIR))
endif

clean:
	@echo Cleaning Project
ifeq (posix,$(SHELLTYPE))
	$(SILENT) rm -f  $(TARGET)
	$(SILENT) rm -rf $(GENERATED)
	$(SILENT) rm -rf $(OBJDIR)
else
	$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
	$(SILENT) if exist $(subst /,\\,$(GENERATED)) rmdir /s /q $(subst /,\\,$(GENERATED))
	$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
endif

prebuild: | $(OBJDIR)
	$(PREBUILDCMDS)

ifneq (,$(PCH))
$(OBJECTS): $(GCH) | $(PCH_PLACEHOLDER)
$(GCH): $(PCH) | prebuild
	@echo $(notdir $<)
	$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
$(PCH_PLACEHOLDER): $(GCH) | $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
	$(SILENT) touch "$@"
else
	$(SILENT) echo $null >> "$@"
endif
else
$(OBJECTS): | prebuild
endif


# File Rules
# #############################################

$(OBJDIR)/Main.o: Source/Main.cpp
	@echo $(notdir $<)
	$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

-include $(OBJECTS:%.o=%.d)
ifneq (,$(PCH))
  -include $(PCH_PLACEHOLDER).d
endif

@starkos
Copy link
Member

starkos commented Jun 25, 2021

Sounds like #1404 would have introduced that one?

@nickclark2016
Copy link
Member

@starkos should we switch it from "rmdir" to "del"? I think that should resolve the issue.

@starkos
Copy link
Member

starkos commented Nov 7, 2021

Ah yep, this line introduced the error. And you're right, it should be del instead of rmdir (the Posix branch uses the correct rm -rf).

@starkos starkos changed the title Make clean is not working when using premake5 Make clean is not working with generated files Nov 26, 2021
starkos added a commit to starkos/premake-core that referenced this issue Nov 26, 2021
starkos added a commit to starkos/premake-core that referenced this issue Nov 26, 2021
starkos added a commit to starkos/premake-core that referenced this issue Jan 4, 2022
KyrietS pushed a commit to KyrietS/premake-core that referenced this issue Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants