Makefile

Makefile #

The framework simplifies managing your application by providing reusable commands and variables. Below is an example of how Loadgen utilizes this framework in its Makefile:

Use Loadgen for example, here is the project’s Makefile looks like:

➜  loadgen git:(main) cat Makefile
SHELL=/bin/bash

# APP info
APP_NAME := loadgen
APP_VERSION := 1.0.0_SNAPSHOT
APP_CONFIG := $(APP_NAME).yml $(APP_NAME).dsl
APP_EOLDate ?= "2025-12-31T10:10:10Z"
APP_STATIC_FOLDER := .public
APP_STATIC_PACKAGE := public
APP_UI_FOLDER := ui
APP_PLUGIN_FOLDER := proxy

include ../framework/Makefile

Highlights #

  • Modular and Reusable: By including ../framework/Makefile, this project inherits a suite of predefined commands and variables, reducing redundancy.
  • Customizable Variables: Project-specific details (e.g., name, version, config files, and folders) are declared at the top for easy configuration.
  • Framework Integration: The framework/Makefile provides consistent functionality across projects, enabling streamlined workflows.

This approach ensures better maintainability and faster setup for new projects.

Example #

To build the Loadgen application using the framework, you can run the following command:

➜  loadgen git:(main) OFFLINE_BUILD=true make build

Explanation of the Command:

  • OFFLINE_BUILD=true: Enables offline build mode, skipping the git pull step for the framework repository.
  • make build: Invokes the build target defined in the framework’s Makefile, compiling the application.

For development builds with race detection and extra debug info:

➜  loadgen git:(main) DEV=true make build

Commands #

CommandDescriptionDependencies/Notes
defaultDefault target, builds the application with race detectionDepends on build-race
envPrints environment variables for debuggingOutputs key paths and repository settings
buildBuilds the main application binary
build-devBuilds the application with debug symbols and development tags
build-cmdBuilds all binaries in the cmd folder
cross-build-cmdCross-compiles binaries for Windows and Linux
update-pluginsUpdates plugin files using plugin discovery toolRequires framework discovery binary
build-raceBuilds the application with race detection and debug informationDepends on clean, config, update-vfs
tarCreates a tarball of the application binary and config fileDepends on build
cross-buildCross-compiles the application for Windows, macOS, and Linux
build-winBuilds the application binary for Windows
build-linux-*Builds the application binary for specific Linux architectures (e.g., amd64, arm64)
build-darwinBuilds the application binary for macOSSupports amd64 and arm64
build-bsdBuilds the application binary for BSD systemsSupports FreeBSD, NetBSD, and OpenBSD
allCleans, configures, and builds binaries for all supported platforms
all-platformBuilds binaries for all platforms, including BSD, Linux, macOS, and Windows
formatFormats all Go source filesUses go fmt
clean_dataRemoves data and logs directories
cleanCleans all build artifacts and resets the output directoryDepends on clean_data
initInitializes the build environmentChecks/clones framework repository

Variables #

VariableDescriptionDefault Value
APP_NAMEApplication nameframework
APP_VERSIONApplication version1.0.0_SNAPSHOT
APP_CONFIGConfiguration file name$(APP_NAME).yml
APP_EOLDateEnd-of-life date for the application"2023-12-31T10:10:10Z"
APP_STATIC_FOLDERPath to static folder.public
APP_STATIC_PACKAGEStatic package namepublic
APP_UI_FOLDERUI folder pathui
APP_PLUGIN_FOLDERPlugins folder pathplugins
APP_PLUGIN_PKGPlugins package name$(APP_PLUGIN_FOLDER)
APP_NEED_CGODetermines if CGO is required (0 = disabled, 1 = enabled)0
VERSIONRelease version from the environment
GOPATHGo workspace path. Can be overridden to use a custom location.~/go
BUILD_NUMBERBuild number001
DEVEnables development mode (adds -tags dev to build). Set to any non-empty value to enable.
OFFLINE_BUILDSkips git pull for the framework during init. Set to any non-empty value to enable.
GOGo commandgo
FRAMEWORK_FOLDERPath to INFINI Framework folder$(INFINI_BASE_FOLDER)/framework
FRAMEWORK_REPOFramework repository URLhttps://github.com/infinilabs/framework.git
FRAMEWORK_BRANCHGit branch for the frameworkmain

Notes #

  • Go Modules: All dependencies are managed via Go modules (go.mod). No external vendor repository is required.
  • Cross-Platform Builds: Targets like build-linux and build-darwin compile binaries for multiple architectures, ensuring compatibility across platforms.
  • Plugin Updates: Plugins are dynamically discovered and updated using a tool within the framework. Ensure plugin-discovery exists and is built.
  • Environment Variables: Many configurations (e.g., GOPATH, VERSION, EOL) can be overridden via environment variables for flexibility.
Edit Edit this page