Skip to content

Instantly share code, notes, and snippets.

@kylefeng28
Last active January 14, 2017 17:08
Show Gist options
  • Save kylefeng28/dd5f3a8c13562428a3989071da5af630 to your computer and use it in GitHub Desktop.
Save kylefeng28/dd5f3a8c13562428a3989071da5af630 to your computer and use it in GitHub Desktop.
COMP 411 Lab 1 Makefile

COMP 411 Lab 1 – Makefile to automate compiling, checking, and submitting

Analytics

Introduction

Compiling files by hand is a pain, so here is simple Makefile that does this for you. It can also run the submit and check scripts for you, so you don't have to type in the commands in by hand. If you are not sure if your submission has gone through, it can also list your submission dates.

In a nutshell, Make is a utility that automates the build process for projects. Tasks are defined in a special file called a Makefile, which is what we have here.

How to use

First, download the Makefile to your lab directory, the same place as your source files.

% cd ~/comp411lab/lab1
% wget https://gist.githubusercontent.com/kylefeng28/dd5f3a8c13562428a3989071da5af630/raw -O Makefile

If this doesn't work for some reason, you could always download the Makefile to your computer and upload it to the server using scp or a client like WinSCP. Be sure that the file is called Makefile, otherwise it will not work.

After downloading the Makefile, you can now run make commands:

  • make all
    • Compiles all source files (ex1.c, ex2.c, ex3.c into ex1, ex2, ex3)
  • make ex1, make ex2, make ex3
    • Compiles the file specified
  • make clean
    • Deletes the compiled programs (does not delete the source files)
  • make submit
    • Runs the submit script (/home/montek/comp411/bin/submitlab1)
  • make check
    • Runs the self-check script (/home/montek/comp411/bin/selfchecklab1)
  • make verify
    • Verifies that you have submitted, and lists submission dates if you have

If you don't specify a command (i.e., if you just run make), it defaults to make all.

.PHONY: all clean submit check
TARGETS=ex1 ex2 ex3
LABNO=1
MYID=$(shell id -un)
LOGDIR=/home/montek/comp411/.log
CC=gcc
CFLAGS=
default: all
# This actually is already defined implicitly
ex(%): %.c
$(CC) $< -o $@
all: clean $(TARGETS)
clean:
rm -f $(TARGETS)
submit:
/home/montek/comp411/bin/submitlab$(LABNO)
check:
/home/montek/comp411/bin/selfchecklab$(LABNO)
verify: SHELL := /bin/bash
verify:
@if compgen -G "$(LOGDIR)/lab$(LABNO)_$(MYID)_*" > /dev/null; then \
echo "You have submissions on the following dates:"; \
i=1; \
for x in $(LOGDIR)/lab$(LABNO)_$(MYID)_*; do \
echo -n "$$i. "; date -r $$x; ((i++)); \
done; \
else \
echo "You haven't submitted yet."; \
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment