Skip to content

Commit 8e71885

Browse files
xuxin930anchao
authored andcommitted
Enhance Makefile to avoid "Argument list too long"
define a macro for split long variable and redefine variable in batch. see details in `apps/Make.defs` `SPLITVARIABLE`. replace the variable reference that caused the error. Signed-off-by: xuxin19 <[email protected]>
1 parent 6bea926 commit 8e71885

File tree

4 files changed

+71
-41
lines changed

4 files changed

+71
-41
lines changed

Application.mk

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,12 @@ register::
266266
endif
267267

268268
.depend: Makefile $(wildcard $(foreach SRC, $(SRCS), $(addsuffix /$(SRC), $(subst :, ,$(VPATH))))) $(DEPCONFIG)
269-
$(Q) $(MKDEP) $(DEPPATH) --obj-suffix .c$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.c,$^) >Make.dep
270-
$(Q) $(MKDEP) $(DEPPATH) --obj-suffix .S$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.S,$^) >>Make.dep
271-
$(Q) $(MKDEP) $(DEPPATH) --obj-suffix $(CXXEXT)$(SUFFIX)$(OBJEXT) "$(CXX)" -- $(CXXFLAGS) -- $(filter %$(CXXEXT),$^) >>Make.dep
269+
$(call SPLITVARIABLE,ALL_DEP_OBJS,$^,100)
270+
$(foreach BATCH, $(ALL_DEP_OBJS_TOTAL), \
271+
$(shell $(MKDEP) $(DEPPATH) --obj-suffix .c$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.c,$(ALL_DEP_OBJS_$(BATCH))) >Make.dep) \
272+
$(shell $(MKDEP) $(DEPPATH) --obj-suffix .S$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.S,$(ALL_DEP_OBJS_$(BATCH))) >>Make.dep) \
273+
$(shell $(MKDEP) $(DEPPATH) --obj-suffix $(CXXEXT)$(SUFFIX)$(OBJEXT) "$(CXX)" -- $(CXXFLAGS) -- $(filter %$(CXXEXT),$(ALL_DEP_OBJS_$(BATCH))) >>Make.dep) \
274+
)
272275
$(Q) touch $@
273276

274277
depend:: .depend

Make.defs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,29 @@ define GETINDEX
122122
)
123123
$(i)
124124
endef
125+
126+
# SPLITVARIABLE - Split long variables into specified batches
127+
# Usage: $(call SPLITVARIABLE, variable-def, variable-ref, batch-size)
128+
#
129+
# Example: VAR:= a b c x y z foo bar
130+
# $(call SPLITVARIABLE, VAR, $(VAR), 3)
131+
# $(foreach, num, $(VAR_TOTAL), $(shell echo $(VAR_$(num))))
132+
# Return new variable definition:
133+
# $(variable-def)_TOTAL : total split sequence , start with 1.
134+
# $(variable-def)_$(num) : newly defined variable , ended with batch num.
135+
# In the case above:
136+
# $(VAR_TOTAL) = 1 2 3
137+
# $(VAR_1) = a b c
138+
# $(VAR_2) = x y z
139+
# $(VAR_3) = foo bar
140+
141+
define SPLITVARIABLE
142+
$(eval PREFIX = $(1))
143+
$(eval BATCH_SIZE = $(3))
144+
$(eval TOTAL_BATCH = $(shell expr $(words $(2)) / $(BATCH_SIZE) + 1))
145+
$(eval $(PREFIX)_TOTAL = $(shell seq 1 $(TOTAL_BATCH)))
146+
$(foreach idx, $($(PREFIX)_TOTAL), \
147+
$(eval FROMINDEX=$(shell expr 1 + $(idx) \* $(BATCH_SIZE) - $(BATCH_SIZE))) \
148+
$(eval $(PREFIX)_$(idx)=$(wordlist $(FROMINDEX), $(shell expr $(FROMINDEX) + $(BATCH_SIZE) - 1), $(2))) \
149+
)
150+
endef

builtin/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,32 @@ builtin_list.c: builtin_list.h builtin_proto.h
3838
registry$(DELIM).updated:
3939
$(Q) touch registry$(DELIM).updated
4040

