Reputation: 5928
http://docs.python.org/2/library/os.path.html#os.path.normpath is perfect.
I have a problem with redundant paths, multiple entries for the same file and it's rather unsightly, it's doing no harm but I'd like to get rid of it. As you will see a file can be specified several times.
The makefile generates itself (any line with DEP
in it is building a makefile to be included) and there are some automated tools at play, dependencies of code files (.cpp
) are generated by GCC with the -MM
flag, that's how I think these are getting into it. The code file's includes are given relative to that files location. Anyway I'd love to fix this!
alec@ATMain ~/cxxtest $ make
CREATING build
CREATING build/Structures
CREATING build/Thing
CREATING build/Thing/listeners
CREATING build/implementations
LISTENER GEN src/Thing/thing.listener
LISTENER src/Thing/thing.listener
DEP GEN src/main.cpp
DEP GEN src/implementations/thing.cpp
COMPILE build/main.o (Due to changes: src/main.cpp src/Thing/thing.h src/Thing/listeners/ThingChangeEmitter.h src/Thing/listeners/../../Structures/LinkedList.h src/Thing/listeners/../../Structures/List.h src/Thing/listeners/../../Structures/Ptr.h src/Thing/listeners/ThingChangeListener.h src/Thing/listeners/../thing.h src/Structures/LinkedList.h src/Structures/Del.h)
COMPILE build/implementations/thing.o (Due to changes: src/implementations/thing.cpp src/implementations/../Thing/listeners/ThingChangeListener.h src/implementations/../Thing/listeners/../thing.h src/implementations/../Thing/listeners/ThingChangeEmitter.h src/implementations/../Thing/listeners/../../Structures/LinkedList.h src/implementations/../Thing/listeners/../../Structures/List.h src/implementations/../Thing/listeners/../../Structures/Ptr.h src/implementations/../Thing/thing.h)
LINK A.out
alec@ATMain ~/cxxtest $ touch ./src/Thing/thing.h
alec@ATMain ~/cxxtest $ make
COMPILE build/main.o (Due to changes: src/Thing/thing.h src/Thing/listeners/../thing.h)
COMPILE build/implementations/thing.o (Due to changes: src/implementations/../Thing/listeners/../thing.h src/implementations/../Thing/thing.h)
LINK A.out
alec@ATMain ~/cxxtest $
Looking at: http://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html
neither real nor abs path seem to do what I want
As I said this doesn't really harm anything, it's just something I'd rather see gone so in:
build/%.d: src/%.cpp | builddir $(LISTENERDS:.ld=.lo)
@echo " DEP GEN "$<
@echo -n $(dir $@) > $@
@if ! $(CXX) $(CXX_FLAGS) $(INCLUDES) -MM $< >> $@; \
then rm $@; \
exit 1; \
fi
@echo " @echo \" \"COMPILE\" \""$$"@"" \"(\"Due to changes: "$$"?\")\"">> $@
@echo " "$$"("PREFIX")"$$"("CXX")" $$"(CXX_FLAGS)" $$"(INCLUDES) -c $< -o "$$"@" >> $@
I expect a solution to apply to the "due to changes" line, not the -MM one. I could write a 2 line Python script to do this but I'd rather not use stuff outside of GnuMake unless I have to (I could of course put this script inside the makefile and have it create then use it :p) but this strikes me as something make ought to be able to do, having said that I can see why it wouldn't need it (different ways of naming the same file).
Upvotes: 0
Views: 222
Reputation: 100956
There's no GNU make function like that, nor any simple way to do it with make functions. The simplest way to do it is to get the compiler to not generate those kinds of paths in the first place.
My suspicion, although you don't provide enough information to tell for sure, is that the value of the $(INCLUDES)
variable contains values like -Isrc/Thing/listeners/..
(at least after expansion). You should modify the setting of these variables so that instead of appending /..
to the end of the directory, you use the GNU make function ($(notdir ...)
) to strip off the last directory. Then these paths would just be -Isrc/Thing
for example, and you would not have the ..
there.
Upvotes: 1