-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (102 loc) · 3.47 KB
/
Makefile
File metadata and controls
139 lines (102 loc) · 3.47 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Version 2.0
# This is a sample Makefile for Phase 2.
#
# make (makes libphase2.a and all tests)
# make phase2 ditto
#
# make testN (makes testN)
# make testN.out (runs testN and puts output in testN.out)
# make tests (makes all testN.out files, i.e. runs all tests)
# make tests_bg (runs all tests in the background)
#
# make testN.v (runs valgrind on testN and puts output in testN.v)
# make valgrind (makes all testN.v files, i.e. runs valgrind on all tests)
#
# make clean (removes all files created by this Makefile)
ifndef PREFIX
PREFIX = $(HOME)
endif
# Set to the part (A or B) of the phase.
PART = A
# Set to Phase 2 version
PHASE2_VERSION = 2.2
# Set to USLOSS version
USLOSS_VERSION = 3.3
# Set to Phase 1 version
PHASE1_VERSION = 1.6
# Set to user library version (same as USLOSS version by default)
USER_VERSION = $(USLOSS_VERSION)
# All .c files in this directory are included in the Phase 2 library.
SRCS = $(wildcard *.c)
# Each .c file in the tests$(PART) subdirectory is a separate test case.
TESTS = $(patsubst %.c,%,$(wildcard tests$(PART)/*.c))
# Change this if you want to change the arguments to valgrind.
VGFLAGS = --track-origins=yes --leak-check=full --max-stackframe=100000
# Change this if you need to link against additional libraries (probably not).
LIBS = -lphase$(PHASE1_VERSION) -lusloss$(USLOSS_VERSION) -lphase$(PHASE2_VERSION) -luser$(USER_VERSION)
# Change this if you want change which flags are passed to the C compiler.
CFLAGS += -Wall -g -std=gnu99
CFLAGS += -DDEBUG
# You shouldn't need to change anything below here.
LIB_DIR = $(PREFIX)/lib
INC_DIR = $(PREFIX)/include
INSTALL_DATA = /usr/bin/install -c
PHASE = phase2
TARGET = libphase$(PHASE2_VERSION).a
INCLUDES = -I$(INC_DIR) -I.
ifeq ($(shell uname),Darwin)
DEFINES += -D_XOPEN_SOURCE
OS = macosx
CFLAGS += -Wno-int-to-void-pointer-cast -Wno-extra-tokens -Wno-unused-label -Wno-unused-function
else
OS = linux
CFLAGS += -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-unused-but-set-variable
endif
CC=gcc
LD=gcc
AR=ar
CFLAGS += $(INCLUDES) $(DEFINES) -Werror
LDFLAGS = -L$(LIB_DIR) -L.
COBJS = ${SRCS:.c=.o}
DEPS = ${COBJS:.o=.d}
TSRCS = {$TESTS:=.c}
TOBJS = ${TESTS:=.o}
TOUTS = ${TESTS:=.out}
TVS = ${TESTS:=.v}
STUBS = p3/p3stubs.o
# The following is to deal with circular dependencies between the USLOSS and phase1
# libraries. Unfortunately the linkers handle this differently on the two OSes.
# Also add flags to warn about duplicate global variables and to make warnings fatal.
ifeq ($(OS), macosx)
LIBFLAGS = -Wl,-all_load $(LIBS)
# The following only works for dynamic libraries. TODO make it work with static.
LDFLAGS += -Wl,-warn_commons -Wl,-fatal_warnings
else
LIBFLAGS = -Wl,--start-group $(LIBS) -Wl,--end-group
LDFLAGS += -Wl,--warn-common -Wl,--fatal-warnings
endif
%.d: %.c
$(CC) -c $(CFLAGS) -MM -MF $@ $<
.PHONY: all tests $(PHASE)
all: $(PHASE)
$(PHASE): $(TARGET) $(TESTS)
$(TARGET): $(COBJS)
$(AR) -r $@ $^
tests: $(TOUTS)
# Remove implicit rules so that "make phaseN" doesn't try to build it from phaseN.c or phaseN.o
% : %.c
% : %.o
%.out: %
./$< 1> $@ 2>&1
$(TESTS): %: $(TARGET) %.o $(STUBS) Makefile
- $(LD) $(LDFLAGS) -o $@ $@.o $(STUBS) $(LIBFLAGS)
clean:
rm -f $(COBJS) $(TARGET) $(TOBJS) $(TESTS) $(DEPS) $(TVS) *.out tests$(PART)/*.out p3/*.o p3/p3stubsTest
%.d: %.c
$(CC) -c $(CFLAGS) -MM -MF $@ $<
valgrind: $(TVS)
%.v: %
valgrind $(VGFLAGS) ./$< 1> $@ 2>&1
p3/p3stubsTest: $(STUBS) p3/p3stubsTest.o
$(LD) $(LDFLAGS) -o $@ $^
-include $(DEPS)