Skip to content

Commit b70150f

Browse files
first commit
0 parents  commit b70150f

9 files changed

+1731
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.o
2+
.deps
3+
cmdline
4+
out
5+
sh61

AUTHORS.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Authors and collaborators
2+
=========================
3+
4+
Students
5+
--------
6+
(List your team members and describe in a couple words how you divided the
7+
work.)
8+
Arthur Abrantes did everything
9+
10+
Collaborators
11+
-------------
12+
(List any other collaborators and describe help you got from other people in
13+
the class.)
14+
I received help from TF in office hours
15+
16+
17+
Citations
18+
---------
19+
(List any other sources consulted.)

GNUmakefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Default optimization level
2+
O ?= 2
3+
4+
all: sh61
5+
6+
-include build/rules.mk
7+
8+
%.o: %.c sh61.h $(BUILDSTAMP)
9+
$(call run,$(CC) $(CPPFLAGS) $(CFLAGS) $(O) $(DEPCFLAGS) -o $@ -c,COMPILE,$<)
10+
11+
sh61: sh61.o helpers.o
12+
$(call run,$(CC) $(CFLAGS) $(O) -o $@ $^ $(LDFLAGS) $(LIBS),LINK $@)
13+
14+
sleep61: sleep61.c
15+
$(call run,$(CC) $(CFLAGS) $(O) -o $@ $^ $(LDFLAGS) $(LIBS),BUILD $@)
16+
17+
check: sh61
18+
perl check.pl
19+
20+
check-%: sh61
21+
perl check.pl $(subst check-,,$@)
22+
23+
clean: clean-main
24+
clean-main:
25+
$(call run,rm -rf sh61 *.o *~ *.bak core *.core,CLEAN)
26+
$(call run,rm -rf $(DEPSDIR) out *.dSYM)
27+
28+
realclean: clean
29+
@echo + realclean
30+
$(V)rm -rf $(DISTDIR) $(DISTDIR).tar.gz
31+
32+
.PRECIOUS: %.o
33+
.PHONY: all clean clean-main check check-%

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CS 61 Problem Set 5
2+
===================
3+
4+
**Fill out both this file and `AUTHORS.md` before submitting.** We grade
5+
anonymously, so put all personally identifying information in `AUTHORS.md`.
6+
7+
Grading notes (if any)
8+
----------------------
9+
I think I lost some style points in my previous attempt solely because I was not checking for failures for when fork() returned -1. However, I am checking that now, so I would really appreciate if my style for this problem set could be regraded.
10+
11+
12+
Extra credit attempted (if any)
13+
-------------------------------

build/rules.mk

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# are we using clang?
2+
ISCLANG := $(shell if $(CC) --version | grep -e 'LLVM\|clang' >/dev/null; then echo 1; else echo 0; fi)
3+
4+
CFLAGS := -std=gnu11 -W -Wall -Wshadow -g $(DEFS) $(CFLAGS)
5+
O ?= -O3
6+
ifeq ($(filter 0 1 2 3 s,$(O)$(NOOVERRIDEO)),$(strip $(O)))
7+
override O := -O$(O)
8+
endif
9+
ifeq ($(SANITIZE),1)
10+
ifeq ($(strip $(shell $(CC) -fsanitize=address -x c -E /dev/null 2>&1 | grep sanitize=)),)
11+
CFLAGS += -fsanitize=address
12+
else
13+
$(info ** WARNING: Your C compiler does not support `-fsanitize=address`.)
14+
endif
15+
ifeq ($(strip $(shell $(CC) -fsanitize=undefined -x c -E /dev/null 2>&1 | grep sanitize=)),)
16+
CFLAGS += -fsanitize=undefined
17+
else
18+
$(info ** WARNING: Your C compiler does not support `-fsanitize=undefined`.)
19+
$(info ** You may want to install gcc-4.9 or greater.)
20+
endif
21+
ifeq ($(ISCLANG),0)
22+
ifeq ($(wildcard /usr/bin/gold),/usr/bin/gold)
23+
CFLAGS += -fuse-ld=gold
24+
endif
25+
endif
26+
endif
27+
28+
# these rules ensure dependencies are created
29+
DEPCFLAGS = -MD -MF $(DEPSDIR)/$*.d -MP
30+
DEPSDIR := .deps
31+
BUILDSTAMP := $(DEPSDIR)/rebuildstamp
32+
DEPFILES := $(wildcard $(DEPSDIR)/*.d)
33+
ifneq ($(DEPFILES),)
34+
include $(DEPFILES)
35+
endif
36+
37+
38+
# when the C compiler or optimization flags change, rebuild all objects
39+
ifneq ($(strip $(DEP_CC)),$(strip $(CC) $(CPPFLAGS) $(CFLAGS) $(O)))
40+
DEP_CC := $(shell mkdir -p $(DEPSDIR); echo >$(BUILDSTAMP); echo "DEP_CC:=$(CC) $(CFLAGS) $(O)" >$(DEPSDIR)/_cc.d)
41+
endif
42+
43+
V = 0
44+
ifeq ($(V),1)
45+
run = $(1) $(3)
46+
xrun = /bin/echo "$(1) $(3)" && $(1) $(3)
47+
else
48+
run = @$(if $(2),/bin/echo " $(2) $(3)" &&,) $(1) $(3)
49+
xrun = $(if $(2),/bin/echo " $(2) $(3)" &&,) $(1) $(3)
50+
endif
51+
runquiet = @$(1) $(3)
52+
53+
# cancel implicit rules we don't want
54+
%: %.c
55+
%.o: %.c
56+
%: %.o
57+
58+
$(BUILDSTAMP):
59+
@mkdir -p $(@D)
60+
@echo >$@
61+
62+
always:
63+
@:
64+
65+
clean-hook:
66+
@:
67+
68+
.PHONY: always clean-hook
69+
.PRECIOUS: %.o

0 commit comments

Comments
 (0)