git.iko.soy/rowtype-yoga/purescript-native
on 127af89 help sign in
129 lines 3.6 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
19PSCPP := pscpp
20SRC := src
21OUTPUT := output
22CC_SRC := $(OUTPUT)/src
23FFI_SRC := ffi
24BIN := main
26override PURSFLAGS += compile --codegen corefn
27override CXXFLAGS += --std=c++11
29CXXVERSION = $(shell $(CXX) --version)
30ifneq (,$(findstring g++,$(CXXVERSION)))
31 PSCPPFLAGS += "--ucns"
32endif
34DEBUG := "-DDEBUG -g"
35RELEASE := "-DNDEBUG -O3"
37INCLUDES := -I $(CC_SRC)
38BIN_DIR := $(OUTPUT)/bin
40PACKAGE_SOURCES = $(subst \,/,$(shell $(PSC_PACKAGE) sources))
41PURESCRIPT_PKGS := $(firstword $(subst /, ,$(PACKAGE_SOURCES)))
43## Not all environments support globstar (** dir pattern)
44rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
46unspecified:
47 @echo
48 @echo "Please specify the type of build you want: 'debug' or 'release'"
49 @echo
50 @echo " debug => not optimized (your app will run slower), good for"
51 @echo " running in a source-level debugger, more (descriptive)"
52 @echo " runtime exceptions"
53 @echo
54 @echo " release => optimized (your app will run faster), less helpful when debugging"
55 @echo
57debug: codegen
58 @$(MAKE) $(BIN) CFLAGS+=$(DEBUG) CXXFLAGS+=$(DEBUG)
60release: codegen
61 @$(MAKE) $(BIN) CFLAGS+=$(RELEASE) CXXFLAGS+=$(RELEASE)
63.PHONY: corefn
64corefn: PURESCRIPT_PKG_SRCS=$(foreach d,$(PACKAGE_SOURCES),$(call rwildcard,$(firstword $(subst *, ,$(d))),*.purs))
65corefn: PURESCRIPT_SRCS=$(call rwildcard,$(SRC)/,*.purs)
66corefn: $(PURESCRIPT_PKGS)
67 @$(PURS) $(PURSFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
69.PHONY: codegen
70codegen: COREFN_SRCS=$(call rwildcard,$(OUTPUT)/,corefn.json)
71codegen: corefn
72 @$(PSCPP) $(PSCPPFLAGS) $(COREFN_SRCS)
74$(PURESCRIPT_PKGS):
75 @echo "Getting packages using" $(PSC_PACKAGE) "..."
76 @$(PSC_PACKAGE) update
78SRCS := $(call rwildcard,$(CC_SRC)/,*.cpp)
79SRCS += $(call rwildcard,$(FFI_SRC)/,*.cpp)
80SRCS += $(call rwildcard,$(FFI_SRC)/,*.cc)
81SRCS += $(call rwildcard,$(FFI_SRC)/,*.mm)
82SRCS += $(call rwildcard,$(FFI_SRC)/,*.c)
83SRCS += $(call rwildcard,$(FFI_SRC)/,*.m)
85OBJS1 = $(SRCS:.cpp=.o)
86OBJS2 = $(OBJS1:.cc=.o)
87OBJS3 = $(OBJS2:.mm=.o)
88OBJS4 = $(OBJS3:.c=.o)
89OBJS = $(OBJS4:.m=.o)
90DEPS = $(OBJS:.o=.d)
92$(BIN): $(OBJS)
93 @echo "Linking" $(BIN_DIR)/$(BIN)
94 @mkdir -p $(BIN_DIR)
95 @$(CXX) $^ -o $(BIN_DIR)/$@ $(LDFLAGS)
97-include $(DEPS)
99%.o: %.cpp
100 @echo "Creating" $@ "(C++)"
101 @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
103%.o: %.cc
104 @echo "Creating" $@ "(C++)"
105 @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
107%.o: %.mm
108 @echo "Creating" $@ "(Objective-C++)"
109 @$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
111%.o: %.c
112 @echo "Creating" $@ "(C)"
113 @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
115%.o: %.m
116 @echo "Creating" $@ "(Objective-C)"
117 @$(CXX) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
119.PHONY: all
120all: release
122.PHONY: clean
123clean:
124 @-rm -f $(OBJS) $(DEPS)
125 @-rm -rf $(OUTPUT)
127.PHONY: run
128run:
129 @$(BIN_DIR)/$(BIN) $(ARGS)