Skip to content

Commit

Permalink
build: use CPPFLAGS instead of INCLUDE in compile targets
Browse files Browse the repository at this point in the history
With this, CFLAGS and CPPFLAGS are used when compiling and LDFLAGS when
linking, just like in the built-in GNU make rules.  From `make -p`:

    COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
    LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
    LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)

Note: It is unclear where the `INCLUDE` variable comes from; it is not
documented in autoconf nor GNU make and automake (which itself is not
used in this repository) only mentions `INCLUDES`:

    `INCLUDES`
	 This does the same job as `AM_CPPFLAGS` (or any per-target
	 `_CPPFLAGS` variable if it is used).  It is an older name for
	 the same functionality.  This variable is deprecated; we
	 suggest using `AM_CPPFLAGS` and per-target `_CPPFLAGS` instead.

Environment: automake 1.16.5-2 and GNU make 4.4.1 on Artix Linux.

See also commit 671c3f2 ("build: actually set LDFLAGS and LIBS in
makefiles", 2022-11-30) / PR netblue30#5504.
  • Loading branch information
kmk3 committed Jan 17, 2024
1 parent 22c728b commit 0c80ce1
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ MANFLAGS = \
# https://www.gnu.org/software/automake/manual/1.16.5/html_node/User-Variables.html
CC=@CC@
CFLAGS=@CFLAGS@
CPPFLAGS=@CPPFLAGS@
LDFLAGS=@LDFLAGS@

# Project variables
Expand Down
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -5308,6 +5308,7 @@ cat <<EOF
Compile options:
CC: $CC
CFLAGS: $CFLAGS
CPPFLAGS: $CPPFLAGS
LDFLAGS: $LDFLAGS
EXTRA_CFLAGS: $EXTRA_CFLAGS
EXTRA_LDFLAGS: $EXTRA_LDFLAGS
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ cat <<EOF
Compile options:
CC: $CC
CFLAGS: $CFLAGS
CPPFLAGS: $CPPFLAGS
LDFLAGS: $LDFLAGS
EXTRA_CFLAGS: $EXTRA_CFLAGS
EXTRA_LDFLAGS: $EXTRA_LDFLAGS
Expand Down
2 changes: 1 addition & 1 deletion src/prog.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OBJS := $(SRCS:.c=.o) $(EXTRA_OBJS)
all: $(TARGET)

%.o : %.c $(HDRS) $(ROOT)/config.mk
$(CC) $(PROG_CFLAGS) $(CFLAGS) $(INCLUDE) -c $< -o $@
$(CC) $(PROG_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

$(PROG): $(OBJS) $(ROOT)/config.mk
$(CC) $(PROG_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Expand Down
2 changes: 1 addition & 1 deletion src/so.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OBJS := $(SRCS:.c=.o) $(EXTRA_OBJS)
all: $(TARGET)

%.o : %.c $(HDRS) $(ROOT)/config.mk
$(CC) $(SO_CFLAGS) $(CFLAGS) $(INCLUDE) -c $< -o $@
$(CC) $(SO_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

$(SO): $(OBJS) $(ROOT)/config.mk
$(CC) $(SO_LDFLAGS) -shared $(LDFLAGS) -o $@ $(OBJS) -ldl
Expand Down

0 comments on commit 0c80ce1

Please sign in to comment.