-
Notifications
You must be signed in to change notification settings - Fork 2
/
ujprog.rb
118 lines (111 loc) · 3.58 KB
/
ujprog.rb
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
class Ujprog < Formula
desc "ULX2S / ULX3S FPGA JTAG programmer"
homepage "https://github.com/f32c/tools"
head "https://github.com/f32c/tools.git"
depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on "libftdi"
depends_on "libusb"
depends_on "libusb-compat"
patch :DATA
def install
cd "ujprog" do
system "cmake", ".", *std_cmake_args
system "make", "install"
end
end
end
__END__
diff --git a/ujprog/CMakeLists.txt b/ujprog/CMakeLists.txt
new file mode 100644
index 0000000..bbe5969
--- /dev/null
+++ b/ujprog/CMakeLists.txt
@@ -0,0 +1,58 @@
+cmake_minimum_required(VERSION 3.10)
+
+# set the project name and version
+project(ujprog VERSION 1.0)
+
+# control where the static and shared libraries are built so that on windows
+# we don't need to tinker with the path to run the executable
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
+
+option(BUILD_STATIC "Build completely static binary" OFF)
+option(BUILD_STATICLIB "Build binary with non default static binaries" OFF)
+
+if (BUILD_STATIC)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+ find_library(LIBFTDISTATIC libftdi.a REQUIRED)
+ find_library(LIBUSB0STATIC libusb.a REQUIRED)
+endif()
+if (BUILD_STATICLIB)
+ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreFoundation -framework IOKit")
+ find_library(LIBFTDISTATIC libftdi1.a REQUIRED)
+ find_library(LIBUSB0STATIC libusb-1.0.a REQUIRED)
+ else()
+ find_library(LIBFTDISTATIC libftdi.a REQUIRED)
+ find_library(LIBUSB0STATIC libusb.a REQUIRED)
+ endif()
+ # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
+endif()
+find_package(LibFTDI1 CONFIG REQUIRED)
+
+link_directories(/usr/local/lib)
+
+# configure a header file to pass the version number only
+configure_file(ujprog.h.in ujprog.h)
+
+# add the executable
+add_executable(ujprog ujprog.c)
+target_include_directories(ujprog PRIVATE ${LIBFTDI_INCLUDE_DIR})
+if (BUILD_STATICLIB)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+ # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
+ set_target_properties(ujprog PROPERTIES LINK_SEARCH_START_STATIC 1)
+ set_target_properties(ujprog PROPERTIES LINK_SEARCH_END_STATIC 1)
+ target_link_libraries(ujprog PUBLIC ${LIBFTDISTATIC} ${LIBUSB0STATIC})
+else()
+ if (BUILD_STATIC)
+ target_link_libraries(ujprog PUBLIC ${LIBFTDISTATIC} ${LIBUSB0STATIC})
+ else()
+ target_link_libraries(ujprog PUBLIC ${LIBFTDI_LIBRARY} usb)
+ endif()
+endif()
+
+# install
+install(TARGETS ujprog DESTINATION bin)
+
diff --git a/ujprog/README.md b/ujprog/README.md
index a6858e5..79214a6 100644
--- a/ujprog/README.md
+++ b/ujprog/README.md
@@ -104,3 +104,16 @@ There can be many problems, I don't know what to do
one of the issues is that ujprog executable may needs
some dynamic linked library of specific version like libusb
+*** CMake ***
+
+It is standard CMake procedure:
+ # mkdir build
+ # cmake ..
+ # make
+ # make install
+
+You can also pass optional parameters:
+
+ # cmake -DBUILD_STATIC=ON -DLIBFTDISTATIC=/opt/libftdi/lib/libftdi.a -DLIBUSB0STATIC=/opt/libusb0/lib/libusb.a ..
+ # make install/strip
+
diff --git a/ujprog/ujprog.h.in b/ujprog/ujprog.h.in
new file mode 100644
index 0000000..6a198e6
--- /dev/null
+++ b/ujprog/ujprog.h.in
@@ -0,0 +1,3 @@
+#define UJPROG_VERSION_MAJOR @ujprog_VERSION_MAJOR@
+#define UJPROG_VERSION_MINOR @ujprog_VERSION_MINOR@
+