Question

I have a package written by someone else; I can't change the files in that package. In that package there's a Makefile with a rule like this:

$(BIN)/progA:   <long list of .o files>
    $(LINK.cc) $^ -o $@

I want to write a GNU make "wrapper" around that Makefile to build a library instead of a binary from the same list of .o files. Ideally I'd like something like this:

include package/Makefile

$(LIB)/progA.so: <magically copy the prerequisites for $(BIN)/progA>
    $(LD) -shared  $(LDFLAGS) $^ $(LIBS) -o $@

Of course, I could just copy-n-paste the list from the package's Makefile to mine, but that package is updated frequently; I prefer it if my build process would auto-magically pick up any changes to the package's changes in its Makefile.

My only other solution is something complex: Use sed or awk or perl to scan the package's Makefile, pull out that list of .o files, and assign it to a variable in my wrapper make file. I'd like to avoid that if I can.

Was it helpful?

Solution

I have two ideas for you:

First, run something like:

make -n bin/progA LINK.cc='OBJECTS:' | grep ^OBJECTS:

then capture the output. You'll have to get rid of the -o etc. by hand from the results though.

The other idea is to run "make -pn" to get a copy of make's database, and parse that with grep or whatever.

The advantage to these vs. just going through the makefile directly is that any variables, etc. will be expanded for you by make.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top