41+
define CONFILE
42+
if [ -n "$(strip $(2))" ]; then cat $(2) >> $1; fi
43+
endef
44+
4145
builtin_list.h: registry$(DELIM).updated
4246
ifeq ($(BDATLIST),)
4347
$(call DELFILE, builtin_list.h)
4448
$(Q) touch builtin_list.h
4549
else
46-
$(call CATFILE, builtin_list.h, $(BDATLIST))
50+
$(shell echo '' > builtin_list.h)
51+
$(call SPLITVARIABLE,BDA,$(BDATLIST),50) \
52+
$(foreach BATCH, $(BDA_TOTAL), \
53+
$(shell $(call CONFILE, builtin_list.h, $(BDA_$(BATCH)))) \
54+
)
4755
endif
4856

4957
builtin_proto.h: registry$(DELIM).updated
5058
ifeq ($(PDATLIST),)
5159
$(call DELFILE, builtin_proto.h)
5260
$(Q) touch builtin_proto.h
5361
else
54-
$(call CATFILE, builtin_proto.h, $(PDATLIST))
62+
$(shell echo '' > builtin_proto.h)
63+
$(call SPLITVARIABLE,PDA,$(PDATLIST),50) \
64+
$(foreach BATCH, $(PDA_TOTAL), \
65+
$(shell $(call CONFILE, builtin_proto.h, $(PDA_$(BATCH)))) \
66+
)
5567
endif
5668

5769
depend:: builtin_list.h builtin_proto.h

testing/ltp/Makefile

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -220,51 +220,40 @@ BLACKWORDS += shmget
220220
BLACKWORDS += shmat
221221
endif
222222

223-
MAINWORDS += "main("
223+
MAINWORDS += "main("
224224

225-
LTP_ORIGS_1 := $(shell find $(TESTDIR) -name *.c | head -n 500)
226-
LTP_ORIGS_2 := $(shell find $(TESTDIR) -name *.c | head -n 1000|tail -n +501)
227-
LTP_ORIGS_3 := $(shell find $(TESTDIR) -name *.c | head -n 1500|tail -n +1001)
228-
LTP_ORIGS_4 := $(shell find $(TESTDIR) -name *.c | head -n 2000|tail -n +1501)
229-
230-
$(foreach word, $(BLACKWORDS), $(eval BLACKLIST+=$(shell grep -lr $(word) $(LTP_ORIGS_1))))
231-
$(foreach src, $(BLACKSRCS), $(eval BLACKLIST+=$(filter %$(src),$(LTP_ORIGS_1))))
232-
233-
$(foreach word, $(BLACKWORDS), $(eval BLACKLIST+=$(shell grep -lr $(word) $(LTP_ORIGS_2))))
234-
$(foreach src, $(BLACKSRCS), $(eval BLACKLIST+=$(filter %$(src),$(LTP_ORIGS_2))))
235-
236-
$(foreach word, $(BLACKWORDS), $(eval BLACKLIST+=$(shell grep -lr $(word) $(LTP_ORIGS_3))))
237-
$(foreach src, $(BLACKSRCS), $(eval BLACKLIST+=$(filter %$(src),$(LTP_ORIGS_3))))
238-
239-
$(foreach word, $(BLACKWORDS), $(eval BLACKLIST+=$(shell grep -lr $(word) $(LTP_ORIGS_4))))
240-
$(foreach src, $(BLACKSRCS), $(eval BLACKLIST+=$(filter %$(src),$(LTP_ORIGS_4))))
241-
242-
LTP_ORIGS_1 := $(filter-out $(BLACKLIST), $(LTP_ORIGS_1))
243-
LTP_ORIGS_2 := $(filter-out $(BLACKLIST), $(LTP_ORIGS_2))
244-
LTP_ORIGS_3 := $(filter-out $(BLACKLIST), $(LTP_ORIGS_3))
245-
LTP_ORIGS_4 := $(filter-out $(BLACKLIST), $(LTP_ORIGS_4))
225+
LTP_ORIGS := $(shell find $(TESTDIR) -name *.c)
226+
ifneq ($(LTP_ORIGS),)
227+
$(call SPLITVARIABLE,ORIGS_SPILT,$(LTP_ORIGS),200)
228+
$(foreach BATCH, $(ORIGS_SPILT_TOTAL), \
229+
$(foreach word, $(BLACKWORDS), $(eval BLACKLIST+=$(shell grep -lr $(word) $(ORIGS_SPILT_$(BATCH))))) \
230+
)
231+
endif
246232

