Makefile Reference

Makefile Reference #

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) DEV=false OFFLINE_BUILD=true make build

Explanation of the Command:

  • DEV=false: Sets the development mode to false, indicating a production build.
  • OFFLINE_BUILD=true: Enables offline build mode, ensuring the build process avoids fetching resources from external sources.
  • make build: Invokes the build target defined in the framework’s Makefile, compiling the application according to the specified settings.

This example demonstrates how you can customize the build process using environment variables while leveraging the reusable commands provided by the framework.

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 files excluding vendor directoryUses 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 repositories

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~/go
BUILD_NUMBERBuild number001
DEVEnables or disables development mode. Set to true for development builds, false for production builds.false
OFFLINE_BUILDEnables offline build mode, preventing the download of external resources during the build process.false
GOGo environment settingsGO15VENDOREXPERIMENT="1" GO111MODULE=off go
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
FRAMEWORK_VENDOR_FOLDERPath to framework vendor folder$(FRAMEWORK_FOLDER)/../vendor/
FRAMEWORK_VENDOR_REPOVendor repository URLhttps://github.com/infinilabs/framework-vendor.git
FRAMEWORK_VENDOR_BRANCHVendor repository branchmain
PREFER_MANAGED_VENDORDetermines whether to use a managed vendor directory or fetch dependencies dynamically. If set to 1, the build process will prioritize the pre-downloaded vendor folder (FRAMEWORK_VENDOR_FOLDER). If set to 0, dependencies will be fetched from the FRAMEWORK_VENDOR_REPO.1

Notes #

  • Framework Dependencies: This Makefile integrates with INFINI Framework, requiring external repositories for the framework and vendor files. Ensure these are cloned and accessible.
  • 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