@@ -147,6 +147,7 @@ Check the cross-compiler:
147
147
Thread model: posix
148
148
gcc version 9.2.0 (GCC)
149
149
150
+ ### Cross-compilation on Linux for MacOS using official libftd2xx library
150
151
Once the toolchain is ready, download and unpack FTD2XX drivers for MacOS:
151
152
152
153
cd <path of the "fireprog" repository>
@@ -159,7 +160,7 @@ Once the toolchain is ready, download and unpack FTD2XX drivers for MacOS:
159
160
7z x D2XX1.4.16.dmg release/D2XX
160
161
mv release/D2XX .
161
162
162
- Rename the shared library file by adding some prefix :
163
+ Rename the shared library file so that its name does not start with "lib" :
163
164
164
165
mv D2XX/libftd2xx.1.4.16.dylib D2XX/backup_libftd2xx.1.4.16.dylib
165
166
cd ..
@@ -214,3 +215,118 @@ The output executable should be statically linked with no dynamic dependencies s
214
215
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1253.0.0)
215
216
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
216
217
218
+ ### Cross-compilation on Linux for MacOS using libftdi and libusb libraries
219
+ Download and unpack * libusb* library:
220
+
221
+ cd <path of the "fireprog" repository>
222
+ # Change one directory up (important!)
223
+ cd ..
224
+ wget -vc https://github.com/libusb/libusb/releases/download/v1.0.23/libusb-1.0.23.tar.bz2
225
+ # Unpack archive
226
+ tar -xvf libusb-1.0.23.tar.bz2
227
+
228
+ Create a local installation directory:
229
+
230
+ cd libusb-1.0.23
231
+ mkdir prefix
232
+ cd ..
233
+
234
+ Configure the build environment, compile and install the library locally:
235
+
236
+ ./configure --host=x86_64-apple-darwin15 --prefix="$(pwd)/prefix" CC=x86_64-apple-darwin15-clang
237
+ make
238
+ make install
239
+
240
+ Check for newly created library files:
241
+
242
+ tree ./prefix/
243
+ ./prefix
244
+ ├── include
245
+ │ └── libusb-1.0
246
+ │ └── libusb.h
247
+ └── lib
248
+ ├── libusb-1.0.0.dylib
249
+ ├── libusb-1.0.a
250
+ ├── libusb-1.0.dylib -> libusb-1.0.0.dylib
251
+ ├── libusb-1.0.la
252
+ └── pkgconfig
253
+ └── libusb-1.0.pc
254
+
255
+ Rename the shared library files so that their names do not start with "lib":
256
+
257
+ mv ./prefix/lib/libusb-1.0.0.dylib ./prefix/lib/backup_libusb-1.0.0.dylib
258
+ mv ./prefix/lib/libusb-1.0.dylib ./prefix/lib/backup_libusb-1.0.dylib
259
+
260
+ This is needed to ** enforce static linking** , so that static library * libusb-1.0.a* instead of * libusb-1.0.dylib* is used by the linker.
261
+
262
+ Download and unpack * libftdi* library:
263
+
264
+ cd <path of the "fireprog" repository>
265
+ # Change one directory up (important!)
266
+ cd ..
267
+ wget -vc https://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.5.tar.bz2
268
+ # Unpack archive
269
+ tar -xvf libftdi1-1.5.tar.bz2
270
+ cd libftdi1-1.5
271
+
272
+ There are only two files which need to be compiled, configuring CMake to support cross-compilation is more difficult than compiling these two files.
273
+
274
+ In order to create header * ftdi_version_i.h* from template * ftdi_version_i.h.in* manually, one needs to learn the versions of the library:
275
+
276
+ MAJOR_VERSION=`grep -P -o "(?<=set\(MAJOR_VERSION)\s*\d+(?=\))" CMakeLists.txt`
277
+ echo ${MAJOR_VERSION}
278
+ 1
279
+
280
+ MINOR_VERSION=`grep -P -o "(?<=set\(MINOR_VERSION)\s*\d+(?=\))" CMakeLists.txt`
281
+ echo ${MINOR_VERSION}
282
+ 5
283
+
284
+ grep -P -o "(?<=set\(VERSION_STRING)\s*.+(?=\))" CMakeLists.txt
285
+ ${MAJOR_VERSION}.${MINOR_VERSION}
286
+
287
+ VERSION_STRING_TEMPLATE=`grep -P -o "(?<=set\(VERSION_STRING)\s*.+(?=\))" CMakeLists.txt`
288
+ VERSION_STRING=$(eval echo ${VERSION_STRING_TEMPLATE}|sed "s/\s//g")
289
+ echo $VERSION_STRING
290
+ 1.5
291
+
292
+ After setting MAJOR_VERSION, MINOR_VERSION, VERSION_STRING environment variables, create * ftdi_version_i.h* from the template:
293
+
294
+ cd src
295
+ sed "s/@MAJOR_VERSION@/${MAJOR_VERSION}/g" ftdi_version_i.h.in > ftdi_version_i.h
296
+ sed -i "s/@MINOR_VERSION@/${MINOR_VERSION}/g" ftdi_version_i.h
297
+ sed -i "s/@VERSION_STRING@/${VERSION_STRING}/g" ftdi_version_i.h
298
+ sed -i "s/@SNAPSHOT_VERSION@/unknown/g" ftdi_version_i.h
299
+
300
+ Compile files:
301
+
302
+ x86_64-apple-darwin15-g++ -c ftdi.c -o ftdi.o -I ../../libusb-1.0.23/libusb/ -I .
303
+ x86_64-apple-darwin15-g++ -c ftdi_stream.c -o ftdi_stream.o -I ../../libusb-1.0.23/libusb/ -I . -Wno-narrowing -fpermissive
304
+
305
+ Bind object files into a static library:
306
+
307
+ x86_64-apple-darwin15-libtool -static ftdi.o ftdi_stream.o -o libftdi1.a
308
+
309
+ The corresponding Makefile is written according to this directory structure:
310
+
311
+ ├── fireprog
312
+ ├── libftdi1-1.5
313
+ └── libusb-1.0.23
314
+
315
+ Now compile the "fireprog":
316
+
317
+ cd <path of the fireprog repository>
318
+ make -f Makefile.MacOS_libftdi
319
+
320
+ Check the output binary:
321
+
322
+ file fireprog
323
+ fireprog: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>
324
+
325
+ The output executable should be statically linked with no dynamic dependencies such as FT2XX:
326
+
327
+ x86_64-apple-darwin15-otool -L fireprog
328
+ fireprog:
329
+ /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
330
+ /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
331
+ /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1253.0.0)
332
+ /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
0 commit comments