Skip to content

Commit e7dffbf

Browse files
committed
Add Linux compiling scripts
1 parent 32a7095 commit e7dffbf

File tree

2 files changed

+299
-0
lines changed

2 files changed

+299
-0
lines changed

GNUmakefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#----------------------------------------------------------------------------
2+
# Makefile for VapourSynth-Retinex, modified based on d2vsource/GNUmakefile
3+
#----------------------------------------------------------------------------
4+
5+
include config.mak
6+
7+
vpath %.cpp $(SRCDIR)
8+
vpath %.h $(SRCDIR)
9+
10+
SRCS = source/VSPlugin.cpp source/Gaussian.cpp source/MSR.cpp source/MSRCP.cpp
11+
12+
OBJS = $(SRCS:%.cpp=%.o)
13+
14+
.PHONY: all install clean distclean dep
15+
16+
all: $(LIBNAME)
17+
18+
$(LIBNAME): $(OBJS)
19+
$(LD) -o $@ $(LDFLAGS) $^ $(LIBS)
20+
-@ $(if $(STRIP), $(STRIP) -x $@)
21+
22+
%.o: %.cpp .depend
23+
$(CXX) $(CXXFLAGS) -c $< -o $@
24+
25+
install: all
26+
install -d $(libdir)
27+
install -m 755 $(LIBNAME) $(libdir)
28+
29+
clean:
30+
$(RM) *.dll *.so *.dylib $(OBJS) .depend
31+
32+
distclean: clean
33+
$(RM) config.*
34+
35+
dep: .depend
36+
37+
ifneq ($(wildcard .depend),)
38+
include .depend
39+
endif
40+
41+
.depend: config.mak
42+
@$(RM) .depend
43+
@$(foreach SRC, $(SRCS:%=$(SRCDIR)/%), $(CXX) $(SRC) $(CXXFLAGS) -MT $(SRC:$(SRCDIR)/%.cpp=%.o) -MM >> .depend;)
44+
45+
config.mak:
46+
./configure

configure

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
#!/bin/sh
2+
3+
#----------------------------------------------------------------------------
4+
# configure script for VapourSynth-Retinex
5+
#----------------------------------------------------------------------------
6+
7+
## This script was modified based on d2vsource/configure.
8+
9+
# -- help -------------------------------------------------------------------
10+
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
11+
cat << EOF
12+
Usage: [PKG_CONFIG_PATH=/foo/bar/lib/pkgconfig] ./configure [options]
13+
options:
14+
-h, --help print help (this)
15+
16+
--install=PATH set dir for install library
17+
[/usr/local/lib/vapoursynth]
18+
19+
--clang, --gcc compile by g++ or clang++ [clang]
20+
--target-os=OS build programs to run on OS [auto]
21+
--cross-prefix=PREFIX use PREFIX for compilation tools
22+
--sysroot=SYSROOT root of cross-build tree
23+
--enable-debug compile with debug symbols and never strip
24+
25+
--extra-cxxflags=XCXXFLAGS add XCXXFLAGS to CXXFLAGS
26+
--extra-ldflags=XLDFLAGS add XLDFLAGS to LDFLAGS
27+
--extra-libs=XLIBS add XLIBS to LIBS
28+
29+
--target=TARGET set target instruction set [sse2]
30+
31+
EOF
32+
exit 1
33+
fi
34+
35+
#-- func --------------------------------------------------------------------
36+
error_exit()
37+
{
38+
echo error: $1
39+
exit 1
40+
}
41+
log_echo()
42+
{
43+
echo $1
44+
echo >> config.log
45+
echo --------------------------------- >> config.log
46+
echo $1 >> config.log
47+
}
48+
49+
cc_check()
50+
{
51+
rm -f conftest.c
52+
if [ -n "$3" ]; then
53+
echo "#include <$3>" >> config.log
54+
echo 'extern "C" {' > conftest.cpp
55+
echo "#include <$3>" >> conftest.cpp
56+
echo } >> conftest.cpp
57+
fi
58+
echo "int main(void){$4 return 0;}" >> config.log
59+
echo "int main(void){$4 return 0;}" >> conftest.cpp
60+
echo $CXX conftest.cpp -o conftest -Werror $1 $2 >> config.log
61+
$CXX conftest.cpp -o conftest -Werror $1 $2 2>> config.log
62+
ret=$?
63+
echo $ret >> config.log
64+
rm -f conftest*
65+
return $ret
66+
}
67+
#----------------------------------------------------------------------------
68+
rm -f config.* .depend
69+
70+
SRCDIR="$(cd $(dirname $0); pwd)"
71+
test "$SRCDIR" = "$(pwd)" && SRCDIR=.
72+
test -n "$(echo $SRCDIR | grep ' ')" && \
73+
error_exit "out-of-tree builds are impossible with whitespace in source path"
74+
75+
# -- init -------------------------------------------------------------------
76+
libdir="/usr/local/lib/vapoursynth"
77+
78+
TARGET_OS=""
79+
CROSS=""
80+
81+
SYSROOT=""
82+
CXX="clang++"
83+
LD="clang++"
84+
STRIP="strip"
85+
86+
test -n "$(which $CXX 2> /dev/null)" || CXX="g++"
87+
test -n "$(which $LD 2> /dev/null)" || LD="g++"
88+
89+
DEBUG=""
90+
91+
LIBNAME=""
92+
93+
CXXFLAGS="-std=c++11 -Wall -I. -I$SRCDIR/include"
94+
LDFLAGS=""
95+
SOFLAGS="-shared -Wl,-Bsymbolic"
96+
DEPLIBS=""
97+
TARGET="-msse2"
98+
99+
# -- options ----------------------------------------------------------------
100+
echo all command lines: > config.log
101+
echo "$*" >> config.log
102+
103+
for opt; do
104+
optarg="${opt#*=}"
105+
case "$opt" in
106+
--install=*)
107+
libdir="$optarg"
108+
;;
109+
--enable-debug)
110+
DEBUG="enabled"
111+
XCXXFLAGS="$XCXXFLAGS -g"
112+
;;
113+
--cxx=*)
114+
CXX="$optarg"
115+
;;
116+
--extra-cxxflags=*)
117+
XCXXFLAGS="$optarg"
118+
;;
119+
--extra-ldflags=*)
120+
XLDFLAGS="$optarg"
121+
;;
122+
--extra-libs=*)
123+
XLIBS="$optarg"
124+
;;
125+
--target-os=*)
126+
TARGET_OS="$optarg"
127+
;;
128+
--cross-prefix=*)
129+
CROSS="$optarg"
130+
;;
131+
--sysroot=*)
132+
CXXFLAGS="$CXXFLAGS --sysroot=$optarg"
133+
LDFLAGS="$LDFLAGS --sysroot=$optarg"
134+
;;
135+
--gcc)
136+
CXX="g++"
137+
LD="g++"
138+
;;
139+
--clang)
140+
CXX="clang++"
141+
LD="clang++"
142+
;;
143+
--target=*)
144+
TARGET="-m$optarg"
145+
;;
146+
*)
147+
error_exit "unknown option $opt"
148+
;;
149+
esac
150+
done
151+
152+
CXXFLAGS="$CXXFLAGS $XCXXFLAGS $TARGET"
153+
LDFLAGS="$LDFLAGS $XLDFLAGS"
154+
155+
CXX="${CROSS}${CXX}"
156+
LD="${CROSS}${LD}"
157+
STRIP="${CROSS}${STRIP}"
158+
for f in "$CXX" "$LD" "$STRIP"; do
159+
test -n "$(which $f 2> /dev/null)" || error_exit "$f is not executable"
160+
done
161+
162+
if test -n "$TARGET_OS"; then
163+
TARGET_OS=$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')
164+
else
165+
TARGET_OS=$($CXX -dumpmachine | tr '[A-Z]' '[a-z]')
166+
fi
167+
case "$TARGET_OS" in
168+
*mingw*)
169+
LIBNAME="Retinex.dll"
170+
SOFLAGS="$SOFLAGS -Wl,--dll,--add-stdcall-alias"
171+
;;
172+
*darwin*)
173+
LIBNAME="libretinex.dylib"
174+
DEPLIBS="$DEPLIBS vapoursynth"
175+
SOFLAGS="$SOFLAGS -dynamiclib -Wl,-undefined,suppress -Wl,-read_only_relocs,suppress -Wl,-flat_namespace"
176+
;;
177+
*linux*)
178+
LIBNAME="libretinex.so"
179+
DEPLIBS="$DEPLIBS vapoursynth"
180+
CXXFLAGS="$CXXFLAGS -fPIC"
181+
SOFLAGS="$SOFLAGS -fPIC"
182+
;;
183+
*)
184+
error_exit "target is unsupported system"
185+
esac
186+
187+
188+
log_echo "CXXFLAGS/LDFLAGS checking..."
189+
if ! cc_check "$CXXFLAGS" "$LDFLAGS"; then
190+
error_exit "invalid CXXFLAGS/LDFLAGS"
191+
fi
192+
if cc_check "-Os -ffast-math $CXXFLAGS" "$LDFLAGS"; then
193+
CXXFLAGS="-Os -ffast-math $CXXFLAGS"
194+
fi
195+
if cc_check "$CXXFLAGS -fexcess-precision=fast" "$LDFLAGS"; then
196+
CXXFLAGS="$CXXFLAGS -fexcess-precision=fast"
197+
fi
198+
199+
PKGCONFIGBIN="pkg-config"
200+
test -n "$(which ${CROSS}${PKGCONFIGBIN} 2> /dev/null)" && \
201+
PKGCONFIGBIN=${CROSS}${PKGCONFIGBIN}
202+
203+
if $PKGCONFIGBIN --exists $DEPLIBS 2> /dev/null; then
204+
LIBS="$($PKGCONFIGBIN --libs $DEPLIBS)"
205+
CXXFLAGS="$CXXFLAGS $($PKGCONFIGBIN --cflags $DEPLIBS)"
206+
else
207+
for lib in $DEPLIBS; do
208+
LIBS="$LIBS -l${lib#lib}"
209+
done
210+
log_echo "warning: pkg-config or pc files not found, lib detection may be inaccurate."
211+
fi
212+
213+
LDFLAGS="$SOFLAGS $LDFLAGS"
214+
LIBS="$LIBS $XLIBS"
215+
216+
217+
cat >> config.mak << EOF
218+
CXX = $CXX
219+
LD = $LD
220+
STRIP = $STRIP
221+
CXXFLAGS = $CXXFLAGS
222+
LDFLAGS = $LDFLAGS
223+
LIBS = $LIBS
224+
SRCDIR = $SRCDIR
225+
LIBNAME = $LIBNAME
226+
libdir = $libdir
227+
EOF
228+
229+
cat >> config.log << EOF
230+
---------------------------------
231+
setting
232+
---------------------------------
233+
EOF
234+
cat config.mak >> config.log
235+
236+
cat << EOF
237+
238+
settings...
239+
CXX = $CXX
240+
LD = $LD
241+
STRIP = $STRIP
242+
CXXFLAGS = $CXXFLAGS
243+
LDFLAGS = $LDFLAGS
244+
LIBS = $LIBS
245+
LIBNAME = $LIBNAME
246+
install path = $libdir
247+
EOF
248+
249+
test "$SRCDIR" = "." || ln -sf $SRCDIR/GNUmakefile .
250+
251+
echo configure finished.
252+
253+
exit 0

0 commit comments

Comments
 (0)