make[1]: *** No rule to make target 'all'. Stop. make: *** [../common/common.mk:94: ../lib/install/lib/libxdp.a] Error 2

104 views Asked by At

I am working on xdp tutorial using the documentation in guthub repository while on first step in basic01 after installing all the dependencies i got this error when I run command "make" as guided in the README.org

This is my MakeFile

# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)

XDP_TARGETS := xdp_pass_kern  
USER_TARGETS := xdp_pass_user

LLC ?= llc
CLANG ?= clang
CC := gcc

COMMON_DIR = ../common
COMMON_OBJS += $(COMMON_DIR)/common_user_bpf_xdp.o

include $(COMMON_DIR)/common.mk

This is my xdp_pass_kern.c which expected to be converted into xdp_pass_kern.o after running command make

/* SPDX-License-Identifier: GPL-2.0 */
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

SEC("xdp")
int  xdp_prog_simple(struct xdp_md *ctx)
{
    return XDP_PASS;
}

char _license[] SEC("license") = "GPL";

This is my common.mk file

# Common Makefile parts for BPF-building with libbpf
# --------------------------------------------------
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
#
# This file should be included from your Makefile like:
#  COMMON_DIR = ../common
#  include $(COMMON_DIR)/common.mk
#
# It is expected that you define the variables:
#  XDP_TARGETS and USER_TARGETS
# as a space-separated list
#
LLC ?= llc
CLANG ?= clang
CC ?= gcc

XDP_C = ${XDP_TARGETS:=.c}
XDP_OBJ = ${XDP_C:.c=.o}
USER_C := ${USER_TARGETS:=.c}
USER_OBJ := ${USER_C:.c=.o}

# Expect this is defined by including Makefile, but define if not
COMMON_DIR ?= ../common
LIB_DIR ?= ../lib

COPY_LOADER ?=
LOADER_DIR ?= $(LIB_DIR)/xdp-tools/xdp-loader
STATS_DIR ?= $(COMMON_DIR)/../basic-solutions

COMMON_OBJS += $(COMMON_DIR)/common_params.o
include $(LIB_DIR)/defines.mk

# Create expansions for dependencies
COMMON_H := ${COMMON_OBJS:.o=.h}

EXTRA_DEPS +=

# BPF-prog kern and userspace shares struct via header file:
KERN_USER_H ?= $(wildcard common_kern_user.h)

CFLAGS += -I$(LIB_DIR)/install/include $(EXTRA_CFLAGS)
BPF_CFLAGS += -I$(LIB_DIR)/install/include $(EXTRA_CFLAGS)
LDFLAGS += -L$(LIB_DIR)/install/lib

BPF_HEADERS := $(wildcard $(HEADER_DIR)/*/*.h) $(wildcard $(INCLUDE_DIR)/*/*.h)

all: llvm-check $(USER_TARGETS) $(XDP_OBJ) $(COPY_LOADER) $(COPY_STATS)

.PHONY: clean $(CLANG) $(LLC)

clean:
    $(Q)rm -f $(USER_TARGETS) $(XDP_OBJ) $(USER_OBJ) $(COPY_LOADER) $(COPY_STATS) *.ll

ifdef COPY_LOADER
$(LOADER_DIR)/$(COPY_LOADER):
    $(Q)make -C $(LOADER_DIR)

$(COPY_LOADER): $(LOADER_DIR)/$(COPY_LOADER)
    $(QUIET_COPY)cp $(LOADER_DIR)/$(COPY_LOADER) $(COPY_LOADER)
endif

ifdef COPY_STATS
$(STATS_DIR)/$(COPY_STATS): $(STATS_DIR)/${COPY_STATS:=.c} $(COMMON_H)
    $(Q)make -C $(STATS_DIR) $(COPY_STATS)

$(COPY_STATS):  $(STATS_DIR)/$(COPY_STATS)
    $(QUIET_COPY)cp $(STATS_DIR)/$(COPY_STATS) $(COPY_STATS)
# Needing xdp_stats imply depending on header files:
EXTRA_DEPS += $(COMMON_DIR)/xdp_stats_kern.h $(COMMON_DIR)/xdp_stats_kern_user.h
endif

# For build dependency on this file, if it gets updated
COMMON_MK = $(COMMON_DIR)/common.mk

llvm-check: $(CLANG) $(LLC)
    @for TOOL in $^ ; do \
        if [ ! $$(command -v $${TOOL} 2>/dev/null) ]; then \
            echo "*** ERROR: Cannot find tool $${TOOL}" ;\
            exit 1; \
        else true; fi; \
    done

$(OBJECT_LIBBPF):
    @if [ ! -d $(LIBBPF_DIR) ]; then \
        echo "Error: Need libbpf submodule" $(LIBBPF_DIR); \
        echo "May need to run git submodule update --init"; \
        exit 1; \
    else \
        cd $(LIBBPF_DIR) && $(MAKE) all OBJDIR=.; \
        mkdir -p build; $(MAKE) install_headers DESTDIR=build OBJDIR=.; \
    fi

$(OBJECT_LIBXDP):
    @if [ ! -d $(LIBXDP_DIR) ]; then \
        echo "Error: Need libxdp submodule" $(LIBXDP_DIR); \
        echo "May need to run git submodule update --init"; \
        exit 1; \
    else \
        cd $(LIBXDP_DIR) && $(MAKE) all OBJDIR=.; \
    fi

# Create dependency: detect if C-file change and touch H-file, to trigger
# target $(COMMON_OBJS)
$(COMMON_H): %.h: %.c
    touch $@

# Detect if any of common obj changed and create dependency on .h-files
$(COMMON_OBJS): %.o: %.h
    $(Q)$(MAKE) -C $(COMMON_DIR)

$(USER_TARGETS): %: %.c  $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) Makefile $(COMMON_MK) $(COMMON_OBJS) $(KERN_USER_H) $(EXTRA_DEPS)
    $(QUIET_CC)$(CC) -Wall $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) $(LIB_OBJS) \
     $< $(LDLIBS)

$(XDP_OBJ): %.o: %.c  Makefile $(COMMON_MK) $(KERN_USER_H) $(EXTRA_DEPS) $(OBJECT_LIBBPF)
    $(QUIET_CLANG)$(CLANG) -S \
        -target bpf \
        -D __BPF_TRACING__ \
        $(BPF_CFLAGS) \
        -Wall \
        -Wno-unused-value \
        -Wno-pointer-sign \
        -Wno-compare-distinct-pointer-types \
        -Werror \
        -O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
    $(QUIET_LLC)$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll}

I am expecting it to create xdp_pass_kern.c into xdp_pass_kern.o for my further steps

You can also check the git repository I am following https://github.com/xdp-project/xdp-tutorial/tree/master/basic01-xdp-pass

Please help me achieve this

1

There are 1 answers

2
MadScientist On

The first thing you should do when trying to debug a makefile, is remove all the @ prefixes so you can see the actual commands being invoked. Else it's like trying to debug a program while sending all its output to /dev/null.

If you have a sufficiently new version of GNU Make you can add the --trace option to the command line and make will print all the commands without you having to edit the makefile and remove the @ chars.

Also, when posting code with an error message at a given line number please make an effort to show us which line that is. We don't want to have to count the lines ourselves.

My suspicion is the problem is here:

    cd $(LIBBPF_DIR) && $(MAKE) all OBJDIR=.; \

I expect it's this sub-make which is throwing the error. Most likely the contents of the LIBBPF_DIR directory (that variable is not being set anywhere that you've shown us so we have no idea what's in it) do not include a Makefile so there's no all rule defined there.

Maybe you're supposed to run ./configure or similar there to create the makefile.