Skip to content

Instantly share code, notes, and snippets.

@carneeki
Last active August 29, 2015 14:26
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/b18fa1e995f34f34e5ac to your computer and use it in GitHub Desktop.
Save carneeki/b18fa1e995f34f34e5ac to your computer and use it in GitHub Desktop.
COMP202 Makefiles
Set up directory layout something like this:
/home/<username>/src/comp202
.
├── lec
│   └── week01
├── Makefile
├── Makefile.mk
├── prac
│   └── week01
│   ├── helloworld.c
│   ├── Makefile
│   ├── name.c
│   ├── numberstars.c
│   └── printarg.c
├── push-ash
├── ssh-ash
└── tut
PRAC = $(shell find prac/week* -type d)
TUT = $(shell find tut/week* -type d)
LEC = $(shell find lec/week* -type d)
clean_PRAC = $(addprefix clean_,$(PRAC))
clean_TUT = $(addprefix clean_,$(TUT))
clean_LEC = $(addprefix clean_,$(LEC))
all : $(PRAC) $(TUT) # DO NOT BUILD lectures!
clean : $(clean_PRAC) $(clean_TUT) $(clean_LEC)
.PHONY : $(PRAC) $(TUT) $(LEC) $(clean_PRAC) $(clean_TUT) $(clean_LEC)
$(PRAC) :
make -C $@
$(TUT) :
make -C $@
$(LEC) :
make -C $@
$(clean_PRAC) :
make -C $(patsubst clean_%,%,$@) clean
$(clean_TUT) :
make -C $(patsubst clean_%,%,$@) clean
push-ash : clean
rsync -avzr * <sid>@ash.science.mq.edu.au:/home/student/<number>/<sid>/comp202
push-home : clean
rsync -avzr * <username>@<home-hostname>:/home/<username>/src/comp202
HOST=$(shell hostname)
# Run clang on laptop/desktop, gcc on ash/iceberg/anywhere else
ifeq ($(HOST),frood-dood)
CC=clang
else ifeq ($(HOST),missy)
CC=clang
else
CC=gcc
endif
ifeq ($(CC),gcc)
CFLAGS=-O3 -m32 -std=c99
else
CFLAGS=
endif
# Place this file in prac/week01/Makefile
# and make similar files for tut/week02/Makefile
# or anywhere else you need them.
include ../../Makefile.mk
SRC=$(wildcard *.c)
OUT=$(SRC:.c=)
all : $(OUT)
% : %.c
$(CC) $(CFLAGS) -o $@ $@.c
clean :
rm -f $(OUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment