forked from GerHobbelt/pthread-win32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile.in
411 lines (342 loc) · 15.1 KB
/
GNUmakefile.in
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# @configure_input@
# --------------------------------------------------------------------------
#
# pthreads-win32 / pthreads4w - POSIX Threads for Windows
# Copyright 1998 John E. Bossom
# Copyright(C) 1999-2021 pthreads-win32 / pthreads4w contributors
#
# Homepage: http://sources.redhat.com/pthreads-win32
#
# 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:
#
# https://sourceforge.net/p/pthreads4w/wiki/Contributors/
#
# 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 3 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
#
# --------------------------------------------------------------------------
#
PACKAGE = @PACKAGE_TARNAME@
VERSION = @PACKAGE_VERSION@
PTW32_VER = 3$(EXTRAVERSION)
# See pthread.h and README for the description of version numbering.
PTW32_VERD = $(PTW32_VER)d
srcdir = @srcdir@
builddir = @builddir@
VPATH = @srcdir@
# FIXME: Replace these path name references with autoconf standards.
DESTROOT = ../PTHREADS-BUILT
DLLDEST = $(DESTROOT)/bin
LIBDEST = $(DESTROOT)/lib
HDRDEST = $(DESTROOT)/include
# i.e.
#
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = ${DESTDIR}@bindir@
includedir = ${DESTDIR}@includedir@
libdir = ${DESTDIR}@libdir@
# FIXME: This is correct for a static library; a DLL import library
# should be called libpthread.dll.a, or some such.
DEST_LIB_NAME = libpthread
# If Running MsysDTK
RM = rm -f
MV = mv -f
CP = cp -f
GREP = grep
MKDIR = mkdir -p
ECHO = echo
TESTNDIR = test ! -d
TESTFILE = test -f
AND = &&
COUNT_UNIQ = uniq -c
# 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
# FIXME: To be removed; autoconf handles this transparently;
# DO NOT use this non-standard feature.
#CROSS =
CC = @CC@
CXX = @CXX@
AR = @AR@
DLLTOOL = @DLLTOOL@
RANLIB = @RANLIB@
RC = @RC@
OD_PRIVATE = @OBJDUMP@ -p
# Build for non-native architecture. E.g. "-m64" "-m32" etc.
# Not 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 =
#
# Look for targets that $(RC) (usually windres) supports then look at any object
# file just built to see which target the compiler used and set the $(RC) target
# to match it.
#
KNOWN_TARGETS := pe-% pei-% elf32-% elf64-% srec symbolsrec verilog tekhex binary ihex
SUPPORTED_TARGETS := $(filter $(KNOWN_TARGETS),$(shell $(RC) --help))
RC_TARGET = --target $(firstword $(filter $(SUPPORTED_TARGETS),$(shell $(OD_PRIVATE) *.$(OBJEXT))))
OPT = $(CLEANUP) -O3 # -finline-functions -findirect-inlining
XOPT =
RCFLAGS = --include-dir=${srcdir}
LFLAGS = $(ARCH)
# Uncomment this if config.h defines RETAIN_WSALASTERROR
# FIXME: autoconf (or GNU make) convention dictates that this should be
# LIBS (or LDLIBS); ideally, it should be set by configure.
#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 PTW32_VER
# above to "2slgcc" for example, to build "pthreadGC2slgcc.dll", etc.
#
# FIXME: in this case, convention would have us use LDFLAGS; once again, if
# we really want this, we should support it via a configure script option.
#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
DEFS = @DEFS@ -DPTW32_BUILD
CFLAGS = $(OPT) $(XOPT) $(ARCH) -I. -I${srcdir} $(DEFS) -Wall
OBJEXT = @OBJEXT@
OEXT = @OBJEXT@
RESEXT = @OBJEXT@
include ${srcdir}/common.mk
DLL_OBJS += $(RESOURCE_OBJS)
STATIC_OBJS += $(RESOURCE_OBJS)
STATIC_OBJS_SMALL += $(RESOURCE_OBJS)
GCE_DLL = pthreadGCE$(PTW32_VER).dll
GCED_DLL= pthreadGCE$(PTW32_VERD).dll
GCE_LIB = libpthreadGCE$(PTW32_VER).a
GCED_LIB= libpthreadGCE$(PTW32_VERD).a
GC_DLL = pthreadGC$(PTW32_VER).dll
GCD_DLL = pthreadGC$(PTW32_VERD).dll
GC_LIB = libpthreadGC$(PTW32_VER).a
GCD_LIB = libpthreadGC$(PTW32_VERD).a
GC_INLINED_STATIC_STAMP = libpthreadGC$(PTW32_VER).inlined_static_stamp
GCD_INLINED_STATIC_STAMP = libpthreadGC$(PTW32_VERD).inlined_static_stamp
GCE_INLINED_STATIC_STAMP = libpthreadGCE$(PTW32_VER).inlined_static_stamp
GCED_INLINED_STATIC_STAMP = libpthreadGCE$(PTW32_VERD).inlined_static_stamp
GC_SMALL_STATIC_STAMP = libpthreadGC$(PTW32_VER).small_static_stamp
GCD_SMALL_STATIC_STAMP = libpthreadGC$(PTW32_VERD).small_static_stamp
GCE_SMALL_STATIC_STAMP = libpthreadGCE$(PTW32_VER).small_static_stamp
GCED_SMALL_STATIC_STAMP = libpthreadGCE$(PTW32_VERD).small_static_stamp
PTHREAD_DEF = pthread.def
help:
@ echo "Run one of the following command lines:"
@ echo "$(MAKE) clean all (build targets GC, GCE, GC-static, GCE-static)"
@ echo "$(MAKE) clean all-tests (build and test all non-debug targets below)"
@ 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" PTW32_VER=$(PTW32_VER) ARCH="$(ARCH)"
all-tests:
$(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 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)
$(MAKE) realclean
@ - $(GREP) Passed *.log | $(COUNT_UNIQ)
@ - $(GREP) FAILED *.log
all-tests-cflags:
$(MAKE) all-tests PTW32_FLAGS="-Wall -Wextra"
@ $(ECHO) "$@ completed."
GC:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" $(GC_DLL)
GC-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(DLL_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCD_DLL)
GCE:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" $(GCE_DLL)
GCE-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(DLL_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_CXX -g -O0" $(GCED_DLL)
GC-static:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS)" $(GC_INLINED_STATIC_STAMP)
GC-static-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCD_INLINED_STATIC_STAMP)
GC-small-static:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" $(GC_SMALL_STATIC_STAMP)
GC-small-static-debug:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CLEANUP=-DPTW32_CLEANUP_C XC_FLAGS="$(GC_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCD_SMALL_STATIC_STAMP)
GCE-static:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS)" $(GCE_INLINED_STATIC_STAMP)
GCE-static-debug:
$(MAKE) XOPT="-DPTW32_BUILD_INLINED -DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCED_INLINED_STATIC_STAMP)
GCE-small-static:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" $(GCE_SMALL_STATIC_STAMP)
GCE-small-static-debug:
$(MAKE) XOPT="-DPTW32_STATIC_LIB" CC=$(CXX) CLEANUP=-DPTW32_CLEANUP_CXX XC_FLAGS="$(GCE_CFLAGS)" OBJ="$(STATIC_OBJS_SMALL)" PTW32_VER=$(PTW32_VERD) OPT="-DPTW32_CLEANUP_C -g -O0" $(GCED_SMALL_STATIC_STAMP)
tests:
@ cd tests
@ $(MAKE) auto
# Very basic install.
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
mkinstalldirs = @MKDIR_P@ $1
.PHONY: install installdirs install-headers
.PHONY: install-dlls install-lib-default install-libs-specific
install: installdirs install-headers install-libs install-dlls
installdirs: ${bindir} ${includedir} ${libdir}
${bindir} ${includedir} ${libdir}:; $(call mkinstalldirs,$@)
install-dlls: $(wildcard ${builddir}/pthreadGC*.dll)
$(INSTALL_DATA) $^ ${bindir}
install-libs: install-libs-specific
install-libs-specific: $(wildcard ${builddir}/libpthreadGC*.a)
$(INSTALL_DATA) $^ ${libdir}
default_libs = $(wildcard $(addprefix $1,$(PTW32_VER)$2 $(PTW32_VERD)$2))
# FIXME: this is a ghastly, utterly non-deterministic hack; who knows
# what it's going to install as the default libpthread.a? Better to
# just explicitly make it a copy of libpthreadGC$(PTW32_VER).a
install-libs: install-lib-default
install-lib-default: $(call default_libs,libpthreadGC,.a)
install-lib-default: $(call default_libs,libpthreadGCE,.a)
$(INSTALL_DATA) $(lastword $^) ${libdir}/$(DEST_LIB_NAME).a
# FIXME: similarly, who knows what this will install? Once again, it
# would be better to explicitly install libpthread.dll.a as a copy of
# libpthreadGC$(PTW32_VER).dll.a
install-libs: install-implib-default
install-implib-default: $(call default_libs,libpthreadGC,.dll.a)
install-implib-default: $(call default_libs,libpthreadGCE,.dll.a)
$(INSTALL_DATA) $(lastword $^) ${libdir}/$(DEST_LIB_NAME).dll.a
install-headers: pthread.h sched.h semaphore.h _ptw32.h
$(INSTALL_DATA) $^ ${includedir}
%.pre: %.c
$(CC) -E -o $@ $(CFLAGS) $^
%.s: %.c
$(CC) -c $(CFLAGS) -DPTW32_BUILD_INLINED -Wa,-ahl $^ > $@
%.o: %.rc
$(RC) $(RC_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$@.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$@.a --def $(PTHREAD_DEF)
$(GC_INLINED_STATIC_STAMP) $(GCE_INLINED_STATIC_STAMP) $(GCD_INLINED_STATIC_STAMP) $(GCED_INLINED_STATIC_STAMP): $(STATIC_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_SMALL)
$(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)
-cd tests && $(MAKE) clean
realclean: clean
-$(RM) lib*.a
-$(RM) *.lib
-$(RM) pthread*.dll
-$(RM) *_stamp
-$(RM) make.log.txt
-cd tests && $(MAKE) realclean
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)