Re: [dev] Special target ".POSIX" in Makefiles

From: Mattias Andrée <maandree_AT_kth.se>
Date: Sat, 1 Jan 2022 20:09:38 +0100

.POSIX:

CC = c99
# Required as POSIX doesn't mandate that it is defined by default

OBJ =\
        alpha.o\
        beta.o\
        gamma.o

LINUX_AMD64_OBJ = $(OBJ:.o=.linux-amd64-o)
OPENBSD_AMD64_OBJ = $(OBJ:.o=.openbsd-amd64-o)

all: myproj-linux-amd64 myproj-openbsd-amd64

myproj-linux-amd64: $(LINUX_AMD64_OBJ)
        $(CC) -o $_AT_ $(LINUX_AMD64_OBJ) $(LDFLAGS_LINUX_AMD64)

myproj-openbsd-amd64: $(OPENBSD_AMD64_OBJ)
        $(CC) -o $_AT_ $(OPENBSD_AMD64_OBJ) $(LDFLAGS_OPENBSD_AMD64)

.c.linux-amd64-o:
        $(CC) -c -o $_AT_ $< $(CFLAGS_LINUX_AMD64) $(CPPFLAGS_LINUX_AMD64)

.c.openbsd-amd64-o:
        $(CC) -c -o $_AT_ $< $(CFLAGS_OPENBSD_AMD64) $(CPPFLAGS_OPENBSD_AMD64)

.SUFFIXES:
.SUFFIXES: .c .linux-amd64-o .openbsd-amd64-o

# NB! Cannot use .linux-amd64.o and .openbsd-amd64.o
# as POSIX requires a dot at the beginning but
# forbids any additional dot



On Sat, 1 Jan 2022 14:08:24 +0100
Ralph Eastwood <tcmreastwood_AT_gmail.com> wrote:

> Hi Mattias,
>
> Happy New Year!
>
> > But I also like makel, but I will give it some more though before I
> rename it a second time.
>
> So... makellint? :D
> I like it; it seems 'makel' is unused as a project name.
>
> Are there any suggestions for handling out-of-source builds using
> POSIX makefiles? I recently had a project where we needed to
> support multiple platforms and so output-ing object files and binaries
> into platform-specific directories was needed.
> I know that GNU's pattern matching rules support this behaviour, i.e.:
>
> $(OBJDIR)/%.o: $(SRCDIR)/%.c
> $(CC) $(CFLAGS) -c $< -o $_AT_
>
> Perhaps just listing all of the object files and source +
> dependencies would be the easiest way in this instance?
>
> Best regards,
> Ralph
>
> --
> Tai Chi Minh Ralph Eastwood
> tcmreastwood_AT_gmail.com
>
Received on Sat Jan 01 2022 - 20:09:38 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 01 2022 - 20:12:07 CET