ocran 1.3.17 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.txt +306 -272
  3. data/LICENSE.txt +22 -22
  4. data/README.md +549 -531
  5. data/exe/ocran +5 -5
  6. data/ext/extconf.rb +15 -0
  7. data/lib/ocran/build_constants.rb +16 -16
  8. data/lib/ocran/build_facade.rb +17 -17
  9. data/lib/ocran/build_helper.rb +110 -105
  10. data/lib/ocran/command_output.rb +22 -22
  11. data/lib/ocran/dir_builder.rb +162 -0
  12. data/lib/ocran/direction.rb +623 -386
  13. data/lib/ocran/file_path_set.rb +69 -69
  14. data/lib/ocran/gem_spec_queryable.rb +172 -172
  15. data/lib/ocran/host_config_helper.rb +57 -37
  16. data/lib/ocran/inno_setup_script_builder.rb +111 -111
  17. data/lib/ocran/launcher_batch_builder.rb +85 -85
  18. data/lib/ocran/library_detector.rb +61 -61
  19. data/lib/ocran/library_detector_posix.rb +55 -0
  20. data/lib/ocran/option.rb +323 -273
  21. data/lib/ocran/refine_pathname.rb +104 -104
  22. data/lib/ocran/runner.rb +115 -105
  23. data/lib/ocran/runtime_environment.rb +46 -46
  24. data/lib/ocran/stub_builder.rb +298 -224
  25. data/lib/ocran/version.rb +5 -5
  26. data/lib/ocran/windows_command_escaping.rb +15 -15
  27. data/lib/ocran.rb +7 -7
  28. data/share/ocran/lzma.exe +0 -0
  29. data/src/Makefile +75 -0
  30. data/src/edicon.c +161 -0
  31. data/src/error.c +100 -0
  32. data/src/error.h +66 -0
  33. data/src/inst_dir.c +334 -0
  34. data/src/inst_dir.h +157 -0
  35. data/src/lzma/7zTypes.h +529 -0
  36. data/src/lzma/Compiler.h +43 -0
  37. data/src/lzma/LzmaDec.c +1363 -0
  38. data/src/lzma/LzmaDec.h +236 -0
  39. data/src/lzma/Precomp.h +10 -0
  40. data/src/script_info.c +246 -0
  41. data/src/script_info.h +7 -0
  42. data/src/stub.c +133 -0
  43. data/src/stub.manifest +29 -0
  44. data/src/stub.rc +3 -0
  45. data/src/system_utils.c +1002 -0
  46. data/src/system_utils.h +209 -0
  47. data/src/system_utils_posix.c +500 -0
  48. data/src/unpack.c +574 -0
  49. data/src/unpack.h +85 -0
  50. data/src/vit-ruby.ico +0 -0
  51. metadata +55 -22
  52. data/share/ocran/edicon.exe +0 -0
  53. data/share/ocran/stub.exe +0 -0
  54. data/share/ocran/stubw.exe +0 -0
@@ -1,224 +1,298 @@
1
- # frozen_string_literal: true
2
- require "tempfile"
3
- require_relative "file_path_set"
4
-
5
- module Ocran
6
- # Utility class that produces the actual executable. Opcodes
7
- # (create_file, mkdir etc) are added by invoking methods on an
8
- # instance of OcranBuilder.
9
- class StubBuilder
10
- Signature = [0x41, 0xb6, 0xba, 0x4e].freeze
11
- OP_END = 0
12
- OP_CREATE_DIRECTORY = 1
13
- OP_CREATE_FILE = 2
14
- OP_SETENV = 3
15
- OP_SET_SCRIPT = 4
16
-
17
- DEBUG_MODE = 0x01
18
- EXTRACT_TO_EXE_DIR = 0x02
19
- AUTO_CLEAN_INST_DIR = 0x04
20
- CHDIR_BEFORE_SCRIPT = 0x08
21
- DATA_COMPRESSED = 0x10
22
-
23
- base_dir = File.expand_path("../../share/ocran", File.dirname(__FILE__))
24
- STUB_PATH = File.expand_path("stub.exe", base_dir)
25
- STUBW_PATH = File.expand_path("stubw.exe", base_dir)
26
- LZMA_PATH = File.expand_path("lzma.exe", base_dir)
27
- EDICON_PATH = File.expand_path("edicon.exe", base_dir)
28
-
29
- attr_reader :data_size
30
-
31
- # chdir_before:
32
- # When set to true, the working directory is changed to the application's
33
- # deployment location at runtime.
34
- #
35
- # debug_mode:
36
- # When the debug_mode option is set to true, the stub will output debug information
37
- # when the exe file is executed. Debug mode can also be enabled within the directive
38
- # code using the enable_debug_mode method. This option is provided to transition to
39
- # debug mode from the initialization point of the stub.
40
- #
41
- # debug_extract:
42
- # When set to true, the runtime file is extracted to the directory where the executable resides,
43
- # and the extracted files remain even after the application exits.
44
- # When set to false, the runtime file is extracted to the system's temporary directory,
45
- # and the extracted files are deleted after the application exits.
46
- #
47
- # gui_mode:
48
- # When set to true, the stub does not display a console window at startup. Errors are shown in a dialog window.
49
- # When set to false, the stub reports errors through the console window.
50
- #
51
- # icon_path:
52
- # Specifies the path to the icon file to be embedded in the stub's resources.
53
- #
54
- def initialize(path, chdir_before: nil, debug_extract: nil, debug_mode: nil,
55
- enable_compression: nil, gui_mode: nil, icon_path: nil)
56
- @dirs = FilePathSet.new
57
- @files = FilePathSet.new
58
- @data_size = 0
59
-
60
- if icon_path && !File.exist?(icon_path)
61
- raise "Icon file #{icon_path} not found"
62
- end
63
-
64
- stub = Tempfile.new("", File.dirname(path))
65
- IO.copy_stream(gui_mode ? STUBW_PATH : STUB_PATH, stub)
66
- stub.close
67
-
68
- if icon_path
69
- system(EDICON_PATH, stub.path, icon_path.to_s, exception: true)
70
- end
71
-
72
- File.open(stub, "ab") do |of|
73
- @of = of
74
- @opcode_offset = @of.size
75
-
76
- write_header(debug_mode, debug_extract, chdir_before, enable_compression)
77
-
78
- b = proc {
79
- yield(self)
80
- write_opcode(OP_END)
81
- }
82
-
83
- if enable_compression
84
- compress(&b)
85
- else
86
- b.yield
87
- end
88
-
89
- write_footer
90
- end
91
-
92
- File.rename(stub, path)
93
- end
94
-
95
- def mkdir(target)
96
- return unless @dirs.add?("/", target)
97
-
98
- write_opcode(OP_CREATE_DIRECTORY)
99
- write_path(target)
100
- end
101
-
102
- def cp(source, target)
103
- unless File.exist?(source)
104
- raise "The file does not exist (#{source})"
105
- end
106
-
107
- return unless @files.add?(source, target)
108
-
109
- write_opcode(OP_CREATE_FILE)
110
- write_path(target)
111
- write_file(source)
112
- end
113
-
114
- # Specifies the final application script to be launched, which can be called
115
- # from any position in the data stream. It cannot be specified more than once.
116
- #
117
- # You can omit setting OP_SET_SCRIPT without issues, in which case
118
- # the stub terminates without launching anything after performing other
119
- # runtime operations.
120
- def exec(image, script, *argv)
121
- if @script_set
122
- raise "Script is already set"
123
- end
124
- @script_set = true
125
-
126
- write_opcode(OP_SET_SCRIPT)
127
- write_string_array(convert_to_native(image), convert_to_native(script), *argv)
128
- end
129
-
130
- def export(name, value)
131
- write_opcode(OP_SETENV)
132
- write_string(name.to_s)
133
- write_string(value.to_s)
134
- end
135
-
136
- def compress
137
- IO.popen([LZMA_PATH, "e", "-si", "-so"], "r+b") do |lzma|
138
- _of, @of = @of, lzma
139
- Thread.new { yield(self); lzma.close_write }
140
- IO.copy_stream(lzma, _of)
141
- @of = _of
142
- end
143
-
144
- # Calculate the position to write the LZMA decompressed size (64-bit unsigned integer)
145
- # @opcode_offset: start position of the data section
146
- # 1: size of the header byte
147
- # 5: size of the LZMA header in bytes
148
- File.binwrite(@of.path, [@data_size].pack("Q<"), @opcode_offset + 1 + 5)
149
- end
150
- private :compress
151
-
152
- def write_header(debug_mode, debug_extract, chdir_before, compressed)
153
- next_to_exe, delete_after = debug_extract, !debug_extract
154
- @of << [0 |
155
- (debug_mode ? DEBUG_MODE : 0) |
156
- (next_to_exe ? EXTRACT_TO_EXE_DIR : 0) |
157
- (delete_after ? AUTO_CLEAN_INST_DIR : 0) |
158
- (chdir_before ? CHDIR_BEFORE_SCRIPT : 0) |
159
- (compressed ? DATA_COMPRESSED : 0)
160
- ].pack("C")
161
- end
162
- private :write_header
163
-
164
- def write_opcode(op)
165
- @of << [op].pack("C")
166
- @data_size += 1
167
- end
168
- private :write_opcode
169
-
170
- def write_size(i)
171
- if i > 0xFFFF_FFFF
172
- raise ArgumentError, "Size #{i} is too large: must be 32-bit unsigned integer (0 to 4294967295)"
173
- end
174
-
175
- @of << [i].pack("V")
176
- @data_size += 4
177
- end
178
- private :write_size
179
-
180
- def write_string(str)
181
- len = str.bytesize + 1 # +1 to account for the null terminator
182
-
183
- if len > 0xFFFF
184
- raise ArgumentError, "String length #{len} is too large: must be less than or equal to 65535 bytes including null terminator"
185
- end
186
-
187
- @of << [len, str].pack("vZ*")
188
- @data_size += 2 + len
189
- end
190
- private :write_string
191
-
192
- def write_string_array(*str_array)
193
- ary = str_array.map(&:to_s)
194
- size = ary.sum(0) { |s| s.bytesize + 1 }
195
- write_size(size)
196
- ary.each_slice(1) { |a| @of << a.pack("Z*") }
197
- @data_size += size
198
- end
199
- private :write_string_array
200
-
201
- def write_file(src)
202
- size = File.size(src)
203
- write_size(size)
204
- IO.copy_stream(src, @of)
205
- @data_size += size
206
- end
207
- private :write_file
208
-
209
- def write_path(path)
210
- write_string(convert_to_native(path))
211
- end
212
- private :write_path
213
-
214
- def write_footer
215
- @of << ([@opcode_offset] + Signature).pack("VC*")
216
- end
217
- private :write_footer
218
-
219
- def convert_to_native(path)
220
- path.to_s.tr(File::SEPARATOR, "\\")
221
- end
222
- private :convert_to_native
223
- end
224
- end
1
+ # frozen_string_literal: true
2
+ require "tempfile"
3
+ require_relative "file_path_set"
4
+
5
+ module Ocran
6
+ # Utility class that produces the actual executable. Opcodes
7
+ # (create_file, mkdir etc) are added by invoking methods on an
8
+ # instance of OcranBuilder.
9
+ class StubBuilder
10
+ Signature = [0x41, 0xb6, 0xba, 0x4e].freeze
11
+
12
+ OP_CREATE_DIRECTORY = 1
13
+ OP_CREATE_FILE = 2
14
+ OP_SETENV = 3
15
+ OP_SET_SCRIPT = 4
16
+ OP_CREATE_SYMLINK = 5
17
+
18
+ DEBUG_MODE = 0x01
19
+ EXTRACT_TO_EXE_DIR = 0x02
20
+ AUTO_CLEAN_INST_DIR = 0x04
21
+ CHDIR_BEFORE_SCRIPT = 0x08
22
+ DATA_COMPRESSED = 0x10
23
+
24
+ WINDOWS = Gem.win_platform?
25
+
26
+ base_dir = File.expand_path("../../share/ocran", File.dirname(__FILE__))
27
+ STUB_PATH = File.expand_path(WINDOWS ? "stub.exe" : "stub", base_dir)
28
+ STUBW_PATH = WINDOWS ? File.expand_path("stubw.exe", base_dir) : nil
29
+ LZMA_PATH = WINDOWS ? File.expand_path("lzma.exe", base_dir) : nil
30
+ EDICON_PATH = WINDOWS ? File.expand_path("edicon.exe", base_dir) : nil
31
+
32
+ def self.find_posix_lzma_cmd
33
+ if system("which lzma > /dev/null 2>&1")
34
+ ["lzma", "--compress", "--stdout"]
35
+ elsif system("which xz > /dev/null 2>&1")
36
+ ["xz", "--format=lzma", "--compress", "--stdout"]
37
+ elsif File.exist?("/opt/homebrew/bin/lzma")
38
+ ["/opt/homebrew/bin/lzma", "--compress", "--stdout"]
39
+ else
40
+ nil
41
+ end
42
+ end
43
+
44
+ LZMA_CMD = WINDOWS ? [LZMA_PATH, "e", "-si", "-so"] : find_posix_lzma_cmd
45
+
46
+ attr_reader :data_size
47
+
48
+ # Clear invalid security directory entries from PE executables
49
+ # This is necessary because some linkers may set non-zero values in the
50
+ # security directory even when there is no actual digital signature
51
+ def self.clear_invalid_security_entry(file_path)
52
+ data = File.binread(file_path)
53
+ return unless data.size > 64 # Minimum PE header size
54
+
55
+ # Read DOS header to find PE header offset
56
+ e_lfanew_offset = 60
57
+ pe_offset = data[e_lfanew_offset, 4].unpack1("L")
58
+ return if pe_offset + 160 > data.size # Not enough room for headers
59
+
60
+ # Calculate security directory offset
61
+ # PE signature (4) + FILE_HEADER (20) + partial OPTIONAL_HEADER to DataDirectory
62
+ security_entry_offset = pe_offset + 4 + 20 + 128
63
+
64
+ # Read security directory entry (VirtualAddress and Size)
65
+ sec_addr = data[security_entry_offset, 4].unpack1("L")
66
+ sec_size = data[security_entry_offset + 4, 4].unpack1("L")
67
+
68
+ # Check if security entry is invalid (points beyond file or size is 0)
69
+ if sec_size != 0 && (sec_addr == 0 || sec_addr >= data.size || sec_addr + sec_size > data.size)
70
+ # Clear the invalid security entry
71
+ data[security_entry_offset, 8] = "\x00" * 8
72
+ File.binwrite(file_path, data)
73
+ end
74
+ end
75
+
76
+ # chdir_before:
77
+ # When set to true, the working directory is changed to the application's
78
+ # deployment location at runtime.
79
+ #
80
+ # debug_mode:
81
+ # When the debug_mode option is set to true, the stub will output debug information
82
+ # when the exe file is executed. Debug mode can also be enabled within the directive
83
+ # code using the enable_debug_mode method. This option is provided to transition to
84
+ # debug mode from the initialization point of the stub.
85
+ #
86
+ # debug_extract:
87
+ # When set to true, the runtime file is extracted to the directory where the executable resides,
88
+ # and the extracted files remain even after the application exits.
89
+ # When set to false, the runtime file is extracted to the system's temporary directory,
90
+ # and the extracted files are deleted after the application exits.
91
+ #
92
+ # gui_mode:
93
+ # When set to true, the stub does not display a console window at startup. Errors are shown in a dialog window.
94
+ # When set to false, the stub reports errors through the console window.
95
+ #
96
+ # icon_path:
97
+ # Specifies the path to the icon file to be embedded in the stub's resources.
98
+ #
99
+ def initialize(path, chdir_before: nil, debug_extract: nil, debug_mode: nil,
100
+ enable_compression: nil, gui_mode: nil, icon_path: nil)
101
+ @dirs = FilePathSet.new
102
+ @files = FilePathSet.new
103
+ @data_size = 0
104
+
105
+ if icon_path && !File.exist?(icon_path)
106
+ raise "Icon file #{icon_path} not found"
107
+ end
108
+
109
+ output_dir = File.dirname(path)
110
+ FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir)
111
+ stub_tmp = File.join(output_dir, ".ocran_stub_#{$$}_#{Time.now.to_i}")
112
+ stub_src = if gui_mode && WINDOWS
113
+ STUBW_PATH
114
+ else
115
+ STUB_PATH
116
+ end
117
+ IO.copy_stream(stub_src, stub_tmp)
118
+ stub = stub_tmp
119
+
120
+ # Clear any invalid security directory entries from the stub (Windows only)
121
+ self.class.clear_invalid_security_entry(stub) if WINDOWS
122
+
123
+ # Embed icon resource (Windows only)
124
+ if icon_path && WINDOWS
125
+ system(EDICON_PATH, stub, icon_path.to_s, exception: true)
126
+ end
127
+
128
+ File.open(stub, "ab") do |of|
129
+ @of = of
130
+ @opcode_offset = @of.size
131
+
132
+ write_header(debug_mode, debug_extract, chdir_before, enable_compression)
133
+
134
+ b = proc {
135
+ yield(self)
136
+ }
137
+
138
+ if enable_compression && LZMA_CMD
139
+ compress(&b)
140
+ else
141
+ b.yield
142
+ end
143
+
144
+ write_footer
145
+ end
146
+
147
+ File.rename(stub, path)
148
+ File.chmod(0755, path) unless WINDOWS
149
+ end
150
+
151
+ def mkdir(target)
152
+ return unless @dirs.add?("/", target)
153
+
154
+ write_opcode(OP_CREATE_DIRECTORY)
155
+ write_path(target)
156
+ end
157
+
158
+ def symlink(link_path, target)
159
+ write_opcode(OP_CREATE_SYMLINK)
160
+ write_path(link_path)
161
+ write_string(target.to_s)
162
+ end
163
+
164
+ def cp(source, target)
165
+ unless File.exist?(source)
166
+ raise "The file does not exist (#{source})"
167
+ end
168
+
169
+ return unless @files.add?(source, target)
170
+
171
+ write_opcode(OP_CREATE_FILE)
172
+ write_path(target)
173
+ write_file(source)
174
+ end
175
+
176
+ # Specifies the final application script to be launched, which can be called
177
+ # from any position in the data stream. It cannot be specified more than once.
178
+ #
179
+ # You can omit setting OP_SET_SCRIPT without issues, in which case
180
+ # the stub terminates without launching anything after performing other
181
+ # runtime operations.
182
+ def exec(image, script, *argv)
183
+ if @script_set
184
+ raise "Script is already set"
185
+ end
186
+ @script_set = true
187
+
188
+ write_opcode(OP_SET_SCRIPT)
189
+ write_string_array(convert_to_native(image), convert_to_native(script), *argv)
190
+ end
191
+
192
+ def export(name, value)
193
+ write_opcode(OP_SETENV)
194
+ write_string(name.to_s)
195
+ write_string(value.to_s)
196
+ end
197
+
198
+ def compress
199
+ raise "No LZMA compressor found" unless LZMA_CMD
200
+
201
+ IO.popen(LZMA_CMD, "r+b") do |lzma|
202
+ _of, @of = @of, lzma
203
+ Thread.new { yield(self); lzma.close_write }
204
+ IO.copy_stream(lzma, _of)
205
+ @of = _of
206
+ end
207
+
208
+ # Calculate the position to write the LZMA decompressed size (64-bit unsigned integer)
209
+ # @opcode_offset: start position of the data section
210
+ # 1: size of the header byte
211
+ # 5: size of the LZMA header in bytes
212
+ File.binwrite(@of.path, [@data_size].pack("Q<"), @opcode_offset + 1 + 5)
213
+ end
214
+ private :compress
215
+
216
+ def write_header(debug_mode, debug_extract, chdir_before, compressed)
217
+ next_to_exe, delete_after = debug_extract, !debug_extract
218
+ @of << [0 |
219
+ (debug_mode ? DEBUG_MODE : 0) |
220
+ (next_to_exe ? EXTRACT_TO_EXE_DIR : 0) |
221
+ (delete_after ? AUTO_CLEAN_INST_DIR : 0) |
222
+ (chdir_before ? CHDIR_BEFORE_SCRIPT : 0) |
223
+ (compressed ? DATA_COMPRESSED : 0)
224
+ ].pack("C")
225
+ end
226
+ private :write_header
227
+
228
+ def write_opcode(op)
229
+ @of << [op].pack("C")
230
+ @data_size += 1
231
+ end
232
+ private :write_opcode
233
+
234
+ def write_size(i)
235
+ if i > 0xFFFF_FFFF
236
+ raise ArgumentError, "Size #{i} is too large: must be 32-bit unsigned integer (0 to 4294967295)"
237
+ end
238
+
239
+ @of << [i].pack("V")
240
+ @data_size += 4
241
+ end
242
+ private :write_size
243
+
244
+ def write_string(str)
245
+ len = str.bytesize + 1 # +1 to account for the null terminator
246
+
247
+ if len > 0xFFFF
248
+ raise ArgumentError, "String length #{len} is too large: must be less than or equal to 65535 bytes including null terminator"
249
+ end
250
+
251
+ write_size(len)
252
+ @of << [str].pack("Z*")
253
+ @data_size += len
254
+ end
255
+ private :write_string
256
+
257
+ def write_string_array(*str_array)
258
+ ary = str_array.map(&:to_s)
259
+
260
+ if ary.any?(&:empty?)
261
+ raise ArgumentError, "Argument list must not contain empty strings"
262
+ end
263
+
264
+ # Append an empty string so that when joined with "\0", the final buffer
265
+ # ends in two consecutive NUL bytes (double–NUL terminator) to mark end-of-list.
266
+ ary << ""
267
+
268
+ size = ary.sum(0) { |s| s.bytesize + 1 }
269
+ write_size(size)
270
+ ary.each_slice(1) { |a| @of << a.pack("Z*") }
271
+ @data_size += size
272
+ end
273
+ private :write_string_array
274
+
275
+ def write_file(src)
276
+ size = File.size(src)
277
+ write_size(size)
278
+ IO.copy_stream(src, @of)
279
+ @data_size += size
280
+ end
281
+ private :write_file
282
+
283
+ def write_path(path)
284
+ write_string(convert_to_native(path))
285
+ end
286
+ private :write_path
287
+
288
+ def write_footer
289
+ @of << ([@opcode_offset] + Signature).pack("VC*")
290
+ end
291
+ private :write_footer
292
+
293
+ def convert_to_native(path)
294
+ WINDOWS ? path.to_s.tr(File::SEPARATOR, "\\") : path.to_s
295
+ end
296
+ private :convert_to_native
297
+ end
298
+ end
data/lib/ocran/version.rb CHANGED
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module Ocran
4
- VERSION = "1.3.17"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Ocran
4
+ VERSION = "1.4.0"
5
+ end
@@ -1,15 +1,15 @@
1
- # frozen_string_literal: true
2
-
3
- module Ocran
4
- module WindowsCommandEscaping
5
- module_function
6
-
7
- def escape_double_quotes(s)
8
- s.to_s.gsub('"', '""')
9
- end
10
-
11
- def quote_and_escape(s)
12
- "\"#{escape_double_quotes(s)}\""
13
- end
14
- end
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Ocran
4
+ module WindowsCommandEscaping
5
+ module_function
6
+
7
+ def escape_double_quotes(s)
8
+ s.to_s.gsub('"', '""')
9
+ end
10
+
11
+ def quote_and_escape(s)
12
+ "\"#{escape_double_quotes(s)}\""
13
+ end
14
+ end
15
+ end
data/lib/ocran.rb CHANGED
@@ -1,7 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
- module Ocran
4
- autoload :VERSION, "ocran/version"
5
-
6
- singleton_class.attr_accessor :option
7
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Ocran
4
+ autoload :VERSION, "ocran/version"
5
+
6
+ singleton_class.attr_accessor :option
7
+ end
data/share/ocran/lzma.exe CHANGED
File without changes
data/src/Makefile ADDED
@@ -0,0 +1,75 @@
1
+ # Detect host OS
2
+ UNAME := $(shell uname -s 2>/dev/null || echo Windows)
3
+ IS_POSIX := $(filter $(UNAME),Linux Darwin)
4
+
5
+ CC := gcc
6
+ CFLAGS := -Wall -O2 -DWITH_LZMA -Ilzma
7
+ LDFLAGS := -s
8
+
9
+ ifneq ($(IS_POSIX),)
10
+ EXEEXT :=
11
+ LDLIBS :=
12
+ GUI_LDFLAGS :=
13
+ STUB_CFLAGS := $(CFLAGS) -D_CONSOLE
14
+ SYSTEM_UTILS_SRC := system_utils_posix.c
15
+ PROG_NAMES := stub
16
+ RESOURCE_OBJ :=
17
+ else
18
+ EXEEXT := .exe
19
+ LDLIBS := -lbcrypt
20
+ GUI_LDFLAGS := -mwindows
21
+ STUB_CFLAGS := $(CFLAGS) -D_CONSOLE
22
+ STUBW_CFLAGS := $(CFLAGS)
23
+ SYSTEM_UTILS_SRC := system_utils.c
24
+ PROG_NAMES := stub stubw edicon
25
+ RESOURCE_OBJ := stub.res
26
+ endif
27
+
28
+ BINDIR := $(CURDIR)/../share/ocran
29
+ BINARIES := $(addsuffix $(EXEEXT), $(PROG_NAMES))
30
+
31
+ LZMA_SRCS := lzma/LzmaDec.c
32
+ LZMA_OBJS := $(LZMA_SRCS:.c=.o)
33
+
34
+ COMMON_SRCS := $(SYSTEM_UTILS_SRC) inst_dir.c script_info.c unpack.c
35
+ COMMON_OBJS := $(COMMON_SRCS:.c=.o) $(LZMA_OBJS) $(RESOURCE_OBJ)
36
+
37
+ VARIANT_SRCS := stub.c error.c
38
+ CONSOLE_OBJS := $(VARIANT_SRCS:.c=_console.o)
39
+ WINDOW_OBJS := $(VARIANT_SRCS:.c=_window.o)
40
+
41
+ .PHONY: all clean install
42
+ all: $(BINARIES)
43
+
44
+ %.o: %.c
45
+ $(CC) $(CFLAGS) -c $< -o $@
46
+
47
+ %_console.o: %.c
48
+ $(CC) $(STUB_CFLAGS) -c $< -o $@
49
+
50
+ %_window.o: %.c
51
+ $(CC) $(STUBW_CFLAGS) -c $< -o $@
52
+
53
+ ifeq ($(IS_POSIX),)
54
+ stub.res: stub.rc
55
+ windres -i stub.rc -O coff -o stub.res
56
+ endif
57
+
58
+ stub$(EXEEXT): $(COMMON_OBJS) $(CONSOLE_OBJS)
59
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
60
+
61
+ ifeq ($(IS_POSIX),)
62
+ stubw$(EXEEXT): $(COMMON_OBJS) $(WINDOW_OBJS)
63
+ $(CC) $(LDFLAGS) $(GUI_LDFLAGS) $^ $(LDLIBS) -o $@
64
+
65
+ edicon$(EXEEXT): edicon.o
66
+ $(CC) $(LDFLAGS) $^ -o $@
67
+ endif
68
+
69
+ clean:
70
+ rm -f $(BINARIES) $(COMMON_OBJS) $(CONSOLE_OBJS) $(WINDOW_OBJS) \
71
+ edicon.o $(RESOURCE_OBJ)
72
+
73
+ install: $(BINARIES)
74
+ mkdir -p $(BINDIR)
75
+ cp -f $(BINARIES) $(BINDIR)/