Skip to content

Commit 9579362

Browse files
committed
Add Windows deploy script
1 parent cda59c1 commit 9579362

File tree

2 files changed

+98
-4
lines changed

2 files changed

+98
-4
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ pacman -S jsoncpp
9696

9797
```shell
9898
# - MinGW build require tool MSYS2, you sould download and install it first, then use pacman in MSYS2 Enviroment
99+
#
99100
# - Assume you're building to mingw64, if you'd like to build to mingw32, replace `mingw-w64-x86_64` with `mingw-w64-i686`
100101
#
101102
# - Some packages are updated and not compatible, so some of the steps are using `pacman -U` to install specific version
102103
# packages with USTC Mirrors, you can change `https://mirrors.ustc.edu.cn/msys2/mingw/x86_64/` to other sources.
103104

104105
# Build deps
105-
pacman -S libintl mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake
106-
pacman -S make
106+
pacman -S libintl mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-make
107107

108108
# Boost
109109
# - It seems that when using Boost 1.66+ will cause build fail
@@ -115,7 +115,7 @@ pacman -S mingw-w64-x86_64-hdf5
115115

116116
# Jsoncpp
117117
# - JSONCPP comes with cmake, so if you've install cmake manually, you're not needed to install JSONCPP again
118-
pacman -S mingw-w64-x86_64-jsoncpp
118+
pacman -S mingw-w64-x86_64-jsoncpp jsoncpp-devel
119119

120120
# FFmpeg
121121
# - Some dll files are missing in MSYS2 MinGW64 FFmpeg package, so you should download it from other builds
@@ -149,7 +149,7 @@ unzip -p ffmpeg-3.4.2-win64-static.zip ffmpeg-3.4.2-win64-static/bin/ffmpeg.exe
149149

150150
> You should grab a FFmpeg 3.x binary from https://ffmpeg.zeranoe.com/ to make it works.
151151
152-
> You should download OpenH264 1.7.0 library file from https://github.com/cisco/openh264/releases manually.
152+
> You should download OpenH264 1.7.0+ library file from https://github.com/cisco/openh264/releases manually.
153153
154154
> If you want to use it on Windows, always use backslash to set file path like `D:\path\to\video.mp4`, even under MSYS2 or Cygwin, or boost cannot find the specific path.
155155
@@ -181,6 +181,27 @@ cmake -G "MinGw Makefiles" ..
181181
mingw32-make.exe animeloop-cli
182182
```
183183

184+
#### Deploy
185+
186+
##### Windows
187+
188+
``` Shell
189+
# copy_dependencies.py script requires ntldd tool
190+
pacman -S mingw-w64-x86_64-ntldd-git
191+
192+
cd animeloop-cli
193+
mkdir dist
194+
cp ./build/animeloop-cli.exe ./dist
195+
196+
# Run copy_dependencies.py to copy dlls
197+
./copy_dependencies.py -f ./dist/animeloop-cli.exe -d ./dist
198+
199+
#
200+
wget http://ciscobinary.openh264.org/openh264-1.8.0-win64.dll.bz2
201+
bzip2 -dc openh264-1.8.0-win64.dll.bz2 > ./dist/openh264-1.8.0-win64.dll
202+
rm openh264-1.8.0-win64.dll.bz2
203+
```
204+
184205
## Usage
185206

186207
```Shell

copy_dependencies.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/mingw64/bin/python2
2+
3+
###############################################################################
4+
#
5+
# The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6+
# Script to find and copy dependencies (msys2 only).
7+
# ./copy_dependencies.py -h for usage.
8+
#
9+
###############################################################################
10+
11+
import argparse
12+
import glob
13+
import os
14+
import re
15+
import shutil
16+
import subprocess
17+
import sys
18+
19+
def cygpath(file):
20+
return subprocess.check_output(["cygpath", "-m", file]).strip()
21+
22+
# ldd does not work well on Windows 10 and is not supported on mingw32
23+
def ldd(files):
24+
ldd_output = subprocess.check_output(["ntldd", "-R"] + files)
25+
# sanitize output
26+
ldd_output = ldd_output.strip()
27+
ldd_output = ldd_output.replace('\\', '/')
28+
# split output into lines
29+
ldd_lines = ldd_output.split(os.linesep)
30+
# parse lines that match this format : <file name> ==> <file path> (<memory address>)
31+
file_pattern = cygpath("/") + "mingw(32|64)/bin/.*"
32+
print file_pattern
33+
pattern = "(.*) => (" + file_pattern + ") \((.*)\)";
34+
regex = re.compile(pattern)
35+
dependencies = {m.group(2) for m in [regex.match(line.strip()) for line in ldd_lines] if m}
36+
return dependencies
37+
38+
parser = argparse.ArgumentParser(description='Find and copy dependencies to a destination directory.')
39+
parser.add_argument('-n', '--no-copy', action='store_true', help='don\'t copy dependencies to destination dir')
40+
parser.add_argument('-v', '--verbose', action='store_true', help='enable verbose mode')
41+
parser.add_argument('-d', '--dest', type=str, default='.', help='destination directory (defaults to current directory)')
42+
parser.add_argument('-f', '--files', metavar='FILE', nargs='+', required=True, help='a file')
43+
parser.add_argument('-e', '--excludes', metavar='FILE', nargs='+', help='a file')
44+
45+
args = parser.parse_args()
46+
47+
# check that args.dest exists and is a directory
48+
if not os.path.isdir(args.dest):
49+
print "Error: destination " + str(args.dest) + " is not a directory"
50+
exit(1)
51+
52+
# find dependencies
53+
dependencies = ldd(args.files)
54+
print "Found " + str(len(dependencies)) + " new dependencies"
55+
56+
# no copy, exit now
57+
if args.no_copy:
58+
exit(0)
59+
60+
# copy dependencies to destination dir
61+
copy_count = 0
62+
for file in dependencies:
63+
dest_file = args.dest + "/" + os.path.basename(file)
64+
if args.excludes and os.path.basename(file) in args.excludes:
65+
print "Ignoring " + file
66+
continue
67+
if not os.path.isfile(dest_file):
68+
print "Copying " + file + " to " + args.dest
69+
shutil.copy2(file, args.dest)
70+
copy_count += 1
71+
print "Copied " + str(copy_count) + " dependencies to " + str(args.dest)
72+
73+
exit(0)

0 commit comments

Comments
 (0)