github.com/jpbruinsslot/dot@v0.0.0-20231229172555-797f05ba0642/Makefile (about)

     1  APP_NAME=dot
     2  
     3  default: build
     4  
     5  all: clean test build
     6  
     7  clean:
     8  	@ echo "+ $@"
     9  	rm -rf ./bin
    10  
    11  # -timeout 	timout in seconds
    12  #  -v		verbose output
    13  test:
    14  	@ echo "+ $@"
    15  	go test -timeout=5s -v
    16  
    17  # `CGO_ENABLED=0`
    18  # Because of dynamically linked libraries, this will statically compile the
    19  # app with all libraries built in. You won't be able to cross-compile if CGO
    20  # is enabled. This is because Go binary is looking for libraries on the
    21  # operating system it’s running in. We compiled our app, but it still is
    22  # dynamically linked to the libraries it needs to run
    23  # (i.e., all the C libraries it binds to). When using a minimal docker image
    24  # the operating system doesn't have these libraries.
    25  #
    26  # `-a`
    27  # Force rebuilding of package, all import will be rebuilt with cgo disabled,
    28  # which means all the imports will be rebuilt with cgo disabled.
    29  #
    30  # `-installsuffix cgo`
    31  # A suffix to use in the name of the package installation directory
    32  #
    33  # `-o`
    34  # Output
    35  #
    36  # `./bin/[name-of-app]`
    37  # Placement of the binary
    38  #
    39  # `.`
    40  # Location of the source files
    41  build:
    42  	@ echo "+ $@"
    43  	CGO_ENABLED=0 go build -a -installsuffix cgo -o ./bin/${APP_NAME} .
    44  
    45  # Cross-compile
    46  # http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
    47  build-linux:
    48  	@ echo "+ $@"
    49  	GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -o ./bin/${APP_NAME}-linux-amd64 .
    50  
    51  build-mac:
    52  	@ echo "+ $@"
    53  	GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -o ./bin/${APP_NAME}-darwin-amd64 .
    54  
    55  .PHONY: all default clean test build build-linux build-mac