summaryrefslogtreecommitdiff
path: root/Examples/Makefile.in
blob: 98be7873fbe0bfde13f4a6fba6eab121cb0f4481 (plain)
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
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
# ------------------------------------------------------------
# SWIG Examples Makefile
#
# This file is used by the examples to build modules.  Assuming
# you ran configure, this file will probably work.  However,
# it's not perfect so you might need to do some hand tweaking.
#
# Other notes:
#
# 1.   Take a look at the prefixes below.   Since SWIG works with
#      multiple target languages, you may need to find out where
#      certain packages have been installed.   Set the prefixes
#      accordingly.
#
# 2.   To use this makefile, set required variables, eg SRCS, INTERFACE,
#      INTERFACEDIR, INCLUDES, LIBS, TARGET, and do a
#           $(MAKE) -f Makefile.template.in SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
#           INCLUDES='$(INCLUDES) LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' \
#           INTERFACEDIR='$(INTERFACEDIR)' TARGET='$(TARGET)' method
#
#      'method' describes what is being built.
#---------------------------------------------------------------

# Regenerate Makefile if Makefile.in or config.status have changed.
Makefile: @srcdir@/Makefile.in ../config.status
	cd .. && $(SHELL) ./config.status Examples/Makefile

# SRCDIR is the relative path to the current source directory
# - For in-source-tree builds, SRCDIR with be either '' or './', but
#   '../' for the test suites that build in a subdir (e.g. C#, Java)
# - For out-of-source-tree builds, SRCDIR will be a relative
#   path ending with a '/'

# SRCDIR_SRCS, etc. are $(SRCS), etc. with $(SRCDIR) prepended
SRCDIR_SRCS    = $(addprefix $(SRCDIR),$(SRCS))
SRCDIR_CSRCS   = $(addprefix $(SRCDIR),$(CSRCS))
SRCDIR_CXXSRCS = $(addprefix $(SRCDIR),$(CXXSRCS))

ifeq (,$(SRCDIR))
SRCDIR_INCLUDE = -I.
else
SRCDIR_INCLUDE = -I. -I$(SRCDIR)
endif

TARGET     =
CC         = @CC@
CXX        = @CXX@
CPPFLAGS   = $(SRCDIR_INCLUDE)
CFLAGS     = @PLATCFLAGS@
CXXFLAGS   = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@
LDFLAGS    =
prefix     = @prefix@
exec_prefix= @exec_prefix@
SRCS       =
INCLUDES   =
LIBS       =
INTERFACE  =
INTERFACEDIR  =
INTERFACEPATH = $(SRCDIR)$(INTERFACEDIR)$(INTERFACE)
SWIGOPT    =

# SWIG_LIB_DIR and SWIGEXE must be explicitly set by Makefiles using this Makefile
SWIG_LIB_DIR = ./Lib
SWIGEXE    = swig
SWIG_LIB_SET = @SWIG_LIB_SET@
SWIGTOOL   =
SWIG       = $(SWIG_LIB_SET) $(SWIGTOOL) $(SWIGEXE)

LIBM       = @LIBM@
LIBC       = @LIBC@
LIBCRYPT   = @LIBCRYPT@
SYSLIBS    = $(LIBM) $(LIBC) $(LIBCRYPT)
LIBPREFIX  =

# RUNTOOL is for use with runtime tools, eg set it to valgrind
RUNTOOL    =
# COMPILETOOL is a way to run the compiler under another tool, or more commonly just to stop the compiler executing
COMPILETOOL=
# RUNPIPE is for piping output of running interpreter/compiled code somewhere, eg RUNPIPE=\>/dev/null
RUNPIPE=

RUNME = runme

IWRAP      = $(INTERFACE:.i=_wrap.i)
ISRCS      = $(IWRAP:.i=.c)
ICXXSRCS   = $(IWRAP:.i=.cxx)
IOBJS      = $(IWRAP:.i=.@OBJEXT@)

##################################################################
# Some options for silent output
##################################################################

ifneq (,$(findstring s, $(filter-out --%, $(MAKEFLAGS))))
  # make -s detected
  SILENT=1
else
  SILENT=
endif

ifneq (,$(SILENT))
  SILENT_OPTION = -s
  SILENT_PIPE = >/dev/null
  ANT_QUIET = -q -logfile /dev/null
else
  SILENT_OPTION =
  SILENT_PIPE =
  ANT_QUIET =
endif

##################################################################
# Dynamic loading for C++
# If you are going to be building dynamic loadable modules in C++,
# you may need to edit this line appropriately.
#
# This line works for g++, but I'm not sure what it might be
# for other C++ compilers
##################################################################

CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
	     -L/usr/local/lib -lg++ -lstdc++ -lgcc

# Solaris workshop 5.0
# CPP_DLLIBS = -L/opt/SUNWspro/lib -lCrun

# Symbols used for using shared libraries
SO=		@SO@
LDSHARED=	@LDSHARED@
CCSHARED=	@CCSHARED@
CXXSHARED=      @CXXSHARED@

# This is used for building shared libraries with a number of C++
# compilers.   If it doesn't work,  comment it out.
@TRYLINKINGWITHCXX@

OBJS      = $(SRCS:.c=.@OBJEXT@) $(CXXSRCS:.cxx=.@OBJEXT@)

distclean:
	rm -f Makefile
	rm -f d/example.mk
	rm -f xml/Makefile

##################################################################
# Very generic invocation of swig
##################################################################

swiginvoke:
	$(SWIG) $(SWIGOPT)

##################################################################
#####                       Tcl/Tk                          ######
##################################################################

# Set these to your local copy of Tcl/Tk.

TCLSH       = tclsh
TCL_INCLUDE = @TCLINCLUDE@
TCL_LIB     = @TCLLIB@
TCL_OPTS    = @LIBS@
TK_OPTS     = -ltk -ltcl @LIBS@

# Extra Tcl specific dynamic linking options
TCL_DLNK   = @TCLDYNAMICLINKING@
TCL_SO     = @TCL_SO@
TCLLDSHARED = @TCLLDSHARED@
TCLCXXSHARED = @TCLCXXSHARED@
TCL_SCRIPT = $(SRCDIR)$(RUNME).tcl

# -----------------------------------------------------------
# Build a new version of the tclsh shell
# -----------------------------------------------------------

tclsh: $(SRCDIR_SRCS)
	$(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE) \
	$(TCL_LIB)  $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET)

tclsh_cpp: $(SRCDIR_SRCS)
	$(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE) \
	$(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET)

# -----------------------------------------------------------
# Build a Tcl dynamic loadable module (you might need to tweak this)
# -----------------------------------------------------------

tcl:  $(SRCDIR_SRCS)
	$(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(TCL_INCLUDE)
	$(TCLLDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO)

# -----------------------------------------------------------
# Build a Tcl7.5 dynamic loadable module for C++
# -----------------------------------------------------------

tcl_cpp: $(SRCDIR_SRCS)
	$(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(TCL_INCLUDE)
	$(TCLCXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(TCL_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(TCL_SO)

# -----------------------------------------------------------------
# Run Tcl example
# -----------------------------------------------------------------

tcl_run:
	$(RUNTOOL) $(TCLSH) $(TCL_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

tcl_version:
	echo 'puts $$tcl_version;exit 0' | $(TCLSH)

# -----------------------------------------------------------------
# Cleaning the Tcl examples
# -----------------------------------------------------------------

tcl_clean:
	rm -f *_wrap* *~ .~* mytclsh@EXEEXT@
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *$(TCL_SO)

##################################################################
#####                       PERL 5                          ######
##################################################################

# You need to set this variable to the Perl5 directory containing the
# files "perl.h", "EXTERN.h" and "XSUB.h".   With Perl5.003, it's
# usually something like /usr/local/lib/perl5/arch-osname/5.003/CORE.

PERL5_INCLUDE= @PERL5EXT@

# Extra Perl specific dynamic linking options
PERL5_DLNK   = @PERL5DYNAMICLINKING@
PERL5_CCFLAGS = @PERL5CCFLAGS@
PERL5_CCDLFLAGS = @PERL5CCDLFLAGS@
PERL5_CCCDLFLAGS = @PERL5CCCDLFLAGS@
PERL5_LDFLAGS = @PERL5LDFLAGS@
PERL = @PERL@
PERL5_LIB = -L$(PERL5_INCLUDE) -l@PERL5LIB@ @LIBS@ $(SYSLIBS)
PERL5_SCRIPT = $(SRCDIR)$(RUNME).pl

# ----------------------------------------------------------------
# Build a Perl5 dynamically loadable module (C)
# ----------------------------------------------------------------

perl5: $(SRCDIR_SRCS)
	$(SWIG) -perl5 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c -Dbool=char $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

# ----------------------------------------------------------------
# Build a Perl5 dynamically loadable module (C++)
# ----------------------------------------------------------------

perl5_cpp: $(SRCDIR_SRCS)
	$(SWIG) -perl5 -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) $(PERL5_CCCDLFLAGS) -I$(PERL5_INCLUDE)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(PERL5_CCDLFLAGS) $(OBJS) $(IOBJS) $(PERL5_LDFLAGS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

# ----------------------------------------------------------------
# Build a module from existing XS C source code.   (ie. from xsubpp).
# ----------------------------------------------------------------
perl5_xs: $(SRCDIR_SRCS)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(INCLUDES) -I$(PERL5_INCLUDE)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $(TARGET)$(SO)

# ----------------------------------------------------------------
# Build a statically linked Perl5 executable
# ----------------------------------------------------------------

perl5_static: $(SRCDIR_SRCS)
	$(SWIG) -perl5 -static -lperlmain.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Dbool=char $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET)

perl5_static_cpp: $(SRCDIR_SRCS)
	$(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET)

# -----------------------------------------------------------------
# Running a Perl5 example
# -----------------------------------------------------------------

perl5_run:
	$(RUNTOOL) $(PERL) -I. $(PERL5_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

perl5_version:
	$(PERL) -v | grep "This is"

# -----------------------------------------------------------------
# Cleaning the Perl5 examples
# -----------------------------------------------------------------

perl5_clean:
	rm -f *_wrap* *~ .~* myperl@EXEEXT@ *.pm
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@

##################################################################
#####                       PYTHON                          ######
##################################################################

PYTHON_FLAGS =

# Make sure these locate your Python installation
ifeq (,$(PY3))
  PYTHON_INCLUDE= $(DEFS) @PYINCLUDE@
  PYTHON_LIB    = @PYLIB@
  PYTHON        = @PYTHON@ $(PYTHON_FLAGS)
else
  PYTHON_INCLUDE= $(DEFS) @PY3INCLUDE@
  PYTHON_LIB    = @PY3LIB@
  PYTHON        = @PYTHON3@ $(PYTHON_FLAGS)
endif

# Extra Python specific linking options
ifeq (,$(PY3))
  PYTHON_DLNK   = @PYTHONDYNAMICLINKING@
  PYTHON_LINK   = @PYLINK@
else
  PYTHON_DLNK   = @PYTHON3DYNAMICLINKING@
  PYTHON_LINK   = @PY3LINK@
endif
PYTHON_SO     = @PYTHON_SO@

# SWIG option for Python3
ifeq (,$(PY3))
  SWIGOPTPY3 =
else
  SWIGOPTPY3 = -py3
endif

PYCODESTYLE       = @PYCODESTYLE@
PYCODESTYLE_FLAGS = --ignore=E252,E30,E402,E501,E731,W291,W391

# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------

python: $(SRCDIR_SRCS)
	$(SWIG) -python $(SWIGOPTPY3) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(PYTHON_INCLUDE)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO)

# -----------------------------------------------------------------
# Build a C++ dynamically loadable module
# -----------------------------------------------------------------

python_cpp: $(SRCDIR_SRCS)
	$(SWIG) -python $(SWIGOPTPY3) -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(PYTHON_INCLUDE)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO)

# -----------------------------------------------------------------
# Build statically linked Python interpreter
#
# These should only be used in conjunction with the %include embed.i
# library file
# -----------------------------------------------------------------

#TKINTER = -L/usr/X11R6.3/lib -L/usr/local/compat/lib -ltk4.0 -ltcl7.4 -lX11
TKINTER =
PYTHON_LIBOPTS = $(PYTHON_LINK) @LIBS@ $(TKINTER) $(SYSLIBS)

python_static: $(SRCDIR_SRCS)
	$(SWIG) -python $(SWIGOPTPY3) -lembed.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \
	$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)

python_static_cpp: $(SRCDIR_SRCS)
	$(SWIG) -python $(SWIGOPTPY3) -c++ -lembed.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \
	$(PYTHON_INCLUDE) $(LIBS)  -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)

# -----------------------------------------------------------------
# Running a Python example
# -----------------------------------------------------------------

ifeq (,$(PY3))
  PYSCRIPT = $(RUNME).py
else
  PYSCRIPT = $(RUNME)3.py
endif

PY2TO3 = @PY2TO3@ `@PY2TO3@ -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'`

python_run: $(PYSCRIPT)
ifneq (,$(PYCODESTYLE))
	$(COMPILETOOL) $(PYCODESTYLE) $(PYCODESTYLE_FLAGS) $(PYSCRIPT)
endif
	env PYTHONPATH=$$PWD $(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE)

ifneq (,$(SRCDIR))
$(RUNME).py: $(SRCDIR)$(RUNME).py
	cp $< $@
endif

$(RUNME)3.py: $(SRCDIR)$(RUNME).py
	cp $< $@
	$(PY2TO3) -w $@ >/dev/null 2>&1

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

python_version:
	$(PYTHON) -V

# -----------------------------------------------------------------
# Cleaning the python examples
# -----------------------------------------------------------------

python_clean:
	rm -rf __pycache__
	rm -f *_wrap* *~ .~* mypython@EXEEXT@ *.pyc
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@ *$(PYTHON_SO)
	rm -f $(TARGET).py
	if test -f $(SRCDIR)$(RUNME).py; then rm -f $(RUNME)3.py $(RUNME)3.py.bak; fi
	case "x$(SRCDIR)" in x|x./);; *) rm -f $(RUNME).py;; esac


##################################################################
#####                       OCTAVE                          ######
##################################################################

# Make sure these locate your Octave installation
OCTAVE        = @OCTAVE@
OCTAVE_CXX    = $(DEFS) @OCTAVE_CPPFLAGS@ @OCTAVE_CXXFLAGS@

# Extra Octave specific dynamic linking options
OCTAVE_DLNK   = @OCTAVE_LDFLAGS@
OCTAVE_SO     = @OCTAVE_SO@

OCTAVE_SCRIPT = $(SRCDIR)$(RUNME).m

# ----------------------------------------------------------------
# Build a C dynamically loadable module
# Note: Octave requires C++ compiler when compiling C wrappers
# ----------------------------------------------------------------

octave: $(SRCDIR_SRCS)
	$(SWIG) -octave $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(INCLUDES) $(OCTAVE_CXX)
	$(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS) $(INCLUDES)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO)

# -----------------------------------------------------------------
# Build a C++ dynamically loadable module
# -----------------------------------------------------------------

octave_cpp: $(SRCDIR_SRCS)
	$(SWIG) -c++ -octave $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(OCTAVE_CXX)
	$(CXXSHARED) -g $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(OCTAVE_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(OCTAVE_SO)

# -----------------------------------------------------------------
# Running an Octave example
# -----------------------------------------------------------------

octave_run:
	env OCTAVE_PATH= OCTAVE_HISTFILE=/dev/null $(RUNTOOL) $(OCTAVE) $(OCTAVE_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

octave_version:
	$(OCTAVE) --version | head -n 1

# -----------------------------------------------------------------
# Cleaning the Octave examples
# -----------------------------------------------------------------

octave_clean:
	rm -rf __pycache__
	rm -f *_wrap* *~ .~* myoctave@EXEEXT@ *.pyc
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@ *$(OCTAVE_SO)

##################################################################
#####                       GUILE                           ######
##################################################################

# Make sure these locate your Guile installation
GUILE         = @GUILE@
GUILE_CFLAGS  = @GUILE_CFLAGS@
GUILE_SO      = @GUILE_SO@
GUILE_LIBS    = @GUILE_LIBS@
GUILE_LIBOPTS = @LIBS@ $(SYSLIBS)
GUILE_LIBPREFIX = lib
GUILE_SCRIPT  = $(SRCDIR)$(RUNME).scm

#------------------------------------------------------------------
# Build a dynamically loaded module with passive linkage
#------------------------------------------------------------------
guile: $(SRCDIR_SRCS)
	$(SWIG) -guile -Linkage passive $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ISRCS) $(SRCDIR_SRCS)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO)

guile_cpp: $(SRCDIR_SRCS)
	$(SWIG) -c++ -guile -Linkage passive $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) $(GUILE_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(GUILE_LIBS) $(LIBS) $(CPP_DLLIBS) -o $(GUILE_LIBPREFIX)$(TARGET)$(GUILE_SO)

guile_externalhdr:
	$(SWIG) -guile -external-runtime $(TARGET)

# -----------------------------------------------------------------
# Build Guile interpreter augmented with extra functions
# -----------------------------------------------------------------

guile_augmented: $(SRCDIR_SRCS)
	$(SWIG) -guile $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) -o $(TARGET)

# -----------------------------------------------------------------
# Build statically linked Guile interpreter
# -----------------------------------------------------------------

guile_static: $(SRCDIR_SRCS)
	$(SWIG) -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \
	  -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \
	  $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile

guile_static_cpp: $(SRCDIR_SRCS)
	$(SWIG) -c++ -guile -lguilemain.i -Linkage ltdlmod $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \
	  -DSWIGINIT="SCM scm_init_$(TARGET)_module(void); scm_init_$(TARGET)_module();" \
	  $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile

guile_simple: $(SRCDIR_SRCS)
	$(SWIG) -guile -lguilemain.i -Linkage simple $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \
	  $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile

guile_simple_cpp: $(SRCDIR_SRCS)
	$(SWIG) -c++ -guile -lguilemain.i -Linkage simple $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \
	  $(GUILE_CFLAGS) $(GUILE_LIBS) $(LIBS) $(GUILE_LIBOPTS) -o $(TARGET)-guile

# -----------------------------------------------------------------
# Running a Guile example
# -----------------------------------------------------------------

guile_run:
	env GUILE_AUTO_COMPILE=0 $(RUNTOOL) $(GUILE) -l $(GUILE_SCRIPT) $(RUNPIPE)

guile_augmented_run:
	env GUILE_AUTO_COMPILE=0 $(RUNTOOL) ./$(TARGET) $(GUILE_RUNOPTIONS) -s $(GUILE_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

guile_version:
	$(GUILE) --version | head -n 1

# -----------------------------------------------------------------
# Cleaning the Guile examples
# -----------------------------------------------------------------

guile_clean:
	rm -f *_wrap* *~ .~* my-guile@EXEEXT@ $(TARGET)@EXEEXT@
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *$(GUILE_SO)

##################################################################
#####                       JAVA                            ######
##################################################################

# You need to set this variable to the java directories containing the
# files "jni.h" and "md.h"
# usually something like /usr/java/include and /usr/java/include/<arch-osname>.
JAVA_INCLUDE= @JAVAINC@

# Extra Java specific dynamic linking options
JAVA_DLNK  = @JAVADYNAMICLINKING@
JAVA_LIBPREFIX = @JAVALIBRARYPREFIX@
JAVASO =@JAVASO@
JAVALDSHARED = @JAVALDSHARED@
JAVACXXSHARED = @JAVACXXSHARED@
JAVACFLAGS = @JAVACFLAGS@
JAVAFLAGS = @JAVAFLAGS@
JAVA = @JAVA@
JAVAC = @JAVAC@ -d .

# ----------------------------------------------------------------
# Build a java dynamically loadable module (C)
# ----------------------------------------------------------------

java: $(SRCDIR_SRCS)
	$(SWIG) -java $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(JAVACFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(JAVA_INCLUDE)
	$(JAVALDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO)

# ----------------------------------------------------------------
# Build a java dynamically loadable module (C++)
# ----------------------------------------------------------------

java_cpp: $(SRCDIR_SRCS)
	$(SWIG) -java -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(JAVACFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JAVA_INCLUDE)
	$(JAVACXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JAVA_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JAVA_LIBPREFIX)$(TARGET)$(JAVASO)

# ----------------------------------------------------------------
# Compile java files
# ----------------------------------------------------------------

java_compile: $(SRCDIR_SRCS)
	$(COMPILETOOL) $(JAVAC) $(addprefix $(SRCDIR),$(JAVASRCS))

# -----------------------------------------------------------------
# Run java example
# -----------------------------------------------------------------

java_run:
	env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(JAVA) $(JAVAFLAGS) $(RUNME) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

java_version:
	$(JAVA) -version
	$(JAVAC) -version || echo "Unknown javac version"

# -----------------------------------------------------------------
# Cleaning the java examples
# -----------------------------------------------------------------

java_clean:
	rm -f *_wrap* *~ .~* *.class `find . -name \*.java | grep -v $(RUNME).java`
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@JAVASO@

##################################################################
#####                       JAVASCRIPT                      ######
##################################################################

# Note: These targets are also from within Makefiles in the Example directories.
# There is a common makefile, 'Examples/javascript/js_example.mk' to simplify
# create a configuration for a new example.

ROOT_DIR = @ROOT_DIR@
JSINCLUDES = @JSCOREINC@ @JSV8INC@
JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@
NODEJS = @NODEJS@
NODEGYP = @NODEGYP@

# ----------------------------------------------------------------
# Creating and building Javascript wrappers
# ----------------------------------------------------------------

javascript_wrapper:
	$(SWIG) -javascript $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH)

javascript_wrapper_cpp: $(SRCDIR_SRCS)
	$(SWIG) -javascript -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH)

