forked from ponylang/ponyc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile-ponyc
1210 lines (1049 loc) · 40.6 KB
/
Makefile-ponyc
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
# Determine the operating system
OSTYPE ?=
ifeq ($(OS),Windows_NT)
OSTYPE = windows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSTYPE = linux
ifndef AR
ifneq (,$(shell which gcc-ar 2> /dev/null))
AR = gcc-ar
endif
endif
ALPINE=$(wildcard /etc/alpine-release)
endif
ifeq ($(UNAME_S),Darwin)
OSTYPE = osx
endif
ifeq ($(UNAME_S),FreeBSD)
OSTYPE = bsd
CXX = c++
endif
ifeq ($(UNAME_S),DragonFly)
OSTYPE = bsd
CXX = c++
endif
ifeq ($(UNAME_S),OpenBSD)
OSTYPE = bsd
CXX = c++
LLVM_CONFIG = /usr/local/bin/llvm-config
default_pic = true
endif
endif
# By default, CC is cc and CXX is g++
# So if you use standard alternatives on many Linuxes
# You can get clang and g++ and then bad things will happen
ifneq (,$(shell $(CC) --version 2>&1 | grep clang))
ifneq (,$(shell $(CXX) --version 2>&1 | grep "Free Software Foundation"))
CXX = c++
endif
ifneq (,$(shell $(CXX) --version 2>&1 | grep "Free Software Foundation"))
$(error CC is clang but CXX is g++. They must be from matching compilers.)
endif
else ifneq (,$(shell $(CC) --version 2>&1 | grep "Free Software Foundation"))
ifneq (,$(shell $(CXX) --version 2>&1 | grep clang))
CXX = c++
endif
ifneq (,$(shell $(CXX) --version 2>&1 | grep clang))
$(error CC is gcc but CXX is clang++. They must be from matching compilers.)
endif
endif
ifdef LTO_PLUGIN
lto := yes
endif
# Default settings (silent release build).
config ?= release
arch ?= native
tune ?= generic
cpu ?= $(arch)
fpu ?=
bits ?= $(shell getconf LONG_BIT)
# linking strategy (static, llvm-static, llvm-dynamic)
# static links everything statically (only works with musl libc)
# llvm-static links llvm statically
# llvm-dynamic links llvm dynamically
link ?= llvm-static
ifndef verbose
SILENT = @
else
SILENT =
endif
# Default to version from `VERSION` file but allowing overridding on the
# make command line like:
# make version="nightly-19710702"
# overridden version *should not* contain spaces or characters that aren't
# legal in filesystem path names
ifndef version
version := $(shell cat VERSION)
ifneq ($(wildcard .git),)
sha := $(shell git rev-parse --short HEAD)
tag := $(version)-$(sha)
else
tag := $(version)
endif
else
tag := $(version)
endif
version_str = "$(tag) [$(config)]\ncompiled with: llvm $(llvm_version) \
-- "$(compiler_version)
# package_name, _version, and _iteration can be overridden by Travis or AppVeyor
package_base_version ?= $(tag)
package_iteration ?= "1"
package_name ?= "ponyc"
package_version = $(package_base_version)-$(package_iteration)
archive = $(package_name)-$(package_version).tar
package = build/$(package_name)-$(package_version)
prefix ?= /usr/local
bindir ?= $(prefix)/bin
includedir ?= $(prefix)/include
libdir ?= $(prefix)/lib
# destdir is for backward compatibility only, use ponydir instead.
ifdef destdir
$(warning Please use ponydir instead of destdir.)
ponydir ?= $(destdir)
endif
ponydir ?= $(libdir)/pony/$(tag)
symlink := yes
ifdef ponydir
ifndef prefix
symlink := no
endif
endif
ifneq (,$(filter $(OSTYPE), osx bsd))
symlink.flags = -sf
else
symlink.flags = -srf
endif
ifneq (,$(filter $(OSTYPE), osx bsd))
SED_INPLACE = sed -i -e
else
SED_INPLACE = sed -i
endif
LIB_EXT ?= a
BUILD_FLAGS = -march=$(arch) -mtune=$(tune) -Werror -Wconversion \
-Wno-sign-conversion -Wextra -Wall
LINKER_FLAGS = -march=$(arch) -mtune=$(tune) $(LDFLAGS)
AR_FLAGS ?= rcs
ALL_CFLAGS = -std=gnu11 -fexceptions \
-DPONY_VERSION=\"$(tag)\" -DLLVM_VERSION=\"$(llvm_version)\" \
-DPONY_COMPILER=\"$(CC)\" -DPONY_ARCH=\"$(arch)\" \
-DBUILD_COMPILER=\"$(compiler_version)\" \
-DPONY_BUILD_CONFIG=\"$(config)\" \
-DPONY_VERSION_STR=\"$(version_str)\" \
-D_FILE_OFFSET_BITS=64
ALL_CXXFLAGS = -std=gnu++11 -fno-rtti
LL_FLAGS = -mcpu=$(cpu)
# Determine pointer size in bits.
BITS := $(bits)
UNAME_M := $(shell uname -m)
ifeq ($(BITS),64)
ifneq (,$(filter $(UNAME_M), x86_64 amd64))
ifeq (,$(filter $(arch), armv8-a))
BUILD_FLAGS += -mcx16
LINKER_FLAGS += -mcx16
endif
endif
endif
ifneq ($(fpu),)
BUILD_FLAGS += -mfpu=$(fpu)
LINKER_FLAGS += -mfpu=$(fpu)
endif
ifdef link
ifeq (,$(filter $(link),static llvm-static llvm-dynamic))
$(error Unknown linking strategy "$(link)")
endif
endif
ifneq (,$(filter $(link),static llvm-static))
LLVM_LINKING =--link-static
ifeq (,$(filter $(OSTYPE),bsd osx))
LINKER_FLAGS += -static-libstdc++
endif
ifneq (,$(shell $(CC) -v 2>&1 | grep gcc))
LINKER_FLAGS += -static-libgcc
endif
$(info "linking llvm statically")
else ifeq ($(link),llvm-dynamic)
ifneq ($(LLVM_VENDOR),true)
LLVM_LINKING =--link-shared
$(info "linking llvm dynamically")
else
$(error "Can't use llvm-dynamic with vendored LLVM at this time")
endif
endif
PONY_BUILD_DIR ?= build/$(config)
PONY_SOURCE_DIR ?= src
PONY_TEST_DIR ?= test
PONY_BENCHMARK_DIR ?= benchmark
comma:= ,
empty:=
space:= $(empty) $(empty)
define USE_CHECK
$$(info Enabling use option: $1)
ifeq ($1,valgrind)
ALL_CFLAGS += -DUSE_VALGRIND
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-valgrind
else ifeq ($1,thread_sanitizer)
ALL_CFLAGS += -fsanitize=thread -DPONY_SANITIZER=\"thread\"
ALL_CXXFLAGS += -fsanitize=thread -DPONY_SANITIZER=\"thread\"
LINKER_FLAGS += -fsanitize=thread -DPONY_SANITIZER=\"thread\"
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-thread_sanitizer
else ifeq ($1,address_sanitizer)
ALL_CFLAGS += -fsanitize=address -DPONY_SANITIZER=\"address\"
ALL_CXXFLAGS += -fsanitize=address -DPONY_SANITIZER=\"address\"
LINKER_FLAGS += -fsanitize=address -DPONY_SANITIZER=\"address\"
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-address_sanitizer
else ifeq ($1,undefined_behavior_sanitizer)
ALL_CFLAGS += -fsanitize=undefined -DPONY_SANITIZER=\"undefined\"
ALL_CXXFLAGS += -fsanitize=undefined -DPONY_SANITIZER=\"undefined\"
LINKER_FLAGS += -fsanitize=undefined -DPONY_SANITIZER=\"undefined\"
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-undefined_behavior_sanitizer
else ifeq ($1,coverage)
ifneq (,$(shell $(CC) -v 2>&1 | grep clang))
# clang
COVERAGE_FLAGS = -O0 -fprofile-instr-generate -fcoverage-mapping
LINKER_FLAGS += -fprofile-instr-generate -fcoverage-mapping
else
ifneq (,$(shell $(CC) -v 2>&1 | grep "gcc version"))
# gcc
COVERAGE_FLAGS = -O0 -fprofile-arcs -ftest-coverage
LINKER_FLAGS += -fprofile-arcs
else
$$(error coverage not supported for this compiler/platform)
endif
ALL_CFLAGS += $(COVERAGE_FLAGS)
ALL_CXXFLAGS += $(COVERAGE_FLAGS)
endif
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-coverage
else ifeq ($1,pooltrack)
ALL_CFLAGS += -DUSE_POOLTRACK
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-pooltrack
else ifeq ($1,dtrace)
DTRACE ?= $(shell which dtrace)
ifeq (, $$(DTRACE))
$$(error No dtrace compatible user application static probe generation tool found)
endif
ALL_CFLAGS += -DUSE_DYNAMIC_TRACE
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-dtrace
else ifeq ($1,actor_continuations)
ALL_CFLAGS += -DUSE_ACTOR_CONTINUATIONS
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-actor_continuations
else ifeq ($1,scheduler_scaling_pthreads)
ALL_CFLAGS += -DUSE_SCHEDULER_SCALING_PTHREADS
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-scheduler_scaling_pthreads
else ifeq ($1,memtrack)
ALL_CFLAGS += -DUSE_MEMTRACK
ALL_CXXFLAGS += -DUSE_MEMTRACK
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-memtrack
else ifeq ($1,memtrack_messages)
ALL_CFLAGS += -DUSE_MEMTRACK -DUSE_MEMTRACK_MESSAGES
ALL_CXXFLAGS += -DUSE_MEMTRACK -DUSE_MEMTRACK_MESSAGES
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-memtrack-messages
else
$$(error ERROR: Unknown use option specified: $1)
endif
endef
ifdef use
$(foreach useitem,$(sort $(subst $(comma),$(space),$(use))),$(eval $(call USE_CHECK,$(useitem))))
endif
ifdef config
ifeq (,$(filter $(config),debug release))
$(error Unknown configuration "$(config)")
endif
endif
ifeq ($(config),release)
BUILD_FLAGS += -O3 -DNDEBUG
LL_FLAGS += -O3
ifeq ($(lto),yes)
BUILD_FLAGS += -flto -DPONY_USE_LTO
LINKER_FLAGS += -flto
ifdef LTO_PLUGIN
AR_FLAGS += --plugin $(LTO_PLUGIN)
endif
ifneq (,$(filter $(OSTYPE),linux bsd))
LINKER_FLAGS += -fuse-linker-plugin -fuse-ld=gold
endif
endif
else
BUILD_FLAGS += -g -DDEBUG
endif
ifeq ($(OSTYPE),osx)
ALL_CFLAGS += -mmacosx-version-min=10.12 -DUSE_SCHEDULER_SCALING_PTHREADS
ALL_CXXFLAGS += -stdlib=libc++ -mmacosx-version-min=10.12
endif
# If we are not cleaning we need LLVM_CONFIG
ifneq ($(MAKECMDGOALS),clean)
ifndef LLVM_CONFIG
ifneq (,$(shell which llvm-config 2> /dev/null))
LLVM_CONFIG = llvm-config
else
$(error No LLVM installation found! Set LLVM_CONFIG environment variable \
to the `llvm-config` binary for your installation)
endif
else ifeq (,$(shell which $(LLVM_CONFIG) 2> /dev/null))
$(error LLVM config $(LLVM_CONFIG) not found! Set LLVM_CONFIG environment \
variable to a valid LLVM installation.)
endif
LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir 2> /dev/null)
LLVM_LINK := $(LLVM_BINDIR)/llvm-link
LLVM_OPT := $(LLVM_BINDIR)/opt
LLVM_LLC := $(LLVM_BINDIR)/llc
LLVM_AS := $(LLVM_BINDIR)/llvm-as
llvm_build_mode := $(shell $(LLVM_CONFIG) --build-mode)
ifeq (Release,$(llvm_build_mode))
LLVM_BUILD_MODE=LLVM_BUILD_MODE_Release
else ifeq (RelWithDebInfo,$(llvm_build_mode))
LLVM_BUILD_MODE=LLVM_BUILD_MODE_RelWithDebInfo
else ifeq (MinSizeRel,$(llvm_build_mode))
LLVM_BUILD_MODE=LLVM_BUILD_MODE_MinSizeRel
else ifeq (Debug,$(llvm_build_mode))
LLVM_BUILD_MODE=LLVM_BUILD_MODE_Debug
else
$(error "Unknown llvm build-mode of $(llvm_build_mode)", aborting)
endif
llvm_version := $(shell $(LLVM_CONFIG) --version)
ifeq ($(OSTYPE),osx)
ifneq (,$(shell which $(LLVM_BINDIR)/llvm-ar 2> /dev/null))
AR = $(LLVM_BINDIR)/llvm-ar
AR_FLAGS := rcs
else
AR = /usr/bin/ar
AR_FLAGS := -rcs
endif
endif
ifeq ($(llvm_version),3.9.1)
else ifeq ($(llvm_version),5.0.2)
else ifeq ($(llvm_version),6.0.1)
else ifeq ($(llvm_version),7.1.0)
else ifeq ($(llvm_version),9.0.1)
else
$(warning WARNING: Unsupported LLVM version: $(llvm_version))
$(warning Please use LLVM 3.9.1, 5.0.2, 6.0.1, 7.1.0, 9.0.1)
endif
# Third party, but prebuilt. Prebuilt libraries are defined as
# (1) a name (stored in prebuilt)
# (2) the linker flags necessary to link against the prebuilt libraries
# (3) a list of include directories for a set of libraries
# (4) a list of the libraries to link against
llvm.libdir := $(CROSS_SYSROOT)$(subst -L,,$(shell $(LLVM_CONFIG) --ldflags $(LLVM_LINKING)))
llvm.ldflags := -L$(llvm.libdir)
#$(info llvm.libdir="$(llvm.libdir)")
#$(info llvm.ldflags="$(llvm.ldflags)")
# Get cflags using llvm-config
llvm.get_cflags := $(LLVM_CONFIG) --cflags $(LLVM_LINKING)
#$(info llvm.get_cflags="$(llvm.get_cflags)")
llvm.cflags := $(shell sh -c "$(llvm.get_cflags)")
#$(info llvm.cflags="$(llvm.cflags)")
# Get include dirs using grep & sed to extract "-I<dir>" and "-isystem<dir>" entries
# that can occur anywhere in the string and <dir> may have a leading spaces, but the
# regex assumes a directory does NOT contain spaces.
# Note: [:space:] is used for greater portability.
llvm.get_include_dirs := echo '$(llvm.cflags)' | grep -oE -- '(^-I[[:space:]]*| -I[[:space:]]*|^-isystem[[:space:]]*| -isystem[[:space:]]*)[^[:space:]]+' | sed -E 's/^[[:space:]]*(-I[[:space:]]*|-isystem[[:space:]]*)//'
#$(info llvm.get_include_dirs="$(llvm.get_include_dirs)")
llvm.include_dirs := $(shell sh -c "$(llvm.get_include_dirs)")
#$(info llvm.include_dirs="$(llvm.include_dirs)")
# Get the compiler output of verbose "-v" and preprocess, "-E" parameters which
# contains the search paths.
verbose_preprocess_string := $(shell echo | $(CC) -v -E - 2>&1)
#$(info verbose_preprocess_string="$(verbose_preprocess_string)")
# We must escape any double quotes, ", and any hash, #, characters.
quoteDblQuote := $(subst ",\",$(verbose_preprocess_string))
#$(info quoteDblQuote="$(quoteDblQuote)")
quoted_verbose_preprocess_string := $(subst \#,\\\#,$(quoteDblQuote))
#$(info quoted_verbose_preprocess_string="$(quoted_verbose_preprocess_string)")
# Now use a sed command line to extract the search paths from the
# quoted verbose preprocess string
get_search_paths := sed 's/\(.*\)search starts here:\(.*\)End of search list.\(.*\)/\2/'
#$(info get_search_paths="$(get_search_paths)")
search_paths := $(shell echo "$(quoted_verbose_preprocess_string)" | $(get_search_paths))
#$(info search_paths="$(search_paths)")
# Note: $(search_paths) is padded with a space on front and back so
# that when we iterate the ${inc_dir} variable is guaranteed to have
# a space at the beginning and end making finding a match easy. If
# there is no match we output the ${inc_dir}.
loopit := \
for inc_dir in $(llvm.include_dirs); do \
if ! echo " $(search_paths) " | grep -q " $${inc_dir} "; then \
echo "-isystem $(CROSS_SYSROOT)$${inc_dir}"; \
fi \
done
#$(info loopit="$(loopit)")
llvm.include = $(shell $(loopit))
#$(info llvm.include="$(llvm.include)")
llvm.libs := $(shell $(LLVM_CONFIG) --libs $(LLVM_LINKING)) $(shell $(LLVM_CONFIG) --system-libs $(LLVM_LINKING))
endif
compiler_version := "$(shell $(CC) --version | sed -n 1p)"
ifeq ($(runtime-bitcode),yes)
ifeq (,$(shell $(CC) -v 2>&1 | grep clang))
$(error Compiling the runtime as a bitcode file requires clang)
endif
endif
makefile_abs_path := $(realpath $(lastword $(MAKEFILE_LIST)))
packages_abs_src := $(shell dirname $(makefile_abs_path))/packages
$(shell mkdir -p $(PONY_BUILD_DIR))
$(info Building into $(PONY_BUILD_DIR))
lib := $(PONY_BUILD_DIR)/lib/$(arch)
bin := $(PONY_BUILD_DIR)
tests := $(PONY_BUILD_DIR)
benchmarks := $(PONY_BUILD_DIR)
obj := $(PONY_BUILD_DIR)/obj-$(arch)
# Libraries. Defined as
# (1) a name and output directory
libponyc := $(lib)
libponycc := $(lib)
libponyrt := $(lib)
ifeq ($(OSTYPE),linux)
libponyrt-pic := $(lib)
endif
# Define special case rules for a targets source files. By default
# this makefile assumes that a targets source files can be found
# relative to a parent directory of the same name in $(PONY_SOURCE_DIR).
# Note that it is possible to collect files and exceptions with
# arbitrarily complex shell commands, as long as ':=' is used
# for definition, instead of '='.
ifneq ($(OSTYPE),windows)
libponyc.except += src/libponyc/platform/signed.cc
libponyc.except += src/libponyc/platform/unsigned.cc
libponyc.except += src/libponyc/platform/vcvars.c
endif
# Handle platform specific code to avoid "no symbols" warnings.
libponyrt.except =
ifneq ($(OSTYPE),windows)
libponyrt.except += src/libponyrt/asio/iocp.c
libponyrt.except += src/libponyrt/lang/win_except.c
endif
ifneq ($(OSTYPE),linux)
libponyrt.except += src/libponyrt/asio/epoll.c
endif
ifneq ($(OSTYPE),osx)
ifneq ($(OSTYPE),bsd)
libponyrt.except += src/libponyrt/asio/kqueue.c
endif
endif
libponyrt.except += src/libponyrt/asio/sock.c
libponyrt.except += src/libponyrt/dist/dist.c
libponyrt.except += src/libponyrt/dist/proto.c
ifeq ($(OSTYPE),linux)
libponyrt-pic.dir := src/libponyrt
libponyrt-pic.except := $(libponyrt.except)
endif
# Third party, but requires compilation. Defined as
# (1) a name and output directory.
# (2) a list of the source files to be compiled.
libgtest := $(lib)
libgtest.dir := lib/gtest
libgtest.files := $(libgtest.dir)/gtest-all.cc
libgbenchmark := $(lib)
libgbenchmark.dir := lib/gbenchmark
libgbenchmark.srcdir := $(libgbenchmark.dir)/src
libblake2 := $(lib)
libblake2.dir := lib/blake2
libblake2.files := $(libblake2.dir)/blake2b-ref.c
# We don't add libponyrt here. It's a special case because it can be compiled
# to LLVM bitcode.
ifeq ($(OSTYPE), linux)
libraries := libponyc libponyrt-pic libgtest libgbenchmark libblake2
else
libraries := libponyc libgtest libgbenchmark libblake2
endif
ifeq ($(OSTYPE), bsd)
extra.bsd.libs = -lpthread -lexecinfo
llvm.libs += $(extra.bsd.libs)
endif
prebuilt := llvm
# Binaries. Defined as
# (1) a name and output directory.
ponyc := $(bin)
binaries := ponyc
# Tests suites are directly attached to the libraries they test.
libponyc.tests := $(tests)
libponyrt.tests := $(tests)
tests := libponyc.tests libponyrt.tests
# Benchmark suites are directly attached to the libraries they test.
libponyc.benchmarks := $(benchmarks)
libponyc.benchmarks.dir := benchmark/libponyc
libponyc.benchmarks.srcdir := $(libponyc.benchmarks.dir)
libponyrt.benchmarks := $(benchmarks)
libponyrt.benchmarks.dir := benchmark/libponyrt
libponyrt.benchmarks.srcdir := $(libponyrt.benchmarks.dir)
benchmarks := libponyc.benchmarks libponyrt.benchmarks
# Define include paths for targets if necessary. Note that these include paths
# will automatically apply to the test suite of a target as well.
libponyc.include := -I src/common/ -I src/libponyrt/ $(llvm.include) \
-isystem lib/blake2
libponycc.include := -I src/common/ $(llvm.include)
libponyrt.include := -I src/common/ -I src/libponyrt/
libponyrt-pic.include := $(libponyrt.include)
libponyc.tests.include := -I src/common/ -I src/libponyc/ -I src/libponyrt \
$(llvm.include) -isystem lib/gtest/
libponyrt.tests.include := -I src/common/ -I src/libponyrt/ -isystem lib/gtest/
libponyc.benchmarks.include := -I src/common/ -I src/libponyc/ \
$(llvm.include) -isystem lib/gbenchmark/include/
libponyrt.benchmarks.include := -I src/common/ -I src/libponyrt/ -isystem \
lib/gbenchmark/include/
ponyc.include := -I src/common/ -I src/libponyrt/ $(llvm.include)
libgtest.include := -isystem lib/gtest/
libgbenchmark.include := -isystem lib/gbenchmark/include/
libblake2.include := -isystem lib/blake2/
ifneq (,$(filter $(OSTYPE), osx bsd))
libponyrt.include += -I $(CROSS_SYSROOT)/usr/local/include
endif
# target specific build options
libponyrt.tests.linkoptions += -rdynamic
ifneq ($(ALPINE),)
libponyrt.tests.linkoptions += -lexecinfo
endif
# link statically
ifeq ($(link),static)
libponyrt.tests.linkoptions += -static
endif
libponyc.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.buildoptions += -D__STDC_LIMIT_MACROS
libponyc.buildoptions += -DPONY_ALWAYS_ASSERT
libponyc.buildoptions += -DLLVM_BUILD_MODE=$(LLVM_BUILD_MODE)
libponyc.tests.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.tests.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.tests.buildoptions += -D__STDC_LIMIT_MACROS
libponyc.tests.buildoptions += -DPONY_ALWAYS_ASSERT
libponyc.tests.buildoptions += -DPONY_PACKAGES_DIR=\"$(packages_abs_src)\"
libponyc.tests.buildoptions += -DLLVM_BUILD_MODE=$(LLVM_BUILD_MODE)
libponyc.tests.linkoptions += -rdynamic
ifneq ($(ALPINE),)
libponyc.tests.linkoptions += -lexecinfo
endif
# link statically
# TODO: uncomment when this is fixed
#ifeq ($(link),static)
# libponyc.tests.linkoptions += -static
#endif
libponyc.benchmarks.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.benchmarks.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.benchmarks.buildoptions += -D__STDC_LIMIT_MACROS
libponyc.benchmarks.buildoptions += -DLLVM_BUILD_MODE=$(LLVM_BUILD_MODE)
libgbenchmark.buildoptions := \
-Wshadow -pedantic -pedantic-errors \
-fstrict-aliasing -Wstrict-aliasing \
-Wno-invalid-offsetof -Wno-deprecated-declarations \
-DHAVE_POSIX_REGEX -DHAVE_STD_REGEX -DHAVE_STEADY_CLOCK
ifneq ($(ALPINE),)
libponyc.benchmarks.linkoptions += -lexecinfo
libponyrt.benchmarks.linkoptions += -lexecinfo
endif
# link statically
ifeq ($(link),static)
libponyc.benchmarks.linkoptions += -static
libponyrt.benchmarks.linkoptions += -static
endif
ponyc.buildoptions = $(libponyc.buildoptions)
ponyc.linkoptions += -rdynamic
ifneq ($(ALPINE),)
ponyc.linkoptions += -lexecinfo
BUILD_FLAGS += -DALPINE_LINUX
endif
# link statically
ifeq ($(link),static)
ponyc.linkoptions += -static
endif
ifeq ($(OSTYPE), linux)
libponyrt-pic.buildoptions += -fpic
libponyrt-pic.buildoptions-ll += -relocation-model=pic
endif
# Set default PIC for compiling if requested
ifdef default_pic
ifeq (true,$(default_pic))
libponyrt.buildoptions += -fpic
libponyrt.buildoptions-ll += -relocation-model=pic
BUILD_FLAGS += -DPONY_DEFAULT_PIC=true
else
ifneq (false,$(default_pic))
$(error default_pic must be true or false)
endif
endif
endif
# target specific disabling of build options
libgtest.disable = -Wconversion -Wno-sign-conversion -Wextra
libgbenchmark.disable = -Wconversion -Wno-sign-conversion
libblake2.disable = -Wconversion -Wno-sign-conversion -Wextra
# Link relationships.
ponyc.links = libponyc libponyrt llvm libblake2
libponyc.tests.links = libgtest libponyc llvm libblake2
libponyc.tests.links.whole = libponyrt
libponyrt.tests.links = libgtest libponyrt
libponyc.benchmarks.links = libblake2 libgbenchmark libponyc libponyrt llvm
libponyrt.benchmarks.links = libgbenchmark libponyrt
ifeq ($(OSTYPE),linux)
ponyc.links += libpthread libdl libatomic
libponyc.tests.links += libpthread libdl libatomic
libponyrt.tests.links += libpthread libdl libatomic
libponyc.benchmarks.links += libpthread libdl libatomic
libponyrt.benchmarks.links += libpthread libdl libatomic
endif
ifeq ($(OSTYPE),bsd)
libponyc.tests.links += libpthread
libponyrt.tests.links += $(extra.bsd.libs)
libponyc.benchmarks.links += libpthread
libponyrt.benchmarks.links += $(extra.bsd.libs)
endif
ifneq (, $(DTRACE))
$(shell $(DTRACE) -h -s $(PONY_SOURCE_DIR)/common/dtrace_probes.d -o $(PONY_SOURCE_DIR)/common/dtrace_probes.h)
endif
# Overwrite the default linker for a target.
ponyc.linker = $(CXX) #compile as C but link as CPP (llvm)
libponyc.benchmarks.linker = $(CXX)
libponyrt.benchmarks.linker = $(CXX)
# make targets
targets := $(libraries) libponyrt $(binaries) $(tests) $(benchmarks)
.PHONY: all $(targets) install uninstall clean stats deploy prerelease check-version test-core test-stdlib-debug test-stdlib test-examples validate-grammar test-ci test-cross-ci benchmark stdlib stdlib-debug
all: $(targets)
@:
# Dependencies
libponyc.depends := libponyrt libblake2
libponyc.tests.depends := libponyc libgtest
libponyrt.tests.depends := libponyrt libgtest
libponyc.benchmarks.depends := libponyc libgbenchmark
libponyrt.benchmarks.depends := libponyrt libgbenchmark
ponyc.depends := libponyc libponyrt
# Generic make section, edit with care.
##########################################################################
# #
# DIRECTORY: Determines the source dir of a specific target #
# #
# ENUMERATE: Enumerates input and output files for a specific target #
# #
# CONFIGURE_COMPILER: Chooses a C or C++ compiler depending on the #
# target file. #
# #
# CONFIGURE_LIBS: Builds a string of libraries to link for a targets #
# link dependency. #
# #
# CONFIGURE_LINKER: Assembles the linker flags required for a target. #
# #
# EXPAND_COMMAND: Macro that expands to a proper make command for each #
# target. #
# #
##########################################################################
define DIRECTORY
$(eval sourcedir := )
$(eval outdir := $(obj)/$(1))
ifdef $(1).srcdir
sourcedir := $($(1).srcdir)
else ifdef $(1).dir
sourcedir := $($(1).dir)
else ifneq ($$(filter $(1),$(tests)),)
sourcedir := $(PONY_TEST_DIR)/$(subst .tests,,$(1))
outdir := $(obj)/tests/$(subst .tests,,$(1))
else ifneq ($$(filter $(1),$(benchmarks)),)
sourcedir := $(PONY_BENCHMARK_DIR)/$(subst .benchmarks,,$(1))
outdir := $(obj)/benchmarks/$(subst .benchmarks,,$(1))
else
sourcedir := $(PONY_SOURCE_DIR)/$(1)
endif
endef
define ENUMERATE
$(eval sourcefiles := )
ifdef $(1).files
sourcefiles := $$($(1).files)
else
sourcefiles := $$(shell find $$(sourcedir) -type f -name "*.c" -or -name\
"*.cc" -or -name "*.ll" | grep -v '.*/\.')
endif
ifdef $(1).except
sourcefiles := $$(filter-out $($(1).except),$$(sourcefiles))
endif
endef
define CONFIGURE_COMPILER
ifeq ($(suffix $(1)),.cc)
compiler := $(CXX)
flags := $(ALL_CXXFLAGS) $(CXXFLAGS)
endif
ifeq ($(suffix $(1)),.c)
compiler := $(CC)
flags := $(ALL_CFLAGS) $(CFLAGS)
endif
ifeq ($(suffix $(1)),.bc)
compiler := $(CC)
flags := $(ALL_CFLAGS) $(CFLAGS)
endif
ifeq ($(suffix $(1)),.ll)
compiler := $(CC)
flags := $(ALL_CFLAGS) $(CFLAGS) -Wno-override-module
endif
endef
define CONFIGURE_LIBS
ifneq (,$$(filter $(1),$(prebuilt)))
linkcmd += $($(1).ldflags)
libs += $($(1).libs)
else
libs += $(subst lib,-l,$(1))
endif
endef
define CONFIGURE_LIBS_WHOLE
ifeq ($(OSTYPE),osx)
wholelibs += -Wl,-force_load,$(lib)/$(1).a
else
wholelibs += $(subst lib,-l,$(1))
endif
endef
define CONFIGURE_LINKER_WHOLE
$(eval wholelibs :=)
ifneq ($($(1).links.whole),)
$(foreach lk,$($(1).links.whole),$(eval $(call CONFIGURE_LIBS_WHOLE,$(lk))))
ifeq ($(OSTYPE),osx)
libs += $(wholelibs)
else
libs += -Wl,--whole-archive $(wholelibs) -Wl,--no-whole-archive
endif
endif
endef
define CONFIGURE_LINKER
$(eval linkcmd := $(LINKER_FLAGS) -L $(lib))
$(eval linker := $(CC))
$(eval libs :=)
ifdef $(1).linker
linker := $($(1).linker)
else ifneq (,$$(filter .cc,$(suffix $(sourcefiles))))
linker := $(CXX)
endif
$(eval $(call CONFIGURE_LINKER_WHOLE,$(1)))
$(foreach lk,$($(1).links),$(eval $(call CONFIGURE_LIBS,$(lk))))
linkcmd += $(libs) -L $(CROSS_SYSROOT)/usr/local/lib $($(1).linkoptions)
endef
define PREPARE
$(eval $(call DIRECTORY,$(1)))
$(eval $(call ENUMERATE,$(1)))
$(eval $(call CONFIGURE_LINKER,$(1)))
$(eval objectfiles := $(subst $(sourcedir)/,$(outdir)/,$(addsuffix .o,\
$(sourcefiles))))
$(eval bitcodefiles := $(subst .o,.bc,$(objectfiles)))
$(eval dependencies := $(subst .c,,$(subst .cc,,$(subst .ll,,$(subst .o,.d,\
$(objectfiles))))))
endef
define EXPAND_OBJCMD
$(eval file := $(subst .o,,$(1)))
$(eval $(call CONFIGURE_COMPILER,$(file)))
ifeq ($(3),libponyrtyes)
ifneq ($(suffix $(file)),.bc)
$(subst .c,,$(subst .cc,,$(subst .ll,,$(1)))): $(subst .c,.bc,$(subst .cc,.bc,$(subst .ll,.bc,$(file))))
@echo '$$(notdir $$<)'
@mkdir -p $$(dir $$@)
$(SILENT)$(compiler) $(flags) -c -o $$@ $$<
else ifeq ($(suffix $(subst .bc,,$(file))),.ll)
$(subst .ll,,$(1)): $(subst $(outdir)/,$(sourcedir)/,$(subst .bc,,$(file)))
@echo '$$(notdir $$<)'
@mkdir -p $$(dir $$@)
$(SILENT)$(LLVM_AS) -o $$@ $$<
else
$(subst .c,,$(subst .cc,,$(1))): $(subst $(outdir)/,$(sourcedir)/,$(subst .bc,,$(file)))
@echo '$$(notdir $$<)'
@mkdir -p $$(dir $$@)
$(SILENT)$(compiler) -MMD -MP $(filter-out $($(2).disable),$(BUILD_FLAGS)) \
$(flags) $($(2).buildoptions) -emit-llvm -c -o $$@ $$< $($(2).include)
endif
else ifeq ($(suffix $(file)),.ll)
$(subst .ll,,$(1)): $(subst $(outdir)/,$(sourcedir)/,$(file))
@echo '$$(notdir $$<)'
@mkdir -p $$(dir $$@)
$(SILENT)$(LLVM_LLC) $(LL_FLAGS) $($(2).buildoptions-ll) -filetype=obj -o $$@ $$<
else
$(subst .c,,$(subst .cc,,$(1))): $(subst $(outdir)/,$(sourcedir)/,$(file))
@echo '$$(notdir $$<)'
@mkdir -p $$(dir $$@)
$(SILENT)$(compiler) -MMD -MP $(filter-out $($(2).disable),$(BUILD_FLAGS)) \
$(flags) $($(2).buildoptions) -c -o $$@ $$< $($(2).include)
endif
endef
define EXPAND_COMMAND
$(eval $(call PREPARE,$(1)))
$(eval ofiles := $(subst .c,,$(subst .cc,,$(subst .ll,,$(objectfiles)))))
$(eval bcfiles := $(subst .c,,$(subst .cc,,$(subst .ll,,$(bitcodefiles)))))
$(eval depends := )
$(foreach d,$($(1).depends),$(eval depends += $($(d))/$(d).$(LIB_EXT)))
ifeq ($(1),libponyrt)
$($(1))/libponyrt.$(LIB_EXT): $(depends) $(ofiles)
@mkdir -p $$(dir $$@)
@echo 'Linking libponyrt'
ifneq (,$(DTRACE))
ifeq ($(OSTYPE), linux)
@echo 'Generating dtrace object file (linux)'
$(SILENT)$(DTRACE) -G -s $(PONY_SOURCE_DIR)/common/dtrace_probes.d -o $(PONY_BUILD_DIR)/dtrace_probes.o
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles) $(PONY_BUILD_DIR)/dtrace_probes.o
else ifeq ($(OSTYPE), bsd)
@echo 'Generating dtrace object file (bsd)'
$(SILENT)rm -f $(PONY_BUILD_DIR)/dtrace_probes.o
$(SILENT)$(DTRACE) -G -s $(PONY_SOURCE_DIR)/common/dtrace_probes.d -o $(PONY_BUILD_DIR)/dtrace_probes.o $(ofiles)
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles) $(PONY_BUILD_DIR)/dtrace_probes.o
$(SILENT)$(AR) $(AR_FLAGS) $(lib)/libdtrace_probes.a $(PONY_BUILD_DIR)/dtrace_probes.o
else
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles)
endif
else
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles)
endif
ifeq ($(runtime-bitcode),yes)
$($(1))/libponyrt.bc: $(depends) $(bcfiles)
@mkdir -p $$(dir $$@)
@echo 'Generating bitcode for libponyrt'
$(SILENT)$(LLVM_LINK) -o $$@ $(bcfiles)
ifeq ($(config),release)
$(SILENT)$(LLVM_OPT) -O3 -o $$@ $$@
endif
libponyrt: $($(1))/libponyrt.bc $($(1))/libponyrt.$(LIB_EXT)
else
libponyrt: $($(1))/libponyrt.$(LIB_EXT)
endif
else ifneq ($(filter $(1),$(libraries)),)
$($(1))/$(1).$(LIB_EXT): $(depends) $(ofiles)
@mkdir -p $$(dir $$@)
@echo 'Linking $(1)'
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles)
$(1): $($(1))/$(1).$(LIB_EXT)
else
$($(1))/$(1): $(depends) $(ofiles)
@mkdir -p $$(dir $$@)
@echo 'Linking $(1)'
$(SILENT)$(linker) -o $$@ $(ofiles) $(linkcmd)
$(1): $($(1))/$(1)
endif
$(foreach bcfile,$(bitcodefiles),$(eval $(call EXPAND_OBJCMD,$(bcfile),$(1),$(addsuffix $(runtime-bitcode),$(1)))))
$(foreach ofile,$(objectfiles),$(eval $(call EXPAND_OBJCMD,$(ofile),$(1),$(addsuffix $(runtime-bitcode),$(1)))))
-include $(dependencies)
endef
$(foreach target,$(targets),$(eval $(call EXPAND_COMMAND,$(target))))
define EXPAND_INSTALL
ifeq ($(OSTYPE),linux)
install-libponyrt-pic: libponyrt-pic
@mkdir -p $(destdir)/lib/$(arch)
$(SILENT)cp $(lib)/libponyrt-pic.a $(DESTDIR)$(ponydir)/lib/$(arch)
endif
install-libponyrt: libponyrt
@mkdir -p $(destdir)/lib/$(arch)
$(SILENT)cp $(lib)/libponyrt.a $(DESTDIR)$(ponydir)/lib/$(arch)
ifeq ($(OSTYPE),linux)
install: libponyc libponyrt libponyrt-pic ponyc
else
install: libponyc libponyrt ponyc
endif
@mkdir -p $(DESTDIR)$(ponydir)/bin
@mkdir -p $(DESTDIR)$(ponydir)/lib/$(arch)
@mkdir -p $(DESTDIR)$(ponydir)/include/pony/detail
$(SILENT)cp $(lib)/libponyrt.a $(DESTDIR)$(ponydir)/lib/$(arch)
ifeq ($(OSTYPE),linux)
$(SILENT)cp $(lib)/libponyrt-pic.a $(DESTDIR)$(ponydir)/lib/$(arch)
endif
ifneq ($(wildcard $(PONY_BUILD_DIR)/lib/$(arch)/libponyrt.bc),)
$(SILENT)cp $(PONY_BUILD_DIR)/lib/$(arch)/libponyrt.bc $(DESTDIR)$(ponydir)/lib/$(arch)
endif
ifneq ($(wildcard $(lib)/libdtrace_probes.a),)
$(SILENT)cp $(lib)/libdtrace_probes.a $(DESTDIR)$(ponydir)/lib/$(arch)
endif
$(SILENT)cp $(lib)/libponyc.a $(DESTDIR)$(ponydir)/lib/$(arch)
$(SILENT)cp $(bin)/ponyc $(DESTDIR)$(ponydir)/bin
$(SILENT)cp src/libponyrt/pony.h $(DESTDIR)$(ponydir)/include
$(SILENT)cp src/common/pony/detail/atomics.h $(DESTDIR)$(ponydir)/include/pony/detail
$(SILENT)cp -r packages $(DESTDIR)$(ponydir)/
ifeq ($$(symlink),yes)
@mkdir -p $(DESTDIR)$(bindir)
@mkdir -p $(DESTDIR)$(libdir)
@mkdir -p $(DESTDIR)$(includedir)/pony/detail
$(SILENT)ln $(symlink.flags) $(ponydir)/bin/ponyc $(DESTDIR)$(bindir)/ponyc
$(SILENT)ln $(symlink.flags) $(ponydir)/lib/$(arch)/libponyrt.a $(DESTDIR)$(libdir)/libponyrt.a
ifeq ($(OSTYPE),linux)
$(SILENT)ln $(symlink.flags) $(ponydir)/lib/$(arch)/libponyrt-pic.a $(DESTDIR)$(libdir)/libponyrt-pic.a
endif
ifneq ($(wildcard $(DESTDIR)$(ponydir)/lib/libponyrt.bc),)
$(SILENT)ln $(symlink.flags) $(ponydir)/lib/libponyrt.bc $(DESTDIR)$(libdir)/libponyrt.bc
endif
ifneq ($(wildcard $(PONY_BUILD_DIR)/libdtrace_probes.a),)
$(SILENT)ln $(symlink.flags) $(ponydir)/lib/$(arch)/libdtrace_probes.a $(DESTDIR)$(libdir)/libdtrace_probes.a
endif
$(SILENT)ln $(symlink.flags) $(ponydir)/lib/$(arch)/libponyc.a $(DESTDIR)$(libdir)/libponyc.a
$(SILENT)ln $(symlink.flags) $(ponydir)/include/pony.h $(DESTDIR)$(includedir)/pony.h
$(SILENT)ln $(symlink.flags) $(ponydir)/include/pony/detail/atomics.h $(DESTDIR)$(includedir)/pony/detail/atomics.h