-
Notifications
You must be signed in to change notification settings - Fork 1
/
glibc.make
99 lines (86 loc) · 3.48 KB
/
glibc.make
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
ifneq (,$(GLIBC-SOURCE-DIR)$(GLIBC-BUILD-DIR))
ifeq (x86_64,$(ARCH))
ifeq (x32,$(TARGET))
LD-SO=$(GLIBC-BUILD-DIR)/elf/ld-linux-x32.so.2
else
LD-SO=$(GLIBC-BUILD-DIR)/elf/ld-linux-x86-64.so.2
endif
else
LD-SO=$(GLIBC-BUILD-DIR)/elf/ld-linux.so.2
endif
GLIBC-PATH=$(GLIBC-BUILD-DIR):.
LIBDL-GLIBC-PATH=:$(GLIBC-BUILD-DIR)/dlfcn
LIBDL-STATIC=$(GLIBC-BUILD-DIR)/dlfcn/libdl.a
LIBDL-DYNAMIC=$(GLIBC-BUILD-DIR)/dlfcn/libdl.so
LIBM-GLIBC-PATH=:$(GLIBC-BUILD-DIR)/math
LIBM-STATIC=$(GLIBC-BUILD-DIR)/math/libm.a
LIBM-DYNAMIC=$(GLIBC-BUILD-DIR)/math/libm.so
LIBPTHREAD-GLIBC-PATH=:$(GLIBC-BUILD-DIR)/nptl
LIBPTHREAD-STATIC=$(GLIBC-BUILD-DIR)/nptl/libpthread.a
LIBPTHREAD-DYNAMIC=$(GLIBC-BUILD-DIR)/nptl/libpthread.so
ifneq ($(wildcard $(GLIBC-BUILD-DIR)/nptl/libpthread_nonshared.a),)
LIBPTHREAD-DYNAMIC+=$(GLIBC-BUILD-DIR)/nptl/libpthread_nonshared.a
endif
LIBGCC-STATIC=$(shell $(CC) --print-file-name=libgcc.a)
LIBGCC-EH-DYNAMIC=$(LIBGCC-STATIC)
LIBGCC-EH-DYNAMIC+=-Wl,--push-state,--as-needed
LIBGCC-EH-DYNAMIC+=$(shell $(CC) --print-file-name=libgcc_s.so)
LIBGCC-EH-DYNAMIC+=-Wl,--pop-state
LIBGCC-EH-STATIC=$(LIBGCC-STATIC)
LIBGCC-EH-STATIC+=$(shell $(CC) --print-file-name=libgcc_eh.a)
RPATH-LINK=-rpath
define build-static
$(CC) -static -nostdlib -nostartfiles -o $@ \
$(GLIBC-BUILD-DIR)/csu/crt1.o $(GLIBC-BUILD-DIR)/csu/crti.o \
`$(CC) --print-file-name=crtbegin.o` \
$($(@F)-LDFLAGS) $^
$(if $(findstring -lm,$($(@F)-LIBS)),$(LIBM-STATIC)) \
$(if $(findstring -lpthread,$($(@F)-LIBS)),$(LIBPTHREAD-STATIC)) \
-Wl,--start-group \
$(LIBGCC-EH-STATIC) \
$(GLIBC-BUILD-DIR)/libc.a \
-Wl,--end-group \
`$(CC) --print-file-name=crtend.o` \
$(GLIBC-BUILD-DIR)/csu/crtn.o
endef
define build-dynamic
$(CC) -Busr/local/bin/ -nostdlib -nostartfiles -o $@ \
-Wl,-dynamic-linker=$(LD-SO) -Wl,-z,nocombreloc \
$(GLIBC-BUILD-DIR)/csu/crt1.o $(GLIBC-BUILD-DIR)/csu/crti.o \
`$(CC) --print-file-name=crtbegin.o` \
-Wl,$(RPATH-LINK)=$(GLIBC-PATH)$(if $(findstring -lpthread,$($(@F)-LIBS)),$(LIBPTHREAD-GLIBC-PATH))$(if $(findstring -lm,$($(@F)-LIBS)),$(LIBM-GLIBC-PATH))$(if $(findstring -ldl,$($(@F)-LIBS)),$(LIBDL-GLIBC-PATH)) \
$($(@F)-LDFLAGS) $^ \
$(if $(findstring -ldl,$($(@F)-LIBS)),$(LIBDL-DYNAMIC)) \
$(if $(findstring -lm,$($(@F)-LIBS)),$(LIBM-DYNAMIC)) \
$(if $(findstring -lpthread,$($(@F)-LIBS)),$(LIBPTHREAD-DYNAMIC)) \
$(GLIBC-BUILD-DIR)/libc.so.6 \
$(LD-SO) $(GLIBC-BUILD-DIR)/libc_nonshared.a $(LIBGCC-EH-DYNAMIC) \
`$(CC) --print-file-name=crtend.o` $(GLIBC-BUILD-DIR)/csu/crtn.o
endef
define build-shared-object
$(CC) -Busr/local/bin/ -nostdlib -nostartfiles -o $@ \
-shared -Wl,-z,nocombreloc \
$(GLIBC-BUILD-DIR)/csu/crti.o \
`$(CC) --print-file-name=crtbeginS.o` \
-Wl,$(RPATH-LINK)=$(GLIBC-PATH)$(if $(findstring -lpthread,$($(@F)-LIBS)),$(LIBPTHREAD-GLIBC-PATH))$(if $(findstring -lm,$($(@F)-LIBS)),$(LIBM-GLIBC-PATH))$(if $(findstring -ldl,$($(@F)-LIBS)),$(LIBDL-GLIBC-PATH)) \
$($(@F)-LDFLAGS) $^ \
$(if $(findstring -ldl,$($(@F)-LIBS)),$(LIBDL-DYNAMIC)) \
$(if $(findstring -lm,$($(@F)-LIBS)),$(LIBM-DYNAMIC)) \
$(if $(findstring -lpthread,$($(@F)-LIBS)),$(LIBPTHREAD-DYNAMIC)) \
$(GLIBC-BUILD-DIR)/libc.so.6 \
$(LD-SO) $(GLIBC-BUILD-DIR)/libc_nonshared.a $(LIBGCC-EH-DYNAMIC) \
`$(CC) --print-file-name=crtendS.o` $(GLIBC-BUILD-DIR)/csu/crtn.o
endef
else
define build-static
$(CC) -static $($(@F)-LDFLAGS) -o $@ $^ $($(@F)-LIBS)
endef
define build-dynamic
$(CC) $($(@F)-LDFLAGS) -o $@ $^ $($(@F)-LIBS) -Wl,-R,.
endef
define build-shared-object
$(CC) -shared $($(@F)-LDFLAGS) -o $@ $^ $($(@F)-LIBS)
endef
endif
clean::
rm -f *.o $(EXES)