Skip to content

Instantly share code, notes, and snippets.

@BGR360
Last active October 6, 2017 19:32
Show Gist options
  • Save BGR360/14e48edf767aed423c88e635a6a3667a to your computer and use it in GitHub Desktop.
Save BGR360/14e48edf767aed423c88e635a6a3667a to your computer and use it in GitHub Desktop.
EECS 482 Platform-Independent Makefile
###########################################################
# EECS 482 Platform-Independent Makefile
# Usage:
# On CAEN: $ make <your_target>
# On OS X: $ make osx <your_target>
# On Ubuntu: $ make ubuntu <your_target>
#
# Copyright 2017 Ben Reeves
# bgreeves@umich.edu
###########################################################
CXX = g++
CXXFLAGS = -std=c++11 -Wall -pedantic -pthread -g3 -DDEBUG
TESTSOURCES = $(wildcard test*.cpp)
TESTS = $(TESTSOURCES:%.cpp=%)
# list of sources used in project
ALLSOURCES = $(wildcard *.cpp)
SOURCES := $(filter-out $(TESTSOURCES), $(ALLSOURCES))
HEADERS = $(wildcard *.h)
#list of all our objects (excluding libcpu.o)
OBJECTS = $(SOURCES:%.cpp=%.o)
LIBFLAGS = -ldl
# ----- MODIFY THESE FOR EACH PROJECT -----
LIBS = libcpu.o
LIBSOSX = libcpu.a
LIBSUBUNTU = libcpu.ubuntu.o
# use 'make osx <target(s)>' to use osx version of the library
osx:
$(eval LIBS := $(LIBSOSX))
$(eval CXXFLAGS += -D_XOPEN_SOURCE -Wno-deprecated-declarations)
# use 'make ubuntu <target(s)>' to use ubuntu version of the library
ubuntu:
$(eval LIBS := $(LIBSUBUNTU))
# Automatically generate any build rules for test*.cpp files
define make_tests
$(1): $$(SOURCES) $$(LIBS) $$(HEADERS) $(1).cpp
$$(CXX) $$(CXXFLAGS) $$(LIBS) $$(LIBFLAGS) $(SOURCES) $(1).cpp -o $(1)
endef
$(foreach test, $(TESTS), $(eval $(call make_tests, $(test))))
alltests: $(TESTS)
# make clean - WARNING: DON'T DELETE libcpu.o!!!!
clean:
rm -rf $(OBJECTS) $(TESTS) *.dSYM
##############################################################################
###################### PUT YOUR CUSTOM TARGETS HERE ##########################
##############################################################################
##############################################################################
########################## END CUSTOM TARGETS ################################
##############################################################################
# these targets do not create any files
.PHONY: clean osx ubuntu
# disable built-in rules
.SUFFIXES:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment