Commit 50fa19c3ad84a5ecd93c2d7d5dca0cd70512295c

Thomas de Grivel 2025-04-26T13:06:39

make uninstall, fix build under windows

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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
diff --git a/Makefile b/Makefile
index 7fd3c1a..122747b 100644
--- a/Makefile
+++ b/Makefile
@@ -880,6 +880,16 @@ lib_links_windows:
 	ln -sf ../../../smtp/.libs/libkc3_smtp-0.dll lib/kc3/0.1/smtp.so
 	ln -sf ../../../socket/.libs/libkc3_socket-0.dll lib/kc3/0.1/socket.so
 
+lib_links_windows_debug:
+	ln -sf ../../../ekc3/.libs/libekc3_debug-0.dll lib/kc3/0.1/ekc3.so
+	ln -sf ../../../event/.libs/libkc3_event_debug-0.dll lib/kc3/0.1/event.so
+	ln -sf ../../../gtk4/.libs/libkc3_gtk4_debug-0.dll lib/kc3/0.1/gtk4.so
+	ln -sf ../../../http/.libs/libkc3_http_debug-0.dll lib/kc3/0.1/http.so
+	ln -sf ../../../json/.libs/libkc3_json_debug-0.dll lib/kc3/0.1/json.so
+	ln -sf ../../../markdown/.libs/libkc3_markdown_debug-0.dll lib/kc3/0.1/markdown.so
+	ln -sf ../../../smtp/.libs/libkc3_smtp_debug-0.dll lib/kc3/0.1/smtp.so
+	ln -sf ../../../socket/.libs/libkc3_socket_debug-0.dll lib/kc3/0.1/socket.so
+
 libkc3_gcovr:
 	${MAKE} clean_cov
 	${MAKE} libkc3_test_cov
@@ -1280,6 +1290,25 @@ test_socket_debug: lib_links_debug
 	${MAKE} -C socket debug
 	${MAKE} -C test test_socket_debug
 
+uninstall:
+	rm -rf ${prefix}/lib/kc3
+	rm -rf ${prefix}/share/kc3
+	${MAKE} -C libtommath uninstall
+	${MAKE} -C libkc3 uninstall
+	${MAKE} -C ikc3 uninstall
+	${MAKE} -C kc3s uninstall
+	${MAKE} -C ekc3 uninstall
+	${MAKE} -C event uninstall
+	${MAKE} -C json uninstall
+	${MAKE} -C markdown uninstall
+	${MAKE} -C smtp uninstall
+	${MAKE} -C socket uninstall
+	${MAKE} -C http uninstall
+	${MAKE} -C httpd uninstall
+	${MAKE} -C window uninstall
+	${MAKE} -C gtk4 uninstall
+#	${MAKE} -C fs uninstall
+
 .PHONY: all \
 	asan \
 	assets \
@@ -1424,4 +1453,5 @@ test_socket_debug: lib_links_debug
 	test_socket \
 	test_socket_asan \
 	test_socket_cov \
-	test_socket_debug
+	test_socket_debug \
+	uninstall
diff --git a/config.subr b/config.subr
index 3030982..a9b82d6 100644
--- a/config.subr
+++ b/config.subr
@@ -412,7 +412,7 @@ config_lib_have() {
     echo "/* generated by configure */" > "$OUT_C"
     echo "int main (void) { return 0; }" >> "$OUT_C"
     if $LIBTOOL --tag CC --mode link ${CC} ${CPPFLAGS} ${CFLAGS} \
-                "$OUT_C" ${LIBS} $@ -o "$OUT" >/dev/null 2>&1; then
+                "$OUT_C" ${LDFLAGS} ${LIBS} $@ -o "$OUT" >/dev/null 2>&1; then
         eval "HAVE_$NAME=true"
         echo "HAVE_$NAME = true" >> ${CONFIG_MK}
     else
diff --git a/ekc3/Makefile b/ekc3/Makefile
index f963fcc..be98ca6 100644
--- a/ekc3/Makefile
+++ b/ekc3/Makefile
@@ -61,6 +61,11 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/ekc3
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
@@ -73,6 +78,7 @@ update_sources:
 	install \
 	test \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/event/Makefile b/event/Makefile
index f963fcc..7ba25d9 100644
--- a/event/Makefile
+++ b/event/Makefile
@@ -49,8 +49,8 @@ gcovr:
 	gcovr --gcov-executable ${GCOV} --html-details libkc3_web.html
 
 install:
-	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/ekc3
-	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/ekc3
+	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/event
+	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/event
 	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB} ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB_DEBUG} ${prefix}/lib
@@ -61,6 +61,11 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/event
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
diff --git a/fs/Makefile b/fs/Makefile
index 09bcd65..bc74d3d 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -43,6 +43,9 @@ gcovr:
 install:
 #	${MAKE} -C fuse install
 
+uninstall:
+#	${MAKE} -C fuse uninstall
+
 .PHONY: \
 	all \
 	asan \
@@ -52,4 +55,5 @@ install:
 	debug \
 	distclean \
 	fuse \
-	install
+	install \
+	uninstall
diff --git a/gtk4/Makefile b/gtk4/Makefile
index 1d41dc2..73b25b5 100644
--- a/gtk4/Makefile
+++ b/gtk4/Makefile
@@ -49,8 +49,8 @@ gcovr:
 	gcovr --gcov-executable ${GCOV} --html-details libkc3_gtk4.html
 
 install:
-	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/ekc3
-	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/ekc3
+	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/gtk4
+	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/gtk4
 	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB} ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB_DEBUG} ${prefix}/lib
@@ -61,6 +61,11 @@ test:
 update_sources:
 	./update_sources
 
+install:
+	rm -rf ${prefix}/include/libkc3/gtk4
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
@@ -73,6 +78,7 @@ update_sources:
 	install \
 	test \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/http/Makefile b/http/Makefile
index f963fcc..7048174 100644
--- a/http/Makefile
+++ b/http/Makefile
@@ -49,8 +49,8 @@ gcovr:
 	gcovr --gcov-executable ${GCOV} --html-details libkc3_web.html
 
 install:
-	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/ekc3
-	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/ekc3
+	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/http
+	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/http
 	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB} ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB_DEBUG} ${prefix}/lib
@@ -61,6 +61,11 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/http
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
@@ -73,6 +78,7 @@ update_sources:
 	install \
 	test \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/httpd/Makefile b/httpd/Makefile
index f7012d0..5309aef 100644
--- a/httpd/Makefile
+++ b/httpd/Makefile
@@ -66,11 +66,14 @@ gdb_httpd: debug
 
 install:
 	mkdir -p ${prefix}/bin
-	install -m 755 .libs/kc3_httpd ${prefix}/bin/kc3_httpd
+	${INSTALL} -m 755 .libs/kc3_httpd ${prefix}/bin/kc3_httpd
 
 lldb_httpd: debug
 	if [ -f kc3_httpd_debug.core ]; then lldb .libs/kc3_httpd_debug kc3_httpd_debug.core; else lldb .libs/kc3_httpd_debug; fi
 
+uninstall:
+	rm -f ${prefix}/bin/kc3_httpd
+
 .PHONY: \
 	all \
 	asan \
@@ -83,6 +86,7 @@ lldb_httpd: debug
 	install \
 	lldb_httpd \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/ikc3/Makefile b/ikc3/Makefile
index 7e888c0..1dd07a5 100644
--- a/ikc3/Makefile
+++ b/ikc3/Makefile
@@ -51,11 +51,14 @@ gdb_ikc3_asan: asan
 
 install:
 	mkdir -p ${prefix}/bin
-	install -m 755 .libs/ikc3 ${prefix}/bin/ikc3
+	${INSTALL} -m 755 .libs/ikc3 ${prefix}/bin/ikc3
 
 lldb_ikc3: debug
 	if [ -f ikc3_debug.core ]; then lldb .libs/ikc3_debug ikc3_debug.core; else lldb .libs/ikc3_debug; fi
 
+uninstall:
+	rm -f ${prefix}/bin/ikc3
+
 .PHONY: \
 	all \
 	asan \
@@ -69,6 +72,7 @@ lldb_ikc3: debug
 	install \
 	lldb_ikc3 \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/json/Makefile b/json/Makefile
index f963fcc..d98855a 100644
--- a/json/Makefile
+++ b/json/Makefile
@@ -49,8 +49,8 @@ gcovr:
 	gcovr --gcov-executable ${GCOV} --html-details libkc3_web.html
 
 install:
-	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/ekc3
-	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/ekc3
+	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/json
+	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/json
 	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB} ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB_DEBUG} ${prefix}/lib
@@ -61,6 +61,11 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/json
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
@@ -73,6 +78,7 @@ update_sources:
 	install \
 	test \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/kc3s/Makefile b/kc3s/Makefile
index a9a2ff6..0b46c32 100644
--- a/kc3s/Makefile
+++ b/kc3s/Makefile
@@ -50,7 +50,10 @@ install:
 	mkdir -p ${prefix}/bin
 	install -m 755 .libs/kc3s ${prefix}/bin/kc3s
 
-.PHONY: all asan cov debug clean clean_cov distclean
+uninstall:
+	rm -f ${prefix}/bin/kc3s
+
+.PHONY: all asan cov debug clean clean_cov distclean install uninstall
 
 include config.mk
 include sources.mk
diff --git a/libkc3/Makefile b/libkc3/Makefile
index e844b7e..cc7b0b8 100644
--- a/libkc3/Makefile
+++ b/libkc3/Makefile
@@ -64,6 +64,11 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
diff --git a/libkc3/struct.c b/libkc3/struct.c
index 384060d..23b86ce 100644
--- a/libkc3/struct.c
+++ b/libkc3/struct.c
@@ -160,24 +160,24 @@ void struct_delete (s_struct *s)
   if (env_global()->pass_by_copy)
     assert(s->ref_count == 1);
   else {
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
     mutex_lock(&s->mutex);
 #endif
     if (s->ref_count <= 0) {
       err_puts("struct_delete: invalid reference count");
       assert(! "struct_delete: invalid reference count");
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
       mutex_unlock(&s->mutex);
 #endif
       return;
     }
     if (--s->ref_count) {
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
       mutex_unlock(&s->mutex);
 #endif
       return;
     }
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
     mutex_unlock(&s->mutex);
 #endif
   }
@@ -285,7 +285,7 @@ s_struct * struct_init (s_struct *s, const s_sym *module)
     }
   }
   tmp.ref_count = 1;
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_init(&tmp.mutex);
 #endif
   *s = tmp;
@@ -339,7 +339,7 @@ s_struct * struct_init_copy (s_struct *s, s_struct *src)
       i++;
     }
   }
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_init(&tmp.mutex);
 #endif
   *s = tmp;
@@ -420,7 +420,7 @@ s_struct * struct_init_with_data (s_struct *s, const s_sym *module,
   tmp.data = data;
   tmp.free_data = free_data;
   tmp.ref_count = 1;
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_init(&tmp.mutex);
 #endif
   *s = tmp;
@@ -434,7 +434,7 @@ s_struct * struct_init_with_type (s_struct *s, s_struct_type *st)
   assert(st);
   pstruct_type_init_copy(&tmp.pstruct_type, &st);
   tmp.ref_count = 1;
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_init(&tmp.mutex);
 #endif
   *s = tmp;
@@ -471,7 +471,7 @@ s_struct * struct_new_copy (s_struct *src)
 s_struct * struct_new_ref (s_struct *s)
 {
   assert(s);
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_lock(&s->mutex);
 #endif
   if (s->ref_count <= 0) {
@@ -480,7 +480,7 @@ s_struct * struct_new_ref (s_struct *s)
     return NULL;
   }
   s->ref_count++;
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_unlock(&s->mutex);
 #endif
   return s;
diff --git a/libkc3/struct_type.c b/libkc3/struct_type.c
index 1cf36e1..1669ddb 100644
--- a/libkc3/struct_type.c
+++ b/libkc3/struct_type.c
@@ -72,7 +72,7 @@ void struct_type_delete (s_struct_type *st)
   if (env_global()->pass_by_copy)
     assert(st->ref_count == 1);
   else {
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
     mutex_lock(&st->mutex);
 #endif
     if (st->ref_count <= 0) {
@@ -81,12 +81,12 @@ void struct_type_delete (s_struct_type *st)
       abort();
     }
     if (--st->ref_count) {
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
       mutex_unlock(&st->mutex);
 #endif
       return;
     }
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
     mutex_unlock(&st->mutex);
 #endif
   }
@@ -204,7 +204,7 @@ s_struct_type * struct_type_init (s_struct_type *st,
 #endif
   }
   tmp.ref_count = 1;
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_init(&tmp.mutex);
 #endif
   *st = tmp;
@@ -232,7 +232,7 @@ s_struct_type * struct_type_init_copy (s_struct_type *st,
   memcpy(tmp.offset, src->offset, tmp.map.count * sizeof(uw));
   tmp.size = src->size;
   tmp.ref_count = 1;
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_init(&tmp.mutex);
 #endif
   *st = tmp;
@@ -288,19 +288,19 @@ s_struct_type * struct_type_new_copy (const s_struct_type *src)
 s_struct_type * struct_type_new_ref (s_struct_type *st)
 {
   assert(st);
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_lock(&st->mutex);
 #endif
   if (st->ref_count <= 0) {
     err_puts("struct_type_new_ref: invalid reference count");
     assert(! "struct_type_new_ref: invalid reference count");
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
     mutex_unlock(&st->mutex);
 #endif
     return NULL;
   }
   st->ref_count++;
-#ifdef HAVE_PTHREAD
+#if HAVE_PTHREAD
   mutex_unlock(&st->mutex);
 #endif
   return st;
diff --git a/libtommath b/libtommath
index 2b4f8c8..3ccbcc8 160000
--- a/libtommath
+++ b/libtommath
@@ -1 +1 @@
-Subproject commit 2b4f8c862fd5564945aa4fa60460c1920315e318
+Subproject commit 3ccbcc870bec6d8f310696ae869f55a29e407911
diff --git a/markdown/Makefile b/markdown/Makefile
index f963fcc..07fc465 100644
--- a/markdown/Makefile
+++ b/markdown/Makefile
@@ -49,8 +49,8 @@ gcovr:
 	gcovr --gcov-executable ${GCOV} --html-details libkc3_web.html
 
 install:
-	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/ekc3
-	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/ekc3
+	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/markdown
+	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/markdown
 	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB} ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB_DEBUG} ${prefix}/lib
@@ -61,6 +61,11 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/markdown
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
diff --git a/smtp b/smtp
index cd1e59c..366ad84 160000
--- a/smtp
+++ b/smtp
@@ -1 +1 @@
-Subproject commit cd1e59cb718ba91dcf28684b27cf5a4f48f9f78d
+Subproject commit 366ad848ad346cc06ccdbad1097fbe1d28e6580f
diff --git a/socket/Makefile b/socket/Makefile
index f963fcc..81f6b12 100644
--- a/socket/Makefile
+++ b/socket/Makefile
@@ -49,8 +49,8 @@ gcovr:
 	gcovr --gcov-executable ${GCOV} --html-details libkc3_web.html
 
 install:
-	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/ekc3
-	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/ekc3
+	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libkc3/socket
+	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${HEADERS} ${prefix}/include/libkc3/socket
 	${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB} ${prefix}/lib
 	${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB_DEBUG} ${prefix}/lib
@@ -61,6 +61,11 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/socket
+	rm -f ${prefix}/lib/${LIB}
+	rm -f ${prefix}/lib/${LIB_DEBUG}
+
 .PHONY: \
 	all \
 	asan \
@@ -73,6 +78,7 @@ update_sources:
 	install \
 	test \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/socket/socket.c b/socket/socket.c
index 376f1a6..0fbda4b 100644
--- a/socket/socket.c
+++ b/socket/socket.c
@@ -26,10 +26,18 @@
 #include "socket.h"
 #include "socket_buf.h"
 
+
+#if (defined(WIN32) || defined(WIN64))
+static bool g_socket_init = false;
+#endif
+
 void socket_clean (void)
 {
-#ifdef WIN32
-  WSACleanup();
+#if (defined(WIN32) || defined(WIN64))
+  if (g_socket_init) {
+    WSACleanup();
+    g_socket_init = false;
+  }
 #endif
 }
 
@@ -42,12 +50,16 @@ void socket_close (p_socket s)
 
 bool socket_init (void)
 {
-#ifdef WIN32
+#if (defined(WIN32) || defined(WIN64))
   static WSADATA wsa_data;
   s32 r;
-  if ((r = WSAStartup(MAKEWORD(2,2), &wsa_data))) {
-    printf("WSAStartup failed with error: %d\n", r);
-    return false;
+  if (! g_socket_init) {
+    printf("socket_init: WSAStartup\n");
+    if ((r = WSAStartup(MAKEWORD(2,2), &wsa_data))) {
+      printf("socket_init: WSAStartup failed with error: %d\n", r);
+      return false;
+    }
+    g_socket_init = true;
   }
 #endif
   return true;
@@ -90,7 +102,8 @@ p_socket socket_init_listen (p_socket s, const s_str *host,
   t_socket sockfd;
   assert(s);
   assert(host);
-  hints.ai_family = AF_INET;
+  if (! socket_init())
+    return NULL;
   e = getaddrinfo(host->ptr.pchar, service->ptr.pchar, &hints, &res0);
   if (e) {
     err_write_1("socket_init_listen(");
@@ -98,6 +111,8 @@ p_socket socket_init_listen (p_socket s, const s_str *host,
     err_write_1(", ");
     err_write_1(service->ptr.pchar);
     err_write_1("): getaddrinfo: ");
+    err_inspect_s32_decimal(&e);
+    err_write_1(" ");
     err_puts((char *) gai_strerror(e));
     assert(! "socket_init_listen: getaddrinfo");
     return NULL;
diff --git a/socket/socket_buf.c b/socket/socket_buf.c
index 968c29d..175edbc 100644
--- a/socket/socket_buf.c
+++ b/socket/socket_buf.c
@@ -16,6 +16,8 @@
 #ifdef WIN32
 # include <winsock2.h>
 # include <ws2tcpip.h>
+# undef errno
+# define errno WSAGetLastError()
 #else
 # include <netdb.h>
 # include <netinet/in.h>
@@ -23,6 +25,7 @@
 
 #include <unistd.h>
 #include <libkc3/kc3.h>
+#include "socket.h"
 #include "socket_addr.h"
 #include "socket_buf.h"
 
@@ -126,6 +129,8 @@ s_socket_buf * socket_buf_init_connect (s_socket_buf *sb,
   assert(sb);
   assert(host);
   assert(service);
+  if (! socket_init())
+    return NULL;
   hints.ai_family = AF_INET;
   e = getaddrinfo(host->ptr.pchar, service->ptr.pchar, &hints, &res0);
   if (e) {
@@ -134,7 +139,9 @@ s_socket_buf * socket_buf_init_connect (s_socket_buf *sb,
     err_write_1(", ");
     err_write_1(service->ptr.pchar);
     err_write_1("): getaddrinfo: ");
-    err_puts((const char *) gai_strerror(e));
+    err_inspect_s32_decimal(&e);
+    err_write_1(" ");
+    err_puts((const char *) gai_strerrorA(e));
     assert(! "socket_buf_init_connect: getaddrinfo");
     return NULL;
   }
diff --git a/socket/types.h b/socket/types.h
index b769875..e71bc7c 100644
--- a/socket/types.h
+++ b/socket/types.h
@@ -13,10 +13,14 @@
 #ifndef HTTP_TYPES_H
 #define HTTP_TYPES_H
 
-#ifdef WIN32
-# include <winsock2.h>
+#ifdef WIN64
+# include <ws2tcpip.h>
 #else
-# include <sys/socket.h>
+# ifdef WIN32
+#  include <winsock2.h>
+# else
+#  include <sys/socket.h>
+# endif
 #endif
 
 #include <libkc3/types.h>
diff --git a/test/Makefile b/test/Makefile
index e99907a..d00bf55 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -240,6 +240,18 @@ test_markdown_cov:
 test_markdown_debug:
 	IKC3=${SRC_TOP}/ikc3/ikc3_debug time ./markdown_test
 
+test_socket:
+	IKC3=${SRC_TOP}/ikc3/ikc3 time ./socket_test
+
+test_socket_asan:
+	IKC3=${SRC_TOP}/ikc3/ikc3_asan time ./socket_test
+
+test_socket_cov:
+	IKC3=${SRC_TOP}/ikc3/ikc3_cov time ./socket_test
+
+test_socket_debug:
+	IKC3=${SRC_TOP}/ikc3/ikc3_debug time ./socket_test
+
 test_valgrind: libkc3_test
 	valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./libkc3_test
 
@@ -272,6 +284,7 @@ test_valgrind: libkc3_test
 	test_httpd_debug \
 	test_ikc3 \
 	test_kc3s \
+	test_socket \
 	test_valgrind
 
 include config.mk
diff --git a/test/kc3s/comments.out b/test/kc3s/comments.out
index 9766475..0aee968 100644
--- a/test/kc3s/comments.out
+++ b/test/kc3s/comments.out
@@ -1 +1 @@
-ok
+ok
diff --git a/window/Makefile b/window/Makefile
index d8609e8..1bc0d8c 100644
--- a/window/Makefile
+++ b/window/Makefile
@@ -107,6 +107,12 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/window
+	rm -f ${prefix}/lib/${LIB}
+	if ${HAVE_CAIRO}; then ${MAKE} -C cairo uninstall; fi
+	if ${HAVE_SDL2}; then ${MAKE} -C sdl2 uninstall; fi
+
 .PHONY: \
 	all \
 	asan \
@@ -129,7 +135,8 @@ update_sources:
 	lldb_demo \
 	lldb_demo_gl \
 	test \
-	update_sources
+	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/window/cairo/Makefile b/window/cairo/Makefile
index a576bcd..a32f02b 100644
--- a/window/cairo/Makefile
+++ b/window/cairo/Makefile
@@ -104,6 +104,13 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/window/cairo
+	rm -f ${prefix}/lib/${LIB}
+	if ${HAVE_COCOA}; then ${MAKE} -C quartz uninstall; fi
+	if ${HAVE_WIN32}; then ${MAKE} -C win32 uninstall; fi
+	if ${HAVE_XCB}; then ${MAKE} -C xcb uninstall; fi
+
 .PHONY: \
 	all \
 	asan \
@@ -120,7 +127,8 @@ update_sources:
 	install \
 	lldb_demo \
 	test \
-	update_sources
+	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/window/cairo/quartz/Makefile b/window/cairo/quartz/Makefile
index d4521b2..ef6ea38 100644
--- a/window/cairo/quartz/Makefile
+++ b/window/cairo/quartz/Makefile
@@ -57,6 +57,8 @@ distclean:
 gdb_demo: debug
 	${MAKE} -C demo gdb_demo
 
+install:
+
 lldb_demo: debug
 	${MAKE} -C demo lldb_demo
 
@@ -66,6 +68,8 @@ test: build
 update_sources:
 	./update_sources
 
+uninstall:
+
 .PHONY: \
 	all \
 	asan \
@@ -79,7 +83,8 @@ update_sources:
 	gen \
 	install \
 	test \
-	update_sources
+	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/window/cairo/win32/Makefile b/window/cairo/win32/Makefile
index eda903f..1ea53ba 100644
--- a/window/cairo/win32/Makefile
+++ b/window/cairo/win32/Makefile
@@ -67,12 +67,16 @@ distclean:
 gdb_demo: debug
 	${MAKE} -C demo gdb_demo
 
+install:
+
 test: build
 	${MAKE} -C demo test
 
 update_sources:
 	./update_sources
 
+uninstall:
+
 .PHONY: \
 	all \
 	asan \
@@ -86,7 +90,8 @@ update_sources:
 	gen \
 	install \
 	test \
-	update_sources
+	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/window/cairo/xcb/Makefile b/window/cairo/xcb/Makefile
index 3b53c45..0b4c6cd 100644
--- a/window/cairo/xcb/Makefile
+++ b/window/cairo/xcb/Makefile
@@ -84,6 +84,11 @@ test: build
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libc3/window/cairo/xcb
+	rm -f ${prefix}/lib/${LIB}
+	${MAKE} -C demo uninstall
+
 .PHONY: \
 	all \
 	asan \
diff --git a/window/cairo/xcb/demo/Makefile b/window/cairo/xcb/demo/Makefile
index 8afd285..c153507 100644
--- a/window/cairo/xcb/demo/Makefile
+++ b/window/cairo/xcb/demo/Makefile
@@ -68,8 +68,8 @@ gdb_demo: debug
 	if [ -f ${PROG_DEBUG}.core ]; then gdb .libs/${PROG_DEBUG} ${PROG_DEBUG}.core; else gdb .libs/${PROG_DEBUG}; fi
 
 install:
-	install -m 755 -d ${prefix}/bin
-	install -m 755 ${PROG} ${prefix}/bin/${PROG}
+	${INSTALL} -m 755 -d ${prefix}/bin
+	${INSTALL} -m 755 ${PROG} ${prefix}/bin/${PROG}
 
 lldb_demo: debug
 	if [ -f ${PROG_DEBUG}.core ]; then lldb .libs/${PROG_DEBUG} ${PROG_DEBUG}.core; else lldb .libs/${PROG_DEBUG}; fi
@@ -77,6 +77,9 @@ lldb_demo: debug
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -f ${prefix}/bin/${PROG}
+
 .PHONY: \
 	all \
 	asan \
@@ -94,6 +97,7 @@ update_sources:
 	install \
 	lldb_demo \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/window/sdl2/Makefile b/window/sdl2/Makefile
index 0d7849e..6ad0f81 100644
--- a/window/sdl2/Makefile
+++ b/window/sdl2/Makefile
@@ -107,6 +107,12 @@ test:
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -rf ${prefix}/include/libkc3/window/sdl2
+	rm -f ${prefix}/lib/${LIB}
+	${MAKE} -C demo uninstall
+	! test -d kubz || ${MAKE} -C kubz uninstall
+
 .PHONY: \
 	all \
 	asan \
@@ -124,6 +130,7 @@ update_sources:
 	lldb_demo \
 	test \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/window/sdl2/configure b/window/sdl2/configure
index 453a39b..0eb9288 100755
--- a/window/sdl2/configure
+++ b/window/sdl2/configure
@@ -46,6 +46,9 @@ config_gnu
 config_i386
 config_win32
 config_win64
+if $HAVE_WIN32; then
+    LIBS="$LIBS -lglu32 -lopengl32"
+fi
 pkg_config libbsd-overlay
 pkg_config libmd
 pkg_config freetype2
diff --git a/window/sdl2/demo/Makefile b/window/sdl2/demo/Makefile
index fecdb0e..60a078b 100644
--- a/window/sdl2/demo/Makefile
+++ b/window/sdl2/demo/Makefile
@@ -85,6 +85,9 @@ lldb_demo: debug
 update_sources:
 	./update_sources
 
+uninstall:
+	rm -f ${prefix}/bin/${PROG}
+
 .PHONY: \
 	all \
 	asan \
@@ -102,6 +105,7 @@ update_sources:
 	install \
 	lldb_demo \
 	update_sources \
+	uninstall
 
 include config.mk
 include sources.mk
diff --git a/window/sdl2/demo/configure b/window/sdl2/demo/configure
index 6b10c52..90fcb76 100755
--- a/window/sdl2/demo/configure
+++ b/window/sdl2/demo/configure
@@ -67,6 +67,9 @@ pkg_config libpng
 if ${HAVE_COCOA}; then
     config_lib OPENGL -framework OpenGL
 fi
+if ${HAVE_WIN32}; then
+    LIBS="$LIBS -lSDL2Main"
+fi
 config_lib OPENGL -lopengl32 -lglu32
 config_lib OPENMP -fopenmp
 config_define HAVE_OPENMP "${HAVE_OPENMP}"
diff --git a/window/sdl2/demo/img/earth.png b/window/sdl2/demo/img/earth.png
new file mode 100644
index 0000000..df1fe95
Binary files /dev/null and b/window/sdl2/demo/img/earth.png differ
diff --git a/window/sdl2/kubz b/window/sdl2/kubz
index bfdfcf4..4bd361a 160000
--- a/window/sdl2/kubz
+++ b/window/sdl2/kubz
@@ -1 +1 @@
-Subproject commit bfdfcf4416f3abb75ddb8cf74bf0a45a7b27fcbc
+Subproject commit 4bd361ae1a05e6a663a96dea85c599f741f03913