forked from lavavu/LavaVu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
226 lines (192 loc) · 5.96 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#Install path
PREFIX ?= lavavu
PROGNAME = LavaVu
PROGRAM = $(PREFIX)/$(PROGNAME)
LIBRARY = $(PREFIX)/lib$(PROGNAME).$(LIBEXT)
SWIGLIB = $(PREFIX)/_$(PROGNAME)Python.so
PYTHON ?= python
PYLIB ?= -L$(shell $(PYTHON) -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())')
PYINC ?= -I$(shell $(PYTHON) -c 'from distutils import sysconfig; print(sysconfig.get_python_inc())')
#Object files path
OPATH ?= tmp
#HTML files path
HTMLPATH = $(PREFIX)/html
#Compilers
CXX ?= g++
CC ?= gcc
#Default flags
DEFINES = -DUSE_ZLIB
CFLAGS = $(FLAGS) -fPIC -Isrc -Wall
CPPFLAGS = $(CFLAGS) -std=c++0x
#For external dependencies
EXTCFLAGS = -O3 -DNDEBUG -fPIC -Isrc
SWIGFLAGS=
#Default to X11 enabled unless explicitly disabled
X11 ?= 1
# Separate compile options per configuration
ifeq ($(CONFIG),debug)
CPPFLAGS += -g -O0 -DDEBUG
else
CPPFLAGS += -O3 -DNDEBUG
endif
#Linux/Mac specific libraries/flags for offscreen & interactive
OS := $(shell uname)
ifeq ($(OS), Darwin)
SWIGFLAGS= -undefined suppress -flat_namespace
CPPFLAGS += -Wno-unknown-warning-option -Wno-c++14-extensions -Wno-shift-negative-value
#Mac OS X with Cocoa + CGL
CPPFLAGS += -FCocoa -FOpenGL -stdlib=libc++
LIBS=-lc++ -ldl -lpthread -framework Cocoa -framework Quartz -framework OpenGL -lobjc -lm -lz
DEFINES += -DUSE_FONTS -DHAVE_CGL
APPLEOBJ=$(OPATH)/CocoaViewer.o
LIBEXT=dylib
LIBBUILD=-dynamiclib
LIBINSTALL=-install_name @loader_path/lib$(PROGNAME).$(LIBEXT)
else
#Linux
LIBS=-ldl -lpthread -lm -lz
DEFINES += -DUSE_FONTS
LIBEXT=so
LIBBUILD=-shared
LIBLINK=-Wl,-rpath='$$ORIGIN'
#Which window type?
ifeq ($(GLFW), 1)
#GLFW optional
LIBS+= -lGL -lglfw
DEFINES += -DHAVE_GLFW
else ifeq ($(EGL), 1)
#EGL (optionally with GLESv2)
ifeq ($(GLES2), 1)
LIBS+= -lEGL -lGLESv2
DEFINES += -DHAVE_EGL -DGLES2
else
LIBS+= -lEGL -lOpenGL
DEFINES += -DHAVE_EGL
endif #GLES2
else ifeq ($(OSMESA), 1)
#OSMesa
LIBS+= -lOSMesa
DEFINES += -DHAVE_OSMESA
else ifeq ($(X11), 1)
#X11
LIBS+= -lGL -lX11
DEFINES += -DHAVE_X11
endif
endif #Linux
#Extra defines passed
DEFINES += $(DEFS)
ifdef SHADER_PATH
DEFINES += -DSHADER_PATH=\"$(SHADER_PATH)\"
endif
#Use LV_LIB_DIRS and LV_INC_DIRS variables if defined
ifdef LV_LIB_DIRS
RP=-Wl,-rpath=
LIBS += -L$(subst :, -L,${LV_LIB_DIRS})
LIBS += ${RP}$(subst :, ${RP},${LV_LIB_DIRS})
endif
ifdef LV_INC_DIRS
CPPFLAGS += -I$(subst :, -I,${LV_INC_DIRS})
endif
#Other optional components
ifeq ($(VIDEO), 1)
CPPFLAGS += -DHAVE_LIBAVCODEC -DHAVE_SWSCALE
LIBS += -lavcodec -lavutil -lavformat -lswscale
endif
#Default libpng disabled, use built in png support
LIBPNG ?= 0
ifeq ($(LIBPNG), 1)
CPPFLAGS += -DHAVE_LIBPNG
LIBS += -lpng
endif
ifeq ($(TIFF), 1)
CPPFLAGS += -DHAVE_LIBTIFF
LIBS += -ltiff
endif
#Source search paths
vpath %.cpp src:src/Main:src:src/jpeg:src/png
vpath %.h src/Main:src:src/jpeg:src/png:src/sqlite3
vpath %.c src/sqlite3
vpath %.cc src
#Always run this script to update version.cpp if git version changes
TMP := $(shell $(PYTHON) version.py)
SRC := $(wildcard src/*.cpp) $(wildcard src/Main/*Viewer.cpp) $(wildcard src/jpeg/*.cpp)
INC := $(wildcard src/*.h) $(wildcard src/Main/*.h)
ifneq ($(LIBPNG), 1)
SRC += $(wildcard src/png/*.cpp)
INC += $(wildcard src/png/*.h)
endif
OBJ := $(SRC:%.cpp=%.o)
#Strip paths (src) from sources
OBJS = $(notdir $(OBJ))
#Add object path
OBJS := $(OBJS:%.o=$(OPATH)/%.o)
ALLOBJS := $(OBJS)
#Additional library objects (no cpp extension so not included above)
ALLOBJS += $(OPATH)/sqlite3.o
#Mac only
ALLOBJS += $(APPLEOBJ)
default: install
.PHONY: install
install: $(PROGRAM) $(SWIGLIB)
@if [ $(PREFIX) != "lavavu" ]; then \
cp -R lavavu/*.py $(PREFIX); \
cp -R lavavu/shaders/*.* $(PREFIX)/shaders; \
cp -R lavavu/html/*.* $(HTMLPATH); \
cp lavavu/font.bin $(PREFIX)/; \
cp lavavu/dict.json $(PREFIX)/; \
fi
.PHONY: force
$(OPATH)/compiler_flags: force | paths
@echo '$(CPPFLAGS)' | cmp -s - $@ || echo '$(CPPFLAGS)' > $@
.PHONY: paths
paths:
@mkdir -p $(OPATH)
@mkdir -p $(PREFIX)
@mkdir -p $(HTMLPATH)
@mkdir -p $(PREFIX)/shaders
#Rebuild *.cpp
$(OBJS): $(OPATH)/%.o : %.cpp $(OPATH)/compiler_flags $(INC) | src/sqlite3/sqlite3.c
$(CXX) $(CPPFLAGS) $(DEFINES) -c $< -o $@
$(PROGRAM): $(LIBRARY) main.cpp | paths
$(CXX) $(CPPFLAGS) $(DEFINES) -c src/Main/main.cpp -o $(OPATH)/main.o
$(CXX) -o $(PROGRAM) $(OPATH)/main.o $(LIBS) -l$(PROGNAME) -L$(PREFIX) $(LIBLINK)
$(LIBRARY): $(ALLOBJS) | paths
$(CXX) -o $(LIBRARY) $(LIBBUILD) $(LIBINSTALL) $(ALLOBJS) $(LIBS)
src/sqlite3/sqlite3.c :
#Ensure the submodule is checked out
git submodule update --init
$(OPATH)/sqlite3.o : src/sqlite3/sqlite3.c
$(CC) $(EXTCFLAGS) -o $@ -c $^
$(OPATH)/CocoaViewer.o : src/Main/CocoaViewer.mm
$(CXX) $(CPPFLAGS) $(DEFINES) -o $@ -c $^
#Python interface
SWIGSRC = src/LavaVuPython_wrap.cxx
SWIGOBJ = $(OPATH)/LavaVuPython_wrap.os
NUMPYINC = $(shell $(PYTHON) -c 'import numpy; print(numpy.get_include())')
ifneq ($(NUMPYINC),)
#Skip build if numpy not found
SWIGOBJ = $(OPATH)/LavaVuPython_wrap.os
endif
.PHONY: swig
swig : $(INC) src/LavaVuPython.i | paths
swig -v -Wextra -python -ignoremissing -O -c++ -DSWIG_DO_NOT_WRAP -outdir $(PREFIX) src/LavaVuPython.i
$(SWIGLIB) : $(LIBRARY) $(SWIGOBJ)
$(CXX) -o $(SWIGLIB) $(LIBBUILD) $(SWIGOBJ) $(SWIGFLAGS) ${PYLIB} -l$(PROGNAME) -L$(PREFIX) $(LIBLINK)
$(SWIGOBJ) : $(SWIGSRC) | src/sqlite3/sqlite3.c
$(CXX) $(CPPFLAGS) ${PYINC} -c $(SWIGSRC) -o $(SWIGOBJ) -I$(NUMPYINC)
docs: src/LavaVu.cpp src/Session.h src/version.cpp
$(PROGRAM) -S -h -p0 : docs:properties quit > docs/src/Property-Reference.md
$(PROGRAM) -S -h -p0 : docs:interaction quit > docs/src/Interaction.md
$(PROGRAM) -S -h -p0 : docs:scripting quit > docs/src/Scripting-Commands-Reference.md
$(PROGRAM) -? > docs/src/Commandline-Arguments.md
#pip install -r docs/src/requirements.txt
sphinx-build docs/src docs/
clean:
-rm -f *~ $(OPATH)/*.o
-rm -f $(PREFIX)/*.so
-rm -f $(PREFIX)/$(PROGNAME)
@if [ $(PREFIX) != "lavavu" ]; then \
-rm -rf $(PREFIX)/html; \
-rm -rf $(PREFIX)/shaders; \
-rm -f $(PREFIX)/*.py; \
fi