http://docs.python.org/2/library/os.path.html#os.path.normpath是完美的。
我有一个冗余路径的问题,同一个文件有多个条目,这很难看,没有害处,但我想把它去掉。正如你所看到的,一个文件可以指定多次。
makefile会生成自己(其中任何一行带有DEP
的代码都会构建一个要包含的makefile),并且有一些自动化工具在发挥作用,代码文件的依赖项(.cpp
)是由带有-MM
标志的GCC生成的,我认为这就是它们进入其中的方式。代码文件的包含是相对于文件位置给出的。不管怎样,我很想解决这个问题!
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 $
查看:http://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html
无论是真实路径还是abs路径似乎都不符合我的要求
正如我所说,这并没有真正伤害到任何东西,只是我宁愿看到一些东西消失:
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 "$$"@" >> $@
我希望解决方案适用于"由于更改"行,而不是-MM行。我可以写一个2行Python脚本来实现这一点,但除非迫不得已,否则我宁愿不使用GnuMake之外的东西(我当然可以把这个脚本放在makefile中,让它创建,然后使用它:p),但这让我觉得make应该能够做一些事情,我说我可以理解为什么它不需要它(对同一文件命名的不同方式)。
没有这样的GNU make函数,也没有任何简单的方法来使用make函数。最简单的方法是让编译器一开始就不生成这些类型的路径。
尽管您没有提供足够的信息来确定,但我怀疑$(INCLUDES)
变量的值包含类似-Isrc/Thing/listeners/..
的值(至少在扩展后)。您应该修改这些变量的设置,以便使用GNU make函数($(notdir ...)
)去掉最后一个目录,而不是将/..
附加到目录的末尾。例如,这些路径将只是-Isrc/Thing
,而那里没有..
。