|
| 1 | +# PureScript to native binary (via C++) Makefile |
| 2 | +# |
| 3 | +# Run 'make' or 'make release' to build an optimized release build |
| 4 | +# Run 'make debug' to build a non-optimized build suitable for debugging |
| 5 | +# |
| 6 | +# You can also perform a parallel build with 'make -jN', where N is the |
| 7 | +# number of cores to use. |
| 8 | +# |
| 9 | +# PURS, SRC, OUTPUT, and BIN can all be overridden with the |
| 10 | +# command itself. For example: 'make BIN=myutil' |
| 11 | +# |
| 12 | +# Flags can be added to either the codegen or native build phases. |
| 13 | +# For example: 'make PURSFLAGS=--codegen,js CXXFLAGS=-DDEBUG LDFLAGS=lgmp' |
| 14 | +# |
| 15 | +# You can also edit the generated version of this file directly. |
| 16 | +# |
| 17 | +PURS := purs |
| 18 | +PSC_PACKAGE := psc-package |
| 19 | +PSCPP := pscpp |
| 20 | +SRC := src |
| 21 | +OUTPUT := output |
| 22 | +CC_SRC := $(OUTPUT)/src |
| 23 | +FFI_SRC := ffi |
| 24 | +BIN := lambda-lantern |
| 25 | + |
| 26 | +override PURSFLAGS += compile --codegen corefn |
| 27 | +override CXXFLAGS += --std=c++11 |
| 28 | + |
| 29 | +CXXVERSION = $(shell $(CXX) --version) |
| 30 | +ifneq (,$(findstring g++,$(CXXVERSION))) |
| 31 | + PSCPPFLAGS += "--ucns" |
| 32 | +endif |
| 33 | + |
| 34 | +DEBUG := "-DDEBUG -g" |
| 35 | +RELEASE := "-DNDEBUG -O3" |
| 36 | + |
| 37 | +INCLUDES := -I $(CC_SRC) |
| 38 | +BIN_DIR := $(OUTPUT)/bin |
| 39 | + |
| 40 | +PACKAGE_SOURCES = $(subst \,/,$(shell $(PSC_PACKAGE) sources)) |
| 41 | +PURESCRIPT_PKGS := $(firstword $(subst /, ,$(PACKAGE_SOURCES))) |
| 42 | + |
| 43 | +## Not all environments support globstar (** dir pattern) |
| 44 | +rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) |
| 45 | + |
| 46 | +debug: codegen |
| 47 | + @$(MAKE) $(BIN) CFLAGS+=$(DEBUG) CXXFLAGS+=$(DEBUG) |
| 48 | + |
| 49 | +release: codegen |
| 50 | + @$(MAKE) $(BIN) CFLAGS+=$(RELEASE) CXXFLAGS+=$(RELEASE) |
| 51 | + |
| 52 | +.PHONY: corefn |
| 53 | +corefn: PURESCRIPT_PKG_SRCS=$(foreach d,$(PACKAGE_SOURCES),$(call rwildcard,$(firstword $(subst *, ,$(d))),*.purs)) |
| 54 | +corefn: PURESCRIPT_SRCS=$(call rwildcard,$(SRC)/,*.purs) |
| 55 | +corefn: $(PURESCRIPT_PKGS) |
| 56 | + @$(PURS) $(PURSFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS) |
| 57 | + |
| 58 | +.PHONY: codegen |
| 59 | +codegen: COREFN_SRCS=$(call rwildcard,$(OUTPUT)/,corefn.json) |
| 60 | +codegen: corefn |
| 61 | + @$(PSCPP) $(PSCPPFLAGS) $(COREFN_SRCS) |
| 62 | + |
| 63 | +$(PURESCRIPT_PKGS): |
| 64 | + @echo "Getting packages using" $(PSC_PACKAGE) "..." |
| 65 | + @$(PSC_PACKAGE) update |
| 66 | + |
| 67 | +SRCS := $(call rwildcard,$(CC_SRC)/,*.cpp) |
| 68 | +SRCS += $(call rwildcard,$(FFI_SRC)/,*.cpp) |
| 69 | +SRCS += $(call rwildcard,$(FFI_SRC)/,*.cc) |
| 70 | +SRCS += $(call rwildcard,$(FFI_SRC)/,*.mm) |
| 71 | +SRCS += $(call rwildcard,$(FFI_SRC)/,*.c) |
| 72 | +SRCS += $(call rwildcard,$(FFI_SRC)/,*.m) |
| 73 | + |
| 74 | +OBJS1 = $(SRCS:.cpp=.o) |
| 75 | +OBJS2 = $(OBJS1:.cc=.o) |
| 76 | +OBJS3 = $(OBJS2:.mm=.o) |
| 77 | +OBJS4 = $(OBJS3:.c=.o) |
| 78 | +OBJS = $(OBJS4:.m=.o) |
| 79 | +DEPS = $(OBJS:.o=.d) |
| 80 | + |
| 81 | +$(BIN): $(OBJS) |
| 82 | + @echo "Linking" $(BIN_DIR)/$(BIN) |
| 83 | + @mkdir -p $(BIN_DIR) |
| 84 | + @$(CXX) $^ -o $(BIN_DIR)/$@ $(LDFLAGS) |
| 85 | + |
| 86 | +-include $(DEPS) |
| 87 | + |
| 88 | +%.o: %.cpp |
| 89 | + @echo "Creating" $@ "(C++)" |
| 90 | + @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@ |
| 91 | + |
| 92 | +%.o: %.cc |
| 93 | + @echo "Creating" $@ "(C++)" |
| 94 | + @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@ |
| 95 | + |
| 96 | +%.o: %.mm |
| 97 | + @echo "Creating" $@ "(Objective-C++)" |
| 98 | + @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@ |
| 99 | + |
| 100 | +%.o: %.c |
| 101 | + @echo "Creating" $@ "(C)" |
| 102 | + @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@ |
| 103 | + |
| 104 | +%.o: %.m |
| 105 | + @echo "Creating" $@ "(Objective-C)" |
| 106 | + @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@ |
| 107 | + |
| 108 | +.PHONY: all |
| 109 | +all: release |
| 110 | + |
| 111 | +.PHONY: clean |
| 112 | +clean: |
| 113 | + @-rm -f $(OBJS) $(DEPS) |
| 114 | + @-rm -rf $(OUTPUT) |
| 115 | + |
| 116 | +.PHONY: run |
| 117 | +run: |
| 118 | + @$(BIN_DIR)/$(BIN) $(ARGS) |
0 commit comments