-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
79 lines (58 loc) · 1.82 KB
/
Makefile
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
# Makefile for TLS examples
# Targets:
# - 'all' build everything
# - 'check' run tests
# - 'clean' delete all build artifacts
CROSS_COMPILE ?= or1k-smh-linux-gnu-
CFLAGS = -Wall -O2 -g
LDFLAGS = -Wl,-rpath=. -L.
CC = $(CROSS_COMPILE)gcc
OBJDUMP = $(CROSS_COMPILE)objdump
DYN_SRC = tls-gd.c \
nontls.c
STATIC_SRC = tls-le.c \
tls-ie.c \
nontls.c
LIB_SRC = x.c \
xy.c
dyn_objs := $(patsubst %.c,%-dynamic.o,$(DYN_SRC) $(LIB_SRC))
static_objs := $(patsubst %.c,%-static.o,$(STATIC_SRC) $(LIB_SRC))
dyn_exe := $(patsubst %.c,%-dynamic,$(DYN_SRC))
static_exe := $(patsubst %.c,%-static,$(STATIC_SRC))
all_exe := $(dyn_exe) $(static_exe) tls-ld-dynamic
all_asm := $(patsubst %.o,%.S,$(dyn_objs) $(static_objs))
all_results := $(patsubst %,test-results-%.out,$(all_exe))
all: all_objs all_exe libx.so $(all_asm)
all_exe: $(all_exe)
all_objs: $(dyn_objs) $(static_objs)
## Building object files
%-dynamic.o: %.c
$(CC) -fpic -c -o $@ $< $(CFLAGS)
%-static.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
%.S: %.o
$(OBJDUMP) -dr $< > $@
## Building shared libs
lib%.so: %-dynamic.o
$(CC) -shared -o $@ $<
## Building executables
tls-gd-dynamic: main.c tls-gd-dynamic.o libx.so
$(CC) -fpic -o $@ $< tls-gd-dynamic.o -lx $(CFLAGS) $(LDFLAGS)
tls-ld-dynamic: main-ld.c libxy.so
$(CC) -fpic -o $@ $< -lxy $(CFLAGS) $(LDFLAGS)
%-dynamic: main.c %-dynamic.o
$(CC) -fpic -o $@ $^ $(CFLAGS)
tls-ie-static: main.c tls-ie-static.o x-static.o
$(CC) -static -o $@ $^ $(CFLAGS)
%-static: main.c %-static.o
$(CC) -static -o $@ $^ $(CFLAGS)
## Test Suite
check: test-results.out
test-results-%.out: %
echo "Running $<..." > $@
( ./$< && echo ok || echo not ok ) >> $@
test-results.out: $(all_results)
cat $^ > test-results.out
## Cleanup
clean:
rm -f *.so *.o *.out $(all_asm) $(all_exe)