Reputation: 1122
I have several shell scripts generating source files. Apart from final, result files, they also create few artifacts, like log files, temporary objects for easier debugging when something goes wrong and so on. I'd like to add custom step to the process run when I select "Project -> Clean..." that would delete all generated files. I'm using automatically generated Makefiles and would like to avoid writing my own. Not that I can't, I just that I'd rather spend my time doing more Real Work than Cumbersome Management.
Upvotes: 2
Views: 2522
Reputation: 51
Here is a way to "clean" a file (with a specific example for a map file) that should work well.
To clean multiple files you could add multiple 'Builders' - one for each of your files. Or, create a script that cleans them all together.
To manage the deletion of the Map file when using "Clean":
Note: build each target (typically Debug and Release) to create the folders for the "Refresh" step below
Replace the default name "New_Builder" with a meaningful name. For this example:
Delete Map File
Enter the name of the program in the Location: edit box.
/bin/rm
Enter the desired arguments to the command
${project_loc}/${config_name:${project_name}}/${project_name}.map
Click on the Refresh tab and select appropriate settings. For this example:
Enable Refresh resources upon completion
Un-check Recursively include sub-folders
Select Specific resources
Click the Specify Resources... button
Expand the specific project and place a check mark next to "Debug" and "Release"
Press the Finish button.
Click on the Build Options tab and select appropriate settings. For this example:
Un-check Allocate Console (necessary for input)
Only check the option During a "Clean" in section Run the builder:
Press the OK button.
Upvotes: 5
Reputation: 1817
@jędrzej-dudkiewicz
Wow! I spent about a workday to solve exactly the same issue, and now I read your post...
But I want to present more "accurate" fix of the problem: you need to add new rule with phony target, let's say superclean
, to the (for example) makefile.targets
file -- it will be included to main makefile
; then you need to add superclean
(separating it by space from other targets already listed there) to the appropriate field "Clean" at "Behaviour" page of the "C/++ Build" in the project properties dialogue. And voilà!
EDIT:
Unfortunately mentioned method may give some unwanted effects. The fact is that the makefile
which is generated by the Eclipse CDT has lines like this:
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif
and when you will try to clean your project make
will try to include files listed in the *_DEPS
variables. This is because ifneq ($(MAKECMDGOALS),clean)
don't work because, in turn, $(MAKECMDGOALS)
holds superclean clean
value in our case. Though this variant may work yet if only you will not insert rule like this one
%.d: %.o
...
somewhere in your project's makefile
. Because in this case make
probably will try to generate the absent .d
files being included.
So I think there is one more way to resolve this issue: simply append a list of the (automatically) generated files which you want to be deleted during cleaning of a project to one of a variables which are mentioned here:
# Other Targets
clean:
-$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) oc
-@echo ' '
This is a quote from autogenerated makefile
. You can do it something like this way:
ifneq ($(findstring clean,$(MAKECMDGOALS)),)
EXECUTABLES+=$(LIST_OF_THE_GENERATED_FILES)
endif
Upvotes: 1
Reputation: 1122
I've found the following solution: In properties, C/C++ Build, Builder Settings, Builder there is "Build command" box and "Use default build command" check box.
So it's pretty simply, though dirty - I've replace "make" with "customMake" - it intercepts invocation, checks for "clean" parameter and executes scripts that I've selected.
It's quite possible that there's a better solution but I had no luck finding it.
There is also another way. Create file makefile.targets in root directory of your project and create rule 'clean' repeating steps executed by makefile from Release/Debug/Whatever directory and add custom steps there. Example:
clean: -$(RM) $(OBJS)$(C_DEPS)$(ARCHIVES) libmpos.a echo PLACE CUSTOM STEPS HERE
Unfortunately make warns about rule override:
../makefile.targets:2: warning: overriding commands for target clean'
makefile:52: warning: ignoring old commands for target
clean'
but it works and seems to be a better solution than previous one.
Upvotes: 0