Re: Avoid relinking when .so file changes

Henrik Carlqvist <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization SunSITE.dk - Supporting Open source
Message-ID <[email protected]>
[email protected] wrote:
> I have a Makefile (GNU Make 3.80).  Let's say I have a target
> for a binary called 'myBinary'.  myBinary depends on a few .so
> files.  When I type 'make myBinary', and the files that generate
> those .so files change, I want the .so files regenerated.
> 
> I don't, however, want 'myBinary' relinked, since the interface to
> the .so file hasn't changed--relinking is unnecessary.

But you want the .so file created if it doesn't already exist I suppose?
 
> So far, my Makefile looks like this:
> 
> myBinary: myBinary.o myLibrary.so
>         g++ --go-go-gadget-linker

One way to fix this would be:

myBinary: myBinary.o $(filter-out $(wildcard myLibrary.so), myLibrary.so)
        g++ --go-go-gadget-linker

With the above rule myBinary depends on myLibrary.so if it doesn't
already exist. But if the file already exist it doesn't care if it is
newer than myBinary. I usually use this method for dependencies on
directories, something like this:

$(O_DIR)/%.o: $(C_DIR)/%.c $(filter-out $(wildcard $(O_DIR)), $(O_DIR))

$(O_DIR):
	mkdir -f $@

Above I want a directory created before I can put files in that directory.
However, once the directory is created I don't want to rebuild files in
it only because it has gotten a new time stamp. Every time a file is
created or deleted in a directory the time stamp of the directory gets
updated.

> How do I change this Makefile to keep the relinking from happening?
> Dropping the .so dependency creates pain, because then 'make -j' doesn't
> work right.

What is the problem with make -j? To me it seems as if dropping the
dependency only would cause the .so file not to be created, regardless of
if the -j flag is used.

regards Henrik
-- 
The address in the header is only to prevent spam. My real address is:
hc8(at)uthyres.com Examples of addresses which go to spammers:
[email protected] root@localhost
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.