247-
$(foreach word, $(MAINWORDS), $(eval LTP_MAINCSRCS_1+=$(shell grep -lr $(word) $(LTP_ORIGS_1))))
248-
$(foreach word, $(MAINWORDS), $(eval LTP_MAINCSRCS_2+=$(shell grep -lr $(word) $(LTP_ORIGS_2))))
249-
$(foreach word, $(MAINWORDS), $(eval LTP_MAINCSRCS_3+=$(shell grep -lr $(word) $(LTP_ORIGS_3))))
250-
$(foreach word, $(MAINWORDS), $(eval LTP_MAINCSRCS_4+=$(shell grep -lr $(word) $(LTP_ORIGS_4))))
233+
$(foreach src, $(BLACKSRCS), $(eval BLACKLIST+=$(filter %$(src),$(LTP_ORIGS))))
251234

252-
LTP_CSRCS_1 := $(filter-out $(LTP_MAINCSRCS_1), $(LTP_ORIGS_1))
253-
LTP_CSRCS_2 := $(filter-out $(LTP_MAINCSRCS_2), $(LTP_ORIGS_2))
254-
LTP_CSRCS_3 := $(filter-out $(LTP_MAINCSRCS_3), $(LTP_ORIGS_3))
255-
LTP_CSRCS_4 := $(filter-out $(LTP_MAINCSRCS_4), $(LTP_ORIGS_4))
235+
LTP_ORIGS := $(filter-out $(BLACKLIST), $(LTP_ORIGS))
236+
ifneq ($(LTP_ORIGS),)
237+
$(call SPLITVARIABLE,ORIGS_SPILT,$(LTP_ORIGS),200)
238+
$(foreach BATCH, $(ORIGS_SPILT_TOTAL), \
239+
$(foreach word, $(MAINWORDS), $(eval LTP_MAINCSRCS+=$(shell grep -lr $(word) $(ORIGS_SPILT_$(BATCH))))) \
240+
)
241+
endif
256242

243+
LTP_CSRCS := $(filter-out $(LTP_MAINCSRCS), $(LTP_ORIGS))
244+
ifneq ($(LTP_MAINCSRCS),)
245+
$(call SPLITVARIABLE,MAINCSRC_SPILT,$(LTP_MAINCSRCS),50)
246+
$(foreach BATCH, $(MAINCSRC_SPILT_TOTAL), \
247+
$(eval PROGNAME+=$(basename $(shell echo $(MAINCSRC_SPILT_$(BATCH)) | xargs -n 1 | awk -F "[/]" '{print "ltp_"$$(NF-2)"_"$$(NF-1)"_"$$(NF)}' | sed s/-/_/g))) \
248+
)
249+
endif
257250

258-
PROGNAME := $(basename $(shell echo $(LTP_MAINCSRCS_1) | xargs -n 1 | awk -F "[/]" '{print "ltp_"$$(NF-2)"_"$$(NF-1)"_"$$(NF)}' | sed s/-/_/g))
259-
PROGNAME += $(basename $(shell echo $(LTP_MAINCSRCS_2) | xargs -n 1 | awk -F "[/]" '{print "ltp_"$$(NF-2)"_"$$(NF-1)"_"$$(NF)}' | sed s/-/_/g))
260-
PROGNAME += $(basename $(shell echo $(LTP_MAINCSRCS_3) | xargs -n 1 | awk -F "[/]" '{print "ltp_"$$(NF-2)"_"$$(NF-1)"_"$$(NF)}' | sed s/-/_/g))
261-
PROGNAME += $(basename $(shell echo $(LTP_MAINCSRCS_4) | xargs -n 1 | awk -F "[/]" '{print "ltp_"$$(NF-2)"_"$$(NF-1)"_"$$(NF)}' | sed s/-/_/g))
262-
MAINSRC = $(LTP_MAINCSRCS_1) $(LTP_MAINCSRCS_2) $(LTP_MAINCSRCS_3) $(LTP_MAINCSRCS_4)
251+
MAINSRC = $(LTP_MAINCSRCS)
263252
PRIORITY = SCHED_PRIORITY_DEFAULT
264253
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
265254
MODULE = $(CONFIG_TESTING_LTP)
266255

267-
CSRCS := $(LTP_CSRCS_1) $(LTP_CSRCS_2) $(LTP_CSRCS_3) $(LTP_CSRCS_4)
256+
CSRCS := $(LTP_CSRCS)
268257
CFLAGS += -I$(CURDIR)
269258
CFLAGS += -I$(TESTDIR)/include
270259
endif

0 commit comments

Comments
 (0)