> I want to compile objects in order of the writting Just because, today, make happens to pick nearly what you want it to do without being told about your ordering constraint, doesn't mean that you should rely on it continuing to do so. You should teach make about that order. You could contrive a function to $(eval) your y.o z.o x.o list into a chain of pairwise dependencies:
z.o: y.o x.o: z.o Like this: martind@sirius:~/tmp/ljh-2022-08-11$ cat Makefile objs = y.o z.o x.o space = $(subst :,,: :) makeDependency = $(eval $(lastword $(1)): $(firstword $(1))) $(foreach pair,$(filter-out guard@@% %@@guard,$(join guard $(objs),$(addprefix @@,$(objs) guard))),$(call makeDependency,$(subst @@,$(space),$(pair)))) martind@sirius:~/tmp/ljh-2022-08-11$ make -p | grep '[xyz]\.o: [xyz].o' make: *** No rule to make target 'y.o', needed by 'z.o'. Stop. z.o: y.o x.o: z.o martind@sirius:~/tmp/ljh-2022-08-11$ ________________________________ From: Bug-make <bug-make-bounces+martin.dorey=hds....@gnu.org> on behalf of ljh <l...@qq.com> Sent: Thursday, August 11, 2022 01:56 To: Philip Guenther <guent...@gmail.com> Cc: psmith <psm...@gnu.org>; bug-make <bug-make@gnu.org> Subject: 回复: Implicit rule for linking multiple object files ***** EXTERNAL EMAIL ***** Thanks Philip, I want to compile objects in order of the writting: y.o z.o x.o . The order of compiling x.o are different in below three cases. I don't understand the difference. x : y.o z.o x.o # compiles x.o last $(CC) $^ -o $@ # with recipe x : y.o z.o # compiles x.o last x : y.o z.o x.o # compiles x.o first My purpose is to keep my Makefile simple. With the patsubst function in Makefile, I just put Makefile with my source files and need to do nothing. It just compiles. But this is gone if the order of compiling matters. x : $(patsubst %.c,%.o,$(wildcard *.c)) Thanks --- # My Minimal Makefile for C, C++ # build shared library with -fPIC, -shared CFLAGS = -Wall -Wextra -g # -O3 -fPIC # CXXFLAGS for .cpp LDFLAGS = # -L../hello # -shared LDLIBS = # -lhello CPPFLAGS = -MMD -MP # -I../hello #CC = $(CXX) # link with CXX for .cpp # target name is basename of one of the source files main : $(patsubst %.c,%.o,$(wildcard *.c)) # .cpp -include *.d clean : ; -rm -fr *.o *.d .PHONY : clean