简体   繁体   English

在gcc makefile中按降序对目标文件进行排序

[英]Sorting object files in gcc makefile in descending order

In my Makefile currently all the object files are sorted alphabetically using 目前在我的Makefile中,所有目标文件都使用字母顺序排序

OBJECTS =$(sort $(OBJECTS_UNSORTED)) in Makefile. Makefile中的OBJECTS = $(对$ {OBJECTS_UNSORTED))进行排序。

I want to sort the files in descending order Is there is a way possible to it? 我想按降序对文件排序是否有可能? Tried the below options but they do not work - 尝试了以下选项,但它们不起作用-

OBJECTS =$((sort -r) $(OBJECTS_UNSORTED)) OBJECTS = $((sort -r)$(OBJECTS_UNSORTED))

There is no simple way to reverse the order of a list of words built into GNU make. 没有简单的方法可以反转GNU make中内置的单词列表的顺序。

You can either use the shell's sort function to do it, like this: 您可以使用shell的sort函数来执行此操作,如下所示:

OBJECTS := $(shell for w in $(OBJECTS_UNSORTED); do echo $$w; done | sort -r)

Or, you can create a recursive function macro in GNU make to do it, like this: 或者,您可以在GNU make中创建一个递归函数宏来执行此操作,如下所示:

reverse = $(if $1,$(call reverse,$(wordlist 2,999999,$1)) $(firstword $1))

OBJECTS := $(call reverse,$(sort $(OBJECTS_UNSORTED)))

This can be achieved by defining a function that prepends a word to a variable. 这可以通过定义将单词附加到变量之前的函数来实现。 By calling this function for each word of a variable that holds sorted words, the words are effectively reversed: 通过为包含排序单词的变量的每个单词调用此函数,可以有效地反转单词:

OBJECTS_SORTED := $(sort $(OBJECTS))

define Prepend
OBJECTS_SORTED_REVERSE := $1 $(OBJECTS_SORTED_REVERSE)
endef

$(foreach variable,$(OBJECTS_SORTED),$(eval $(call Prepend,$(variable))))

$(info $(OBJECTS_SORTED_REVERSE))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM