-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (65 loc) · 2.66 KB
/
Makefile
File metadata and controls
76 lines (65 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
CC := gcc
# You may change this if you like. However, the grader will use these
# CFLAGS! Note that _DEFAULT_SOURCE must be defined for your source to
# find the functions brk() and sbrk(), and -fPIC is required for
# building the shared library libcsemalloc.so.
CFLAGS := -g -Wall -Werror -std=c99 -fPIC -D_DEFAULT_SOURCE
# These are the included tests. You may modify this line if you like,
# but your modifications will not be submitted. (You might, for
# example, want to temporarily remove tests that are known to fail.)
#
# You can add tests to this list that will be compiled and run when you
# invoke make test. See the test and tests/% rules, below.
TESTS := test_bulk test_simple_malloc
all: libcsemalloc.so
# This rule generates an ELF shared object that can be used to test your
# malloc against any UNIX application! Applications that use threading
# are likely to fail in unexpected ways, but single-threaded
# applications will probably work fine.
#
# You can use this library by running the application as follows:
#
# LD_PRELOAD=./libcsemalloc.so command
#
# For example, to use your malloc implementation in the standard UNIX ls
# command, you would run:
#
# LD_PRELOAD=./libcsemalloc.so ls
#
# Note that the given code will not successfully run ls, as it does not
# implement realloc. It will, however, run `ls --help` and several
# other commands (that do not use realloc).
libcsemalloc.so: src/mm.o src/bulk.o
$(CC) -shared -fPIC -o $@ $^
test: $(TESTS) $(NEWTESTS)
@echo
@for test in $^; do \
printf "Running %-30s: " "$$test"; \
(./$$test && echo "passed") || echo "failed"; \
done
@echo
# This rule ensures that 'make submission' builds the tar file that you
# must submit to Autograder.
submission: malloc.tar
# This rule creates the submission tarfile. You should not change it.
malloc.tar: src/mm.c
tar cf $@ $^
# This pattern rule should be starting to look familiar. It will use
# the definitions of CC and CFLAGS, above, to create an object file from
# a source C file.
%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS)
# This pattern will build any self-contained test file in tests/. If
# your test file needs more support, you will need to write an explicit
# rule for it.
#
# To add a test, create a file called tests/testname.c that contains a
# main function and all of the relevant test code, then add the basename
# of the file (e.g., testname in this example) to TESTS, above.
%: tests/%.o src/mm.o src/bulk.o
$(CC) -o $@ $^
clean:
rm -f $(TESTS) libcsemalloc.so malloc.tar
rm -f src/*.o tests/*.o *~ src/*~ tests/*~
# See previous assignments for a description of .PHONY
.PHONY: all clean submission test