Skip to content

Instantly share code, notes, and snippets.

@quocle108
Created April 29, 2020 09:38
Show Gist options
  • Save quocle108/d006758d5ca939c5bacda676af3b5e90 to your computer and use it in GitHub Desktop.
Save quocle108/d006758d5ca939c5bacda676af3b5e90 to your computer and use it in GitHub Desktop.
# Specify the target file and the install directory
OUTPUTFILE=hello
INSTALLDIR=binaries
# Default target
.PHONY: all
all: $(OUTPUTFILE)
# This rule tells make how to build hello from hello.cpp
#OUTPUTFILE: helloworld.cpp
# g++ -o hello hello.cpp
# we also can use automatic variables
# the variable $< represents the filename of the first prerequisite, and the variable $^ represents the sequence of prerequisites, separated by spaces
# https://www.gnu.org/software/make/manual/make.html#Automatic-Variables
$(OUTPUTFILE): helloworld.cpp
g++ -o $@ $<
# Copy hello to the binaries subdirectory
.PHONY: install
install:
mkdir -p $(INSTALLDIR)
cp -p $(OUTPUTFILE) $(INSTALLDIR)
# Delete hello
.PHONY: clean
clean:
rm -f $(OUTPUTFILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment