0

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.

  • If the package is updated frequently, submit a feature request so that they put the object files in an `OBJS` variable instead of hard-coding it in a rule. – Kaz Dec 11 '14 at 03:48
  • > *I have a package written by someone else; I can't change the files in that package.* This requirement is not realistic. If you have your own computer, and a copy of the files, you can do whatever you want. You can apply patches, import to a repository where you maintain your own branch and so forth. – Kaz Dec 11 '14 at 03:50

1 Answers1

0

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.

MadScientist
  • 92,819
  • 9
  • 109
  • 136