linux sh : Makefile_userland_pf_ring_template

Keywords: Makefile JSON shell CentOS

Preface

Put the project in hand into pf_ring, organize a Makefile template, and make a template for the later test project of pf_ring.

Think of the Makefile content previously posted on the blog, copy and paste it to the local Makefile, and then r\n appears at the end, causing Makefile to not run.
There are two simple ways to solve this problem:
* Install dos2unix and use dos2unix -n make_file_path_name make_file_path_name_new to replace r n with R.
When you encounter a complex Makefile, dos2unix recognizes binary characters (actually, there is no binary character, it is a bug in dos2unix), which makes it impossible to convert.

centos : yum install dos2unix unix2dos

ubuntu : aptitude install tofrodos
unix2dos Corresponding todos   dos2unix Corresponding fromdos
  • Use Source Insight 4.0 to paste the Makefile and save it as a unix return file. This method is very simple.

Makefile template using pf_ring client code

# ==============================================================================
# @file Makefile_userland_pf_ring_template
# @brief Makefile template for userland pf_ring linux app, pf_ring is 6.6.0
#   lostspeed 2018-04-25
#   doc\pf_ring\Makefile_userland_pf_ring_template
# ==============================================================================

MAKE_VER = ./main/Makefile 1.1.0.1 build 2018-04-25 15:06
BIN = my_linux_app_use_userland_pf_ring

BIN_OUT = "../bin/"
# cat string
BIN_OUT := $(BIN)

TARGETS = ${BIN}

CFLAGS = -Wall \
    -D HAVE_VSNPRINTF \
    -D HAVE_SNPRINTF \
    -D ENABLE_BPF \
    -D HAVE_PF_RING \
    -D HAVE_PF_RING_ZC \
    -g

CC = g++

INC_PATH = -I. \
    -I.. \
    -I../../../../lic \
    -I../../../../commons \
    -I../../../../third_party/INIReader/1.0.0.1 \
    -I../../../../third_party/json-parser/1.0.0.1 \
    -I../../../../third_party/libaio/1.0.0.1 \
    -I../../../../third_party/pf_ring_release/include/libpcap-1.7.4 \
    -I../../../../third_party/pf_ring_release/include/libpcap-1.7.4/pcap \
    -I../../../../third_party/plog/1.0.0.1 \
    -I../../../common_business/1.1.0.0 \
    -I./helper \
    -I./ring_queue \
    -I./ring_queue/inc \

MY_LIBS =

PCAP_LIBS = ../../../../third_party/pf_ring_release/lib/libs/libpcap.a \
    ../../../../third_party/pf_ring_release/lib/libs/libpfring.a

PRJ_LIBS = ${MY_LIBS} ${PCAP_LIBS}
# LIB_LINK_OPT = -lstdc++ -pthread -lpthread -lrt -ldl
LIB_LINK_OPT = -lpthread -ldl

DEPEND_CODE_DIR = ../../../../third_party/INIReader/1.0.0.1/ \
    ../../../../third_party/json-parser/1.0.0.1/ \
    ../../../../commons/file \
    ../../../../commons/net \
    ../../../../commons/string \
    ../../../../commons/const \
    ../../../../1.1/common_business/1.1.0.0 \

DEPEND_CODE_SRC = $(shell find $(DEPEND_CODE_DIR) -name '*.cpp')
DEPEND_CODE_OBJ = $(DEPEND_CODE_SRC:.cpp=.o)

# Root directory files can't be done with find, they will traverse to subdirectories.
ROOT_CODE_SRC = $(wildcard *.cpp)
ROOT_CODE_OBJ = $(ROOT_CODE_SRC:.cpp=.o)

SUB_CODE_DIR = ./helper/ \
    ./ring_queue/ \

SUB_CODE_SRC = $(shell find $(SUB_CODE_DIR) -name '*.cpp')
SUB_CODE_OBJ = $(SUB_CODE_SRC:.cpp=.o)

help:
    @echo make help
    @echo command list:
    @echo   make rebuild

    @echo "DEPEND_CODE_DIR = " $(DEPEND_CODE_DIR)
    @echo "DEPEND_CODE_SRC = " $(DEPEND_CODE_SRC)
    @echo "DEPEND_CODE_OBJ = " $(DEPEND_CODE_OBJ)

    @echo "SUB_CODE_DIR = " $(SUB_CODE_DIR)
    @echo "SUB_CODE_SRC = " $(SUB_CODE_SRC)
    @echo "SUB_CODE_OBJ = " $(SUB_CODE_OBJ)

show_version:
    @echo ================================================================================
    @echo ${MAKE_VER}
    @echo ================================================================================
    ls -l -p --time-style="+%Y-%m-%d %H:%M:%S" $(find `pwd`)
    @echo --------------------------------------------------------------------------------

clean:
    clear
    @echo ================================================================================
    rm -f $(BIN)
    @echo ================================================================================
    rm -f $(ROOT_CODE_OBJ)
    @echo ================================================================================
    rm -f $(DEPEND_CODE_OBJ)
    @echo ================================================================================
    rm -f $(SUB_CODE_OBJ)
    @echo ================================================================================

all: ${TARGETS}
    @echo Makefile all...

    @echo **==============================================================================
    if [ -f $(BIN) ] ; \
    then \
        cp $(BIN) ../bin/ ; \
        echo "build ok :)" ; \
    else \
        echo "build failed :(" ; \
    fi;
    @echo **==============================================================================

$(BIN): $(ROOT_CODE_OBJ) $(DEPEND_CODE_OBJ) $(SUB_CODE_OBJ)
    ${CC} ${CFLAGS} ${INC_PATH} \
    $(ROOT_CODE_OBJ) $(DEPEND_CODE_OBJ) $(SUB_CODE_OBJ) \
    ${PRJ_LIBS} ${LIB_LINK_OPT} \
    -o ${BIN} \

.cpp.o:
    @echo $<
    @echo build $^ ...
    ${CC} ${CFLAGS} ${INC_PATH} -c $^ -o $@

rebuild:
    @echo Makefile rebuild...
    make -f Makefile_userland_pf_ring_template clean
    make -f Makefile_userland_pf_ring_template all

Posted by scast on Tue, 05 Feb 2019 19:39:16 -0800