Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append to beginning of list

I have a makefile that lists the source files: (shortened to relevant)

SRCFOLDER=src/
SOURCES= main.cpp
OBJECTS=$(SOURCES:.cpp=.o)

and I would like to concate the strings together, but for each one in SOURCES. As you can see above, I do it for OBJECTS, but I want to do it like this: (pseudocode)

foreach(src in SOURCES)
  src = concate(SRCFOLDER, src)

so that if SOURCES was main.cpp window.cpp, the result would be src/main.cpp src/window.cpp.

I tried this:

SOURCES=$(SOURCES:*=$(SRCFOLDER)/*)

but I get this error:

makefile:12: *** Recursive variable `SOURCES' references itself (eventually). Stop.
like image 355
Cole Tobin Avatar asked Jul 17 '12 01:07

Cole Tobin


People also ask

Does append add to the beginning of a list?

The append() method adds an item to the end of the list.

How do I add an item to the beginning of a list?

insert(index, value)this inserts an item at a given position. The first argument is the index of the element before which you are going to insert your element, so array. insert(0, x) inserts at the front of the list, and array. insert(len(array), x) is equivalent to array.

How do I add to the beginning of a list in Python?

There are four methods to add elements to a List in Python. append() : append the element to the end of the list. insert() : inserts the element before the given index. extend() : extends the list by appending elements from the iterable.

Does append Add to start or end?

An English dictionary defines the words append and extend as: append: add (something) to the end of a written document.


1 Answers

SRCFOLDER := src
SOURCES := main.cpp window.cpp
SOURCES := $(addprefix $(SRCFOLDER)/, $(SOURCES))
like image 158
Beta Avatar answered Sep 25 '22 19:09

Beta