1

I've time and again used the standard Makefile for building out of tree modules. It is reproduced below:

# Comment/uncomment the following line to disable/enable debugging
DEBUG = y

# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
    DEBFLAGS = -O0 -g3 -DSCULL_DEBUG # "-O" is needed to expand inlines
else
    DEBFLAGS = -O2
endif

LDDINC=$(PWD)/../include

EXTRA_CFLAGS += $(DEBFLAGS)
EXTRA_CFLAGS += -I$(LDDINC)


ifneq ($(KERNELRELEASE),)
    # call from kernel build system
    @echo 'called from kernel build system' #<-- FAILS HERE
    scull-objs := main.o pipe.o access.o
    obj-m   := scull.o
else
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD       := $(shell pwd)
    modules:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

install:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
    cd /lib/modules/$(shell uname -r) && depmod -a

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

depend .depend dep:
    $(CC) $(EXTRA_CFLAGS) -M *.c > .depend


ifeq (.depend,$(wildcard .depend))
include .depend
endif

I would like make to print custom string messages as it processes this Makefile so I tried adding @echo messages (see FAILS HERE in the code). But doing so fails with the following error:

Makefile:25: *** recipe commences before first target. Stop.

the offending line is marked above. Is there anyway I can do what I intend to do?

AjB
  • 890
  • 13
  • 34
  • Remove the leading tabs in lines that are not recipes. Tabs are meaningful for make, you should not use them just to indent the content of `ifneq...else...endif`. – Renaud Pacalet Jul 15 '19 at 04:48
  • 2
    Use simple `$(info MESSAGE)`. – 0andriy Jul 15 '19 at 07:06
  • @RenaudPacalet yes you were right. With echo it doesn't work when TABs are added to something that is not a recipe. Thank you. Do you blog somewhere? – AjB Jul 15 '19 at 07:41
  • Possible duplicate of ["commence before first target. Stop." error](https://stackoverflow.com/questions/2912689/commence-before-first-target-stop-error) – Tsyvarev Jul 15 '19 at 08:02

0 Answers0