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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
#
# --------------------------------------------------------------------------
#
# Pthreads-win32 - POSIX Threads Library for Win32
# Copyright(C) 1998 John E. Bossom
# Copyright(C) 1999,2012 Pthreads-win32 contributors
#
# The current list of contributors is contained
# in the file CONTRIBUTORS included with the source
# code distribution. The list can also be seen at the
# following World Wide Web location:
# http://sources.redhat.com/pthreads-win32/contributors.html
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library in the file COPYING.LIB;
# if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
#
DLL_VER = 2$(EXTRAVERSION)
# See pthread.h and README for the description of version numbering.
DLL_VERD= $(DLL_VER)d
DESTROOT = ../PTHREADS-BUILT
DEST_LIB_NAME = libpthread.a
DLLDEST = $(DESTROOT)/bin
LIBDEST = $(DESTROOT)/lib
HDRDEST = $(DESTROOT)/include
# If Running MsysDTK
RM = rm -f
MV = mv -f
CP = cp -f
MKDIR = mkdir -p
ECHO = echo
TESTNDIR = test ! -d
TESTFILE = test -f
AND = &&
# If not.
#RM = erase
#MV = rename
#CP = copy
#MKDIR = mkdir
#ECHO = echo
#TESTNDIR = if exist
#TESTFILE = if exist
# AND =
# For cross compiling use e.g.
# make CROSS=x86_64-w64-mingw32- clean GC-inlined
CROSS =
AR = $(CROSS)ar
DLLTOOL = $(CROSS)dlltool
CC = $(CROSS)gcc
CXX = $(CROSS)g++
RANLIB = $(CROSS)ranlib
RC = $(CROSS)windres
# Build for non-native architecture. E.g. "-m64" "-m32" etc.
# Not fully tested fully, needs gcc built with "--enable-multilib"
# Check your "gcc -v" output for the options used to build your gcc.
# You can set this as a shell variable or on the make comand line.
# You don't need to uncomment it here unless you want to hardwire
# a value.
#ARCH =
ifeq ($(ARCH),-m32)
RES_TARGET = --target pe-i386
endif
ifeq ($(ARCH),-m64)
RES_TARGET = --target pe-x86-64
endif
OPT = $(CLEANUP) -O3 # -finline-functions -findirect-inlining
XOPT =
RCFLAGS = --include-dir=.
LFLAGS = $(ARCH)
# Uncomment this if config.h defines RETAIN_WSALASTERROR
#LFLAGS += -lws2_32
#
# Uncomment this next to link the GCC/C++ runtime libraries statically
# (Be sure to read about these options and their associated caveats
# at http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)
#
# NOTE 1: Doing this appears to break GCE:pthread_cleanup_*(), which
# relies on C++ class destructors being called when leaving scope.
#
# NOTE 2: If you do this DO NOT distribute your pthreads DLLs with
# the official filenaming, i.e. pthreadVC2.dll, etc. Instead, change DLL_VER
# above to "2slgcc" for example, to build "pthreadGC2slgcc.dll", etc.
#
#LFLAGS += -static-libgcc -static-libstdc++
# ----------------------------------------------------------------------
# The library can be built with some alternative behaviour to
# facilitate development of applications on Win32 that will be ported
# to other POSIX systems. Nothing definable here will make the library
# non-compliant, but applications that make assumptions that POSIX
# does not garrantee may fail or misbehave under some settings.
#
# PTW32_THREAD_ID_REUSE_INCREMENT
# Purpose:
# POSIX says that applications should assume that thread IDs can be
# recycled. However, Solaris and some other systems use a [very large]
# sequence number as the thread ID, which provides virtual uniqueness.
# Pthreads-win32 provides pseudo-unique IDs when the default increment
# (1) is used, but pthread_t is not a scalar type like Solaris's.
#
# Usage:
# Set to any value in the range: 0 <= value <= 2^wordsize
#
# Examples:
# Set to 0 to emulate non recycle-unique behaviour like Linux or *BSD.
# Set to 1 for recycle-unique thread IDs (this is the default).
# Set to some other +ve value to emulate smaller word size types
# (i.e. will wrap sooner).
#
#PTW32_FLAGS = "-DPTW32_THREAD_ID_REUSE_INCREMENT=0"
#
# ----------------------------------------------------------------------
GC_CFLAGS = $(PTW32_FLAGS)
GCE_CFLAGS = $(PTW32_FLAGS) -mthreads
## Mingw
#MAKE ?= make
CFLAGS = $(OPT) $(XOPT) $(ARCH) -I. -DHAVE_CONFIG_H -Wall
OBJEXT = o
RESEXT = o
include common.mk
DLL_OBJS += $(RESOURCE_OBJS)
STATIC_OBJS += $(RESOURCE_OBJS)
GCE_DLL = pthreadGCE$(DLL_VER).dll
GCED_DLL= pthreadGCE$(DLL_VERD).dll
GCE_LIB = libpthreadGCE$(DLL_VER).a
GCED_LIB= libpthreadGCE$(DLL_VERD).a
GC_DLL = pthreadGC$(DLL_VER).dll
GCD_DLL = pthreadGC$(DLL_VERD).dll
GC_LIB = libpthreadGC$(DLL_VER).a
GCD_LIB = libpthreadGC$(DLL_VERD).a
GC_INLINED_STATIC_STAMP = libpthreadGC$(DLL_VER).inlined_static_stamp
GCD_INLINED_STATIC_STAMP = libpthreadGC$(DLL_VERD).inlined_static_stamp
GCE_INLINED_STATIC_STAMP = libpthreadGCE$(DLL_VER).inlined_static_stamp
GCED_INLINED_STATIC_STAMP = libpthreadGCE$(DLL_VERD).inlined_static_stamp
GC_SMALL_STATIC_STAMP = libpthreadGC$(DLL_VER).small_static_stamp
GCD_SMALL_STATIC_STAMP = libpthreadGC$(DLL_VERD).small_static_stamp
GCE_SMALL_STATIC_STAMP = libpthreadGCE$(DLL_VER).small_static_stamp
GCED_SMALL_STATIC_STAMP = libpthreadGCE$(DLL_VERD).small_static_stamp
PTHREAD_DEF = pthread.def
help:
@ echo "Run one of the following command lines:"
@ echo "$(MAKE) clean GC (to build the GNU C dll with C cleanup code)"
@ echo "$(MAKE) clean GC-debug (to build the GNU C debug dll with C cleanup code)"
@ echo "$(MAKE) clean GCE (to build the GNU C dll with C++ exception handling)"
@ echo "$(MAKE) clean GCE-debug (to build the GNU C debug dll with C++ exception handling)"
@ echo "$(MAKE) clean GC-static (to build the GNU C static lib with C cleanup code)"
@ echo "$(MAKE) clean GC-static-debug (to build the GNU C static debug lib with C cleanup code)"
@ echo "$(MAKE) clean GCE-static (to build the GNU C++ static lib with C++ cleanup code)"
@ echo "$(MAKE) clean GCE-static-debug (to build the GNU C++ static debug lib with C++ cleanup code)"
@ echo "$(MAKE) clean GC-small-static (to build the GNU C static lib with C cleanup code)"
@ echo "$(MAKE) clean GC-small-static-debug (to build the GNU C static debug lib with C cleanup code)"
@ echo "$(MAKE) clean GCE-small-static (to build the GNU C++ static lib with C++ cleanup code)"
@ echo "$(MAKE) clean GCE-small-static-debug (to build the GNU C++ static debug lib with C++ cleanup code)"
all:
@ $(MAKE) clean GC
@ $(MAKE) clean GCE
@ $(MAKE) clean GC-static
@ $(MAKE) clean GCE-static
TEST_ENV = PTW32_FLAGS="$(PTW32_FLAGS) -DNO_ERROR_DIALOGS" DLL_VER=$(DLL_VER) ARCH="$(ARCH)"
all-tests:
$(MAKE) realclean GC-small-static
cd tests && $(MAKE) clean GC-small-static $(TEST_ENV) && $(MAKE) clean GCX-small-static $(TEST_ENV)
$(MAKE) realclean GCE-small-static
cd tests && $(MAKE) clean GCE-small-static $(TEST_ENV)
@ $(ECHO) "$@ completed successfully."
$(MAKE) realclean GC
cd tests && $(MAKE) clean GC $(TEST_ENV) && $(MAKE) clean GCX $(TEST_ENV)
$(MAKE) realclean GCE
cd tests && $(MAKE) clean GCE $(TEST_ENV)
$(MAKE) realclean GC-static
cd tests && $(MAKE) clean GC-static $(TEST_ENV) && $(MAKE) clean GCX-static $(TEST_ENV)
$(MAKE) realclean GCE-static
cd tests && $(MAKE) clean GCE-static $(TEST_ENV)
$(MAKE) realclean
all-tests-cflags:
$(MAKE) all-tests PTW32_FLAGS="-Wall -Wextra"
@ $(ECHO) "$@ completed successfully."
GC:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CLEANUP=-D__CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" $(GC_DLL)
GC-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CLEANUP=-D__CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" DLL_VER=$(DLL_VERD) OPT="-D__CLEANUP_C -g -O0" $(GCD_DLL)
GCE:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CC=$(CXX) CLEANUP=-D__CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" $(GCE_DLL)
GCE-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CC=$(CXX) CLEANUP=-D__CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" DLL_VER=$(DLL_VERD) OPT="-D__CLEANUP_CXX -g -O0" $(GCED_DLL)
GC-static:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CLEANUP=-D__CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" $(GC_INLINED_STATIC_STAMP)
GC-static-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CLEANUP=-D__CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" DLL_VER=$(DLL_VERD) OPT="-D__CLEANUP_C -g -O0" $(GCD_INLINED_STATIC_STAMP)
GC-small-static:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CLEANUP=-D__CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS)" $(GC_SMALL_STATIC_STAMP)
GC-small-static-debug:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CLEANUP=-D__CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS)" DLL_VER=$(DLL_VERD) OPT="-D__CLEANUP_C -g -O0" $(GCD_SMALL_STATIC_STAMP)
GCE-static:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-D__CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" $(GCE_INLINED_STATIC_STAMP)
GCE-static-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-D__CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" DLL_VER=$(DLL_VERD) OPT="-D__CLEANUP_C -g -O0" $(GCED_INLINED_STATIC_STAMP)
GCE-small-static:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-D__CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS)" $(GCE_SMALL_STATIC_STAMP)
GCE-small-static-debug:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-D__CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS)" DLL_VER=$(DLL_VERD) OPT="-D__CLEANUP_C -g -O0" $(GCED_SMALL_STATIC_STAMP)
tests:
@ cd tests
@ $(MAKE) auto
# Very basic install. It assumes "realclean" was done just prior to build target if
# you want the installed $(DEVDEST_LIB_NAME) to match that build.
install:
-$(TESTNDIR) $(DLLDEST) $(AND) $(MKDIR) $(DLLDEST)
-$(TESTNDIR) $(LIBDEST) $(AND) $(MKDIR) $(LIBDEST)
-$(TESTNDIR) $(HDRDEST) $(AND) $(MKDIR) $(HDRDEST)
$(CP) pthreadGC*.dll $(DLLDEST)
$(CP) libpthreadGC*.a $(LIBDEST)
$(CP) pthread.h $(HDRDEST)
$(CP) sched.h $(HDRDEST)
$(CP) semaphore.h $(HDRDEST)
-$(TESTFILE) libpthreadGC$(DLL_VER).a $(AND) $(CP) libpthreadGC$(DLL_VER).a $(LIBDEST)/$(DEST_LIB_NAME)
-$(TESTFILE) libpthreadGC$(DLL_VERD).a $(AND) $(CP) libpthreadGC$(DLL_VERD).a $(LIBDEST)/$(DEST_LIB_NAME)
-$(TESTFILE) libpthreadGCE$(DLL_VER).a $(AND) $(CP) libpthreadGCE$(DLL_VER).a $(LIBDEST)/$(DEST_LIB_NAME)
-$(TESTFILE) libpthreadGCE$(DLL_VERD).a $(AND) $(CP) libpthreadGCE$(DLL_VERD).a $(LIBDEST)/$(DEST_LIB_NAME)
%.pre: %.c
$(CC) -E -o $@ $(CFLAGS) $^
%.s: %.c
$(CC) -c $(CFLAGS) -DPTW32_BUILD_INLINED -Wa,-ahl $^ > $@
%.o: %.rc
$(RC) $(RES_TARGET) $(RCFLAGS) $(CLEANUP) -o $@ -i $<
.SUFFIXES: .dll .rc .c .o
.c.o:; $(CC) -c -o $@ $(CFLAGS) $(XC_FLAGS) $<
$(GC_DLL) $(GCD_DLL): $(DLL_OBJS)
$(CC) $(OPT) -shared -o $@ $^ $(LFLAGS)
$(DLLTOOL) -z pthread.def $^
$(DLLTOOL) -k --dllname $@ --output-lib lib$(basename $@).a --def $(PTHREAD_DEF)
$(GCE_DLL) $(GCED_DLL): $(DLL_OBJS)
$(CC) $(OPT) -mthreads -shared -o $@ $^ $(LFLAGS)
$(DLLTOOL) -z pthread.def $^
$(DLLTOOL) -k --dllname $@ --output-lib lib$(basename $@).a --def $(PTHREAD_DEF)
$(GC_INLINED_STATIC_STAMP) $(GCE_INLINED_STATIC_STAMP) $(GCD_INLINED_STATIC_STAMP) $(GCED_INLINED_STATIC_STAMP): $(DLL_OBJS)
$(RM) $(basename $@).a
$(AR) -rsv $(basename $@).a $^
$(ECHO) touched > $@
$(GC_SMALL_STATIC_STAMP) $(GCE_SMALL_STATIC_STAMP) $(GCD_SMALL_STATIC_STAMP) $(GCED_SMALL_STATIC_STAMP): $(STATIC_OBJS)
$(RM) $(basename $@).a
$(AR) -rsv $(basename $@).a $^
$(ECHO) touched > $@
clean:
-$(RM) *~
-$(RM) *.i
-$(RM) *.s
-$(RM) *.o
-$(RM) *.obj
-$(RM) *.exe
-$(RM) *.manifest
-$(RM) $(PTHREAD_DEF)
realclean: clean
-$(RM) lib*.a
-$(RM) *.lib
-$(RM) pthread*.dll
-$(RM) *_stamp
-cd tests && $(MAKE) clean
var_check_list =
define var_check_target
var-check-$(1):
@for src in $($(1)); do \
fgrep -q "\"$$$$src\"" $(2) && continue; \
echo "$$$$src is in \$$$$($(1)), but not in $(2)"; \
exit 1; \
done
@grep '^# *include *".*\.c"' $(2) | cut -d'"' -f2 | while read src; do \
echo " $($(1)) " | fgrep -q " $$$$src " && continue; \
echo "$$$$src is in $(2), but not in \$$$$($(1))"; \
exit 1; \
done
@echo "$(1) <-> $(2): OK"
var_check_list += var-check-$(1)
endef
$(eval $(call var_check_target,PTHREAD_SRCS,pthread.c))
srcs-vars-check: $(var_check_list)
|