git.iko.soy/rowtype-yoga/purescript-native
on 0cd4f99 help sign in
124 lines 3.4 kB history raw
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'
12# Flags can be added to either the codegen or native build phases.
13# For example: 'make PURSFLAGS=--codegen,js CXXFLAGS=-DDEBUG LDFLAGS=lgmp'
15# You can also edit the generated version of this file directly.
17PURS := purs
18PSC_PACKAGE := psc-package
19PSGO := psgo
20SRC := src
21OUTPUT := output
22CC_SRC := $(OUTPUT)/src
23FFI_SRC := ffi
24BIN := main
26override PURSFLAGS += compile --codegen corefn
27override CXXFLAGS += --std=c++11
29DEBUG := "-DDEBUG -g"
30RELEASE := "-DNDEBUG -O3"
32INCLUDES := -I $(CC_SRC)
33BIN_DIR := $(OUTPUT)/bin
35PACKAGE_SOURCES = $(subst \,/,$(shell $(PSC_PACKAGE) sources))
36PURESCRIPT_PKGS := $(firstword $(subst /, ,$(PACKAGE_SOURCES)))
38## Not all environments support globstar (** dir pattern)
39rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
41unspecified:
42 @echo
43 @echo "Please specify the type of build you want: 'debug' or 'release'"
44 @echo
45 @echo " debug => not optimized (your app will run slower), good for"
46 @echo " running in a source-level debugger, more (descriptive)"
47 @echo " runtime exceptions"
48 @echo
49 @echo " release => optimized (your app will run faster), less helpful when debugging"
50 @echo
52debug: codegen
53 go build -o $(BIN_DIR)/$(BIN) $(BIN)
55release: codegen
56 go build -o $(BIN_DIR)/$(BIN) $(BIN)
58.PHONY: corefn
59corefn: PURESCRIPT_PKG_SRCS=$(foreach d,$(PACKAGE_SOURCES),$(call rwildcard,$(firstword $(subst *, ,$(d))),*.purs))
60corefn: PURESCRIPT_SRCS=$(call rwildcard,$(SRC)/,*.purs)
61corefn: $(PURESCRIPT_PKGS)
62 @$(PURS) $(PURSFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
64.PHONY: codegen
65codegen: COREFN_SRCS=$(call rwildcard,$(OUTPUT)/,corefn.json)
66codegen: corefn
67 @$(PSGO) $(PSGOFLAGS) $(COREFN_SRCS)
69$(PURESCRIPT_PKGS):
70 @echo "Getting packages using" $(PSC_PACKAGE) "..."
71 @$(PSC_PACKAGE) update
73SRCS := $(call rwildcard,$(CC_SRC)/,*.cpp)
74SRCS += $(call rwildcard,$(FFI_SRC)/,*.cpp)
75SRCS += $(call rwildcard,$(FFI_SRC)/,*.cc)
76SRCS += $(call rwildcard,$(FFI_SRC)/,*.mm)
77SRCS += $(call rwildcard,$(FFI_SRC)/,*.c)
78SRCS += $(call rwildcard,$(FFI_SRC)/,*.m)
80OBJS1 = $(SRCS:.cpp=.o)
81OBJS2 = $(OBJS1:.cc=.o)
82OBJS3 = $(OBJS2:.mm=.o)
83OBJS4 = $(OBJS3:.c=.o)
84OBJS = $(OBJS4:.m=.o)
85DEPS = $(OBJS:.o=.d)
87$(BIN): $(OBJS)
88 @echo "Linking" $(BIN_DIR)/$(BIN)
89 @mkdir -p $(BIN_DIR)
90 @$(CXX) $^ -o $(BIN_DIR)/$@ $(LDFLAGS)
92-include $(DEPS)
94%.o: %.cpp
95 @echo "Creating" $@ "(C++)"
96 @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
98%.o: %.cc
99 @echo "Creating" $@ "(C++)"
100 @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
102%.o: %.mm
103 @echo "Creating" $@ "(Objective-C++)"
104 @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
106%.o: %.c
107 @echo "Creating" $@ "(C)"
108 @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
110%.o: %.m
111 @echo "Creating" $@ "(Objective-C)"
112 @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
114.PHONY: all
115all: release
117.PHONY: clean
118clean:
119 @-rm -f $(OBJS) $(DEPS)
120 @-rm -rf $(OUTPUT)
122.PHONY: run
123run:
124 @$(BIN_DIR)/$(BIN) $(ARGS)