Skip to content

Commit

Permalink
remove unnecessary bits from Makefile and action
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed Feb 28, 2024
1 parent cedce4e commit dc7ed88
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 144 deletions.
30 changes: 6 additions & 24 deletions .github/actions/build-dependencies/action.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
name: Build Dependencies
description: |
Install build dependencies to test and compile btfhub artifacts
inputs:
# set default versions in a single place (as default)
go-version:
description: go version
required: true
default: "1.20.13"
runs:
using: composite
steps:
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Install ubuntu packages
run: |
export DEBIAN_FRONTEND=noninteractive
Expand All @@ -20,16 +18,7 @@ runs:
sudo apt-get install -y software-properties-common
sudo apt-get install -y devscripts ubuntu-dev-tools
shell: bash
- name: Install golang
run: |
rm -rf /usr/local/go
curl -L -o /tmp/go.tar.xz https://go.dev/dl/go${{ inputs.go-version }}.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf /tmp/go.tar.xz
sudo update-alternatives --remove-all go || true
sudo update-alternatives --remove-all gofmt || true
sudo update-alternatives --install /usr/bin/go go /usr/local/go/bin/go 1
sudo update-alternatives --install /usr/bin/gofmt gofmt /usr/local/go/bin/gofmt 1
shell: bash

- name: Install llvm
run: |
export DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -77,12 +66,5 @@ runs:
./3rdparty/pahole.sh
shell: bash
- name: Install staticchecker
run: |
GOROOT=/usr/local/go GOPATH=$HOME/go go install honnef.co/go/tools/cmd/staticcheck@latest
sudo cp $HOME/go/bin/staticcheck /usr/bin/
shell: bash
- name: Install goimports-reviser
run: |
GOROOT=/usr/local/go GOPATH=$HOME/go go install github.com/incu6us/goimports-reviser/v3@latest
sudo cp $HOME/go/bin/goimports-reviser /usr/bin/
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
btfhub
# archives
/archive
# makefile leftovers
.check*
# JetBrains
.idea/
121 changes: 3 additions & 118 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,19 @@ all: btfhub
.ONESHELL:
SHELL = /bin/sh

PARALLEL = $(shell $(CMD_GREP) -c ^processor /proc/cpuinfo)
MAKE = make
MAKEFLAGS += --no-print-directory

#
# tools
#

CMD_TR ?= tr
CMD_CUT ?= cut
CMD_AWK ?= awk
CMD_SED ?= sed
CMD_GIT ?= git
CMD_RM ?= rm
CMD_MKDIR ?= mkdir
CMD_TOUCH ?= touch
CMD_GO ?= go
CMD_GREP ?= grep
CMD_CAT ?= cat
CMD_MD5 ?= md5sum
CMD_RSYNC ?= rsync
CMD_CLANG ?= clang
CMD_STATICCHECK ?= staticcheck

.check_%:
#
@command -v $* >/dev/null
if [ $$? -ne 0 ]; then
echo "missing required tool $*"
exit 1
else
touch $@ # avoid target rebuilds due to inexistent file
fi

#
# tools version
#

GO_VERSION = $(shell $(CMD_GO) version 2>/dev/null | $(CMD_AWK) '{print $$3}' | $(CMD_SED) 's:go::g' | $(CMD_CUT) -d. -f1,2)
GO_VERSION_MAJ = $(shell echo $(GO_VERSION) | $(CMD_CUT) -d'.' -f1)
GO_VERSION_MIN = $(shell echo $(GO_VERSION) | $(CMD_CUT) -d'.' -f2)

.checkver_$(CMD_GO): \
| .check_$(CMD_GO)
#
@if [ ${GO_VERSION_MAJ} -eq 1 ]; then
if [ ${GO_VERSION_MIN} -lt 18 ]; then
echo -n "you MUST use golang 1.18 or newer, "
echo "your current golang version is ${GO_VERSION}"
exit 1
fi
fi
touch $@

#
# version
#
Expand All @@ -74,27 +33,13 @@ VERSION ?= $(if $(RELEASE_TAG),$(RELEASE_TAG),$(LAST_GIT_TAG))
#

DEBUG ?= 0
UNAME_M := $(shell uname -m)
UNAME_R := $(shell uname -r)

