[OpenIndiana-discuss] How do I get OpenIndana's make (not gmake) to accept the following

Richard Sharpe realrichardsharpe at gmail.com
Sun Jun 3 18:50:38 UTC 2012


On Sun, Jun 3, 2012 at 11:25 AM, James Carlson <carlsonj at workingcode.com> wrote:
> On 6/3/2012 11:17 AM, Richard Sharpe wrote:
>> Hmmm, that does not _seem_ to be the case. Regardless of whether I have
>>
>>    .SUFFIXES: .o .so
>>
>> or
>>
>>    .SUFFIXES: .so .o
>>
>> I still get the same message indicating that it does not know how to
>> build a .so from a .o
>>
>> (The indent above is for exposition purposes, the .SUFFIXES: is hard
>> up against the left hand column in the Makefile.)
>
> That's not quite how the old-style implicit suffix rules work.  They
> don't chain together in arbitrary ways, so the match is between suffixes
> and dependencies.
>
> Note that this is true of all implementations of 'make' -- not just the
> one in OpenIndiana, but also GNU make and BSD make and others.

Well, that may be true, except, the original Makefile snippet has
successfully been used on FreeBSD and Linux (Fedora 14).

Expanding the snippet a bit more, what I currently have that is
working (and, it is always possible that I have accidentally found
something that works for gmake under Linux and the FreeBSD make, but
for reasons that I don't understand :-)

-----------------------------------------------------------
# Change these targets to the names of your modules if building out of tree
MODULES         = skel_opaque.so shadow_copy_test.so \
                skel_transparent.so

all: $(MODULES)

# Pattern rules

.SUFFIXES: .so

.o.so:
        @echo "Linking $<"
        @$(CC) $(LDSHFLAGS) $(LDFLAGS) $*.o -o $*.so

.c.o:
        @echo "Compiling $<"
        @$(CC) $(FLAGS) -c $< -D$*_init=samba_init_module

install: default
        $(INSTALLCMD) -d $(VFS_LIBDIR)
        $(INSTALLCMD) -m 755 *.$(SHLIBEXT) $(VFS_LIBDIR)

# Misc targets
clean:
        rm -rf .libs
        rm -f core *~ *% *.bak *.o *.$(SHLIBEXT)

distclean: clean
        rm -f config.status config.cache Makefile
------------------------------------------------

> In other words, if you need foo.so and have only foo.c, then 'make' will
> look for an implicit rule of the form ".c.so".  If such a rule exists,
> it uses it.  If not, it's done with the implicit rule search.

OK ... but

> If you have a ".o.so" rule, then either the "foo.o" file must already
> exist for that rule to fire, or you need a dependency from the .so to
> the .o file; otherwise, it's ignored.

The above works for Linux and FreeBSD ...

> If you have another dependency to complete the chain, then 'make' will
> find the rules you're specifying.  For example, if you have this:
>
> all:    foo.so
> foo.so: foo.o
>
> Then make goes through these steps: first, it wants a target to build,
> and it finds "all."  "All" depends on "foo.so", so it needs that.
> "foo.so" depends on "foo.o", so, even though "foo.o" doesn't exist, it
> goes on to build "foo.o" from the existing "foo.c", then looks for the
> ".o.so" rule, and finds it.
>
> You can see some of the subtleties of this if you remove the "foo.so:"
> dependency rule above and do "make foo.o" then "make".  The first run
> will create "foo.o".  The second will create "foo.so" as expected.

I will give what you suggest a try ... if it works on all three
platforms then I am happy.

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)



More information about the OpenIndiana-discuss mailing list