File: build-w64.sh

package info (click to toggle)
hamlib 4.6.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,984 kB
  • sloc: ansic: 262,996; sh: 6,135; cpp: 1,578; perl: 876; makefile: 855; python: 148; awk: 58; xml: 26
file content (319 lines) | stat: -rwxr-xr-x 10,265 bytes parent folder | download
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/bin/sh

# Builds Hamlib 4.x W64 binary distribution.

# A script to build a set of W64 binary DLLs and executables from a Hamlib
# source tarball.  This script assumes that the Hamlib source tarball has been
# extracted to the directory specified in $BUILD_DIR and that libusb-1.x.y has
# also been extracted to $BUILD_DIR.

# See README.build-Windows for complete details.


# Set this to a desired directory
BUILD_DIR=~/builds

# Set this to LibUSB archive extracted in $BUILD_DIR
LIBUSB_VER=libusb-1.0.24

# Set to the correct HOST_ARCH= line for your MinGW installation
HOST_ARCH=x86_64-w64-mingw32

# Set to the strip name for your version of MinGW
HOST_ARCH_STRIP=x86_64-w64-mingw32-strip

# Set to the dlltool name for your version of MinGW
HOST_ARCH_DLLTOOL=x86_64-w64-mingw32-dlltool

# Error return codes.  See /usr/include/sysexits.h
EX_USAGE=64
EX_NOINPUT=66


# Pass name of Hamlib archive extracted in $BUILD_DIR
if test $# -ne 1
then
    echo
    echo "Usage: $(basename $0) hamlib-version"
    echo "See README.build-Windows for more information."
    echo

    exit ${EX_USAGE}
fi

# Make sure the Hamlib archive is where we expect
if test -d ${BUILD_DIR}/$1
then
    echo
    echo "Building W64 binaries in ${BUILD_DIR}/$1"
    echo

    cd ${BUILD_DIR}/$1
else
    echo
    echo "Build directory, ${BUILD_DIR}/$1 not found!"
    echo "Check path for $1 or correct the version number."
    echo

    exit ${EX_NOINPUT}
fi

RELEASE=$(/usr/bin/awk 'BEGIN{FS="["; RS="]"} /\[4\./ {print $2;exit}' ./configure.ac)
HL_FILENAME=hamlib-w64-${RELEASE}
INST_DIR=$(pwd)/mingw64-inst
ZIP_DIR=$(pwd)/${HL_FILENAME}
LIBUSB_1_0_BIN_PATH=${BUILD_DIR}/${LIBUSB_VER}


# Create W64 specific README.w64-bin file
cat > README.w64-bin <<END_OF_README
What is it?
===========

This ZIP archive or Windows installer contains a build of Hamlib-$RELEASE
cross-compiled for MS Windows 64 bit using MinGW under Debian GNU/Linux 10
(nice, heh!).

This software is copyrighted. The library license is LGPL, and the *.EXE files
licenses are GPL.  Hamlib comes WITHOUT ANY WARRANTY. See the LICENSE.txt,
COPYING.txt, and COPYING.LIB.txt files.

Supporting documentation in the form of Unix manual pages have also been
included after being converted to HTML.


Installation and Configuration
==============================

Extract the ZIP archive into a convenient location, C:\Program Files is a
reasonable choice.

Make sure *all* the .DLL files are in your PATH (leave them in the bin
directory and set the PATH).  To set the PATH environment variable in Windows
2000, Windows XP, and Windows 7 (need info on Vista and Windows 8/10) do the
following:

 * W2k/XP: Right-click on "My Computer"
   Win7: Right-click on "Computer"

 * W2k/XP: Click the "Advanced" tab of the "System Properties" dialog
   Win7: Click the "Advanced system settings" link in the System dialog

 * Click the "Environment Variables" button of the pop-up dialog

 * Select "Path" in the "System variables" box of the "Environment Variables"
   dialog

   NB: If you are not the administrator, system policy may not allow editing
   the path variable.  The complete path to an executable file will need to be
   given to run one of the Hamlib programs.

 * Click the Edit button

 * Now add the Hamlib path in the "Variable Value:" edit box.  Be sure to put
   a semi-colon ';' after the last path before adding the Hamlib path (NB. The
   entire path is highlighted and will be erased upon typing a character so
   click in the box to unselect the text first.  The PATH is important!!)
   Append the Hamlib path, e.g. C:\Program Files\hamlib-w64-$RELEASE\bin

 * Click OK for all three dialog boxes to save your changes.


Testing with the Hamlib Utilities
=================================

To continue, be sure you have read the README.betatester file, especially the
"Testing Hamlib" section.  The primary means of testing is by way of the
rigctl utility for radios, the rotctl utility for rotators and the ampctl
utility for amplifiers.  Each is a command line program that is interactive
or can act on a single command and exit.

Documentation for each utility can be found as an HTML file in the doc
directory.

In short, the command syntax is of the form:

  rigctl -m 1020 -r COM1 -vvvvv

  -m -> Radio model 1020, or Yaesu FT-817 (use 'rigctl -l' for a list)
  -r -> Radio device, in this case COM1
  -v -> Verbosity level.  For testing four or five v characters are required.
        Five 'v's set a debug level of TRACE which generates a lot of screen
        output showing communication to the radio and values of important
        variables.  These traces are vital information for Hamlib rig backend
        development.

To run rigctl or rotctl open a cmd window (Start|Run|enter 'cmd' in the
dialog).  If text scrolls off the screen, you can scroll back with the mouse.
To copy output text into a mailer or editor (I recommend Notepad++, a free
editor also licensed under the GPL), highlight the text as a rectangle in the
cmd window, press <Enter> (or right-click the window icon in the upper left
corner and select Edit, then Copy), and paste it into your editor with Ctl-V
(or Edit|Paste from the typical GUI menu).

All feedback is welcome to the mail address below.


Uninstall
=========

To uninstall, simply delete the Hamlib directory.  You may wish to edit the
PATH as above to remove the Hamlib bin path, if desired.


Information for w64 Programmers
=================================

The DLL has a cdecl interface.

There is a libhamlib-4.def definition file for MS Visual C++/Visual Studio in
lib/msvc.  Refer to the sample commands below to generate a local
libhamlib-4.lib file for use with the VC++/VS linker.

Simply #include <hamlib/rig.h> (add directory to include path), include
libhamlib-4.lib in your project and you are done.  Note: VC++/VS cannot
compile all the Hamlib code, but the API defined by rig.h has been made MSVC
friendly :-)

As the source code for the library DLLs is licensed under the LGPL, your
program is not considered a "derivative work" when using the published Hamlib
API and normal linking to the front-end library, and may be of a license of
your choosing.

As of 08 Sep 2022 a .lib file is generated using the MinGW dlltool utility.
If this file does not work for your project, follow the steps in the following
section:

For linking the library with MS Visual C++ 2003, from the directory you
installed Hamlib run the following commands to generate the libhamlib-4.lib
file needed for linking with your MSVC project:

cd lib\msvc
c:\Program Files\Microsoft Visual C++ Toolkit 2003\bin\link.exe /lib /machine:amd64 /def:libhamlib-4.def

To do the same for Visual Studio 2017:

cd lib\msvc
c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x86\bin\link.exe /lib /machine:i386 /def:libhamlib-4.def

and for VS 2019:

cd lib\msvc
c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\Hostx64\x86\bin\link.exe /lib /machine:i386 /def:libhamlib-4.def

NOTE: feedback is requested on the previous two command examples as these do
not appear to be correct to generate a 64 bit libhamlib-4.lib file!

For VS 2022:

cd lib/msvc
c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x86\lib.exe /lib /machine:i386 /def:libhamlib-4.def

The published Hamlib API may be found at:

http://hamlib.sourceforge.net/manuals/4.1/index.html


Thank You!
==========

Patches, feedback, and contributions are welcome.

Please report problems or success to hamlib-developer@lists.sourceforge.net

Cheers,
Stephane Fillod - F8CFE
Mike Black - W9MDB
Nate Bargmann - N0NB
http://www.hamlib.org

END_OF_README


# Configure and build hamlib for x86_64-w64-mingw32, with libusb-1.0

./configure --host=${HOST_ARCH} \
 --prefix=${INST_DIR} \
 --without-cxx-binding \
 --disable-static \
 CPPFLAGS="-I${LIBUSB_1_0_BIN_PATH}/include" \
 LDFLAGS="-L${LIBUSB_1_0_BIN_PATH}/MinGW64/dll"


make -j 4 install

mkdir -p ${ZIP_DIR}/bin ${ZIP_DIR}/lib/msvc ${ZIP_DIR}/lib/gcc ${ZIP_DIR}/include ${ZIP_DIR}/doc
cp -a src/libhamlib.def ${ZIP_DIR}/lib/msvc/libhamlib-4.def
todos ${ZIP_DIR}/lib/msvc/libhamlib-4.def
cp -a ${INST_DIR}/include/hamlib ${ZIP_DIR}/include/.
todos ${ZIP_DIR}/include/hamlib/*.h

# C++ binding is useless on w64 because of ABI
for f in *class.h
do
    rm ${ZIP_DIR}/include/hamlib/${f}
done

for f in AUTHORS ChangeLog COPYING COPYING.LIB LICENSE README.md README.betatester README.w64-bin THANKS
do
    cp -a ${f} ${ZIP_DIR}/${f}.txt
    todos ${ZIP_DIR}/${f}.txt
done

# Generate HTML documents from nroff formatted man files
for f in doc/man1/*.1 doc/man7/*.7
do
    /usr/bin/groff -mandoc -Thtml >${f}.html ${f}
    cp -a ${f}.html ${ZIP_DIR}/doc/.
done

cd ${BUILD_DIR}/$1

# Copy build files into specific locations for Zip file
for f in *.exe
do
    cp -a ${INST_DIR}/bin/${f} ${ZIP_DIR}/bin/.
done

cp -a ${INST_DIR}/bin/libhamlib-?.dll ${ZIP_DIR}/bin/.
cp -a ${INST_DIR}/lib/libhamlib.dll.a ${ZIP_DIR}/lib/gcc/.

# NB: Strip Hamlib DLLs and EXEs
${HOST_ARCH_STRIP} ${ZIP_DIR}/bin/*.exe ${ZIP_DIR}/bin/*hamlib-*.dll

# Copy needed third party DLLs
cp -a /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll ${ZIP_DIR}/bin/.
cp -a ${LIBUSB_1_0_BIN_PATH}/MinGW64/dll/libusb-1.0.dll ${ZIP_DIR}/bin/libusb-1.0.dll

# Required for MinGW with GCC 6.3 (Debian 9)
FILE="/usr/lib/gcc/i686-w64-mingw32/6.3-posix/libgcc_s_sjlj-1.dll"
if test -f "$FILE"
then
    cp -a ${FILE} ${ZIP_DIR}/bin/.
fi

# Required for MinGW with GCC 8.3 (Debian 10)
FILE="/usr/lib/gcc/i686-w64-mingw32/8.3-posix/libgcc_s_sjlj-1.dll"
if test -f "$FILE"
then
    cp -a ${FILE} ${ZIP_DIR}/bin/.
fi

# Required for MinGW with GCC 10 (Debian 11)
FILE="/usr/lib/gcc/i686-w64-mingw32/10-posix/libgcc_s_dw2-1.dll"
if test -f "$FILE"
then
    cp -a ${FILE} ${ZIP_DIR}/bin/.
fi

# Required for MinGW with GCC 12 (Debian 12)
FILE="/usr/lib/gcc/i686-w64-mingw32/12-posix/libgcc_s_dw2-1.dll"
if test -f "$FILE"
then
    cp -a ${FILE} ${ZIP_DIR}/bin/.
fi

# Generate .lib file for MSVC
${HOST_ARCH_DLLTOOL} --input-def ${ZIP_DIR}/lib/msvc/libhamlib-4.def --output-lib ${ZIP_DIR}/lib/msvc/libhamlib-4.lib

/usr/bin/zip -r ${HL_FILENAME}.zip $(basename ${ZIP_DIR})