Skip to content

Instantly share code, notes, and snippets.

@carneeki
Last active September 3, 2015 11:37
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 carneeki/e2b04704e32edd1be81a to your computer and use it in GitHub Desktop.
Save carneeki/e2b04704e32edd1be81a to your computer and use it in GitHub Desktop.
I keep my assignments and modules in a structure like this:
~/comp202/assignments/a-01$ tree
.
├── Makefile - the 'master Makefile'
├── Makefile.mk - includes used by master and sub-makes
├── stage1 - stage1 directory
│   ├── expected-output.csv
│   ├── filestruct-desc.txt
│   ├── initialisation-spec.txt
│   ├── lab
│   ├── Makefile - stage 1 Makefile
│   ├── output-1.mine
│   ├── stage1
│   └── stage1.c
├── stage1.mk - stage 1 Makefile (the original copy)
├── stage2 - stage 2 directory
│   ├── filestruct-desc.txt
│   ├── input-1.bin
│   ├── input-2.bin
│   ├── input-3.bin
│   ├── Makefile - stage 2 Makefile
│   ├── output-1.csv
│   ├── output-2.csv
│   ├── output-3.csv
│   ├── stage2.c
│   └── stage2.h
├── stage2.mk - stage 2 Makefile (the original copy)
└── stage3.mk - stage 3 Makefile (the original copy)
the master Makefile has multiple targets, which take the following form:
stageN-init - which creates a directory for stageN and copies the stageN.mk file into stageN/Makefile
stageN-get - gets the tar file (with the lab command), extracts the contents, and deletes the tar file
Each individual stage will have their own Makefile with the following targets:
all / stageN / (leave blank) will build the stageN executable.
clean - remove the executable and test outputs leaving sources, inputs, and expected outputs
test - runs test data and compares outputs with expected outputs using the diff command
submit - submit all the .c and .h files to automarker
As an added feature, the master Makefile will allow you to use the following targets:
stageN - build the stage
stageN-clean
stageN-test
stageN-submit
So the way how you might work on module 2:
1) cd ~/comp202/assignments/a-01
2) make stage2-init
<does some stuff>
3) make stage2-get
<does some stuff>
4) cd stage2
5) edit stage2.c (and maybe a stage3.h and any other .c and .h files you see fit)
6) make
<builds stage2>
7) make test
<runs some tests>
Then you'll repeat steps 5,6,7 over and over until you're satisfied your program works correctly.
8) make submit
Hopefully you get 2.0/2.0 on all your modules!
Good luck :)
include Makefile.mk
# INIT targets
stage1-init:
mkdir stage1
touch stage1/stage1.c
cp stage1.mk stage1/Makefile
stage2-init:
mkdir stage2
touch stage2/stage2.c
cp stage2.mk stage2/Makefile
stage3-init:
mkdir stage3
touch stage3/stage3.c
cp stage3.mk stage3/Makefile
stage4-init:
mkdir stage4
touch stage4/stage4.c
cp stage4.mk stage4/Makefile
stage5-init:
mkdir stage5
touch stage5/stage5.c
cp stage5.mk stage5/Makefile
# GET targets
stage1-get : stage1-init
$(LAB) -g 1.1
tar -xf stage1.tar
rm stage1.tar
stage2-get : stage2-init
$(LAB) -g 1.2
tar -xf stage2.tar
rm stage2.tar
stage3-get : stage3-init
$(LAB) -g 1.3
tar -xf stage3.tar
rm stage3.tar
stage4-get : stage4-init
$(LAB) -g 1.4
tar -xf stage4.tar
rm stage4.tar
stage5-get : stage5-init
$(LAB) -g 1.5
tar -xf stage5.tar
rm stage5.tar
# BUILD targets
all: stage1 stage2 stage3 stage4 stage5
stage1:
make -C $@
stage2:
make -C $@
stage3:
make -C $@
stage4:
make -C $@
stage5:
make -C $@
# TEST targets
test : stage1-test stage2-test stage3-test stage4-test stage5-test
stage1-test:
make -C stage1 test
stage2-test:
make -C stage2 test
stage3-test:
make -C stage3 test
stage4-test:
make -C stage4 test
stage5-test:
make -C stage5 test
# CLEAN targets
clean : stage1-clean stage2-clean stage3-clean stage4-clean stage5-clean
stage1-clean:
make -C stage1 clean
stage2-clean:
make -C stage2 clean
stage3-clean:
make -C stage3 clean
stage4-clean:
make -C stage4 clean
stage5-clean:
make -C stage5 clean
submit : stage1-submit stage2-submit stage3-submit stage4-submit stage5-submit
# SUBMIT targets
stage1-submit:
make -C stage1 submit
stage2-submit:
make -C stage2 submit
stage3-submit:
make -C stage3 submit
stage4-submit:
make -C stage4 submit
stage5-submit:
make -C stage5 submit
LAB=/home/units/comp202/lab
CC=gcc
#CC=clang # uncomment only if you know what you're doing
CFLAGS=-Wall -m32
include ../Makefile.mk
SRC=$(wildcard *.c)
OUT=$(SRC:.c=)
SUBMIT=$(wildcard *.c *.h)
all : $(OUT)
clean :
rm -f stage1 *.mine
% : %.c
$(CC) $(CFLAGS) -o $@ $@.c
test : stage1
./stage1 > output-1.mine
diff -u expected-output.csv output-1.mine
submit :
$(LAB) -s 1.1 $(SUBMIT)
submit-force :
$(LAB) -sf 1.1 $(SUBMIT)
marks :
$(LAB) -m 1.1
include ../Makefile.mk
SRC=$(wildcard *.c)
OUT=$(SRC:.c=)
SUBMIT=$(wildcard *.c *.h)
all : $(OUT)
clean :
rm -f $(OUT) *.mine
% : %.c
$(CC) $(CFLAGS) -o $@ $@.c
test : $(OUT)
./$(OUT) input-1.bin > output-1.mine
./$(OUT) input-2.bin > output-2.mine
./$(OUT) input-3.bin > output-3.mine
diff -u output-1.csv output-1.mine
diff -u output-2.csv output-2.mine
diff -u output-3.csv output-3.mine
submit :
$(LAB) -s 1.2 $(SUBMIT)
submit-force :
$(LAB) -sf 1.2 $(SUBMIT)
marks :
$(LAB) -m 1.2
include ../Makefile.mk
SRC=$(wildcard *.c)
OUT=stage3
SUBMIT=$(wildcard *.c *.h)
all : $(OUT)
clean :
rm -f $(OUT) *.mine *.csv
stage3 :
$(CC) $(CFLAGS) -o $@ $(SRC)
test : $(OUT)
./$(OUT) input-1.bin output-1.mine
./$(OUT) input-2.bin output-2.mine
./$(OUT) input-3.bin output-3.mine
diff -u output-1.bin output-1.mine
diff -u output-2.bin output-2.mine
diff -u output-3.bin output-3.mine
csv : test
../stage2/stage2 output-1.mine > output-1.mine.csv
../stage2/stage2 output-2.mine > output-2.mine.csv
../stage2/stage2 output-3.mine > output-3.mine.csv
../stage2/stage2 output-1.bin > output-1.csv
../stage2/stage2 output-2.bin > output-2.csv
../stage2/stage2 output-3.bin > output-3.csv
submit :
$(LAB) -s 1.3 $(SUBMIT)
submit-force :
$(LAB) -sf 1.3 $(SUBMIT)
marks :
$(LAB) -m 1.3
include ../Makefile.mk
SRC=$(wildcard *.c)
OUT=stage4
SUBMIT=$(wildcard *.c *.h)
all : $(OUT)
clean :
rm -f $(OUT) *.mine *.csv
stage4 :
$(CC) $(CFLAGS) -o $@ $(SRC)
run-1 : $(OUT)
./$(OUT) input-1.bin output-1.mine
run-2 : $(OUT)
./$(OUT) input-2.bin output-2.mine
run-3 : $(OUT)
./$(OUT) input-3.bin output-3.mine
run : run-1 run-2 run-3
test : run
diff -u output-1.bin output-1.mine
diff -u output-2.bin output-2.mine
diff -u output-3.bin output-3.mine
csv : run
../stage2/stage2 output-1.mine > output-1.mine.csv
../stage2/stage2 output-2.mine > output-2.mine.csv
../stage2/stage2 output-3.mine > output-3.mine.csv
../stage2/stage2 output-1.bin > output-1.csv
../stage2/stage2 output-2.bin > output-2.csv
../stage2/stage2 output-3.bin > output-3.csv
submit :
$(LAB) -s 1.4 $(SUBMIT)
submit-force :
$(LAB) -sf 1.4 $(SUBMIT)
marks :
$(LAB) -m 1.4
include ../Makefile.mk
SRC=$(wildcard *.c)
OUT=stage5
SUBMIT=$(wildcard *.c *.h)
all : $(OUT)
debug :
$(CC) -g $(CFLAGS) -o $(OUT) $(SRC)
clean :
rm -f $(OUT) *.mine *.csv debug
stage5 :
$(CC) $(CFLAGS) -o $(OUT) $(SRC)
run-1 : $(OUT)
./$(OUT) input-1.bin output-1.mine
run-2 : $(OUT)
./$(OUT) input-2.bin output-2.mine
run-3 : $(OUT)
./$(OUT) input-3.bin output-3.mine
run : run-1 run-2 run-3
test : run
diff -u output-1.bin output-1.mine
diff -u output-2.bin output-2.mine
diff -u output-3.bin output-3.mine
csv : run
../stage2/stage2 output-1.mine > output-1.mine.csv
../stage2/stage2 output-2.mine > output-2.mine.csv
../stage2/stage2 output-3.mine > output-3.mine.csv
../stage2/stage2 output-1.bin > output-1.csv
../stage2/stage2 output-2.bin > output-2.csv
../stage2/stage2 output-3.bin > output-3.csv
submit :
$(LAB) -s 1.5 $(SUBMIT)
submit-force :
$(LAB) -sf 1.5 $(SUBMIT)
marks :
$(LAB) -m 1.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment