-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
219 lines (155 loc) · 5.05 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
DWST_VERSION = 2.3-git
SRC_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
HOSTPREFIX =
CC = $(HOSTPREFIX)gcc
AR = $(HOSTPREFIX)ar
CPPFLAGS = -DNO_DBGHELP -DLIBDWARF_STATIC
OPT = -O3
LDFLAGS = -s
FRAME_POINTER = -fno-omit-frame-pointer -fno-optimize-sibling-calls
INCLUDE = -I$(SRC_DIR)libdwarf -I$(SRC_DIR)mgwhelp -I$(SRC_DIR)include
WARN = -Wall -Wextra -Wno-implicit-fallthrough
CFLAGS = $(CPPFLAGS) $(OPT) $(WARN) $(FRAME_POINTER) $(INCLUDE)
CFLAGS_STATIC = $(CFLAGS) -DDWST_STATIC
CFLAGS_SHARED = $(CFLAGS) -DDWST_SHARED
CFLAGS_LIBDWARF = $(CFLAGS) -DDW_TSHASHTYPE=uintptr_t \
-I$(SRC_DIR)zlib \
-Wno-unused \
-Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
# libdwarf
DWARF_SRC_REL = \
dwarf_abbrev.c \
dwarf_alloc.c \
dwarf_debuglink.c \
dwarf_debugnames.c \
dwarf_die_deliv.c \
dwarf_dsc.c \
dwarf_error.c \
dwarf_find_sigref.c \
dwarf_fission_to_cu.c \
dwarf_form.c \
dwarf_frame.c \
dwarf_frame2.c \
dwarf_global.c \
dwarf_gnu_index.c \
dwarf_groups.c \
dwarf_harmless.c \
dwarf_init_finish.c \
dwarf_leb.c \
dwarf_line.c \
dwarf_loc.c \
dwarf_locationop_read.c \
dwarf_loclists.c \
dwarf_macro5.c \
dwarf_memcpy_swap.c \
dwarf_names.c \
dwarf_query.c \
dwarf_ranges.c \
dwarf_rnglists.c \
dwarf_str_offsets.c \
dwarf_string.c \
dwarf_tied.c \
dwarf_tsearchhash.c \
dwarf_util.c \
dwarf_xu_index.c \
DWARF_SRC = $(patsubst %,libdwarf/%,$(DWARF_SRC_REL))
DWARF_OBJ = $(patsubst %.c,%.o,$(DWARF_SRC))
# mgwhelp
DWARF_PE_SRC_REL = dwarf_pe.c \
DWARF_PE_SRC = $(patsubst %,mgwhelp/%,$(DWARF_PE_SRC_REL))
DWARF_PE_OBJ = $(patsubst %.c,%.o,$(DWARF_PE_SRC))
# zlib
ZLIB_SRC_REL = adler32.c \
crc32.c \
inffast.c \
inflate.c \
inftrees.c \
uncompr.c \
zutil.c \
ZLIB_SRC = $(patsubst %,zlib/%,$(ZLIB_SRC_REL))
ZLIB_OBJ = $(patsubst %.c,%.o,$(ZLIB_SRC))
# dwarfstack
DWST_SRC_REL = dwst-file.c \
dwst-process.c \
dwst-location.c \
dwst-exception.c \
dwst-exception-dialog.c \
DWST_HEADER_REL = dwarfstack.h \
DWST_SRC = $(patsubst %,src/%,$(DWST_SRC_REL))
DWST_OBJ = $(patsubst %.c,%.o,$(DWST_SRC))
DWST_DLL_OBJ = $(patsubst %.c,%.dll.o,$(DWST_SRC))
INC = include/dwarfstack.h
LIB = lib/libdwarfstack.a lib/libdwarfstack.dll.a
BIN = bin/dwarfstack.dll
BUILD = $(LIB) $(BIN) $(INC)
all: $(BUILD)
.SUFFIXES: .c .o .dll.o
src libdwarf mgwhelp zlib include lib bin:
@mkdir -p $@
ifneq ($(SRC_DIR),./)
vpath %.c $(SRC_DIR)
$(DWST_OBJ) $(DWST_DLL_OBJ) : | src
$(DWARF_OBJ) : | libdwarf
$(DWARF_PE_OBJ) : | mgwhelp
$(ZLIB_OBJ) : | zlib
$(INC): $(SRC_DIR)$(INC) | include
cp -fp $< $@
endif
share/licenses/dwarfstack/LICENSE.txt: $(SRC_DIR)LICENSE.txt
@mkdir -p share/licenses/dwarfstack
cp -fp $< $@
# libdwarf
$(DWARF_OBJ) $(DWARF_PE_OBJ): %.o: %.c
$(CC) -c $(CFLAGS_LIBDWARF) -o $@ $<
# static library
.c.o:
$(CC) -c $(CFLAGS_STATIC) -o $@ $<
lib/libdwarfstack.a: $(DWARF_OBJ) $(ZLIB_OBJ) $(DWARF_PE_OBJ) $(DWST_OBJ) | lib
$(AR) rcs $@ $(DWARF_OBJ) $(ZLIB_OBJ) $(DWARF_PE_OBJ) $(DWST_OBJ)
# shared library
.c.dll.o:
$(CC) -c $(CFLAGS_SHARED) -o $@ $<
bin/dwarfstack.dll: $(DWARF_OBJ) $(ZLIB_OBJ) $(DWARF_PE_OBJ) $(DWST_DLL_OBJ) | lib bin
$(CC) $(LDFLAGS) -shared -o $@ $(DWARF_OBJ) $(ZLIB_OBJ) $(DWARF_PE_OBJ) $(DWST_DLL_OBJ) -ldbghelp -Wl,--out-implib,lib/libdwarfstack.dll.a -lgdi32 -lstdc++
lib/libdwarfstack.dll.a: bin/dwarfstack.dll
clean:
rm -rf $(DWARF_OBJ) $(ZLIB_OBJ) $(DWARF_PE_OBJ) $(DWST_OBJ) $(DWST_DLL_OBJ) lib bin
# install
PREFIX = /usr/local
install: $(BUILD)
@mkdir -p $(PREFIX)/include $(PREFIX)/lib $(PREFIX)/bin
cp -f $(INC) $(PREFIX)/include
cp -f $(LIB) $(PREFIX)/lib
cp -f $(BIN) $(PREFIX)/bin
# builds
build32 build64:
@mkdir -p $@
FORCE:
build32/bin/dwarfstack.dll: FORCE | build32
$(MAKE) -C build32 -f ../Makefile HOSTPREFIX=i686-w64-mingw32- bin/dwarfstack.dll
build64/bin/dwarfstack.dll: FORCE | build64
$(MAKE) -C build64 -f ../Makefile HOSTPREFIX=x86_64-w64-mingw32- bin/dwarfstack.dll
build32/dwarfstack-$(DWST_VERSION)-mingw.tar.xz: build32/bin/dwarfstack.dll
$(MAKE) -C build32 -f ../Makefile HOSTPREFIX=i686-w64-mingw32- package
build64/dwarfstack-$(DWST_VERSION)-mingw.tar.xz: build64/bin/dwarfstack.dll
$(MAKE) -C build64 -f ../Makefile HOSTPREFIX=x86_64-w64-mingw32- package
dwarfstack%.dll: build%/bin/dwarfstack.dll
cp -fp $< $@
# package
packages: package-src package32 package64 package-dlls
dwarfstack-$(DWST_VERSION)-mingw.tar.xz: $(BUILD) share/licenses/dwarfstack/LICENSE.txt
@rm -f $@
tar -cJf $@ $^
dwarfstack-$(DWST_VERSION).tar.xz:
@rm -f $@
CURDIR=`pwd`; cd $(SRC_DIR) && git archive "HEAD^{tree}" |xz >$$CURDIR/$@
dwarfstack-$(DWST_VERSION)-mingw%.tar.xz: build%/dwarfstack-$(DWST_VERSION)-mingw.tar.xz
cp -fp $< $@
dwarfstack-$(DWST_VERSION)-dlls.7z: LICENSE.txt dwarfstack32.dll dwarfstack64.dll
@rm -f $@
7z a -mx=9 $@ $^
package: dwarfstack-$(DWST_VERSION)-mingw.tar.xz
package-src: dwarfstack-$(DWST_VERSION).tar.xz
package32: dwarfstack-$(DWST_VERSION)-mingw32.tar.xz
package64: dwarfstack-$(DWST_VERSION)-mingw64.tar.xz
package-dlls: dwarfstack-$(DWST_VERSION)-dlls.7z