ifeq ($(DEBUG),1)
GO_DEBUG_FLAG =
else
GO_DEBUG_FLAG = -w
endif

ifeq ($(UNAME_M),x86_64)
ARCH = x86_64
LINUX_ARCH = x86
GO_ARCH = amd64
endif

ifeq ($(UNAME_M),aarch64)
ARCH = arm64
LINUX_ARCH = arm64
GO_ARCH = arm64
endif

#
# variables
#
Expand All @@ -112,18 +57,13 @@ ifeq ($(STATIC), 1)
GO_TAGS := $(GO_TAGS),netgo
endif

GO_ENV =
GO_ENV += GOOS=linux
GO_ENV += CC=$(CMD_CLANG)
GO_ENV += GOARCH=$(GO_ARCH)
GO_ENV = CC=$(CMD_CLANG)

SRC_DIRS = ./cmd/ ./pkg/
SRC = $(shell find $(SRC_DIRS) -type f -name '*.go' ! -name '*_test.go')

$(PROGRAM): \
$(SRC) \
| .check_$(CMD_GO) \
.checkver_$(CMD_GO)
$(SRC)
#
$(GO_ENV) $(CMD_GO) build \
-tags $(GO_TAGS) \
Expand All @@ -139,9 +79,7 @@ $(PROGRAM): \

.PHONY: test-unit
test-unit: \
$(SRC) \
| .check_$(CMD_GO) \
.checkver_$(CMD_GO)
$(SRC)
#
$(GO_ENV) \
$(CMD_GO) test \
Expand All @@ -157,8 +95,6 @@ test-unit: \

.PHONY: check-vet
check-vet: \
| .check_$(CMD_GO) \
.checkver_$(CMD_GO) \
#
$(GO_ENV) \
$(CMD_GO) vet \
Expand All @@ -168,63 +104,13 @@ check-vet: \

.PHONY: check-staticcheck
check-staticcheck: \
| .check_$(CMD_GO) \
.checkver_$(CMD_GO) \
#
$(GO_ENV) \
$(CMD_STATICCHECK) -f stylish \
-tags $(GO_TAGS) \
./cmd/... \
./pkg/...

#
# repository
#

BTFHUB_ARCHIVE_DIR ?= ../btfhub-archive
LOCAL_ARCHIVE_DIR ?= ./archive

.PHONY: bring
bring: \
| .check_$(CMD_RSYNC)
#
@echo ""
@if [ ! -d $(BTFHUB_ARCHIVE_DIR) ]; then
echo "ERROR: make sure to have the btfhub-archive repository at $(BTFHUB_ARCHIVE_DIR)"
echo ""
exit 1
fi
echo -n "WARNING: this will delete all the files in $(LOCAL_ARCHIVE_DIR), press enter to continue"
echo -n " ... "
read nop
echo ""
$(CMD_RSYNC) -av --delete --exclude=.git* $(BTFHUB_ARCHIVE_DIR)/ $(LOCAL_ARCHIVE_DIR)/
echo ""

.PHONY: take
take: \
| .check_$(CMD_RSYNC)
#
@echo ""
if [ ! -d $(BTFHUB_ARCHIVE_DIR) ]; then
echo "ERROR: make sure to have the btfhub-archive repository at $(BTFHUB_ARCHIVE_DIR)"
echo ""
exit 1
fi
echo -n "WARNING: this will take files from $(LOCAL_ARCHIVE_DIR) into $(BTFHUB_ARCHIVE_DIR), press enter to continue"
echo -n " ... "
echo ""
read nop
$(CMD_RSYNC) -av \
--exclude=.git* \
--exclude=*.deb \
--exclude=*.ddeb \
--exclude=*.rpm \
$(LOCAL_ARCHIVE_DIR)/ $(BTFHUB_ARCHIVE_DIR)/
echo ""
echo "INFO: now goto $(BTFHUB_ARCHIVE_DIR) and commit the changes"
echo ""

#
# clean
#
Expand All @@ -233,4 +119,3 @@ take: \
clean:
#
$(CMD_RM) -rf $(PROGRAM)
$(CMD_RM) -f .check*

0 comments on commit dc7ed88

Please sign in to comment.