forked from gap-system/gap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.rules
1296 lines (1039 loc) · 42.6 KB
/
Makefile.rules
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
########################################################################
#
# Makefile rules for GAP, to be included from GNUmakefile.
# Partially based on the git and ScummVM build systems.
#
# This requires GNU make!!! You have been warned.
#
# To learn more about the GAP build system, see README.buildsys.md
#
########################################################################
########################################################################
# Default rule: build gap
########################################################################
all: gap$(EXEEXT) gac libgap CITATION doc/versiondata build/gap
.PHONY: all
# Backwards compatibility: add "default" target as alias for "all"
default: all
.PHONY: default
########################################################################
# Source files
#
# We avoid line continuations, instead use repeatedly "SOURCES+=". This
# makes it trivial to comment out lines, or to insert conditionals.
########################################################################
SOURCES =
SOURCES += src/ariths.c
SOURCES += src/bags.c
SOURCES += src/blister.c
SOURCES += src/bool.c
SOURCES += src/calls.c
SOURCES += src/code.c
SOURCES += src/collectors.cc
SOURCES += src/compiler.c
SOURCES += src/costab.c
SOURCES += src/cyclotom.c
SOURCES += src/debug.c
SOURCES += src/dt.c
SOURCES += src/dteval.c
SOURCES += src/error.c
SOURCES += src/exprs.c
SOURCES += src/finfield.c
SOURCES += src/funcs.c
SOURCES += src/gap.c
SOURCES += src/gaptime.c
SOURCES += build/version.c # generated source file
SOURCES += src/gvars.c
SOURCES += src/hookintrprtr.c
SOURCES += src/info.c
SOURCES += src/integer.c
SOURCES += src/intfuncs.c
SOURCES += src/intrprtr.c
SOURCES += src/io.c
SOURCES += src/iostream.c
ifeq ($(HPCGAP),no) # we don't support a kernel API in HPC-GAP atm
SOURCES += src/libgap-api.c
endif
SOURCES += src/listfunc.c
SOURCES += src/listoper.c
SOURCES += src/lists.c
SOURCES += src/macfloat.c
SOURCES += src/modules_builtin.c
SOURCES += src/modules.c
SOURCES += src/objcftl.c
SOURCES += src/objects.c
SOURCES += src/objfgelm.cc
SOURCES += src/objpcgel.cc
SOURCES += src/objset.c
SOURCES += src/opers.cc
SOURCES += src/permutat.cc
SOURCES += src/plist.c
SOURCES += src/pperm.cc
SOURCES += src/precord.c
SOURCES += src/profile.c
SOURCES += src/range.c
SOURCES += src/rational.c
SOURCES += src/read.c
SOURCES += src/records.c
SOURCES += src/saveload.c
SOURCES += src/scanner.c
SOURCES += src/sctable.c
SOURCES += src/sha256.c
SOURCES += src/set.c
SOURCES += src/stats.c
SOURCES += src/streams.c
SOURCES += src/stringobj.c
SOURCES += src/symbols.c
SOURCES += src/syntaxtree.c
SOURCES += src/sysfiles.c
SOURCES += src/sysroots.c
SOURCES += src/sysstr.c
SOURCES += src/system.c
SOURCES += src/tietze.c
SOURCES += src/tracing.c
SOURCES += src/trans.cc
SOURCES += src/trycatch.c
SOURCES += src/vars.c
SOURCES += src/vec8bit.c
SOURCES += src/vecffe.c
SOURCES += src/vecgf2.c
SOURCES += src/vector.c
SOURCES += src/weakptr.c
SOURCES += $(GC_SOURCES)
ifeq ($(HPCGAP),yes)
SOURCES += src/hpc/aobjects.c
SOURCES += src/hpc/cpu.c
SOURCES += src/hpc/misc.c
SOURCES += src/hpc/region.c
SOURCES += src/hpc/serialize.c
SOURCES += src/hpc/thread.c
SOURCES += src/hpc/threadapi.c
SOURCES += src/hpc/tls.c
SOURCES += src/hpc/traverse.c
endif
# allow overriding ffdata.c with a fixed version for cross compilation
ifneq ("$(wildcard $(srcdir)/src/ffdata.c)","")
SOURCES += src/ffdata.c
else
SOURCES += build/ffdata.c
endif
# allow overriding ffdata.h with a fixed version for cross compilation
ifneq ("$(wildcard $(srcdir)/src/ffdata.h)","")
FFDATA_H := $(srcdir)/src/ffdata.h
else
FFDATA_H := $(builddir)/build/ffdata.h
endif
# deal with C sources generated by gac
SOURCES_NOCOMP := $(SOURCES)
SOURCES_NOCOMP += src/compstat_empty.c
SOURCES_NOCOMP += src/main.c
SOURCE_C_OPER1 := $(builddir)/build/c_oper1.c
SOURCE_C_TYPE1 := $(builddir)/build/c_type1.c
ifeq ($(HPCGAP),yes)
ifneq ("$(wildcard $(srcdir)/src/hpc/c_oper1.c)","")
SOURCE_C_OPER1 := $(srcdir)/src/hpc/c_oper1.c
endif
ifneq ("$(wildcard $(srcdir)/src/hpc/c_type1.c)","")
SOURCE_C_TYPE1 := $(srcdir)/src/hpc/c_type1.c
endif
else
ifneq ("$(wildcard $(srcdir)/src/c_oper1.c)","")
SOURCE_C_OPER1 := $(srcdir)/src/c_oper1.c
endif
ifneq ("$(wildcard $(srcdir)/src/c_type1.c)","")
SOURCE_C_TYPE1 := $(srcdir)/src/c_type1.c
endif
endif
SOURCES += $(SOURCE_C_OPER1) $(SOURCE_C_TYPE1)
SOURCES += src/compstat.c
SOURCES_ALL := $(SOURCES)
SOURCES_ALL += src/compstat_empty.c
SOURCES_ALL += src/main.c
########################################################################
#
########################################################################
SYSINFO_CC := $(CC)
SYSINFO_CXX := $(CXX)
########################################################################
# Preprocessor flags
#
# GAP_CPPFLAGS is for the GAP build system, while SYSINFO_CPPFLAGS is
# for use by gac, and for package build systems. The latter does not
# contain warning flags, and uses absolute include paths.
########################################################################
GAP_CPPFLAGS =
SYSINFO_CPPFLAGS =
# First add include paths
# The "build/" directory contains generated header files and thus is
# placed into the list of include directories.
GAP_CPPFLAGS += -I$(builddir)/build
SYSINFO_CPPFLAGS += -I$(abs_builddir)/build
# The other source files are relative to the srcdir
GAP_CPPFLAGS += -I$(srcdir)/src
SYSINFO_CPPFLAGS += -I$(abs_srcdir)/src
# For backwards compatibility with certain packages and their kernel
# extensions, also add the root of the srcdir to the package CPPFLAGS
SYSINFO_CPPFLAGS += -I$(abs_srcdir)
# Add GAP_DEFINES (from autoconf, contains -D flags)
GAP_CPPFLAGS += $(GAP_DEFINES)
SYSINFO_CPPFLAGS += $(GAP_DEFINES)
# Add flags for dependencies
GAP_CPPFLAGS += $(GMP_CPPFLAGS)
GAP_CPPFLAGS += $(ZLIB_CPPFLAGS)
GAP_CPPFLAGS += $(READLINE_CPPFLAGS)
GAP_CPPFLAGS += $(BOEHM_GC_CPPFLAGS)
GAP_CPPFLAGS += $(LIBATOMIC_OPS_CPPFLAGS)
# For packages, only libatomic headers are needed, as they are
# used in hpc/atomic.h
SYSINFO_CPPFLAGS += $(LIBATOMIC_OPS_CPPFLAGS)
# Finally add user provided flags
GAP_CPPFLAGS += $(CPPFLAGS)
SYSINFO_CPPFLAGS += $(CPPFLAGS)
########################################################################
# C compiler flags
########################################################################
GAP_CFLAGS = $(ABI_CFLAGS)
SYSINFO_CFLAGS = $(ABI_CFLAGS)
GAP_CFLAGS += $(PTHREAD_CFLAGS)
SYSINFO_CFLAGS += $(PTHREAD_CFLAGS)
GAP_CFLAGS += $(JULIA_CFLAGS) # not added to SYSINFO_CFLAGS
# Finally add user provided CFLAGS
GAP_CFLAGS += $(CFLAGS)
SYSINFO_CFLAGS += $(CFLAGS)
########################################################################
# C++ compiler flags
########################################################################
GAP_CXXFLAGS = $(ABI_CFLAGS)
SYSINFO_CXXFLAGS = $(ABI_CFLAGS)
GAP_CXXFLAGS += $(PTHREAD_CFLAGS)
SYSINFO_CXXFLAGS += $(PTHREAD_CFLAGS)
# Finally add user provided CXXFLAGS
GAP_CXXFLAGS += $(CXXFLAGS)
SYSINFO_CXXFLAGS += $(CXXFLAGS)
########################################################################
# Linker flags
########################################################################
GAP_LDFLAGS = $(ABI_CFLAGS)
SYSINFO_LDFLAGS = $(ABI_CFLAGS)
# Add flags for dependencies
GAP_LDFLAGS += $(GMP_LDFLAGS)
GAP_LDFLAGS += $(ZLIB_LDFLAGS)
GAP_LDFLAGS += $(READLINE_LDFLAGS)
GAP_LDFLAGS += $(JULIA_LDFLAGS)
GAP_LDFLAGS += $(BOEHM_GC_LDFLAGS)
GAP_LDFLAGS += $(LIBATOMIC_OPS_LDFLAGS)
GAP_LDFLAGS += $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
# Finally add user provided flags
GAP_LDFLAGS += $(LDFLAGS)
SYSINFO_LDFLAGS += $(LDFLAGS)
# libs
GAP_LIBS =
# Add flags for dependencies
GAP_LIBS += $(GMP_LIBS)
GAP_LIBS += $(ZLIB_LIBS)
GAP_LIBS += $(READLINE_LIBS)
GAP_LIBS += $(JULIA_LIBS)
GAP_LIBS += $(BOEHM_GC_LIBS)
GAP_LIBS += $(LIBATOMIC_OPS_LIBS)
# Finally add user provided flags
GAP_LIBS += $(LIBS)
########################################################################
# gac flags
########################################################################
#
# Determine flags for building kernel extensions for use in GAC
#
# For now we basically support GCC and clang, on Linux/macOS/Windows,
# and as a side effect also some other systems such as FreeBSD.
# Support for other compilers or operating systems will require some
# extra tweaks.
#
ifneq (,$(findstring cygwin,$(host_os)))
GAC_CFLAGS =
GAC_LDFLAGS = -shared -Wl,$(abs_builddir)/bin/$(GAPARCH)/gap.dll -Wl,--enable-auto-image-base
# Note: the above won't be correct after "make install"; but then I am not
# sure we care about "make install" on Cygwin, so I am not going to work on
# this until someone specifically asks for it (and even then I'll require
# that person to help test it)
else
ifneq (,$(findstring darwin,$(host_os)))
GAC_CFLAGS = -fno-common
GAC_LDFLAGS = -bundle -undefined dynamic_lookup -Wl,-no_fixup_chains
else
GAC_CFLAGS = -fPIC
GAC_LDFLAGS = -shared -fPIC
endif
endif
########################################################################
# additional settings for use in sysinfo.gap
########################################################################
# paths to gap and gac executable
SYSINFO_GAP = $(abs_builddir)/gap
SYSINFO_GAC = $(abs_builddir)/gac
########################################################################
# Object files
########################################################################
# OBJS shall contain the names of all object files that constitute GAP.
# So turn all FOO/bar.c and FOO/bar.cc file names in SOURCES into
# build/obj/FOO/bar.c.o resp. build/obj/FOO/bar.cc.o
OBJS = $(patsubst %,build/obj/%.o,$(SOURCES))
OBJS_NOCOMP = $(patsubst %,build/obj/%.o,$(SOURCES_NOCOMP))
########################################################################
# Quiet rules.
#
# Replace regular output with quiet messages, unless V is set,
# e.g. "make V=1"
########################################################################
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
QUIET_CC = @echo " C $< => $(OBJFILE)";
QUIET_CXX = @echo " CXX $< => $(OBJFILE)";
QUIET_LINK = @echo " LINK $@";
QUIET_SED = @echo " SED $< => $@";
QUIET = @
endif
endif
########################################################################
# Rules for automatic header dependency tracking.
#
# This is somewhat similar to what automake does, but relies on compiler
# support. The result is much simpler.
#
# So, here is what happens :We instruct the compiler via some flags to
# create a "build/deps/FOO.d" file whenever it compiles "FOO.c". This file
# encodes the header dependencies of "FOO.c" in a way that make can read
# (i.e. simply as a bunch of make targets with dependencies). Then, to
# let make track the header dependencies, we include the *.d files.
#
# For a detailed explanation of a very similar scheme, read this:
# https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
#
########################################################################
# List of all dependency tracking files, derived from SOURCES; the use of
# wildcard ensures that only existing files are listed
DEPFILES = $(wildcard $(patsubst %,build/deps/%.d,$(SOURCES_ALL)))
# Include the dependency tracking files
-include $(DEPFILES)
# the name of the .d and .o file generated by one of our compiler
# rules; you may wonder why we don't just use $@ here: this is needed
# because our compile rules have two targets, the .o and the .d file;
# and the value of $@ will be whichever of the two files triggered the
# compiler rule, so we cannot use it directly
DEPFILE = build/deps/$(*D)/$(<F).d
OBJFILE = build/obj/$(*D)/$(<F).o
# The following flags instruct the compiler to enable advanced
# dependency tracking. Supported by GCC 3 and newer; clang; Intel C
# compiler; and more.
#
# TODO: use configure to compute DEPFLAGS, so that we can
# disable it for compilers that don't support it, resp. replace it
# something that works for that compiler
DEPFLAGS = -MQ $(OBJFILE) -MMD -MP -MF $(DEPFILE)
########################################################################
# Compiler rules
#
# Note that these rules have two targets, the .o and the .d file; this
# models their relationship accurately and allows us to deal with some
# corner cases, e.g. when switching branches after a file got renamed;
# unfortunately it also means we can't just use $@ here (see comments on
# DEPFILE and OBJFILE above)
########################################################################
obj_deps = build/config.h build/version.h $(FFDATA_H)
# Build rule for C++ source files
#
# We disable support for exceptions and RTTI as we don't use them and they
# cause compiler/linker issues in some build configurations; but we are
# careful to not put these into GAP_CXXFLAGS, as kernel extensions may want to
# use GAP_CXXFLAGS but also may need to interface with C++ code in
# libraries that use exceptions.
build/obj/%.cc.o: %.cc cnf/GAP-CXXFLAGS cnf/GAP-CPPFLAGS $(obj_deps)
@$(MKDIR_P) build/obj/$(*D) build/deps/$(*D)
$(QUIET_CXX)$(CXX) $(DEPFLAGS) $(GAP_CXXFLAGS) -fno-exceptions -fno-rtti $(WARN_CXXFLAGS) $(GAP_CPPFLAGS) -c $< -o $(OBJFILE)
@echo "$<:" >> $(DEPFILE)
# Build rule for C source files
build/obj/%.c.o: %.c cnf/GAP-CFLAGS cnf/GAP-CPPFLAGS $(obj_deps)
@$(MKDIR_P) build/obj/$(*D) build/deps/$(*D)
$(QUIET_CC)$(CC) $(DEPFLAGS) $(GAP_CFLAGS) $(WARN_CFLAGS) $(GAP_CPPFLAGS) -c $< -o $(OBJFILE)
@echo "$<:" >> $(DEPFILE)
########################################################################
# Linker rules for gap executable
########################################################################
LINK=$(CC)
SHLIB_MAJOR = $(GAP_KERNEL_MAJOR_VERSION)
ifneq (,$(findstring cygwin,$(host_os)))
SHLIB_EXT=.dll
LIBGAP_FULL = libgap$(SHLIB_EXT)
LINK_SHLIB_FLAGS = -shared -Wl,--enable-auto-image-base -Wl,--out-implib,libgap.dll.a
else ifneq (,$(findstring darwin,$(host_os)))
SHLIB_EXT=.dylib
LIBGAP_FULL = libgap.$(SHLIB_MAJOR)$(SHLIB_EXT)
LIBGAP_COMPAT_VER = $(shell expr $(GAP_KERNEL_MAJOR_VERSION) + 1 )
LIBGAP_CURRENT_VER = $(LIBGAP_COMPAT_VER).$(GAP_KERNEL_MINOR_VERSION)
LINK_SHLIB_FLAGS = -dynamiclib
LINK_SHLIB_FLAGS += -compatibility_version $(LIBGAP_COMPAT_VER)
LINK_SHLIB_FLAGS += -current_version $(LIBGAP_CURRENT_VER)
LINK_SHLIB_FLAGS += -Wl,-single_module
LINK_SHLIB_FLAGS += -headerpad_max_install_names
GAP_CPPFLAGS += -DPIC
GAP_CFLAGS += -fno-common
GAP_CXXFLAGS += -fno-common
else
# Note: the following was tested on Linux -- patches making this work better
# on e.g. FreeBSD/OpenBSD/... are highly welcome
SHLIB_EXT=.so
LIBGAP_FULL = libgap$(SHLIB_EXT).$(SHLIB_MAJOR)
LINK_SHLIB_FLAGS = -shared -fPIC -DPIC -Wl,-soname,$(LIBGAP_FULL)
GAP_CPPFLAGS += -DPIC
GAP_CFLAGS += -fPIC
GAP_CXXFLAGS += -fPIC
GAP_LDFLAGS += -Wl,--export-dynamic
endif
ifneq (,$(findstring darwin,$(host_os)))
INSTALL_NAME_TOOL = @install_name_tool
else
INSTALL_NAME_TOOL = @echo > /dev/null
endif
libgap: libgap$(SHLIB_EXT) $(LIBGAP_FULL)
.PHONY: libgap
# Linking rule and dependencies for libgap
$(LIBGAP_FULL): $(OBJS) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
$(QUIET_LINK)$(LINK) -o $@ $(LINK_SHLIB_FLAGS) $(GAP_LDFLAGS) $(OBJS) $(GAP_LIBS)
ifneq (,$(findstring cygwin,$(host_os)))
# increase stack size, the default is too small (see issue #1522)
GAP_LDFLAGS += -Wl,--stack,16777216
# Allow multiple definitions so we can declare a function multiple times with 'extern inline'
GAP_LDFLAGS += -Wl,--allow-multiple-definition
# Special build rules for CYGWIN / Windows: In order to allow kernel
# extensions, we employ a trick: GAP itself is compiled into DLL, in which
# GAP's standard main function is renamed. And gap.exe is a tiny binary which
# loads that DLL and calls the renamed main function.
all: bin/$(GAPARCH)/gap.dll
bin/$(GAPARCH)/gap.dll: libgap$(SHLIB_EXT)
@$(MKDIR_P) bin/$(GAPARCH)
cp $< $@
# build rule for the main gap executable
gap$(EXEEXT): build/obj/src/main.c.o libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) -Wl,--export-all-symbols $< $(GAP_LIBS) -L${abs_builddir} -lgap -o $@
@( if which peflags > /dev/null ; then peflags --cygwin-heap=2048 gap$(EXEEXT) ; fi )
else
# create a symlink libgap.so -> libgap.so.9 resp. libgap.dylib -> libgap.9.dylib
libgap$(SHLIB_EXT): $(LIBGAP_FULL)
@rm -f $@
ln -sf $< $@
# build rule for the main gap executable
gap$(EXEEXT): build/obj/src/main.c.o $(OBJS) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) $< $(OBJS) $(GAP_LIBS) -o $@
# generate a modified copy of main.c for use by the `gap-install` binary
build/main.c: src/main.c config.status
@echo "#define SYS_DEFAULT_PATHS \"$(libdir)/gap;$(datarootdir)/gap\"" > $@
@cat $< >> $@
# build rule for the gap executable used by the `install-bin` target
build/gap-install: build/obj/build/main.c.o libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) $< $(GAP_LIBS) -L${abs_builddir} -lgap -o $@
$(INSTALL_NAME_TOOL) -change $(LIBGAP_FULL) $(libdir)/$(LIBGAP_FULL) $@
endif
########################################################################
# Rules for rebuilding C code generated from GAP code via gac.
########################################################################
build/gap-nocomp$(EXEEXT): $(OBJS_NOCOMP) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) $(OBJS_NOCOMP) $(GAP_LIBS) -o $@
build/c_%.c: $(srcdir)/lib/%.g build/gap-nocomp$(EXEEXT)
@$(MKDIR_P) $(@D)
@"$(abs_srcdir)"/cnf/gap-c-gen.sh $< $@ $(basename $(notdir $<)) build/gap-nocomp$(EXEEXT)
.PRECIOUS: build/c_%.c
########################################################################
# The "ffdata" target regenerates build/ffdata.{c,h} using etc/ffgen.c
########################################################################
ffgen: $(srcdir)/etc/ffgen.c src/common.h build/config.h
$(QUIET_CC)$(CC) -Wall -Wextra $(GAP_CPPFLAGS) $< -o $@
build/ffdata.h build/ffdata.c: ffgen
./ffgen -b build/ffdata
########################################################################
# The "tags" target regenerates the tags file using Exuberant Ctags
########################################################################
tags:
cd $(abs_srcdir) && etc/tags.sh --recurse lib hpcgap/lib src
etags:
cd $(abs_srcdir) && etc/tags.sh -e --recurse lib hpcgap/lib src
.PHONY: tags etags
########################################################################
# Rules for 'make clean'
########################################################################
distclean: clean
rm -rf autom4te.cache
rm -f config.log config.status GNUmakefile
rm -f doc/make_doc
rm -f doc/*/*.aux doc/*/*.bbl doc/*/*.blg doc/*/*.brf doc/*/*.idx doc/*/*.ilg doc/*/*.ind doc/*/*.log doc/*/*.out doc/*/*.pnr doc/*/*.tex doc/*/*.toc
rm -rf tags
rm -rf TAGS
clean:
rm -rf bin/$(GAPARCH)
rm -rf build
rm -rf extern/build extern/install
rm -f bin/gap.sh sysinfo.gap*
rm -f gap$(EXEEXT) gac ffgen
rm -f libgap$(SHLIB_EXT) $(LIBGAP_FULL)
rm -f libgap.pc
rm -rf .libs
rm -f doc/wsp.g
rm -f cnf/GAP-*
rmdir bin cnf dev doc extern src 2>/dev/null || : # remove dirs if they are now empty
.PHONY: clean distclean
########################################################################
# Rules for 'make install'
#
#
# WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING
#
# The following code has not yet been tested very extensively, so use at your
# own peril -- that said, if you find any issues with them NOT COVERED BELOW
# or have suggestions for improvements, please contact us.
#
# The main thing that is missing (no need to inform us about it) is that it
# does not install packages -- doing so is tricky, depending on what
# assumptions one is willing to make or require; we may never support this
# *here*; instead individual packages may gain a `make install`. How to
# go about this exactly has not yet been decided.
#
########################################################################
install: install-bin install-doc install-gaproot install-sysinfo install-headers install-libgap
@echo "+--------------------------------------------------------------------------+"
@echo "| WARNING, 'make install' support is still experimental, and may be buggy. |"
@echo "| It also does not take care of installing GAP packages (and may never). |"
@echo "| |"
@echo "| If you observe any issues with 'make install', please report them to us |"
@echo "| via support@gap-system.org or https://github.com/gap-system/gap/issues |"
@echo "+--------------------------------------------------------------------------+"
install-bin: build/gap-install
# install a special build of gap with SYS_DEFAULT_PATHS set suitably
$(INSTALL) -d -m 0755 $(DESTDIR)$(bindir)
$(INSTALL) -m 0755 build/gap-install $(DESTDIR)$(bindir)/gap
# for backwards compatibility, also install it into $(libdir)/gap
$(INSTALL) -d -m 0755 $(DESTDIR)$(libdir)/gap
$(INSTALL) -m 0755 build/gap-install $(DESTDIR)$(libdir)/gap/gap
# install gac
sed -e "s;@SYSINFO_GAPROOT@;$(libdir)/gap;" < $(srcdir)/cnf/gac.in > $(DESTDIR)$(bindir)/gac
chmod 0755 $(DESTDIR)$(bindir)/gac
install-doc:
# TODO: should this depend on the 'doc' target? but that target is phony
# and will re-run each time it is invoked, which is not really what we want.
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap/doc
$(INSTALL) -m 0644 $(srcdir)/doc/gapmacro.tex $(DESTDIR)$(datarootdir)/gap/doc/
$(INSTALL) -m 0644 $(srcdir)/doc/manualindex $(DESTDIR)$(datarootdir)/gap/doc/
for book in ref tut hpc ; do \
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap/doc/$$book ; \
for ext in css html js txt pdf six lab; do \
$(INSTALL) -m 0644 $(srcdir)/doc/$$book/*.$$ext $(DESTDIR)$(datarootdir)/gap/doc/$$book/ ; \
done \
done
# install most of the GAP "root" directory (containing arch independent files),
# with a few exceptions: the `doc` dir is installed by `install-doc`, and
# `install-sysinfo` creates `sysinfo.gap`
install-gaproot: CITATION
# create subdirectories
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap/pkg
# install GAP library files
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap/hpcgap
for dir in grp lib lib/hpc hpcgap/lib hpcgap/lib/hpc hpcgap/lib/distributed ; do \
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap/$$dir ; \
$(INSTALL) -m 0644 $(srcdir)/$$dir/*.g* $(DESTDIR)$(datarootdir)/gap/$$dir ; \
done
# install various files in the root dir
$(INSTALL) -m 0644 CITATION $(DESTDIR)$(datarootdir)/gap/
$(INSTALL) -m 0644 $(srcdir)/CONTRIBUTING.md $(DESTDIR)$(datarootdir)/gap/
$(INSTALL) -m 0644 $(srcdir)/COPYRIGHT $(DESTDIR)$(datarootdir)/gap/
$(INSTALL) -m 0644 $(srcdir)/INSTALL.md $(DESTDIR)$(datarootdir)/gap/
$(INSTALL) -m 0644 $(srcdir)/LICENSE $(DESTDIR)$(datarootdir)/gap/
$(INSTALL) -m 0644 $(srcdir)/README.md $(DESTDIR)$(datarootdir)/gap/
# install helpers for developers
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap/etc
$(INSTALL) -m 0755 $(srcdir)/etc/convert.pl $(DESTDIR)$(datarootdir)/gap/etc/
$(INSTALL) -d -m 0755 $(DESTDIR)$(datarootdir)/gap/etc/vim
$(INSTALL) -m 0644 $(srcdir)/etc/vim/*.* $(DESTDIR)$(datarootdir)/gap/etc/vim/
# the following lines adjust variables for the installed sysinfo.gap
install-sysinfo: SYSINFO_CPPFLAGS = -I${includedir}/gap -I${includedir} $(GAP_DEFINES)
install-sysinfo: SYSINFO_LDFLAGS = $(ABI_CFLAGS)
install-sysinfo: SYSINFO_GAP = $(bindir)/gap
install-sysinfo: SYSINFO_GAC = $(bindir)/gac
install-sysinfo: GMP_PREFIX =
install-sysinfo:
$(INSTALL) -d -m 0755 $(DESTDIR)$(libdir)/gap
@echo "$$sysinfo_gap" > $(DESTDIR)$(libdir)/gap/sysinfo.gap
chmod 0644 $(DESTDIR)$(libdir)/gap/sysinfo.gap
# install kernel headers
install-headers: $(FFDATA_H) build/version.h
$(INSTALL) -d -m 0755 $(DESTDIR)$(includedir)/gap
$(INSTALL) -m 0644 $(srcdir)/src/*.h $(DESTDIR)$(includedir)/gap
$(INSTALL) -m 0644 $(FFDATA_H) $(DESTDIR)$(includedir)/gap
$(INSTALL) -m 0644 $(builddir)/build/version.h $(DESTDIR)$(includedir)/gap
$(INSTALL) -d -m 0755 $(DESTDIR)$(includedir)/gap/hpc
$(INSTALL) -m 0644 $(srcdir)/src/hpc/*.h $(DESTDIR)$(includedir)/gap/hpc
install-libgap: $(LIBGAP_FULL) libgap.pc
$(INSTALL) -d -m 0755 $(DESTDIR)$(libdir)
$(INSTALL) -m 0644 $(LIBGAP_FULL) $(DESTDIR)$(libdir)
ln -sf $(LIBGAP_FULL) $(DESTDIR)$(libdir)/libgap$(SHLIB_EXT)
$(INSTALL_NAME_TOOL) -id $(libdir)/$(LIBGAP_FULL) $(DESTDIR)$(libdir)/$(LIBGAP_FULL)
$(INSTALL) -d -m 0755 $(DESTDIR)$(libdir)/pkgconfig
$(INSTALL) -m 0644 libgap.pc $(DESTDIR)$(libdir)/pkgconfig
.PHONY: install install-bin install-doc install-gaproot install-headers install-libgap
########################################################################
# Building subprojects
########################################################################
# master target for external dependencies / subprojects
EXTERN_FILES =
# pass on some settings to external dependencies / subprojects which use
# autoconf; this is helpful for cross compilation
EXTERN_CONFIGFLAGS := \
CC="$(CC)" \
CXX="$(CXX)" \
--build="$(build)" \
--host="$(host)"
#
# GMP
#
ifeq ($(BUILD_GMP),yes)
GMP_BUILDDIR := extern/build/gmp
# GMP_PREREQ := $(GMP_BUILDDIR)/config.status
GMP_FILES := $(GMP_PREFIX)/lib/libgmp.la
EXTERN_FILES += $(GMP_FILES)
# Note: we pass the ABI flag to gmp, and also --enable-shared ; the latter
# is there for the benefit of cygwin builds, where GMP otherwise defaults
# to building only a static library.
# We touch gmp.info so GMP does not think it is out of date and rebuilds it,
# because that requires makeinfo
gmp: $(GMP_FILES)
$(GMP_FILES):
touch "$(abs_srcdir)/extern/gmp/doc/gmp.info"
MAKE=$(MAKE) $(srcdir)/cnf/build-extern.sh gmp "$(abs_srcdir)/extern/gmp" \
$(EXTERN_CONFIGFLAGS) \
ABI="$(ABI)" \
--disable-static \
--enable-shared
.PHONY: gmp
# TODO: add clean, distclean, check targets?
# TODO: pass on cachfile?
# TODO: pass on certain *FLAGS ?
else
gmp:
echo "Using external GMP, nothing to do be done"
endif # BUILD_GMP
#
# ZLIB
#
ifeq ($(BUILD_ZLIB),yes)
ZLIB_BUILDDIR := extern/build/zlib
ZLIB_PREFIX := extern/install/zlib
# ZLIB_PREREQ := $(ZLIB_BUILDDIR)/config.status
ZLIB_FILES := $(ZLIB_PREFIX)/include/zlib.h
EXTERN_FILES += $(ZLIB_FILES)
zlib: $(ZLIB_FILES)
ifneq (,$(findstring cygwin,$(host_os)))
$(ZLIB_FILES):
MAKE=$(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" $(srcdir)/cnf/build-cygwin-zlib.sh
else
$(ZLIB_FILES):
MAKE=$(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" $(srcdir)/cnf/build-extern.sh zlib "$(abs_srcdir)/extern/zlib"
endif
.PHONY: zlib
# TODO: add clean, distclean, check targets?
# TODO: pass on cachfile?
# TODO: pass on certain *FLAGS ?
else
zlib:
echo "Using external zlib, nothing to do be done"
endif # BUILD_ZLIB
#
# libatomic_ops
#
ifeq ($(BUILD_LIBATOMIC_OPS),yes)
LIBATOMIC_OPS_BUILDDIR := extern/build/libatomic_ops
LIBATOMIC_OPS_PREFIX := extern/install/libatomic_ops
#LIBATOMIC_OPS_PREREQ := $(LIBATOMIC_OPS_BUILDDIR)/config.status
LIBATOMIC_OPS_FILES := $(LIBATOMIC_OPS_PREFIX)/lib/libatomic_ops.la
EXTERN_FILES += $(LIBATOMIC_OPS_FILES)
libatomic_ops: $(LIBATOMIC_OPS_FILES)
$(LIBATOMIC_OPS_FILES):
MAKE=$(MAKE) $(srcdir)/cnf/build-extern.sh libatomic_ops "$(abs_srcdir)/hpcgap/extern/libatomic_ops" \
$(EXTERN_CONFIGFLAGS) \
--disable-static \
--enable-shared
.PHONY: libatomic_ops
endif # BUILD_LIBATOMIC_OPS
#
# Boehm GC
#
ifeq ($(BUILD_BOEHM_GC),yes)
# TODO: ensure Boehm GC is built *after* libatomic_ops, at least if
# we are building or own libatomic_ops.
# Also, ensure that it uses the right version of libatomic_ops,
# by passing --with-libatomic-ops=...
# TODO: refactor code which handles dependencies like GMP, Boehm, libatomic,
# to reduce code duplication.
BOEHM_GC_BUILDDIR := extern/build/gc
BOEHM_GC_PREFIX := extern/install/gc
#BOEHM_GC_PREREQ := $(BOEHM_GC_BUILDDIR)/config.status
BOEHM_GC_FILES := $(BOEHM_GC_PREFIX)/lib/libgc.la
EXTERN_FILES += $(BOEHM_GC_FILES)
boehm: gc # alias
gc: $(BOEHM_GC_FILES)
$(BOEHM_GC_FILES):
MAKE=$(MAKE) $(srcdir)/cnf/build-extern.sh gc "$(abs_srcdir)/hpcgap/extern/gc" \
$(EXTERN_CONFIGFLAGS) \
ATOMIC_OPS_CFLAGS="$(LIBATOMIC_OPS_CPPFLAGS)" \
ATOMIC_OPS_LIBS="$(LIBATOMIC_OPS_LDFLAGS)" \
--disable-static \
--enable-shared \
--enable-large-config
ifeq ($(BUILD_LIBATOMIC_OPS),yes)
$(BOEHM_GC_FILES): $(LIBATOMIC_OPS_FILES)
endif
.PHONY: boehm gc
endif # BUILD_BOEHM_GC
# ensure subprojects are built and "installed" before compiling and linking GAP
gap$(EXEEXT): $(EXTERN_FILES)
$(OBJS): $(EXTERN_FILES)
$(OBJS_NOCOMP): $(EXTERN_FILES)
ifeq ($(HPCGAP),yes)
$(SOURCES): $(EXTERN_FILES)
endif
#
# regenerate sysinfo.gap if necessary
#
define sysinfo_gap
# This file has been generated by the GAP build system,
# DO NOT EDIT MANUALLY!
# This file exists for use by the GAP compiler `gac` and also by the build
# systems of GAP packages.
#
# It is deliberately written in a way that makes it usable from shell scripts
# *and* Makefiles: It only consists of comment lines like this one, starting
# with a '#'; blank linkes; or lines containing assignments of the form
# VARIABLE_NAME="CONTENT"
# GAParch: the "architecture" of this GAP build. First comes the result of
# `config.guess`. Next one of the strings "-default", "-hpcgap", "-julia" to
# indicate various major build variants of GAP. Then the ABI (32 or 64). Then
# a string of the form '-kvNNN' where NNN is the GAP kernel major version.
#
# Used to decide where to load package binaries from (to support installing
# binaries for multiple architectures in parallel on a single computer).
GAParch=$(GAPARCH)
# GAP_ABI: indicates whether GAP was built in 32 or 64 bit mode.
# Deprecated, may be removed in a future GAP release.
# Possible values: 32, 64
GAP_ABI=$(ABI)
# GAP_HPCGAP: indicates whether HPC-GAP support was compiled in.
# Possible values: yes, no
GAP_HPCGAP=$(HPCGAP)
# GAP_VERSION: GAP version.
GAP_VERSION="$(GAP_VERSION)"
# GAP_BUILD_VERSION: GAP build version. For releases, this is identical to
# GAP_VERSION. For development builds, it is the version followed by extra
# data indicating which git commit the build was based on
GAP_BUILD_VERSION="$(GAP_BUILD_VERSION)"
# GAP_KERNEL_{MAJOR,MINOR}_VERSION: the GAP kernel version (both integer values).
GAP_KERNEL_MAJOR_VERSION=$(GAP_KERNEL_MAJOR_VERSION)
GAP_KERNEL_MINOR_VERSION=$(GAP_KERNEL_MINOR_VERSION)
# GAP: path to the `gap` executable (may be a shell script)
GAP="$(SYSINFO_GAP)"
# GAC: path to the `gac` executable (may be a shell script)
GAC="$(SYSINFO_GAC)"
# File extension used by object files created by GAC
GAP_OBJEXT=o
# Build flags for use by `gac` resp. package build systems: these correspond to
# the usual variables as used by e.g. autotools, with the added prefix `GAP_`.
GAP_CC="$(SYSINFO_CC)"
GAP_CXX="$(SYSINFO_CXX)"
GAP_CFLAGS="$(SYSINFO_CFLAGS)"
GAP_CXXFLAGS="$(SYSINFO_CXXFLAGS)"
GAP_CPPFLAGS="$(SYSINFO_CPPFLAGS)"
GAP_LDFLAGS="$(SYSINFO_LDFLAGS)"
# Extra flags for use by `gac`
GAC_CFLAGS="$(GAC_CFLAGS)"
GAC_LDFLAGS="$(GAC_LDFLAGS)"
# For packages: the search prefix for GMP used by GAP
# (this is left empty when none was specified, or when
# GAP is installed via 'make install')
GMP_PREFIX="$(GMP_PREFIX)"
endef
export sysinfo_gap
all: sysinfo.gap
sysinfo.gap: config.status $(srcdir)/Makefile.rules cnf/GAP-CFLAGS cnf/GAP-CPPFLAGS cnf/GAP-CXXFLAGS cnf/GAP-LDFLAGS cnf/GAP-LIBS
@rm -f sysinfo.gap # in case this is a symlink created by an older version of the build system
@echo "$$sysinfo_gap" > $@
########################################################################
# Specifying GAP calls to use for the test suite and building manuals
########################################################################
GAPARGS=
TESTGAPcore = $(abs_builddir)/gap --quitonbreak -b -q -r $(GAPARGS)
TESTGAPauto = $(TESTGAPcore) -m 100m -o 1g -x 80
TESTGAP = $(TESTGAPauto) -A
########################################################################
# Documentation rules
########################################################################
# Alias for backwards compatibility
manuals: doc
doc: gap$(EXEEXT) doc/make_doc doc/versiondata
doc/make_doc
html: gap$(EXEEXT) doc/make_doc doc/versiondata
doc/make_doc nopdf
clean-doc:
rm -f doc/*/chap*.html doc/*/chap*.txt doc/*/*.css doc/*/*.js
rm -f doc/*/chooser.html doc/*/manual*.pdf
rm -f doc/*/*.{aux,bbl,blg,brf,idx,ilg,ind,lab,log,out,pnr,six,tex,toc}
rm -f doc/manualbib.xml.bib
# FIXME: we currently build the manual inside $srcdir; so we don't want "make clean"
# to remove it, as other builds might share the manual.
#clean: clean-doc
# Manual consistency check
check-manuals: all
cd doc/ref && $(TESTGAP) testconsistency.g
.PHONY: doc clean-doc manuals check-manuals html
#
check: all
$(TESTGAPcore) $(top_srcdir)/tst/testinstall.g
# citests runs a subset of the tests run by CI -- this is SLOW and still doesn't
# quite cover everything (e.g. we don't test out-of-tree builds and `make install`)
citests: all
SRCDIR=$(abs_srcdir) dev/ci.sh testmockpkg testspecial test-compile testlibgap testkernel testworkspace testinstall
LIBGAPTESTS := $(addprefix tst/testlibgap/,basic api wscreate wsload trycatch)
build-testlibgap: ${LIBGAPTESTS}