문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top