Skip to content

Commit

Permalink
update makefile, add install-client target (#223)
Browse files Browse the repository at this point in the history
* update makefile, add install-client target

- enables to build client only
- when building with DEFAULT_HOST environment variable set, default hostname is compiled in to the binary (no config file needed)

* remove init config host
  • Loading branch information
ph4r05 authored May 3, 2024
1 parent 41be3fa commit abadfae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ jobs:
with:
packages: gcc rpm alien rsync pkg-config libudev-dev
- uses: actions/checkout@v3
- run: make init-config-host
- run: make rpm

34 changes: 21 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ BINARY=keymaster

# These are the values we want to pass for Version and BuildTime
VERSION=1.15.3
DEFAULT_HOST?=
DEFAULT_LDFLAGS=-X main.Version=${VERSION}
CLIENT_LDFLAGS=${DEFAULT_LDFLAGS} -X main.defaultHost=${DEFAULT_HOST}
#BUILD_TIME=`date +%FT%T%z`

# keymaster client requires special tags on linux
Expand All @@ -20,40 +23,45 @@ ifneq ($(OS),Windows_NT)
ifeq ($(UNAME_S),Linux)
EXTRA_BUILD_FLAGS+= -tags=hidraw
endif
CLIENT_DEST?="./cmd./keymaster/"
else
CLIENT_DEST?=".\\\\cmd\\\\keymaster\\\\"
endif


# Setup the -ldflags option for go build here, interpolate the variable values
#LDFLAGS=-ldflags "-X github.com/ariejan/roll/core.Version=${VERSION} -X github.com/ariejan/roll/core.BuildTime=${BUILD_TIME}"

all: init-config-host cmd/keymasterd/binData.go
cd cmd/keymaster; go install ${EXTRA_BUILD_FLAGS} -ldflags "-X main.Version=${VERSION}"
cd cmd/keymasterd; go install -ldflags "-X main.Version=${VERSION}"
cd cmd/keymaster-unlocker; go install -ldflags "-X main.Version=${VERSION}"
cd cmd/keymaster-eventmond; go install -ldflags "-X main.Version=${VERSION}"
all: install-client
cd cmd/keymasterd; go install -ldflags "${DEFAULT_LDFLAGS}"
cd cmd/keymaster-unlocker; go install -ldflags "${DEFAULT_LDFLAGS}"
cd cmd/keymaster-eventmond; go install -ldflags "${DEFAULT_LDFLAGS}"

build: cmd/keymasterd/binData.go
go build ${EXTRA_BUILD_FLAGS} -ldflags "-X main.Version=${VERSION}" -o bin/ ./...
go build ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" -o bin/ ./...

cmd/keymasterd/binData.go:
-go-bindata -fs -o cmd/keymasterd/binData.go -prefix cmd/keymasterd/data cmd/keymasterd/data/...

install-client: cmd/keymasterd/binData.go
cd cmd/keymaster; go install ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}"

build-client: cmd/keymasterd/binData.go
go build -ldflags "${CLIENT_LDFLAGS}" -o bin $(CLIENT_DEST)

win-client: client-test
go build -ldflags "-X main.Version=${VERSION}" -o bin .\cmd\keymaster\
go build -ldflags "${CLIENT_LDFLAGS}" -o bin .\cmd\keymaster\

client-test:
go test -v ./cmd/keymaster/...

get-deps: init-config-host
get-deps:
go get -t ./...

clean:
rm -f bin/*
rm -f keymaster-*.tar.gz

init-config-host:
@test -f cmd/keymaster/config_host.go || (cp -p templates/config_host_go cmd/keymaster/config_host.go && echo 'Created initial cmd/keymaster/config_host.go')

${BINARY}-${VERSION}.tar.gz:
mkdir ${BINARY}-${VERSION}
rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" lib/ ${BINARY}-${VERSION}/lib/
Expand All @@ -71,11 +79,11 @@ rpm: ${BINARY}-${VERSION}.tar.gz

tar: ${BINARY}-${VERSION}.tar.gz

test: init-config-host
test:
make -f makefile.certs
go test ./...

verbose-test: init-config-host
verbose-test:
go test -v ./...

format:
Expand Down
6 changes: 4 additions & 2 deletions cmd/keymaster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ const (

const userAgentAppName = "keymaster"
const defaultVersionNumber = "No version provided"
const defaultConfigHost = ""

var (
// Must be a global variable in the data segment so that the build
// process can inject the version number on the fly when building the
// binary. Use only from the Usage() function.
Version = defaultVersionNumber
defaultHost = defaultConfigHost
userAgentString = userAgentAppName
)

Expand Down Expand Up @@ -110,10 +112,10 @@ func loadConfigFile(client *http.Client, logger log.Logger) (
if err != nil {
logger.Fatal(err)
}
} else if len(defaultConfigHost) > 1 { // if there is a configHost AND there is NO config file, create one
} else if len(defaultHost) > 1 { // if there is a configHost AND there is NO config file, create one
if _, err := os.Stat(*configFilename); os.IsNotExist(err) {
err = config.GetConfigFromHost(
*configFilename, defaultConfigHost, client, logger)
*configFilename, defaultHost, client, logger)
if err != nil {
logger.Fatal(err)
}
Expand Down
3 changes: 0 additions & 3 deletions templates/config_host_go

This file was deleted.

0 comments on commit abadfae

Please sign in to comment.