forked from ponylang/ponyc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
787 lines (683 loc) · 24.4 KB
/
Makefile
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
# Determine the operating system
OSTYPE ?=
ifeq ($(OS),Windows_NT)
OSTYPE = windows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSTYPE = linux
ifneq (,$(shell which gcc-ar 2> /dev/null))
AR = gcc-ar
endif
endif
ifeq ($(UNAME_S),Darwin)
OSTYPE = osx
endif
ifeq ($(UNAME_S),FreeBSD)
OSTYPE = freebsd
CXX = c++
endif
endif
ifndef lto
ifeq ($(UNAME_S),Darwin)
# turn lto on for OSX if user hasn't specified a value
lto := yes
endif
endif
ifdef LTO_PLUGIN
lto := yes
endif
# Default settings (silent release build).
config ?= release
arch ?= native
bits ?= $(shell getconf LONG_BIT)
ifndef verbose
SILENT = @
else
SILENT =
endif
ifneq ($(wildcard .git),)
tag := $(shell cat VERSION)-$(shell git rev-parse --short HEAD)
else
tag := $(shell cat VERSION)
endif
# package_name, _version, and _iteration can be overriden by Travis or AppVeyor
package_base_version ?= $(tag)
package_iteration ?= "1"
package_name ?= "ponyc-unknown"
package_conflicts ?= "ponyc-release"
package_version = $(package_base_version)-$(package_iteration)
archive = $(package_name)-$(package_version).tar
package = build/$(package_name)-$(package_version)
symlink := yes
ifdef destdir
ifndef prefix
symlink := no
endif
endif
ifneq (,$(filter $(OSTYPE), osx freebsd))
symlink.flags = -sf
else
symlink.flags = -srf
endif
prefix ?= /usr/local
destdir ?= $(prefix)/lib/pony/$(tag)
LIB_EXT ?= a
BUILD_FLAGS = -march=$(arch) -Werror -Wconversion \
-Wno-sign-conversion -Wextra -Wall
LINKER_FLAGS = -march=$(arch)
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)\" \
-D_FILE_OFFSET_BITS=64
ALL_CXXFLAGS = -std=gnu++11 -fno-rtti
# Determine pointer size in bits.
BITS := $(bits)
ifeq ($(BITS),64)
BUILD_FLAGS += -mcx16
LINKER_FLAGS += -mcx16
endif
PONY_BUILD_DIR ?= build/$(config)
PONY_SOURCE_DIR ?= src
PONY_TEST_DIR ?= test
ifdef use
ifneq (,$(filter $(use), valgrind))
ALL_CFLAGS += -DUSE_VALGRIND
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-valgrind
endif
ifneq (,$(filter $(use), pooltrack))
ALL_CFLAGS += -DUSE_POOLTRACK
PONY_BUILD_DIR := $(PONY_BUILD_DIR)-pooltrack
endif
ifneq (,$(filter $(use), 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
endif
endif
ifdef config
ifeq (,$(filter $(config),debug release))
$(error Unknown configuration "$(config)")
endif
endif
ifeq ($(config),release)
BUILD_FLAGS += -O3 -DNDEBUG
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 freebsd))
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.8
ALL_CXXFLAGS += -stdlib=libc++ -mmacosx-version-min=10.8
endif
ifndef LLVM_CONFIG
ifneq (,$(shell which /usr/local/opt/[email protected]/bin/llvm-config 2> /dev/null))
LLVM_CONFIG = /usr/local/opt/[email protected]/bin/llvm-config
LLVM_LINK = /usr/local/opt/[email protected]/bin/llvm-link
LLVM_OPT = /usr/local/opt/[email protected]/bin/opt
else ifneq (,$(shell which llvm-config-3.9 2> /dev/null))
LLVM_CONFIG = llvm-config-3.9
LLVM_LINK = llvm-link-3.9
LLVM_OPT = opt-3.9
else ifneq (,$(shell which llvm-config-3.8 2> /dev/null))
LLVM_CONFIG = llvm-config-3.8
LLVM_LINK = llvm-link-3.8
LLVM_OPT = opt-3.8
else ifneq (,$(shell which llvm-config-mp-3.8 2> /dev/null))
LLVM_CONFIG = llvm-config-mp-3.8
LLVM_LINK = llvm-link-mp-3.8
LLVM_OPT = opt-mp-3.8
else ifneq (,$(shell which llvm-config-3.7 2> /dev/null))
LLVM_CONFIG = llvm-config-3.7
LLVM_LINK = llvm-link-3.7
LLVM_OPT = opt-3.7
else ifneq (,$(shell which llvm-config-3.6 2> /dev/null))
LLVM_CONFIG = llvm-config-3.6
LLVM_LINK = llvm-link-3.6
LLVM_OPT = opt-3.6
else ifneq (,$(shell which llvm-config39 2> /dev/null))
LLVM_CONFIG = llvm-config39
LLVM_LINK = llvm-link39
LLVM_OPT = opt39
else ifneq (,$(shell which llvm-config38 2> /dev/null))
LLVM_CONFIG = llvm-config38
LLVM_LINK = llvm-link38
LLVM_OPT = opt38
else ifneq (,$(shell which llvm-config37 2> /dev/null))
LLVM_CONFIG = llvm-config37
LLVM_LINK = llvm-link37
LLVM_OPT = opt37
else ifneq (,$(shell which llvm-config36 2> /dev/null))
LLVM_CONFIG = llvm-config36
LLVM_LINK = llvm-link36
LLVM_OPT = opt36
else ifneq (,$(shell which /usr/local/opt/llvm/bin/llvm-config 2> /dev/null))
LLVM_CONFIG = /usr/local/opt/llvm/bin/llvm-config
LLVM_LINK = /usr/local/opt/llvm/bin/llvm-link
LLVM_OPT = /usr/local/opt/llvm/bin/opt
else ifneq (,$(shell which llvm-config 2> /dev/null))
LLVM_CONFIG = llvm-config
LLVM_LINK = llvm-link
LLVM_OPT = opt
endif
endif
ifndef LLVM_CONFIG
$(error No LLVM installation found!)
endif
llvm_version := $(shell $(LLVM_CONFIG) --version)
ifeq ($(OSTYPE),osx)
llvm_bindir := $(shell $(LLVM_CONFIG) --bindir)
ifneq (,$(shell which $(llvm_bindir)/llvm-ar 2> /dev/null))
AR = $(llvm_bindir)/llvm-ar
AR_FLAGS := rcs
else ifneq (,$(shell which llvm-ar-mp-3.8 2> /dev/null))
AR = llvm-ar-mp-3.8
AR_FLAGS := rcs
else ifneq (,$(shell which llvm-ar-3.8 2> /dev/null))
AR = llvm-ar-3.8
AR_FLAGS := rcs
else
AR = /usr/bin/ar
AR_FLAGS := -rcs
endif
endif
ifeq ($(llvm_version),3.6.2)
else ifeq ($(llvm_version),3.7.1)
else ifeq ($(llvm_version),3.8.1)
else ifeq ($(llvm_version),3.9.1)
else
$(warning WARNING: Unsupported LLVM version: $(llvm_version))
$(warning Please use LLVM 3.6.2, 3.7.1, 3.8.1, or 3.9.1)
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
$(shell mkdir -p $(PONY_BUILD_DIR))
lib := $(PONY_BUILD_DIR)
bin := $(PONY_BUILD_DIR)
tests := $(PONY_BUILD_DIR)
obj := $(PONY_BUILD_DIR)/obj
# 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),freebsd)
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_main.cc $(libgtest.dir)/gtest-all.cc
# 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
else
libraries := libponyc libgtest
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.ldflags := $(shell $(LLVM_CONFIG) --ldflags)
llvm.include.dir := $(shell $(LLVM_CONFIG) --includedir)
include.paths := $(shell echo | cc -v -E - 2>&1)
ifeq (,$(findstring $(llvm.include.dir),$(include.paths)))
# LLVM include directory is not in the existing paths;
# put it at the top of the system list
llvm.include := -isystem $(llvm.include.dir)
else
# LLVM include directory is already on the existing paths;
# do nothing
llvm.include :=
endif
llvm.libs := $(shell $(LLVM_CONFIG) --libs) -lz -lncurses
ifeq ($(OSTYPE), freebsd)
llvm.libs += -lpthread
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
# 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)
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/ $(llvm.include) \
-isystem lib/gtest/
libponyrt.tests.include := -I src/common/ -I src/libponyrt/ -isystem lib/gtest/
ponyc.include := -I src/common/ -I src/libponyrt/ $(llvm.include)
libgtest.include := -isystem lib/gtest/
ifneq (,$(filter $(OSTYPE), osx freebsd))
libponyrt.include += -I /usr/local/include
endif
# target specific build options
libponyc.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.buildoptions += -D__STDC_LIMIT_MACROS
libponyc.tests.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.tests.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.tests.buildoptions += -D__STDC_LIMIT_MACROS
ponyc.buildoptions = $(libponyc.buildoptions)
ifeq ($(OSTYPE), linux)
libponyrt-pic.buildoptions += -fpic
endif
# target specific disabling of build options
libgtest.disable = -Wconversion -Wno-sign-conversion -Wextra
# Link relationships.
ponyc.links = libponyc libponyrt llvm
libponyc.tests.links = libgtest libponyc libponyrt llvm
libponyrt.tests.links = libgtest libponyrt
ifeq ($(OSTYPE),linux)
ponyc.links += pthread dl
libponyc.tests.links += pthread dl
libponyrt.tests.links += pthread dl
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)
# make targets
targets := $(libraries) libponyrt $(binaries) $(tests)
.PHONY: all $(targets) install uninstall clean stats deploy prerelease
all: $(targets)
@:
# Dependencies
libponyc.depends := libponyrt
libponyc.tests.depends := libponyc libgtest
libponyrt.tests.depends := libponyrt libgtest
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).dir
sourcedir := $($(1).dir)
else ifneq ($$(filter $(1),$(tests)),)
sourcedir := $(PONY_TEST_DIR)/$(subst .tests,,$(1))
outdir := $(obj)/tests/$(subst .tests,,$(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" | 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
endef
define CONFIGURE_LIBS
ifneq (,$$(filter $(1),$(prebuilt)))
linkcmd += $($(1).ldflags)
libs += $($(1).libs)
else
libs += -l$(subst lib,,$(1))
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
$(foreach lk,$($(1).links),$(eval $(call CONFIGURE_LIBS,$(lk))))
linkcmd += $(libs) $($(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 .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,,$(1))): $(subst .c,.bc,$(subst .cc,.bc,$(file)))
@echo '$$(notdir $$<)'
@mkdir -p $$(dir $$@)
$(SILENT)$(compiler) $(flags) -c -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
$(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,,$(objectfiles))))
$(eval bcfiles := $(subst .c,,$(subst .cc,,$(bitcodefiles))))
$(eval depends := )
$(foreach d,$($(1).depends),$(eval depends += $($(d))/$(d).$(LIB_EXT)))
ifeq ($(1),libponyrt)
$($(1))/libponyrt.$(LIB_EXT): $(depends) $(ofiles)
@echo 'Linking libponyrt'
ifneq (,$(DTRACE))
ifeq ($(OSTYPE), linux)
@echo 'Generating dtrace object file'
$(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
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles)
endif
else
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles)
endif
ifeq ($(runtime-bitcode),yes)
$($(1))/libponyrt.bc: $(depends) $(bcfiles)
@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)
@echo 'Linking $(1)'
$(SILENT)$(AR) $(AR_FLAGS) $$@ $(ofiles)
$(1): $($(1))/$(1).$(LIB_EXT)
else
$($(1))/$(1): $(depends) $(ofiles)
@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: libponyc libponyrt libponyrt-pic ponyc
else
install: libponyc libponyrt ponyc
endif
@mkdir -p $(destdir)/bin
@mkdir -p $(destdir)/lib
@mkdir -p $(destdir)/include/pony/detail
$(SILENT)cp $(PONY_BUILD_DIR)/libponyrt.a $(destdir)/lib
ifeq ($(OSTYPE),linux)
$(SILENT)cp $(PONY_BUILD_DIR)/libponyrt-pic.a $(destdir)/lib
endif
ifneq ($(wildcard $(PONY_BUILD_DIR)/libponyrt.bc),)
$(SILENT)cp $(PONY_BUILD_DIR)/libponyrt.bc $(destdir)/lib
endif
$(SILENT)cp $(PONY_BUILD_DIR)/libponyc.a $(destdir)/lib
$(SILENT)cp $(PONY_BUILD_DIR)/ponyc $(destdir)/bin
$(SILENT)cp src/libponyrt/pony.h $(destdir)/include
$(SILENT)cp src/common/pony/detail/atomics.h $(destdir)/include/pony/detail
$(SILENT)cp -r packages $(destdir)/
ifeq ($$(symlink),yes)
@mkdir -p $(prefix)/bin
@mkdir -p $(prefix)/lib
@mkdir -p $(prefix)/include/pony/detail
$(SILENT)ln $(symlink.flags) $(destdir)/bin/ponyc $(prefix)/bin/ponyc
$(SILENT)ln $(symlink.flags) $(destdir)/lib/libponyrt.a $(prefix)/lib/libponyrt.a
ifeq ($(OSTYPE),linux)
$(SILENT)ln $(symlink.flags) $(destdir)/lib/libponyrt-pic.a $(prefix)/lib/libponyrt-pic.a
endif
ifneq ($(wildcard $(destdir)/lib/libponyrt.bc),)
$(SILENT)ln $(symlink.flags) $(destdir)/lib/libponyrt.bc $(prefix)/lib/libponyrt.bc
endif
$(SILENT)ln $(symlink.flags) $(destdir)/lib/libponyc.a $(prefix)/lib/libponyc.a
$(SILENT)ln $(symlink.flags) $(destdir)/include/pony.h $(prefix)/include/pony.h
$(SILENT)ln $(symlink.flags) $(destdir)/include/pony/detail/atomics.h $(prefix)/include/pony/detail/atomics.h
endif
endef
$(eval $(call EXPAND_INSTALL))
define EXPAND_UNINSTALL
uninstall:
-$(SILENT)rm -rf $(destdir) 2>/dev/null ||:
-$(SILENT)rm $(prefix)/bin/ponyc 2>/dev/null ||:
-$(SILENT)rm $(prefix)/lib/libponyrt.a 2>/dev/null ||:
ifeq ($(OSTYPE),linux)
-$(SILENT)rm $(prefix)/lib/libponyrt-pic.a 2>/dev/null ||:
endif
ifneq ($(wildcard $(prefix)/lib/libponyrt.bc),)
-$(SILENT)rm $(prefix)/lib/libponyrt.bc 2>/dev/null ||:
endif
-$(SILENT)rm $(prefix)/lib/libponyc.a 2>/dev/null ||:
-$(SILENT)rm $(prefix)/include/pony.h 2>/dev/null ||:
-$(SILENT)rm -r $(prefix)/include/pony/ 2>/dev/null ||:
endef
$(eval $(call EXPAND_UNINSTALL))
test: all
@$(PONY_BUILD_DIR)/libponyc.tests
@$(PONY_BUILD_DIR)/libponyrt.tests
@$(PONY_BUILD_DIR)/ponyc -d -s --verify packages/stdlib
@./stdlib --sequential
@rm stdlib
test-examples: all
@PONYPATH=. $(PONY_BUILD_DIR)/ponyc -d -s examples
@./examples1
@rm examples1
test-ci: all
@$(PONY_BUILD_DIR)/ponyc --version
@$(PONY_BUILD_DIR)/libponyc.tests
@$(PONY_BUILD_DIR)/libponyrt.tests
@$(PONY_BUILD_DIR)/ponyc -d -s --verify packages/stdlib
@./stdlib --sequential
@rm stdlib
@$(PONY_BUILD_DIR)/ponyc --verify packages/stdlib
@./stdlib --sequential
@rm stdlib
@PONYPATH=. $(PONY_BUILD_DIR)/ponyc -d -s examples
@./examples1
@rm examples1
# Note: linux only
# FIXME: why is $(branch) empty?
define EXPAND_DEPLOY
deploy: test
$(SILENT)sh .bintray.sh debian "$(package_version)" "$(package_name)"
$(SILENT)sh .bintray.sh rpm "$(package_version)" "$(package_name)"
$(SILENT)sh .bintray.sh source "$(package_version)" "$(package_name)"
@mkdir build/bin
@mkdir -p $(package)/usr/bin
@mkdir -p $(package)/usr/include/pony/detail
@mkdir -p $(package)/usr/lib
@mkdir -p $(package)/usr/lib/pony/$(package_version)/bin
@mkdir -p $(package)/usr/lib/pony/$(package_version)/include/pony/detail
@mkdir -p $(package)/usr/lib/pony/$(package_version)/lib
$(SILENT)cp build/release/libponyc.a $(package)/usr/lib/pony/$(package_version)/lib
$(SILENT)cp build/release/libponyrt.a $(package)/usr/lib/pony/$(package_version)/lib
ifeq ($(OSTYPE),linux)
$(SILENT)cp build/release/libponyrt-pic.a $(package)/usr/lib/pony/$(package_version)/lib
endif
ifneq ($(wildcard build/release/libponyrt.bc),)
$(SILENT)cp build/release/libponyrt.bc $(package)/usr/lib/pony/$(package_version)/lib
endif
$(SILENT)cp build/release/ponyc $(package)/usr/lib/pony/$(package_version)/bin
$(SILENT)cp src/libponyrt/pony.h $(package)/usr/lib/pony/$(package_version)/include
$(SILENT)cp src/common/pony/detail/atomics.h $(package)/usr/lib/pony/$(package_version)/include/pony/detail
$(SILENT)ln -s /usr/lib/pony/$(package_version)/lib/libponyrt.a $(package)/usr/lib/libponyrt.a
ifeq ($(OSTYPE),linux)
$(SILENT)ln -s /usr/lib/pony/$(package_version)/lib/libponyrt-pic.a $(package)/usr/lib/libponyrt-pic.a
endif
ifneq ($(wildcard /usr/lib/pony/$(package_version)/lib/libponyrt.bc),)
$(SILENT)ln -s /usr/lib/pony/$(package_version)/lib/libponyrt.bc $(package)/usr/lib/libponyrt.bc
endif
$(SILENT)ln -s /usr/lib/pony/$(package_version)/lib/libponyc.a $(package)/usr/lib/libponyc.a
$(SILENT)ln -s /usr/lib/pony/$(package_version)/bin/ponyc $(package)/usr/bin/ponyc
$(SILENT)ln -s /usr/lib/pony/$(package_version)/include/pony.h $(package)/usr/include/pony.h
$(SILENT)ln -s /usr/lib/pony/$(package_version)/include/pony/detail/atomics.h $(package)/usr/include/pony/detail/atomics.h
$(SILENT)cp -r packages $(package)/usr/lib/pony/$(package_version)/
$(SILENT)build/release/ponyc packages/stdlib -rexpr -g -o $(package)/usr/lib/pony/$(package_version)
$(SILENT)fpm -s dir -t deb -C $(package) -p build/bin --name $(package_name) --conflicts $(package_conflicts) --version $(package_base_version) --iteration "$(package_iteration)" --description "The Pony Compiler"
$(SILENT)fpm -s dir -t rpm -C $(package) -p build/bin --name $(package_name) --conflicts $(package_conflicts) --version $(package_base_version) --iteration "$(package_iteration)" --description "The Pony Compiler"
$(SILENT)git archive HEAD > build/bin/$(archive)
$(SILENT)cp -r $(package)/usr/lib/pony/$(package_version)/stdlib-docs stdlib-docs
$(SILENT)tar rvf build/bin/$(archive) stdlib-docs
$(SILENT)bzip2 build/bin/$(archive)
$(SILENT)rm -rf $(package) build/bin/$(archive) stdlib-docs
endef
$(eval $(call EXPAND_DEPLOY))
stats:
@echo
@echo '------------------------------'
@echo 'Compiler and standard library '
@echo '------------------------------'
@echo
@cloc --read-lang-def=pony.cloc src packages
@echo
@echo '------------------------------'
@echo 'Test suite:'
@echo '------------------------------'
@echo
@cloc --read-lang-def=pony.cloc test
clean:
@rm -rf $(PONY_BUILD_DIR)
@rm -f src/common/dtrace_probes.h
-@rmdir build 2>/dev/null ||:
@echo 'Repository cleaned ($(PONY_BUILD_DIR)).'
help:
@echo 'Usage: make [config=name] [arch=name] [use=opt,...] [target]'
@echo
@echo 'CONFIGURATIONS:'
@echo ' debug (default)'
@echo ' release'
@echo
@echo 'ARCHITECTURE:'
@echo ' native (default)'
@echo ' [any compiler supported architecture]'
@echo
@echo 'USE OPTIONS:'
@echo ' valgrind'
@echo ' pooltrack'
@echo ' dtrace'
@echo
@echo 'TARGETS:'
@echo ' libponyc Pony compiler library'
@echo ' libponyrt Pony runtime'
@echo ' libponyrt-pic Pony runtime -fpic'
@echo ' libponyc.tests Test suite for libponyc'
@echo ' libponyrt.tests Test suite for libponyrt'
@echo ' ponyc Pony compiler executable'
@echo
@echo ' all Build all of the above (default)'
@echo ' test Run test suite'
@echo ' install Install ponyc'
@echo ' uninstall Remove all versions of ponyc'
@echo ' stats Print Pony cloc statistics'
@echo ' clean Delete all build files'
@echo