On 2026-10-11 18:11, Ivan Sandovin via Users list for the GNU implementation of 
make wrote:
> And instead of a one big messy line I saw this evening for example,
> I would have had something like this instead:
> 
> clang -fPIC\
> -I/gnu/store/nwmbm2shx5b802qkg5rprwrgpgahg5rk-cairo-1.18.4/include/cairo\
> -I/gnu/store/xm3nf1yqvyqbnyl96hrwpgcs46x9ncc9-fontconfig-minimal-2.17.1/include\
> -I/gnu/store/iy5mr27rgi7a6xccqyy1c1bd1qzl45f0-expat-2.7.1/include\
> -I/gnu/store/dzzmymi0fi5abxwcgb3mklv5yjap8p3r-freetype-2.13.3/include/freetype2\
> -I/gnu/store/d0z2k2wfx5bppl5ilplwsaj5d3bdcc41-libpng-1.6.39/include/libpng16\
> -I/gnu/store/2jzflb96n50lknzn7znfq9ri4qlbifjc-zlib-1.3.1/include\
> -I/gnu/store/18arfnhyzwyz3hi8d20x5y3d4mi97n9g-libxext-1.3.6/include\
> ...
> 
> Is there any way I can hook into gnu make "command printing routine" at all?
> This is my question.

Abbreviated printing of commands in Makefiles is done with custom coding.

You can hide it behind macros.

In the TXR Makefile (https://www.kylheku.com/cgit/txr/tree/Makefile) I do it
with a macro called ABBREV which prints the abbreviation, and SH
which actually executes the command invisibly.

If VERBOSE is enabled, then ABBREV prints nothing (expands to a @: command),
but SH prints details. Otherwise ABBREV prints the abbreviation and SH prints
nothing.

Here is a sample run with the default abbreviated behavior:

$ make
COPY y.tab.h.shipped -> y.tab.h
CC txr.c -> opt/txr.o
COPY lex.yy.c.shipped -> lex.yy.c
CC lex.yy.c -> opt/lex.yy.o
COPY y.tab.c.shipped -> y.tab.c
CC y.tab.c -> opt/y.tab.o

And with VERBOSE=y:

$ make VERBOSE=y
rm -f y.tab.h
cp y.tab.h.shipped y.tab.h
mkdir -p opt/
cc -MMD -MT opt/txr.o -O2 -fno-stack-protector -no-pie -fno-pie -iquote . 
-std=c99 -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64 -Wall -Wextra -Werror=implicit-function-declaration 
-Werror=missing-prototypes -Werror=strict-prototypes 
-Werror=old-style-definition -Werror=vla -Werror=declaration-after-statement 
-fno-diagnostics-show-caret -g -DPROG_NAME=\"txr\" -DTXR_REL_PATH=\"bin/txr\" 
-DTXR_INST_PATH=\"/usr/local/bin/txr\" -DEXE_SUFF=\"\" -DTXR_VER=\"302\" -c -o 
opt/txr.o txr.c
rm -f lex.yy.c
cp lex.yy.c.shipped lex.yy.c
cc -MMD -MT opt/lex.yy.o -O2 -fno-stack-protector -no-pie -fno-pie -iquote . 
-std=c99 -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64 -Wall -Wextra -Werror=implicit-function-declaration 
-Werror=missing-prototypes -Werror=strict-prototypes 
-Werror=old-style-definition -Werror=vla -Werror=declaration-after-statement 
-fno-diagnostics-show-caret -g -c -o opt/lex.yy.o lex.yy.c
rm -f y.tab.c
cp y.tab.c.shipped y.tab.c


Here is an excerpt of the system. There are a few variants of ABBREV
for a few different conventions:

V = $(if $(VERBOSE),,@)

ABBREV = $(if $(VERBOSE),\
           @:,\
           @printf "%s %s -> %s\n" $(1) \
           "$(patsubst $(top_srcdir)%,%,$<)" $@)
ABBREVN = $(if $(VERBOSE),\
            @:,\
            @printf "%s %s -> %s\n" $(1) \
            "$(patsubst $(top_srcdir)%,%,$^)" $@)
ABBREV3 = $(if $(VERBOSE),@:,@printf "%s %s -> %s\n" $(1) "$(3)" $(2))
ABBREV3SH = $(if $(VERBOSE),:,printf "%s %s -> %s\n" $(1) "$(3)" $(2))

define SH
$(if $(VERBOSE),                                        \
  $(1),                                                 \
  $(V)cmd='$(subst ','\'',$(1))' ;                      \
  if ! eval "$$cmd" ; then                              \
    printf "make: failing command:\n%s\n" "$$cmd";      \
    exit 1;                                             \
  fi)
endef

define COMPILE_C
$(call ABBREV,CC)
$(call SH,$(TXR_CC) $(OPT_FLAGS) $(TXR_CFLAGS) -c -o $@ $<)
endef

define COMPILE_C_WITH_DEPS
$(call ABBREV,CC)
$(call SH,$(TXR_CC) -MMD -MT $@ $(1) $(TXR_CFLAGS) -c -o $@ $<)
endef

define LINK_PROG
$(call ABBREVN,LINK)
$(call SH,$(TXR_CC) $(1) $(TXR_CFLAGS) $(TXR_LDFLAGS) -o $@ $^ $(TXR_LDLIBS))
endef

The macro COMPILE_C_WITH_DEPS is used in a rule like this:

opt/%.o: $(top_srcdir)%.c
        $(call COMPILE_C_WITH_DEPS,$(OPT_FLAGS))



  • pretty pri... Ivan Sandovin via Users list for the GNU implementation of make
    • Re: p... Simon Richter
    • Re: p... Paul Smith
      • R... Ivan Sandovin via Users list for the GNU implementation of make
        • ... Tim Murphy
    • Re: p... Kaz Kylheku

Reply via email to