git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add example Makefile
b351f82Andy Arvanitis
support/Makefilenew file+94
@@ -0,0 +1,94 @@
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 CFLAGS=-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+PSOBJC := purecc
20+SRC := src
21+OUTPUT := output
22+CC_SRC := $(OUTPUT)/src
23+FFI_SRC := ffi
24+BIN := main
25+
26+override PURSFLAGS += compile --codegen corefn
27+override CFLAGS += --std=c++11
28+
29+DEBUG := "-DDEBUG -g"
30+RELEASE := "-O3"
31+
32+INCLUDES := -I $(CC_SRC)
33+BIN_DIR := $(OUTPUT)/bin
34+
35+PACKAGE_SOURCES = $(subst \,/,$(shell $(PSC_PACKAGE) sources))
36+PURESCRIPT_PKGS := $(firstword $(subst /, ,$(PACKAGE_SOURCES)))
37+
38+## Not all environments support globstar (** dir pattern)
39+rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
40+
41+release: codegen
42+ @$(MAKE) $(BIN) CFLAGS+=$(RELEASE)
43+
44+debug: codegen
45+ @$(MAKE) $(BIN) CFLAGS+=$(DEBUG)
46+
47+.PHONY: corefn
48+corefn: PURESCRIPT_PKG_SRCS=$(foreach d,$(PACKAGE_SOURCES),$(call rwildcard,$(firstword $(subst *, ,$(d))),*.purs))
49+corefn: PURESCRIPT_SRCS=$(call rwildcard,$(SRC)/,*.purs)
50+corefn: $(PURESCRIPT_PKGS)
51+ @$(PURS) $(PURSFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
52+
53+.PHONY: codegen
54+codegen: COREFN_SRCS=$(call rwildcard,$(OUTPUT)/,corefn.json)
55+codegen: corefn
56+ @$(PSOBJC) $(COREFN_SRCS)
57+
58+$(PURESCRIPT_PKGS):
59+ @echo "Getting packages using" $(PSC_PACKAGE) "..."
60+ @$(PSC_PACKAGE) update
61+
62+SRCS := $(call rwildcard,$(CC_SRC)/,*.cpp)
63+SRCS += $(call rwildcard,$(FFI_SRC)/,*.cpp)
64+SRCS += $(call rwildcard,$(FFI_SRC)/,*.c)
65+
66+OBJS1 = $(SRCS:.cpp=.o)
67+OBJS = $(OBJS1:.c=.o)
68+DEPS = $(OBJS:.o=.d)
69+
70+$(BIN): $(OBJS)
71+ @echo "Linking" $(BIN_DIR)/$(BIN)
72+ @mkdir -p $(BIN_DIR)
73+ @$(CXX) $^ -o $(BIN_DIR)/$@ $(LDFLAGS)
74+
75+-include $(DEPS)
76+
77+%.o: %.cpp
78+ @echo "Creating" $@
79+ @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
80+
81+%.o: %.c
82+ @echo "Creating" $@
83+ @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
84+
85+.PHONY: all
86+all: release
87+
88+.PHONY: clean
89+clean:
90+ @-rm -rf $(OUTPUT)
91+
92+.PHONY: run
93+run:
94+ @$(BIN_DIR)/$(BIN) $(ARGS)