Skip to content

Instantly share code, notes, and snippets.

@lstarnes1024
Last active August 29, 2015 14:15
Show Gist options
  • Save lstarnes1024/713e68585d3e804a6e92 to your computer and use it in GitHub Desktop.
Save lstarnes1024/713e68585d3e804a6e92 to your computer and use it in GitHub Desktop.
Makefile for CS 240 PA 2 (annotated version)
# An example Makefile for C++
# Author: Lee Starnes <starnelt@dukes.jmu.edu>
#
# This is written for use with PA2 in Dr. Rahman's
# CS 240 sections for Spring 2015.
#
# Usage: run 'make' in this directory in a terminal
#
# If you want to edit this for a future project, you
# just need to change the 'SRCS' list and replace the
# 'out' target with targets for each executable you want.
#------------------
# Common variables
#------------------
# Use g++ as the C++ compiler
CXX = g++
# Compile with the following options:
# -std=c++11: use the new C++11 standard instead of the default C++03
# -g: generate debugging symbols (for use with gdb)
# -Wall: warn about all types of possible programming errors
CXXFLAGS = -std=c++11 -g -Wall
# Flags for the C Preprocessor (CPP).
# The C Preprocessor evaluates macros and preprocessor directives
# (e.g. #include, #define, #ifdef, #ifndef, #else, #end).
# Typically, this is used for telling the compiler where
# to find headers for libraries.
#
# -I.: look for includes in the current directory (.)
CPPFLAGS = -I.
# This is a list of what libraries you want your final executables
# and libraries to be linked against. The usual arguments are a mix
# of -lNAME (link against libNAME) and -L/PATH (look for the libraries
# in /PATH).
# The C++ Standard Template Library is included automatically, so this
# is empty.
LIBS =
# A list of source files you want to build.
# Note that this is indented with TAB and that all lines
# but the last end with '\'.
SRCS = \
billTypeImpl.cpp \
dateTypeImpl.cpp \
doctorTypeImpl.cpp \
patientTypeImpl.cpp \
personTypeImpl.cpp \
mainProg.cpp
# A list of object files to build.
# This is made automatically by replacing '.cpp' with '.o' in $(SRCS).
OBJS = ${SRCS:.cpp=.o}
#--------------
# Target rules
#--------------
# Special rule: compile *.cpp to make *.o
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
# Create 'out' by linking together the object files
# This is the main executable for this project.
# This depends on everything in $(OBJS) being built.
out: $(OBJS)
$(CXX) $(CXXFLAGS) $(LIBS) $^ -o $@
# Define the default target to be 'out'
default: out
# Clean up any unneeded objects
clean:
rm *.o out
# Run the project's main executable:
run: out
./out
# Tell make not to assume that 'clean' and 'run' create files with those names:
.PHONY: clean run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment