Makefile on MAC OS

wahyu eko hadi saputro
1 min readMay 1, 2023

On Unix systems, a Makefile is a text file that contains a set of rules for building a program or a set of programs. Make is a build automation tool that reads these rules and uses them to build the program or programs.

Makefiles are often used to automate the process of building and compiling software on Unix-based systems, including Linux and macOS. A typical Makefile consists of a set of targets and dependencies, where each target represents a file that needs to be built, and each dependency represents a file that the target depends on.

create makefile

# Define the Go compiler and linker
GO := go
GOLDFLAGS := -ldflags="-s -w"


# Build go app
build:
$(GO) build $(GOLDFLAGS) -o my_app


run:
./my_app


# Define a "clean" target to remove generated files
clean:
rm -f my_app

create go file with name main.go

package main


import (
"fmt"
)


func main() {
fmt.Println("Hello, World!")
}
simple project structure
wahyu@wahyus-mbp hallo % make clean
rm -f my_app
wahyu@wahyus-mbp hallo % make build
go build -ldflags="-s -w" -o my_app
wahyu@wahyus-mbp hallo % make run
./my_app
Hello, World!
wahyu@wahyus-mbp hallo %

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response