javascript_build: $(SRCDIR_SRCS)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(JSINCLUDES)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

javascript_build_cpp: $(SRCDIR_SRCS)
ifeq (node,$(JSENGINE))
	sed -e 's|$$srcdir|./$(SRCDIR)|g' $(SRCDIR)binding.gyp.in > binding.gyp
	MAKEFLAGS= $(NODEGYP) --loglevel=silent configure build 1>>/dev/null
else
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

endif

# These targets are used by the test-suite:

javascript: $(SRCDIR_SRCS) javascript_custom_interpreter
	$(SWIG) -javascript $(SWIGOPT) $(INTERFACEPATH)
ifeq (jsc, $(ENGINE))
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(JSINCLUDES)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
else # (v8 | node) # v8 and node must be compiled as c++
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
endif

javascript_cpp: $(SRCDIR_SRCS) javascript_custom_interpreter
	$(SWIG) -javascript -c++ $(SWIGOPT) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

# -----------------------------------------------------------------
# Running a Javascript example
# -----------------------------------------------------------------

javascript_custom_interpreter:
	(cd $(ROOT_DIR)/Tools/javascript && $(MAKE) JSENGINE='$(JSENGINE)')

ifeq (node,$(JSENGINE))
javascript_run:
	env NODE_PATH=$$PWD:$(SRCDIR) $(RUNTOOL) $(NODEJS) $(SRCDIR)$(RUNME).js $(RUNPIPE)
else
javascript_run: javascript_custom_interpreter
	$(RUNTOOL) $(ROOT_DIR)/Tools/javascript/javascript -$(JSENGINE) -L $(TARGET) $(SRCDIR)$(RUNME).js $(RUNPIPE)
endif

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

javascript_version:
ifeq (, $(ENGINE))
	@if [ "$(NODEJS)" != "" ]; then \
	  echo "Node.js: `($(NODEJS) --version)`"; \
	  echo "node-gyp: `($(NODEGYP) --version)`"; \
	else \
	  echo "Version depends on the interpreter"; \
	fi
endif
ifeq (node, $(ENGINE))
	echo "Node.js: `($(NODEJS) --version)`"
	echo "node-gyp: `($(NODEGYP) --version)`"
endif
ifeq (jsc, $(ENGINE))
	@if [ "@JSCOREVERSION@" != "" ]; then \
	  echo "@JSCOREVERSION@"; \
	else \
	  echo "Unknown JavascriptCore version."; \
	fi
endif
ifeq (v8, $(ENGINE))
	echo "Unknown v8 version."
endif

# -----------------------------------------------------------------
# Cleaning the Javascript examples
# -----------------------------------------------------------------

javascript_clean:
	rm -rf build
	rm -f *_wrap* $(RUNME)
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@
	rm -f binding.gyp example-gypcopy.cxx
	cd $(ROOT_DIR)/Tools/javascript && $(MAKE) -s clean

##################################################################
#####                       ANDROID                         ######
##################################################################

ANDROID = @ANDROID@
ANDROID_NDK_BUILD = @NDKBUILD@
ANDROID_ADB = @ADB@
ANT = @ANT@
TARGETID = 1

# ----------------------------------------------------------------
# Build an Android dynamically loadable module (C)
# ----------------------------------------------------------------

android: $(SRCDIR_SRCS)
	$(ANDROID) $(SILENT_OPTION) update project --target $(TARGETID) --name $(PROJECTNAME) --path .
	$(SWIG) -java $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH)
	+$(ANDROID_NDK_BUILD) $(SILENT_PIPE)
	$(ANT) $(ANT_QUIET) debug

# ----------------------------------------------------------------
# Build an Android dynamically loadable module (C++)
# ----------------------------------------------------------------

android_cpp: $(SRCDIR_SRCS)
	$(ANDROID) $(SILENT_OPTION) update project --target $(TARGETID) --name $(PROJECTNAME) --path .
	$(SWIG) -java -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cpp $(INTERFACEPATH)
	+$(ANDROID_NDK_BUILD) $(SILENT_PIPE)
	$(ANT) $(ANT_QUIET) debug

# ----------------------------------------------------------------
# Android install
# ----------------------------------------------------------------

android_install:
	-$(ANDROID_ADB) uninstall $(PACKAGENAME)
	$(ANDROID_ADB) install $(INSTALLOPTIONS) bin/$(PROJECTNAME)-debug.apk

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

android_version:
	$(ANDROID_ADB) version

# -----------------------------------------------------------------
# Cleaning the Android examples
# -----------------------------------------------------------------

android_clean:
	test -n "$(SRCDIR)" && cd $(SRCDIR) ; $(ANT) -q -logfile /dev/null clean
	rm -f $(INTERFACEDIR)$(TARGET)_wrap.*
	rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
	rm -rf obj

##################################################################
#####                       MZSCHEME                        ######
##################################################################

MZSCHEME = mzscheme
MZC = @MZC@
MZDYNOBJ = @MZDYNOBJ@
MZSCHEME_SO = @MZSCHEME_SO@
MZSCHEME_SCRIPT = $(SRCDIR)$(RUNME).scm

# ----------------------------------------------------------------
# Build a C/C++ dynamically loadable module
# ----------------------------------------------------------------

mzscheme: $(SRCDIR_SRCS)
	$(SWIG) -mzscheme $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(COMPILETOOL) $(MZC) `echo " $(CPPFLAGS) $(INCLUDES) $(CFLAGS)" | sed 's/ -/ ++ccf -/g'` --cc $(ISRCS) $(SRCDIR_SRCS)
	$(COMPILETOOL) $(MZC) --ld $(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS)

mzscheme_cpp: $(SRCDIR_SRCS)
	$(SWIG) -mzscheme -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	env CFLAGS= $(COMPILETOOL) $(MZC) `echo " $(CPPFLAGS) $(INCLUDES) $(CXXFLAGS)" | sed 's/ -/ ++ccf -/g'` --cc $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS)
	$(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS)

# -----------------------------------------------------------------
# Run mzscheme example
# -----------------------------------------------------------------

mzscheme_run:
	env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(MZSCHEME) -r $(MZSCHEME_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

mzscheme_version:
	$(MZSCHEME) -v
	$(MZC) -v

# -----------------------------------------------------------------
# Cleaning the mzscheme examples
# -----------------------------------------------------------------

mzscheme_clean:
	rm -f *_wrap* *~ .~*
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *$(MZSCHEME_SO)

##################################################################
#####                          Ocaml                         #####
##################################################################

OCC=$(COMPILETOOL) @OCAMLC@
OCC_WITH_PP=env TMPDIR=./localtmp $(OCC)
# TMPDIR above is a workaround for some ocamlc versions, such as 4.05.0, which always create a temp file of the same name breaking parallel make (seemingly only when -pp is used)
OCAMLDLGEN=$(COMPILETOOL) @OCAMLDLGEN@
OCAMLFIND=$(COMPILETOOL) @OCAMLFIND@
OCAMLMKTOP=$(COMPILETOOL) @OCAMLMKTOP@
NOLINK ?= false
OCAMLPP= -pp "camlp4o ./swigp4.cmo"
OCAMLP4WHERE=`$(COMPILETOOL) @CAMLP4@ -where`

ocaml_core:
	mkdir -p ./localtmp
	$(SWIG) -ocaml -co swig.mli 2>/dev/null
	$(SWIG) -ocaml -co swig.ml 2>/dev/null
	$(SWIG) -ocaml -co swigp4.ml 2>/dev/null
	$(OCC) -c swig.mli
	$(OCC) -c swig.ml
	$(OCC_WITH_PP) -I $(OCAMLP4WHERE) -pp "camlp4o pa_extend.cmo q_MLast.cmo" -c swigp4.ml

ocaml_static: $(SRCDIR_SRCS)
	$(SWIG) -ocaml $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCDIR_SRCS)
	$(OCC) -g -c $(INTERFACE:%.i=%.mli)
	$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
	test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
	$(NOLINK) || $(OCC) -g -ccopt -g -cclib -g -custom -o $(RUNME) swig.cmo $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)"

ocaml_dynamic: $(SRCDIR_SRCS)
	$(SWIG) -ocaml $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCDIR_SRCS)
	$(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(CCSHARED) -o $(INTERFACE:%.i=%@SO@) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) $(LIBS)
	$(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > $(INTERFACE:%.i=%_dynamic.ml)
	mv $(INTERFACE:%.i=%_dynamic.ml) $(INTERFACE:%.i=%.ml)
	rm $(INTERFACE:%.i=%.mli)
	$(OCAMLFIND) $(OCC) -g -c -package dl $(INTERFACE:%.i=%.ml)
	test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
	$(NOLINK) || $(OCAMLFIND) $(OCC) -g -ccopt -g -cclib -g -custom -o $(RUNME) swig.cmo -package dl -linkpkg $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo)

ocaml_static_toplevel: $(SRCDIR_SRCS)
	$(SWIG) -ocaml $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCDIR_SRCS)
	$(OCC) -g -c $(INTERFACE:%.i=%.mli)
	$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
	test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
	$(NOLINK) || $(OCAMLMKTOP) swig.cmo -I $(OCAMLP4WHERE) dynlink.cma camlp4o.cma swigp4.cmo -cclib "$(LIBS)" -g -ccopt -g -cclib -g -custom -o $(RUNME)_top $(INTERFACE:%.i=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS)

ocaml_static_cpp: $(SRCDIR_SRCS)
	$(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
	$(OCC) -cc '$(CXX) $(CPPFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS)
	$(OCC) -g -c $(INTERFACE:%.i=%.mli)
	$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
	test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
	$(NOLINK) || $(OCC) -g -ccopt -g -cclib -g -custom -o $(RUNME) swig.cmo $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)" -cc '$(CXX)'

ocaml_static_cpp_toplevel: $(SRCDIR_SRCS)
	$(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
	$(OCC) -cc '$(CXX) $(CPPFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS)
	$(OCC) -g -c $(INTERFACE:%.i=%.mli)
	$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
	test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
	$(NOLINK) || $(OCAMLMKTOP) -cc '$(CXX) $(CPPFLAGS)' swig.cmo -I $(OCAMLP4WHERE) dynlink.cma camlp4o.cma swigp4.cmo -cclib "$(LIBS)" -g -ccopt -g -cclib -g -custom -o $(RUNME)_top $(INTERFACE:%.i=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS)

ocaml_dynamic_cpp: $(SRCDIR_SRCS)
	$(SWIG) -ocaml -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
	$(OCC) -cc '$(CXX) $(CPPFLAGS)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" $(ICXXSRCS:%.cxx=%.c) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) -ccopt -fPIC
	$(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(INTERFACE:%.i=%@SO@) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) $(CPP_DLLIBS) $(LIBS)
	$(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > $(INTERFACE:%.i=%_dynamic.ml)
	mv $(INTERFACE:%.i=%_dynamic.ml) $(INTERFACE:%.i=%.ml)
	rm $(INTERFACE:%.i=%.mli)
	$(OCAMLFIND) $(OCC) -g -c -package dl $(INTERFACE:%.i=%.ml)
	test -z "$(PROGFILE)" || $(OCC_WITH_PP) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
	$(NOLINK) || $(OCAMLFIND) swig.cmo $(OCC) -cclib -export-dynamic -g -ccopt -g -cclib -g -custom -o $(RUNME) -package dl -linkpkg $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX)'

# -----------------------------------------------------------------
# Run ocaml example
# -----------------------------------------------------------------

ocaml_run:
	$(RUNTOOL) ./$(RUNME) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

ocaml_version:
	$(OCC) -version

# -----------------------------------------------------------------
# Cleaning the Ocaml examples
# -----------------------------------------------------------------

ocaml_clean:
	rm -f *_wrap* *~ .~* *.cmo *.cmi *.mli $(TARGET).ml $(RUNME) $(RUNME)_top swig.ml swigp4.ml
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@
	rm -rf ./localtmp

##################################################################
#####                       RUBY                            ######
##################################################################

# Make sure these locate your Ruby installation
RUBY_CFLAGS= @RUBYCCDLFLAGS@ $(DEFS)
RUBY_INCLUDE= @RUBYINCLUDE@
RUBY_LIB     = @RUBYLIB@
RUBY_DLNK = @RUBYDYNAMICLINKING@
RUBY_LIBOPTS = @RUBYLINK@ @LIBS@ $(SYSLIBS)
RUBY_SO = @RUBYSO@
RUBY = @RUBY@
RUBY_SCRIPT = $(SRCDIR)$(RUNME).rb


# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------

ruby: $(SRCDIR_SRCS)
	$(SWIG) -ruby $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(RUBY_CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(RUBY_INCLUDE)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO)

# -----------------------------------------------------------------
# Build a C++ dynamically loadable module
# -----------------------------------------------------------------

ruby_cpp: $(SRCDIR_SRCS)
	$(SWIG) -c++ -ruby $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(RUBY_INCLUDE)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(RUBY_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(RUBY_SO)

# -----------------------------------------------------------------
# Build statically linked Ruby interpreter
#
# These should only be used in conjunction with the %include embed.i
# library file
# -----------------------------------------------------------------

ruby_static: $(SRCDIR_SRCS)
	$(SWIG) -ruby -lembed.i $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(RUBY_CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) \
	$(RUBY_INCLUDE) $(LIBS) -L$(RUBY_LIB) $(RUBY_LIBOPTS) -o $(TARGET)

ruby_cpp_static: $(SRCDIR_SRCS)
	$(SWIG) -c++ -ruby -lembed.i $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(RUBY_CFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) \
	$(RUBY_INCLUDE) $(LIBS)  -L$(RUBY_LIB) $(RUBY_LIBOPTS) -o $(TARGET)

# -----------------------------------------------------------------
# Run Ruby example
# -----------------------------------------------------------------

ruby_run:
	$(RUNTOOL) $(RUBY) $(RUBYFLAGS) -I. $(RUBY_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

ruby_version:
	$(RUBY) -v

# -----------------------------------------------------------------
# Cleaning the Ruby examples
# -----------------------------------------------------------------

ruby_clean:
	rm -f *_wrap* *~ .~* myruby@EXEEXT@
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *$(RUBY_SO)

##################################################################
#####                       PHP7                            ######
##################################################################

PHP         = @PHP@
PHP_INCLUDE = @PHPINC@
PHP_SO      = @PHP_SO@
PHP_SCRIPT  = $(SRCDIR)$(RUNME).php

# -------------------------------------------------------------------
# Build a PHP dynamically loadable module (C)
# -------------------------------------------------------------------

php: $(SRCDIR_SRCS)
	$(SWIG) -php7 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)

# --------------------------------------------------------------------
# Build a PHP dynamically loadable module (C++)
# --------------------------------------------------------------------

php_cpp: $(SRCDIR_SRCS)
	$(SWIG) -php7 -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)

# -----------------------------------------------------------------
# Running a PHP example
# -----------------------------------------------------------------

php_run:
	$(RUNTOOL) $(PHP) -n -q -d extension_dir=. -d safe_mode=Off -d display_errors=stderr $(PHP_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

php_version:
	$(PHP) -v | head -n 1

# -----------------------------------------------------------------
# Cleaning the PHP examples
# -----------------------------------------------------------------

php_clean:
	rm -f *_wrap* *~ .~* example.php php_example.h
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *$(PHP_SO)

##################################################################
#####                      CSHARP                           ######
##################################################################

# Extra CSharp specific dynamic linking options
CSHARP_DLNK  = @CSHARPDYNAMICLINKING@
CSHARP_LIBPREFIX = @CSHARPLIBRARYPREFIX@
CSHARPCOMPILER = @CSHARPCOMPILER@
CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@
CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@
CSHARPCFLAGS = @CSHARPCFLAGS@
CSHARPFLAGS =
CSHARPOPTIONS =
CSHARPSO = @CSHARPSO@
CSHARP_RUNME = ./$(RUNME).exe

# ----------------------------------------------------------------
# Build a CSharp dynamically loadable module (C)
# ----------------------------------------------------------------

csharp: $(SRCDIR_SRCS)
	$(SWIG) -csharp $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO)

# ----------------------------------------------------------------
# Build a CSharp dynamically loadable module (C++)
# ----------------------------------------------------------------

csharp_cpp: $(SRCDIR_SRCS)
	$(SWIG) -csharp -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO)

