Skip to content

Instantly share code, notes, and snippets.

@ellotheth
Last active December 21, 2015 13:49
Show Gist options
  • Save ellotheth/6315832 to your computer and use it in GitHub Desktop.
Save ellotheth/6315832 to your computer and use it in GitHub Desktop.
Linux makefiles for Coursera's 'Algorithms I' class, derived from https://class.coursera.org/algs4partI-003/forum/thread?thread_id=63#post-432
# Stick this one at the top of your Algorithms class directory; it
# will be sourced from all the individual code directories.
SUFFIXES:
.PHONY: build run checkstyle findbugs deliver clean cleanall
# My java binaries, classpath and class binary path are all already
# sourced in my ~/.bashrc, so I don't need to specify them here:
# JAVAC = "$(JAVA_HOME)/bin/javac"
# JAVA = "$(JAVA_HOME)/bin/java"
# JAR = "$(JAVA_HOME)/bin/jar"
# CP = .:$(ALGO)/stdlib.jar:$(ALGO)/algs4.jar
# ALGOBIN = $(ALGO)/bin
JAVAC = javac
JAVA = java
JAR = jar
# Change this to your algo class directory:
ALGO = $(HOME)/coursera/algo_i
# Optional
ALGODATA = $(ALGO)/data
ALGOSRC = $(ALGO)/src
PROG ?= $(word 1,$(CLASSES))
CLASSFILES = $(patsubst %,%.class,$(CLASSES))
TESTCLASSES = $(patsubst %,Test%,$(CLASSES))
TESTFILES = $(patsubst %,%.class,$(TESTCLASSES))
JAVAFILES = $(patsubst %,%.java,$(CLASSES))
%.class: %.java
# $(JAVAC) -cp $(CP) $<
$(JAVAC) $<
build: $(CLASSFILES)
run: build
$(JAVA) $(PROG) $(CMDLINE)
checkstyle: $(JAVAFILES)
checkstyle $^
findbugs: $(CLASSFILES)
findbugs $^
test: build $(TESTFILES)
$(JAVA) org.junit.runner.JUnitCore $(TESTCLASSES)
# By default, 'deliver' runs your unit tests. If you're not unit
# testing, you can replace 'test' with 'build':
# deliver: build checkstyle findbugs
deliver: test checkstyle findbugs
$(JAR) cfMv $(PROG).zip $(JAVAFILES)
clean:
rm -f *.class
cleanall: clean
rm -f *.zip
# Make one of these per source directory, assumed to be a child of
# the common.mk directory.
# List the classes to be compiled here
CLASSES = HelloAlgo
# Anything you want to throw on the command line for `make run`
CMDLINE = 1024 100
MAKEFILE_DIRECTORY := $(dir $(word 1,$(MAKEFILE_LIST)))
include $(MAKEFILE_DIRECTORY)/../common.mk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment