Skip to content

Commit

Permalink
new build system, abandoned premake. Linker issues left to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Blessing committed Nov 26, 2014
1 parent 712462e commit 2ee5ba5
Show file tree
Hide file tree
Showing 128 changed files with 697 additions and 240 deletions.
18 changes: 1 addition & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,7 @@
*.s
*.ll
*.bc
Makefile
bin
Build
Bench
*.make
lib
obj
output
hmm*
work
.gitattributes
*.bc
_ReSharper.*

# Visual Studio files
*.vcxproj*
*.sln
*.suo
*.opensdf
*.sdf

164 changes: 164 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
ifeq ($(verbose),1)
PRINT := @echo "$(1)";
endif

# default settings (silent debug build)
LIB_EXT ?= a
BUILD_FLAGS = -m64 -mcx16 -march=native -Werror
LINKER_FLAGS =
ALL_CFLAGS = -std=gnu11
ALL_CXXFLAGS = -std=gnu++11
DEFINES =
PRINT =

ifeq ($(config),release)
BUILD_FLAGS += -O3
LINKER_FLAGS += -fuse-ld=gold
DEFINES += NDEBUG
else
config = debug
BUILD_FLAGS += -g
DEFINES += DEBUG
endif

PONY_BUILD_DIR ?= build/$(config)
PONY_SOURCE_DIR ?= src
PONY_TEST_DIR ?= test

lib := $(PONY_BUILD_DIR)/lib
bin := $(PONY_BUILD_DIR)/bin
tests := $(PONY_BUILD_DIR)/tests

$(shell mkdir -p $(lib))
$(shell mkdir -p $(bin))
$(shell mkdir -p $(tests))

obj := $(PONY_BUILD_DIR)/obj

LINKER_FLAGS += -L $(lib)/

# libraries
libponyc := $(lib)/libponyc
libponycc := $(lib)/libponycc
libponyrt := $(lib)/libponyrt

# 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 '='.
libponycc.dir := src/libponyc
libponycc.files := src/libponyc/debug/dwarf.cc
libponycc.files += src/libponyc/debug/symbols.cc
libponycc.files += src/libponyc/codegen/host.cc

libponyc.except := $(libponycc.files)
libponyc.except += src/libponyc/platform/signed.cc
libponyc.except += src/libponyc/platform/unsigned.cc
libponyc.except += src/libponyc/platform/vcvars.c

# Third party, but requires compilation. Defined as
# (1) a name and output directory.
# (2) a list of the source files to be compiled.
gtest := $(lib)
gtest.dir := lib/gtest
gtest.files := $(gtest.dir)/gtest_main.cc $(gtest.dir)/gtest-all.cc

libraries := libponyc libponycc libponyrt gtest

# Third party, but prebuilt. Prebuilt libraries are defined as
# (1) a name (without a target directory), stored in "prebuilt".
# (2) the linker flags necessary to link against the prebuilt library/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-3.5 --ldflags)
llvm.include := $(shell llvm-config-3.5 --includedir)
llvm.libs := $(shell llvm-config-3.5 --libs)

prebuilt := llvm

# Binaries. Defined as
# (1) a name and output directory.
ponyc := $(bin)

binaries := ponyc

# 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 := src/common/ $(llvm.include)/
libponycc.include := src/common/ $(llvm.include)/
libponyrt.include := src/common/ src/libponyrt/

ponyc.include := src/common/
gtest.include := lib/gtest/

# Tests suites are directly attached to the libraries they test.
libponyc.tests := $(tests)
libponyrt.tests := $(tests)

tests := libponyc.tests libponyrt.tests

# target specific build options

# link relationships
libponyc.links = -lponycc

# make targets
targets := $(libraries) $(binaries) $(tests)

.PHONY: all $(targets)

all: $(targets)

-include Rules.mk

$(foreach target,$(targets),$(eval $(call EXPAND_COMMAND,$(target))))

# dependencies
libponycc:
libponyrt:
libponyc: libponycc libponyrt
libponyc.tests: libponyc gtest
libponyrt.tests: libponyrt gtest
ponyc: libponyc
gtest:

stats:
@echo
@echo '------------------------------'
@echo 'Compiler and standard library '
@echo '------------------------------'
@echo
@cloc --read-lang-def=misc/pony.cloc src packages
@echo
@echo '------------------------------'
@echo 'Test suite:'
@echo '------------------------------'
@echo
@cloc --read-lang-def=misc/pony.cloc test

clean:
@rm -rf build
@echo 'Repository cleaned.'

help:
@echo
@echo 'Usage: make [config=name] [target]'
@echo
@echo "CONFIGURATIONS:"
@echo " debug"
@echo " release"
@echo
@echo 'TARGETS:'
@echo ' libponyc Pony compiler library'
@echo ' libponycc Pony compiler C++ LLVM bindings'
@echo ' libponyrt Pony runtime'
@echo ' libponyc.tests Test suite for libponyc'
@echo ' libponyrt.tests Test suite for libponyrt'
@echo ' ponyc Pony compiler executable'
@echo
@echo ' all Build all targets (default)'
@echo ' stats Print Pony cloc statistics'
@echo ' clean Delete all build files'
@echo
90 changes: 90 additions & 0 deletions Rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
empty :=
space := $(empty) $(empty)

##########################################################################
# #
# DIRECTORY: determines the source dir of a specific target #
# #
# ENUMERATE: enumerates input and output files for a specific target #
# #
# PICK_COMPILER: Chooses a C or C++ compiler depending on the 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 PICK_COMPILER
$(eval compiler := $(CC) $(ALL_CFLAGS))

ifneq ($$(filter $(suffix $(sourcefiles)),.cc),)
compiler := $(CXX) $(ALL_CXXFLAGS)
endif
endef

define PREPARE
$(eval $(call DIRECTORY,$(1)))
$(eval $(call ENUMERATE,$(1)))
$(eval $(call PICK_COMPILER,$(sourcefiles)))
$(eval objectfiles := $(subst $(sourcedir)/,$(outdir)/,$(addsuffix .o,$(sourcefiles))))
$(eval dependencies := $(subst .o,.d,$(objectfiles)))
endef

define EXPAND_OBJCMD
$(subst .c,,$(subst .cc,,$(1))): $(subst $(outdir)/,$(sourcedir)/,$(subst .o,,$(1)))
@echo 'COMPILE $$(notdir $$<)'
@mkdir -p $$(dir $$@)
@$(compiler) $(BUILD_FLAGS) -c -o $$@ $$< -I $(subst $(space), -I ,$($(2).include))
endef

define EXPAND_DEPCMD
$(subst .c,,$(subst .cc,,$(1))): $(subst $(outdir)/,$(sourcedir)/,$(subst .d,,$(1)))
@echo 'DEPEND $$(notdir $$@)'
@mkdir -p $$(dir $$@)
@$(compiler) -MM -MT $$(subst .d,.o,$$@) -MF $$@ $(BUILD_FLAGS) $$<
endef

define EXPAND_COMMAND
$(eval $(call PREPARE,$(1)))
$(eval ofiles := $(subst .c,,$(subst .cc,,$(objectfiles))))

ifneq ($(filter $(1),$(libraries)),)
$(1): $(ofiles)
@echo 'LINK $(1)'
@$(compiler) -o $($(1))/$(1).$(LIB_EXT) $(ofiles) $(LINKER_FLAGS) $($(1).ldflags) $($(1).links)
else
$(1): $(ofiles)
@echo 'BINARY $(1)'
@$(compiler) -o $($(1))/$(1) $(ofiles) $(LINKER_FLAGS) $($(1).ldflags) $($(1).links)
endif

$(foreach ofile,$(objectfiles),$(eval $(call EXPAND_OBJCMD,$(ofile),$(1))))
$(foreach dfile,$(dependencies),$(eval $(call EXPAND_DEPCMD,$(dfile))))

endef
Binary file added build/debug/lib/gtest.a
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ actor Updater
match others
| var next: Array[Updater] val =>
try next(i).receive(consume data) end
let test = data
end
end
end
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2ee5ba5

Please sign in to comment.