# ----------------------------------------------------------------
# Compile CSharp files
# ----------------------------------------------------------------

ifneq (,$(SRCDIR))
SRCDIR_CSHARPSRCS = $(addprefix $(SRCDIR),$(CSHARPSRCS))
else
SRCDIR_CSHARPSRCS =
endif

csharp_compile: $(SRCDIR_SRCS)
	$(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPOPTIONS) $(CSHARPSRCS) $(SRCDIR_CSHARPSRCS)

# -----------------------------------------------------------------
# Run CSharp example
# -----------------------------------------------------------------

csharp_run:
	env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) $(CSHARP_RUNME) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

# Version check below also works with MS csc.exe which does not understand --version
csharp_version:
	$(CSHARPCOMPILER) --version | head -n 1
	if test -n "$(CSHARPCILINTERPRETER)" ; then "$(CSHARPCILINTERPRETER)" --version ; fi

# -----------------------------------------------------------------
# Cleaning the CSharp examples
# -----------------------------------------------------------------

csharp_clean:
	rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe *.exe.mdb gc.log `find . -name \*.cs | grep -v $(RUNME).cs`
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@CSHARPSO@

##################################################################
#####                      LUA                              ######
##################################################################

# lua flags
LUA_INCLUDE= @LUAFLAGS@
LUA_LIB    = @LUALINK@

# Extra specific dynamic linking options
LUA_DLNK   = @LUADYNAMICLINKING@
LUA_SO     = @LUA_SO@

LUA        = @LUABIN@
LUA_SCRIPT = $(SRCDIR)$(RUNME).lua

# Extra code for lua static link
LUA_INTERP = ../lua.c

# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------

lua: $(SRCDIR_SRCS)
	$(SWIG) -lua $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(LUA_INCLUDE)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) -o $(LIBPREFIX)$(TARGET)$(LUA_SO)

# -----------------------------------------------------------------
# Build a C++ dynamically loadable module
# -----------------------------------------------------------------

lua_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS)
	$(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(INCLUDES) $(LUA_INCLUDE)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO)

lua_externalhdr:
	$(SWIG) -lua -external-runtime $(TARGET)

lua_swig_cpp:
	$(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)

# -----------------------------------------------------------------
# Build statically linked Lua interpreter
# -----------------------------------------------------------------

lua_static: $(SRCDIR_SRCS)
	$(SWIG) -lua -module example $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)  $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \
	$(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET)

lua_static_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS)
	$(SWIG) -c++ -lua -module example $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \
	$(LUA_INCLUDE) $(LIBS)  $(LUA_LIB) -o $(TARGET)

# -----------------------------------------------------------------
# Run Lua example
# -----------------------------------------------------------------

lua_run:
	$(RUNTOOL) $(LUA) $(LUA_SCRIPT) $(RUNPIPE)

lua_embed_run:
	$(RUNTOOL) ./$(TARGET) $(LUA_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

lua_version:
	$(LUA) -v | head -n 1

# -----------------------------------------------------------------
# Cleaning the lua examples
# -----------------------------------------------------------------

lua_clean:
	rm -f *_wrap* *~ .~* mylua@EXEEXT@
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *$(LUA_SO)

##################################################################
#####                   ALLEGRO CL                          ######
##################################################################

ALLEGROCL    = @ALLEGROCLBIN@
ALLEGROCL_SCRIPT=$(RUNME).lisp

allegrocl: $(SRCDIR_SRCS)
	$(SWIG) -allegrocl -cwrap $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

allegrocl_cpp: $(SRCDIR_SRCS)
	$(SWIG) -c++ -allegrocl $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

# -----------------------------------------------------------------
# Run ALLEGRO CL example
# -----------------------------------------------------------------

allegrocl_run:
	$(RUNTOOL) $(ALLEGROCL) -batch -s $(ALLEGROCL_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

allegrocl_version:
	$(ALLEGROCL) --version

# -----------------------------------------------------------------
# Cleaning the ALLEGRO CL examples
# -----------------------------------------------------------------

allegrocl_clean:
	rm -f *_wrap* *~ .~*
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@

##################################################################
#####                      CFFI                             ######
##################################################################

CFFI = @CFFIBIN@
CFFI_SCRIPT=$(RUNME).lisp

cffi: $(SRCDIR_SRCS)
	$(SWIG) -cffi $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
#	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS)
#	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

cffi_cpp: $(SRCDIR_SRCS)
	$(SWIG) -c++ -cffi $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)

# -----------------------------------------------------------------
# Run CFFI example
# -----------------------------------------------------------------

cffi_run:
	$(RUNTOOL) $(CFFI) -batch -s $(CFFI_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

cffi_version:
	$(CFFI) --version

# -----------------------------------------------------------------
# Cleaning the CFFI examples
# -----------------------------------------------------------------

cffi_clean:
	rm -f *_wrap* *~ .~*
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@

##################################################################
#####                      R                                ######
##################################################################

R = R
RCXXSRCS = $(INTERFACE:.i=_wrap.cpp) #Need to use _wrap.cpp for R build system as it does not understand _wrap.cxx
RRSRC = $(INTERFACE:.i=.R)
R_CFLAGS=-fPIC
R_OPT = --slave --quiet --no-save --no-restore
R_SCRIPT=$(SRCDIR)$(RUNME).R

# need to compile .cxx files outside of R build system to make sure that
# we get -fPIC
# CMD SHLIB stdout is piped to /dev/null to prevent echo of compiler command

# ----------------------------------------------------------------
# Build a R dynamically loadable module (C)
# ----------------------------------------------------------------

r: $(SRCDIR_SRCS)
	$(SWIG) -r $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
ifneq ($(SRCDIR_SRCS),)
	$(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(R_CFLAGS) $(SRCDIR_SRCS) $(INCLUDES)
endif
	+( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CFLAGS="$(CFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null )

# ----------------------------------------------------------------
# Build a R dynamically loadable module (C++)
# ----------------------------------------------------------------
r_cpp: $(SRCDIR_CXXSRCS)
	$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
ifneq ($(SRCDIR_CXXSRCS),)
	$(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(R_CFLAGS) $(SRCDIR_CXXSRCS) $(INCLUDES)
endif
	+( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CXXFLAGS="$(CXXFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )

# -----------------------------------------------------------------
# Run R example
# -----------------------------------------------------------------

r_run:
	$(RUNTOOL) $(R) $(R_OPT) -f $(R_SCRIPT) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

r_version:
	$(R) --version | head -n 1

# -----------------------------------------------------------------
# Cleaning the R examples
# -----------------------------------------------------------------

r_clean:
	rm -f *_wrap* *~ .~*
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@ NAMESPACE
	rm -f $(RRSRC) $(RUNME).Rout .RData

##################################################################
#####                 SCILAB                                ######
##################################################################

SCILAB = @SCILAB@
SCILAB_INC= @SCILABINCLUDE@
SCILAB_OPT = @SCILABOPT@
SCILAB_LIBPREFIX = lib

# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------

scilab:
	$(SWIG) -scilab $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SCILAB_INC) $(INCLUDES) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(IOBJS) $(OBJS) $(LIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO)

# ----------------------------------------------------------------
# Build a C++ dynamically loadable module
# ----------------------------------------------------------------

scilab_cpp:
	$(SWIG) -c++ -scilab $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SCILAB_INC) $(INCLUDES) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(IOBJS) $(OBJS) $(LIBS) $(CPP_DLLIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO)

# -----------------------------------------------------------------
# Running a Scilab example
# -----------------------------------------------------------------

scilab_run:
	env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(SCILAB) $(SCILAB_OPT) -f $(SRCDIR)$(RUNME).sci $(RUNPIPE)

# -----------------------------------------------------------------
# Scilab version
# -----------------------------------------------------------------

scilab_version:
	echo `$(SCILAB) -version | head -1`

# -----------------------------------------------------------------
# Cleaning the scilab examples
# -----------------------------------------------------------------

scilab_clean:
	rm -f *_wrap* *~ .~*
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@
	rm -f *.sce

##################################################################
#####                        Go                             ######
##################################################################

# TODO: The Go make targets need simplifying to use configure time
# configuration or to use Make's ifeq rather than using lots of
# runtime shell code. The output will then be a lot less verbose.

GO = @GO@
GOGCC = @GOGCC@
GCCGO = @GCCGO@
GO1 = @GO1@
GO12 = @GO12@
GO13 = @GO13@
GO15 = @GO15@
GOC = @GOC@
GOOPT = @GOOPT@
GCCGOOPT = @GCCGOOPT@
GOVERSIONOPTION = @GOVERSIONOPTION@

GOSWIGARG = `if $(GOGCC) ; then echo -gccgo; fi`
GOCOMPILEARG = `if $(GO15); then echo tool compile; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` `if $(GO13) || $(GO15); then echo -pack ; fi`

GOSRCS = $(INTERFACE:.i=.go)
GOCSRCS = $(INTERFACE:.i=_gc.c)

GOLD = `if $(GO15); then echo link; else echo $(GOC:c=l); fi`
GOTOOL = `if $(GO1) ; then echo go tool; fi`
GOPACK = `if $(GO1) ; then echo go tool pack; else echo gopack; fi`

GOPACKAGE = $(notdir $(INTERFACE:.i=.a))

GOPATHPARENTDIR = gopath/$(GOMOD)/src
GOPATHDIR = $(GOPATHPARENTDIR)/$(INTERFACE:.i=)

GOOBJEXT = `if $(GO15); then echo o; else echo $(GOC:c=); fi`
GOGCOBJS = $(GOSRCS:.go=.$(GOOBJEXT))
GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@)

# ----------------------------------------------------------------
# Build a Go module (C)
# ----------------------------------------------------------------

$(GOPATHPARENTDIR)/go.mod:
	@mkdir gopath 2>/dev/null || true
	@mkdir gopath/$(GOMOD) 2>/dev/null || true
	@mkdir gopath/$(GOMOD)/src 2>/dev/null || true
	@mkdir $(GOPATHDIR) 2>/dev/null || true
	echo "module swigtests" > $(GOPATHDIR)/go.mod
	echo "" >> $(GOPATHDIR)/go.mod
	echo "go 1.12" >> $(GOPATHDIR)/go.mod
	mv -f $(GOPATHDIR)/go.mod $(GOPATHPARENTDIR)/go.mod

go_nocgo: $(SRCDIR_SRCS)
	$(SWIG) -go -no-cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \
	  $(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \
	else \
	  $(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \
	  $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \
	fi
	if $(GOGCC) ; then \
	  $(COMPILETOOL) $(GCCGO) -g -c -I . $(GOSRCS); \
	else \
	  $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS); \
	  $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \
	  rm -f $(GOPACKAGE); \
	  if $(GO13) || $(GO15); then \
	    cp $(GOGCOBJS) $(GOPACKAGE); \
	    $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \
	  elif $(GO12); then \
	    $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \
	  else \
	    $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \
	  fi; \
	fi
	if test -f $(SRCDIR)$(RUNME).go; then \
	  if $(GOGCC) ; then \
	    $(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \
	  elif $(GO12) || $(GO13) || $(GO15); then \
	    $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CC)" -extldflags "$(CFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  else \
	    $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  fi; \
	fi

go: $(SRCDIR_SRCS) $(GOPATHPARENTDIR)/go.mod
	$(SWIG) -go -import-prefix swigtests $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	@mkdir gopath 2>/dev/null || true
	@mkdir gopath/$(GOMOD) 2>/dev/null || true
	@mkdir gopath/$(GOMOD)/src 2>/dev/null || true
	@mkdir $(GOPATHDIR) 2>/dev/null || true
	rm -f $(GOPATHDIR)/*
	cp $(ISRCS) $(GOPATHDIR)/
	if test -f $(IWRAP:.i=.h); then \
	  cp $(IWRAP:.i=.h) $(GOPATHDIR)/; \
	fi
	if test -n "$(SRCDIR_SRCS)"; then \
	  cp $(SRCDIR_SRCS) $(GOPATHDIR)/; \
	fi
	cp $(GOSRCS) $(GOPATHDIR)/
	GOPATH=`pwd`/gopath/$(GOMOD); \
	export GOPATH; \
	CGO_CPPFLAGS="$(CPPFLAGS) $(INCLUDES) -I `cd $(SRCDIR) && pwd` -I `pwd`"; \
	export CGO_CPPFLAGS; \
	CGO_CFLAGS="$(CFLAGS)"; \
	export CGO_CFLAGS; \
	CGO_LDFLAGS="$(LDFLAGS) -lm"; \
	export CGO_LDFLAGS; \
	(cd $(GOPATHDIR)/ && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o $(GOPACKAGE))
	if $(GOGCC); then \
	  cp $(GOPATHDIR)/$(GOPACKAGE) $(GOPATHDIR)/$(GOPACKAGE:.a=.gox); \
	fi
	if test -f $(SRCDIR)$(RUNME).go; then \
	  if $(GOGCC) ; then \
	    $(COMPILETOOL) $(GCCGO) -c -g -I $(GOPATHDIR) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOPATHDIR)/$(GOPACKAGE); \
	  elif $(GO12) || $(GO13) || $(GO15); then \
	    $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I $(GOPATHDIR) -o $(RUNME).$(GOOBJEXT) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -L $(GOPATHDIR) -linkmode external -extld "$(CC)" -extldflags "$(CFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  else \
	    $(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  fi; \
	fi

# ----------------------------------------------------------------
# Build a Go module (C++)
# ----------------------------------------------------------------

go_cpp_nocgo: $(SRCDIR_SRCS)
	$(SWIG) -go -c++ -no-cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \
	  if test -n "$(SRCDIR_CXXSRCS)$(SRCDIR_SRCS)"; then \
	    $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(INCLUDES); \
	  fi; \
	  $(foreach f,$(ICXXSRCS), \
	    $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) -o $(addsuffix .@OBJEXT@,$(basename $f)) $f $(INCLUDES); \
	  ) \
	else \
	  $(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES); \
	  $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \
	fi
	if ! $(GOGCC) ; then \
	  $(foreach f,$(GOSRCS), \
	    $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . -o $(addsuffix .$(GOOBJEXT),$(basename $f)) $f \
	  ); \
	  $(foreach f,$(GOCSRCS), \
	    $(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} \
	    -o $(addsuffix .$(GOOBJEXT),$(basename $f)) $f; \
	  ) \
	  rm -f $(GOPACKAGE); \
	  if $(GO13) || $(GO15); then \
	    cp $(GOGCOBJS) $(GOPACKAGE); \
	    $(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \
	  elif $(GO12); then \
	    $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \
	  else \
	    $(COMPILETOOL) $(GOPACK) grc $(GOPACKAGE) $(GOGCOBJS) $(GOCSRCS:.c=.$(GOOBJEXT)); \
	  fi; \
	else \
	  $(foreach f,$(GOSRCS), \
	    $(COMPILETOOL) $(GCCGO) -g -c -I . -o $(addsuffix .@OBJEXT@,$(basename $f)) $f \
	  ); \
	fi
	if test -f $(SRCDIR)$(RUNME).go; then \
	  if $(GOGCC) ; then \
	    $(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \
	  elif $(GO12) || $(GO13) || $(GO15); then \
	    $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CXX)" -extldflags "$(CXXFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  else \
	    $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  fi; \
	fi

go_cpp: $(SRCDIR_SRCS) $(GOPATHPARENTDIR)/go.mod
	$(SWIG) -go -c++ -import-prefix swigtests $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	@mkdir gopath 2>/dev/null || true
	@mkdir gopath/$(GOMOD) 2>/dev/null || true
	@mkdir gopath/$(GOMOD)/src 2>/dev/null || true
	@mkdir $(GOPATHDIR) 2>/dev/null || true
	rm -f $(GOPATHDIR)/*
	cp $(ICXXSRCS) $(GOPATHDIR)/
	if test -f $(IWRAP:.i=.h); then \
	  cp $(IWRAP:.i=.h) $(GOPATHDIR)/; \
	fi
	if test -n "$(SRCDIR_CXXSRCS)"; then \
	  cp $(SRCDIR_CXXSRCS) $(GOPATHDIR)/; \
	fi
	if test -n "$(SRCDIR_SRCS)"; then \
	  cp $(SRCDIR_SRCS) $(GOPATHDIR)/; \
	fi
	cp $(GOSRCS) $(GOPATHDIR)/
	GOPATH=`pwd`/gopath/$(GOMOD); \
	export GOPATH; \
	CGO_CPPFLAGS="$(CPPFLAGS) $(INCLUDES) -I `cd $(SRCDIR) && pwd` -I `pwd`"; \
	export CGO_CPPFLAGS; \
	CGO_CFLAGS="$(CFLAGS)"; \
	export CGO_CFLAGS; \
	CGO_CXXFLAGS="$(CXXFLAGS)"; \
	export CGO_CXXFLAGS; \
	CGO_LDFLAGS="$(LDFLAGS) -lm"; \
	export CGO_LDFLAGS; \
	(cd $(GOPATHDIR) && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o $(GOPACKAGE))
	if $(GOGCC); then \
	  cp $(GOPATHDIR)/$(GOPACKAGE) $(GOPATHDIR)/$(GOPACKAGE:.a=.gox); \
	fi
	if test -f $(SRCDIR)$(RUNME).go; then \
	  if $(GOGCC) ; then \
	    $(COMPILETOOL) $(GCCGO) -g -c -I $(GOPATHDIR) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOPATHDIR)/$(GOPACKAGE) -lstdc++; \
	  elif $(GO12) || $(GO13) || $(GO15); then \
	    $(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I $(GOPATHDIR) -o $(RUNME).$(GOOBJEXT) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -L $(GOPATHDIR) -linkmode external -extld "$(CXX)" -extldflags "$(CXXFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  else \
	    $(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
	    $(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
	  fi; \
	fi

# -----------------------------------------------------------------
# Running Go example
# -----------------------------------------------------------------

go_run:
	env $(RUNTOOL) ./$(RUNME) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

go_version:
	$(GO) $(GOVERSIONOPTION)

# -----------------------------------------------------------------
# Cleaning the Go examples
# -----------------------------------------------------------------

go_clean:
	rm -f *_wrap* *_gc* *.gox .~* $(RUNME) $(GOSRCS)
	rm -rf gopath
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *.[568] *.a *@SO@

##################################################################
#####                         D                             ######
##################################################################

DLIBPREFIX = @DLIBPREFIX@

ifeq (,$(D_VERSION))
  D_VERSION = @DDEFAULTVERSION@
endif

ifeq (2,$(D_VERSION))
  SWIGD = $(SWIG) -d -d2
  DCOMPILER = @D2COMPILER@
else
  SWIGD = $(SWIG) -d
  DCOMPILER = @D1COMPILER@
endif

D_RUNME = ./$(RUNME)

# ----------------------------------------------------------------
# Build a dynamically loadable D wrapper for a C module
# ----------------------------------------------------------------

d: $(SRCDIR_SRCS)
	$(SWIGD) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
	$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES)
	$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)

# ----------------------------------------------------------------
# Build a dynamically loadable D wrapper for a C++ module
# ----------------------------------------------------------------

d_cpp: $(SRCDIR_SRCS)
	$(SWIGD) -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
	$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES)
	$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)

# ----------------------------------------------------------------
# Compile D files
# ----------------------------------------------------------------

# Clear the DFLAGS environment variable for the compiler call itself
# to work around a discrepancy in argument handling between DMD and LDC.
d_compile: $(SRCDIR_SRCS)
	DFLAGS="" $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)

# -----------------------------------------------------------------
# Run D example
# -----------------------------------------------------------------

d_run:
	env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(D_RUNME) $(RUNPIPE)

# -----------------------------------------------------------------
# Version display
# -----------------------------------------------------------------

d_version:
	# Needs improvement!
	echo D version guess - $(D_VERSION)

# -----------------------------------------------------------------
# Clean the D examples
# -----------------------------------------------------------------

d_clean:
	rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe `find . -name \*.d | grep -v $(RUNME).d`
	rm -f core @EXTRA_CLEAN@
	rm -f *.@OBJEXT@ *@SO@