Skip to content

Instantly share code, notes, and snippets.

@Clumsy-Coder
Created October 28, 2016 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Clumsy-Coder/4de8cae3e845728c2d169aaa3e1e429d to your computer and use it in GitHub Desktop.
Save Clumsy-Coder/4de8cae3e845728c2d169aaa3e1e429d to your computer and use it in GitHub Desktop.
Makefile for compiling one C++ file. Used for compiling problems from uva or uhunt
CC = g++
CFLAGS = -Wall -g
MAKECMDGOALS := $(filter-out clean, $(MAKECMDGOALS))
INCLUDE = -I./$(MAKECMDGOALS)
OBJS = $(MAKECMDGOALS).o
.PHONY: $(MAKECMDGOALS) clean
# command for compiling source file, removing any junk files
# and running the compiled file
# to use command, type the following
# make <filename>
#
# note: the command does not take file extentions.
# example:
# make helloWorld
#
# Assumes the source file is .cpp
$(MAKECMDGOALS): $(OBJS)
$(CC) $(CFLAGS) $^ -o Main-$@
rm -rf *.o *~ *% *# .#*
./Main-$(MAKECMDGOALS)
%.o : %.cpp
$(CC) -c $(CFLAGS) $<
# for cleaning up the compiled file and any junk files.
# to use command, type the following:
# make clean
clean:
rm -rf *.o *~ *% *# .#*
rm Main-*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment