1# This makefile is compatible with MS nmake and can be used as a
2# replacement for buildlib.bat. I've changed the target from an ordinary dll
3# (/LD) to a debugging dll (/LDd).
4# 
5# The variables $DLLDEST and $LIBDEST hold the destination directories for the
6# dll and the lib, respectively. Probably all that needs to change is $DEVROOT.
7
8
9# DLL_VER:
10# See pthread.h and README - This number is computed as 'current - age'
11DLL_VER	= 2
12DLL_VERD= $(DLL_VER)d
13
14DEVROOT	= C:\pthreads
15
16DLLDEST	= $(DEVROOT)\dll
17LIBDEST	= $(DEVROOT)\lib
18HDRDEST	= $(DEVROOT)\include
19
20DLLS	= pthreadVCE$(DLL_VER).dll pthreadVSE$(DLL_VER).dll pthreadVC$(DLL_VER).dll \
21		  pthreadVCE$(DLL_VERD).dll pthreadVSE$(DLL_VERD).dll pthreadVC$(DLL_VERD).dll
22INLINED_STAMPS	= pthreadVCE$(DLL_VER).stamp pthreadVSE$(DLL_VER).stamp pthreadVC$(DLL_VER).stamp \
23				  pthreadVCE$(DLL_VERD).stamp pthreadVSE$(DLL_VERD).stamp pthreadVC$(DLL_VERD).stamp
24STATIC_STAMPS	= pthreadVCE$(DLL_VER).static pthreadVSE$(DLL_VER).static pthreadVC$(DLL_VER).static \
25				  pthreadVCE$(DLL_VERD).static pthreadVSE$(DLL_VERD).static pthreadVC$(DLL_VERD).static
26
27CC	= cl
28CPPFLAGS = /I. /DHAVE_PTW32_CONFIG_H
29XCFLAGS = /W3 /MD /nologo
30CFLAGS	= /O2 /Ob2 $(XCFLAGS)
31CFLAGSD	= /Z7 $(XCFLAGS)
32
33# Uncomment this if config.h defines RETAIN_WSALASTERROR
34#XLIBS = wsock32.lib
35
36# Default cleanup style
37CLEANUP	= __CLEANUP_C
38
39# C++ Exceptions
40VCEFLAGS	= /EHsc /TP $(CPPFLAGS) $(CFLAGS)
41VCEFLAGSD	= /EHsc /TP $(CPPFLAGS) $(CFLAGSD)
42#Structured Exceptions
43VSEFLAGS	= $(CPPFLAGS) $(CFLAGS)
44VSEFLAGSD	= $(CPPFLAGS) $(CFLAGSD)
45#C cleanup code
46VCFLAGS		= $(CPPFLAGS) $(CFLAGS)
47VCFLAGSD	= $(CPPFLAGS) $(CFLAGSD)
48
49DLL_INLINED_OBJS = \
50		pthread.obj \
51		version.res
52
53# Aggregate modules for inlinability
54DLL_OBJS	= \
55		attr.obj \
56		barrier.obj \
57		cancel.obj \
58		cleanup.obj \
59		condvar.obj \
60		create.obj \
61		dll.obj \
62		autostatic.obj \
63		errno.obj \
64		exit.obj \
65		fork.obj \
66		global.obj \
67		misc.obj \
68		mutex.obj \
69		nonportable.obj \
70		private.obj \
71		rwlock.obj \
72		sched.obj \
73		semaphore.obj \
74		signal.obj \
75		spin.obj \
76		sync.obj \
77		tsd.obj \
78		version.res
79
80# Separate modules for minimising the size of statically linked images
81SMALL_STATIC_OBJS	= \
82		pthread_attr_init.obj \
83		pthread_attr_destroy.obj \
84		pthread_attr_getdetachstate.obj \
85		pthread_attr_setdetachstate.obj \
86		pthread_attr_getstackaddr.obj \
87		pthread_attr_setstackaddr.obj \
88		pthread_attr_getstacksize.obj \
89		pthread_attr_setstacksize.obj \
90		pthread_attr_getscope.obj \
91		pthread_attr_setscope.obj \
92		pthread_attr_setschedpolicy.obj \
93		pthread_attr_getschedpolicy.obj \
94		pthread_attr_setschedparam.obj \
95		pthread_attr_getschedparam.obj \
96		pthread_attr_setinheritsched.obj \
97		pthread_attr_getinheritsched.obj \
98		pthread_barrier_init.obj \
99		pthread_barrier_destroy.obj \
100		pthread_barrier_wait.obj \
101		pthread_barrierattr_init.obj \
102		pthread_barrierattr_destroy.obj \
103		pthread_barrierattr_setpshared.obj \
104		pthread_barrierattr_getpshared.obj \
105		pthread_setcancelstate.obj \
106		pthread_setcanceltype.obj \
107		pthread_testcancel.obj \
108		pthread_cancel.obj \
109		cleanup.obj \
110		pthread_condattr_destroy.obj \
111		pthread_condattr_getpshared.obj \
112		pthread_condattr_init.obj \
113		pthread_condattr_setpshared.obj \
114		pthread_cond_destroy.obj \
115		pthread_cond_init.obj \
116		pthread_cond_signal.obj \
117		pthread_cond_wait.obj \
118		create.obj \
119		dll.obj \
120		autostatic.obj \
121		errno.obj \
122		pthread_exit.obj \
123		fork.obj \
124		global.obj \
125		pthread_mutex_init.obj \
126		pthread_mutex_destroy.obj \
127		pthread_mutexattr_init.obj \
128		pthread_mutexattr_destroy.obj \
129		pthread_mutexattr_getpshared.obj \
130		pthread_mutexattr_setpshared.obj \
131		pthread_mutexattr_settype.obj \
132		pthread_mutexattr_gettype.obj \
133		pthread_mutexattr_setrobust.obj \
134		pthread_mutexattr_getrobust.obj \
135		pthread_mutex_lock.obj \
136		pthread_mutex_timedlock.obj \
137		pthread_mutex_unlock.obj \
138		pthread_mutex_trylock.obj \
139		pthread_mutex_consistent.obj \
140		pthread_mutexattr_setkind_np.obj \
141		pthread_mutexattr_getkind_np.obj \
142		pthread_getw32threadhandle_np.obj \
143		pthread_getunique_np.obj \
144		pthread_delay_np.obj \
145		pthread_num_processors_np.obj \
146		pthread_win32_attach_detach_np.obj \
147		pthread_equal.obj \
148		pthread_getconcurrency.obj \
149		pthread_once.obj \
150		pthread_self.obj \
151		pthread_setconcurrency.obj \
152		pthread_rwlock_init.obj \
153		pthread_rwlock_destroy.obj \
154		pthread_rwlockattr_init.obj \
155		pthread_rwlockattr_destroy.obj \
156		pthread_rwlockattr_getpshared.obj \
157		pthread_rwlockattr_setpshared.obj \
158		pthread_rwlock_rdlock.obj \
159		pthread_rwlock_wrlock.obj \
160		pthread_rwlock_unlock.obj \
161		pthread_rwlock_tryrdlock.obj \
162		pthread_rwlock_trywrlock.obj \
163		pthread_setschedparam.obj \
164		pthread_getschedparam.obj \
165		pthread_timechange_handler_np.obj \
166		ptw32_is_attr.obj \
167		ptw32_processInitialize.obj \
168		ptw32_processTerminate.obj \
169		ptw32_threadStart.obj \
170		ptw32_threadDestroy.obj \
171		ptw32_tkAssocCreate.obj \
172		ptw32_tkAssocDestroy.obj \
173		ptw32_callUserDestroyRoutines.obj \
174		ptw32_timespec.obj \
175		ptw32_throw.obj \
176		ptw32_getprocessors.obj \
177		ptw32_calloc.obj \
178		ptw32_new.obj \
179		ptw32_reuse.obj \
180		ptw32_rwlock_check_need_init.obj \
181		ptw32_cond_check_need_init.obj \
182		ptw32_mutex_check_need_init.obj \
183		ptw32_semwait.obj \
184		ptw32_relmillisecs.obj \
185		ptw32_MCS_lock.obj \
186		sched_get_priority_max.obj \
187		sched_get_priority_min.obj \
188		sched_setscheduler.obj \
189		sched_getscheduler.obj \
190		sched_yield.obj \
191		sem_init.obj \
192		sem_destroy.obj \
193		sem_trywait.obj \
194		sem_timedwait.obj \
195		sem_wait.obj \
196		sem_post.obj \
197		sem_post_multiple.obj \
198		sem_getvalue.obj \
199		sem_open.obj \
200		sem_close.obj \
201		sem_unlink.obj \
202		signal.obj \
203		pthread_kill.obj \
204		ptw32_spinlock_check_need_init.obj \
205		pthread_spin_init.obj \
206		pthread_spin_destroy.obj \
207		pthread_spin_lock.obj \
208		pthread_spin_unlock.obj \
209		pthread_spin_trylock.obj \
210		pthread_detach.obj \
211		pthread_join.obj \
212		pthread_key_create.obj \
213		pthread_key_delete.obj \
214		pthread_setspecific.obj \
215		pthread_getspecific.obj \
216		w32_CancelableWait.obj \
217		version.res
218
219INCL	= config.h implement.h semaphore.h pthread.h need_errno.h
220
221ATTR_SRCS	= \
222		pthread_attr_init.c \
223		pthread_attr_destroy.c \
224		pthread_attr_getdetachstate.c \
225		pthread_attr_setdetachstate.c \
226		pthread_attr_getstackaddr.c \
227		pthread_attr_setstackaddr.c \
228		pthread_attr_getstacksize.c \
229		pthread_attr_setstacksize.c \
230		pthread_attr_getscope.c \
231		pthread_attr_setscope.c
232
233BARRIER_SRCS = \
234		pthread_barrier_init.c \
235		pthread_barrier_destroy.c \
236		pthread_barrier_wait.c \
237		pthread_barrierattr_init.c \
238		pthread_barrierattr_destroy.c \
239		pthread_barrierattr_setpshared.c \
240		pthread_barrierattr_getpshared.c
241
242CANCEL_SRCS	= \
243		pthread_setcancelstate.c \
244		pthread_setcanceltype.c \
245		pthread_testcancel.c \
246		pthread_cancel.c 
247
248CONDVAR_SRCS	= \
249		ptw32_cond_check_need_init.c \
250		pthread_condattr_destroy.c \
251		pthread_condattr_getpshared.c \
252		pthread_condattr_init.c \
253		pthread_condattr_setpshared.c \
254		pthread_cond_destroy.c \
255		pthread_cond_init.c \
256		pthread_cond_signal.c \
257		pthread_cond_wait.c
258
259EXIT_SRCS	= \
260		pthread_exit.c
261
262MISC_SRCS	= \
263		pthread_equal.c \
264		pthread_getconcurrency.c \
265		pthread_kill.c \
266		pthread_once.c \
267		pthread_self.c \
268		pthread_setconcurrency.c \
269		ptw32_calloc.c \
270		ptw32_MCS_lock.c \
271		ptw32_new.c \
272		ptw32_reuse.c \
273		ptw32_relmillisecs.c \
274		w32_CancelableWait.c
275
276MUTEX_SRCS	= \
277		ptw32_mutex_check_need_init.c \
278		pthread_mutex_init.c \
279		pthread_mutex_destroy.c \
280		pthread_mutexattr_init.c \
281		pthread_mutexattr_destroy.c \
282		pthread_mutexattr_getpshared.c \
283		pthread_mutexattr_setpshared.c \
284		pthread_mutexattr_settype.c \
285		pthread_mutexattr_gettype.c \
286		pthread_mutexattr_setrobust.c \
287		pthread_mutexattr_getrobust.c \
288		pthread_mutex_lock.c \
289		pthread_mutex_timedlock.c \
290		pthread_mutex_unlock.c \
291		pthread_mutex_trylock.c \
292		pthread_mutex_consistent.c
293
294NONPORTABLE_SRCS = \
295		pthread_mutexattr_setkind_np.c \
296		pthread_mutexattr_getkind_np.c \
297		pthread_getw32threadhandle_np.c \
298		pthread_getunique_np.c \
299		pthread_delay_np.c \
300		pthread_num_processors_np.c \
301		pthread_win32_attach_detach_np.c \
302		pthread_timechange_handler_np.c 
303
304PRIVATE_SRCS	= \
305		ptw32_is_attr.c \
306		ptw32_processInitialize.c \
307		ptw32_processTerminate.c \
308		ptw32_threadStart.c \
309		ptw32_threadDestroy.c \
310		ptw32_tkAssocCreate.c \
311		ptw32_tkAssocDestroy.c \
312		ptw32_callUserDestroyRoutines.c \
313		ptw32_semwait.c \
314		ptw32_timespec.c \
315		ptw32_throw.c \
316		ptw32_getprocessors.c
317
318RWLOCK_SRCS	= \
319		ptw32_rwlock_check_need_init.c \
320		ptw32_rwlock_cancelwrwait.c \
321		pthread_rwlock_init.c \
322		pthread_rwlock_destroy.c \
323		pthread_rwlockattr_init.c \
324		pthread_rwlockattr_destroy.c \
325		pthread_rwlockattr_getpshared.c \
326		pthread_rwlockattr_setpshared.c \
327		pthread_rwlock_rdlock.c \
328		pthread_rwlock_timedrdlock.c \
329		pthread_rwlock_wrlock.c \
330		pthread_rwlock_timedwrlock.c \
331		pthread_rwlock_unlock.c \
332		pthread_rwlock_tryrdlock.c \
333		pthread_rwlock_trywrlock.c
334
335SCHED_SRCS	= \
336		pthread_attr_setschedpolicy.c \
337		pthread_attr_getschedpolicy.c \
338		pthread_attr_setschedparam.c \
339		pthread_attr_getschedparam.c \
340		pthread_attr_setinheritsched.c \
341		pthread_attr_getinheritsched.c \
342		pthread_setschedparam.c \
343		pthread_getschedparam.c \
344		sched_get_priority_max.c \
345		sched_get_priority_min.c \
346		sched_setscheduler.c \
347		sched_getscheduler.c \
348		sched_yield.c
349
350SEMAPHORE_SRCS = \
351		sem_init.c \
352		sem_destroy.c \
353		sem_trywait.c \
354		sem_timedwait.c \
355		sem_wait.c \
356		sem_post.c \
357		sem_post_multiple.c \
358		sem_getvalue.c \
359		sem_open.c \
360		sem_close.c \
361		sem_unlink.c
362
363SPIN_SRCS	= \
364		ptw32_spinlock_check_need_init.c \
365		pthread_spin_init.c \
366		pthread_spin_destroy.c \
367		pthread_spin_lock.c \
368		pthread_spin_unlock.c \
369		pthread_spin_trylock.c
370
371SYNC_SRCS	= \
372		pthread_detach.c \
373		pthread_join.c
374
375TSD_SRCS	= \
376		pthread_key_create.c \
377		pthread_key_delete.c \
378		pthread_setspecific.c \
379		pthread_getspecific.c
380
381
382help:
383	@ echo Run one of the following command lines:
384	@ echo nmake clean VCE   (to build the MSVC dll with C++ exception handling)
385	@ echo nmake clean VSE   (to build the MSVC dll with structured exception handling)
386	@ echo nmake clean VC    (to build the MSVC dll with C cleanup code)
387	@ echo nmake clean VCE-inlined   (to build the MSVC inlined dll with C++ exception handling)
388	@ echo nmake clean VSE-inlined   (to build the MSVC inlined dll with structured exception handling)
389	@ echo nmake clean VC-inlined    (to build the MSVC inlined dll with C cleanup code)
390	@ echo nmake clean VC-static     (to build the MSVC static lib with C cleanup code)
391	@ echo nmake clean VCE-debug   (to build the debug MSVC dll with C++ exception handling)
392	@ echo nmake clean VSE-debug   (to build the debug MSVC dll with structured exception handling)
393	@ echo nmake clean VC-debug    (to build the debug MSVC dll with C cleanup code)
394	@ echo nmake clean VCE-inlined-debug   (to build the debug MSVC inlined dll with C++ exception handling)
395	@ echo nmake clean VSE-inlined-debug   (to build the debug MSVC inlined dll with structured exception handling)
396	@ echo nmake clean VC-inlined-debug    (to build the debug MSVC inlined dll with C cleanup code)
397	@ echo nmake clean VC-static-debug     (to build the debug MSVC static lib with C cleanup code)
398
399all:
400	@ $(MAKE) /E clean VCE-inlined
401	@ $(MAKE) /E clean VSE-inlined
402	@ $(MAKE) /E clean VC-inlined
403	@ $(MAKE) /E clean VCE-inlined-debug
404	@ $(MAKE) /E clean VSE-inlined-debug
405	@ $(MAKE) /E clean VC-inlined-debug
406
407VCE:
408	@ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGS)" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).dll
409
410VCE-debug:
411	@ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGSD)" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).dll
412
413VSE:
414	@ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGS)" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).dll
415
416VSE-debug:
417	@ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGSD)" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).dll
418
419VC:
420	@ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGS)" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).dll
421
422VC-debug:
423	@ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGSD)" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).dll
424
425#
426# The so-called inlined DLL is just a single translation unit with
427# inlining optimisation turned on.
428#
429VCE-inlined:
430	@ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VER).stamp
431
432VCE-inlined-debug:
433	@ $(MAKE) /E /nologo EHFLAGS="$(VCEFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_CXX pthreadVCE$(DLL_VERD).stamp
434
435VSE-inlined:
436	@ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VER).stamp
437
438VSE-inlined-debug:
439	@ $(MAKE) /E /nologo EHFLAGS="$(VSEFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_SEH pthreadVSE$(DLL_VERD).stamp
440
441VC-inlined:
442	@ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGS) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).stamp
443
444VC-inlined-debug:
445	@ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGSD) /DPTW32_BUILD_INLINED" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).stamp
446
447VC-static:
448	@ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGS) /DPTW32_BUILD_INLINED /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VER).static
449
450VC-static-debug:
451	@ $(MAKE) /E /nologo EHFLAGS="$(VCFLAGSD) /DPTW32_BUILD_INLINED /DPTW32_STATIC_LIB" CLEANUP=__CLEANUP_C pthreadVC$(DLL_VERD).static
452
453realclean: clean
454	if exist pthread*.dll del pthread*.dll
455	if exist pthread*.lib del pthread*.lib
456	if exist *.manifest del *.manifest
457	if exist *.stamp del *.stamp
458
459clean:
460	if exist *.obj del *.obj
461	if exist *.def del *.def
462	if exist *.ilk del *.ilk
463	if exist *.pdb del *.pdb
464	if exist *.exp del *.exp
465	if exist *.map del *.map
466	if exist *.o del *.o
467	if exist *.i del *.i
468	if exist *.res del *.res
469
470
471install:
472	copy pthread*.dll $(DLLDEST)
473	copy pthread*.lib $(LIBDEST)
474	copy pthread.h $(HDRDEST)
475	copy sched.h $(HDRDEST)
476	copy semaphore.h $(HDRDEST)
477
478$(DLLS): $(DLL_OBJS)
479	$(CC) /LDd /Zi /nologo $(DLL_OBJS) /link /implib:$*.lib $(XLIBS) /out:$@
480
481$(INLINED_STAMPS): $(DLL_INLINED_OBJS)
482	$(CC) /LDd /Zi /nologo $(DLL_INLINED_OBJS) /link /implib:$*.lib $(XLIBS) /out:$*.dll
483
484$(STATIC_STAMPS): $(DLL_INLINED_OBJS)
485	if exist $*.lib del $*.lib
486	lib $(DLL_INLINED_OBJS) /out:$*.lib
487
488.c.obj:
489	$(CC) $(EHFLAGS) /D$(CLEANUP) -c $<
490
491# TARGET_CPU is an environment variable set by Visual Studio Command Prompt
492# as provided by the SDK
493.rc.res:
494	rc /dPTW32_ARCH$(TARGET_CPU) /dPTW32_RC_MSC /d$(CLEANUP) $<
495
496.c.i:
497	$(CC) /P /O2 /Ob1 $(VCFLAGS) $<
498
499attr.obj:	attr.c $(ATTR_SRCS) $(INCL)
500barrier.obj:	barrier.c $(BARRIER_SRCS) $(INCL)
501cancel.obj:	cancel.c $(CANCEL_SRCS) $(INCL)
502condvar.obj:	condvar.c $(CONDVAR_SRCS) $(INCL)
503exit.obj:	exit.c $(EXIT_SRCS) $(INCL)
504misc.obj:	misc.c $(MISC_SRCS) $(INCL)
505mutex.obj:	mutex.c $(MUTEX_SRCS) $(INCL)
506nonportable.obj:	nonportable.c $(NONPORTABLE_SRCS) $(INCL)
507private.obj:	private.c $(PRIVATE_SRCS) $(INCL)
508rwlock.obj:	rwlock.c $(RWLOCK_SRCS) $(INCL)
509sched.obj:	sched.c $(SCHED_SRCS) $(INCL)
510semaphore.obj:	semaphore.c $(SEMAPHORE_SRCS) $(INCL)
511spin.obj:	spin.c $(SPIN_SRCS) $(INCL)
512sync.obj:	sync.c $(SYNC_SRCS) $(INCL)
513tsd.obj:	tsd.c $(TSD_SRCS) $(INCL)
514version.res:	version.rc $(INCL)
515