github.com/gojue/ecapture@v0.8.2/functions.mk (about)

     1  
     2  .check_%:
     3  	@command -v $* >/dev/null
     4  	if [ $$? -ne 0 ]; then
     5  		echo "eCapture Makefile: missing required tool $*"
     6  		exit 1
     7  	else
     8  		touch $@ # avoid target rebuilds due to inexistent file
     9  	fi
    10  
    11  
    12  #  clang 编译器版本检测,llvm检测,
    13  .checkver_$(CMD_CLANG): \
    14  	| .check_$(CMD_CLANG)
    15  #
    16  	@echo $(shell date)
    17  	@if [ ${CLANG_VERSION} -lt 9 ]; then
    18  		echo -n "you MUST use clang 9 or newer, "
    19  		echo "your current clang version is ${CLANG_VERSION}"
    20  		exit 1
    21  	fi
    22  	$(CMD_TOUCH) $@ # avoid target rebuilds over and over due to inexistent file
    23  
    24  
    25  # golang 版本检测  1.21 以上
    26  .checkver_$(CMD_GO): \
    27  	| .check_$(CMD_GO)
    28  	@if [ ${GO_VERSION_MAJ} -eq 1 ]; then
    29  		if [ ${GO_VERSION_MIN} -lt 21 ]; then
    30  			echo -n "you MUST use golang 1.21 or newer, "
    31  			echo "your current golang version is ${GO_VERSION}"
    32  			exit 1
    33  		fi
    34  	fi
    35  	touch $@
    36  
    37  # bpftool version
    38  .checkver_$(CMD_BPFTOOL): \
    39  	| .check_$(CMD_BPFTOOL)
    40  
    41  define allow-override
    42    $(if $(or $(findstring environment,$(origin $(1))),\
    43              $(findstring command line,$(origin $(1)))),,\
    44      $(eval $(1) = $(2)))
    45  endef
    46  
    47  define gobuild
    48  	CGO_ENABLED=1 \
    49  	CGO_CFLAGS='-O2 -g -gdwarf-4 -I$(CURDIR)/lib/libpcap/' \
    50  	CGO_LDFLAGS='-O2 -g -L$(CURDIR)/lib/libpcap/ -lpcap -static' \
    51  	GOOS=linux GOARCH=$(GOARCH) CC=$(CMD_CC_PREFIX)$(CMD_CC) \
    52  	$(CMD_GO) build -tags $(TARGET_TAG) -ldflags "-w -s -X 'github.com/gojue/ecapture/cli/cmd.GitVersion=$(TARGET_TAG)_$(GOARCH):$(VERSION_NUM):$(VERSION_FLAG)' -linkmode=external -extldflags -static " -o $(OUT_BIN)
    53  	$(CMD_FILE) $(OUT_BIN)
    54  endef
    55  
    56  
    57  define CHECK_IS_NON_CORE
    58  $(if $(filter $(1),$(2)),-nocore,)
    59  endef
    60  
    61  # build and tar
    62  define release_tar
    63  	$(call allow-override,CORE_PREFIX,$(call CHECK_IS_NON_CORE,$(2),nocore))
    64  	$(call allow-override,TAR_DIR,ecapture-$(DEB_VERSION)-$(1)-$(GOARCH)$(CORE_PREFIX))
    65  	$(call allow-override,OUT_ARCHIVE,$(OUTPUT_DIR)/$(TAR_DIR).tar.gz)
    66  	$(CMD_MAKE) clean
    67  	ANDROID=$(ANDROID) $(CMD_MAKE) $(2)
    68  	# create the tar ball and checksum files
    69  	$(CMD_MKDIR) -p $(TAR_DIR)
    70  	$(CMD_CP) LICENSE $(TAR_DIR)/LICENSE
    71  	$(CMD_CP) CHANGELOG.md $(TAR_DIR)/CHANGELOG.md
    72  	$(CMD_CP) README.md $(TAR_DIR)/README.md
    73  	$(CMD_CP) README_CN.md $(TAR_DIR)/README_CN.md
    74  	$(CMD_CP) $(OUTPUT_DIR)/ecapture $(TAR_DIR)/ecapture
    75  	$(CMD_TAR) -czf $(OUT_ARCHIVE) $(TAR_DIR)
    76  endef