demake 0.1.2 → 0.2.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.
data/bin/demake CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # demake - Single self-contained executeable script which uses Ruby to generate decorated make files
3
+ # demake - Executeable script which uses Ruby to generate decorated make files
4
4
  # for multiple related applications.
5
5
  #
6
+ require 'rbconfig' # Needed by older versions of Ruby
6
7
  require 'pipetext'
7
8
 
8
- demake_version = "0.1.2"
9
+ demake_version = "0.2.0"
9
10
 
10
11
  @silent = false
11
12
  @compiler = "gcc"
@@ -13,22 +14,25 @@ demake_version = "0.1.2"
13
14
  #@compiler = "arm-none-eabi-gcc"
14
15
  #@compiler = "arm-linux-gnu-gcc"
15
16
 
17
+ @strip = true
18
+ @debug_enabled = true
16
19
  # Raise if you have more cores and a long compile time
17
20
  @num_threads = 8
18
21
 
19
- WIDTH = 75
20
- BOX_WIDTH = WIDTH + "\t@echo".length # To normalize for Makefile format
21
- SHORT_WIDTH = BOX_WIDTH - 8
22
+ WIDTH = 75
23
+ BOX_WIDTH = WIDTH + "\t@echo".length # To normalize for Makefile format
24
+ SHORT_WIDTH = BOX_WIDTH - 8
22
25
 
23
- # Where to install binaries
26
+ # Where to install binaries / libraries
24
27
  @prefix = "/usr/local/bin/"
25
- @library_prefix = "/usr/local/lib64/"
28
+ @library_prefix = "/usr/local/lib/"
26
29
 
27
30
  # Contains code, does not get touched
28
31
  @source_directory = "src"
29
32
 
30
- # Both of these get completely blown away with make clean
33
+ # These get completely blown away with make clean
31
34
  @binary_directory = "bin"
35
+ @library_directory = "lib"
32
36
  @object_directory = "obj"
33
37
 
34
38
  @working_directory = Dir.pwd
@@ -38,6 +42,8 @@ SHORT_WIDTH = BOX_WIDTH - 8
38
42
  @replace_with = "|mo|n"
39
43
  # The space at the end helps with some fonts that cut the emoji with the next letter
40
44
  @emoji_build = "|Y|[construction]|n "
45
+ @emoji_library = "|Y|[books]|n "
46
+ @emoji_license = "|b|[scroll]|n "
41
47
  @emoji_clean = "|r|[fire]|n "
42
48
  @emoji_debug = "|n|[bug] "
43
49
  @emoji_install = "|s|[nut and bolt]|n "
@@ -51,18 +57,46 @@ SHORT_WIDTH = BOX_WIDTH - 8
51
57
  @pipe = Class.new.extend(PipeText)
52
58
 
53
59
  @flags = String.new
54
- @debug_flags = "-DDEBUG -g -Wall -Wextra -Wunused-variable -Wundef -Wconversion -Wshadow -Wcast-qual -Wwrite-strings "
60
+ @optimize_flags = String.new
61
+ @compiler_flags = String.new
62
+ @library_compiler_flags = String.new
63
+ @linker_flags = String.new
64
+ @debug_flags = String.new
55
65
  @linux_flags = String.new
56
66
  @x86_64_flags = String.new
57
67
  @aarch64_flags = String.new
68
+ @riscv_flags = String.new
58
69
  @darwin_flags = String.new
59
70
  @windows_flags = String.new
60
71
  @freebsd_flags = String.new
72
+ @library_linker_flags = String.new
61
73
  @libraries = String.new
74
+ @linker_libraries = String.new
75
+ @library_linker_libraries = String.new
62
76
  @raw_binary_files = String.new
77
+ @ruby_headers = String.new
78
+ @ruby_library = String.new
79
+ if(RbConfig::CONFIG["rubyhdrdir"] != nil &&
80
+ RbConfig::CONFIG["rubyarchhdrdir"] != nil)
81
+ @ruby_headers = "-I" + RbConfig::CONFIG["rubyhdrdir"] +
82
+ " -I" + RbConfig::CONFIG["rubyarchhdrdir"]
83
+ elsif(RbConfig::CONFIG["rubyhdrdir"] != nil)
84
+ @ruby_headers = "-I" + RbConfig::CONFIG["rubyhdrdir"]
85
+ elsif(RbConfig::CONFIG["rubyarchhdrdir"] != nil)
86
+ @ruby_headers = " -I" + RbConfig::CONFIG["rubyarchhdrdir"]
87
+ else
88
+ @ruby_headers = "-I" + RbConfig::CONFIG["includedir"]
89
+ end
90
+ if(RbConfig::CONFIG["LIBRUBYARG"] != nil)
91
+ @ruby_library = RbConfig::CONFIG["LIBRUBYARG"] +
92
+ " -Wl,-rpath," + RbConfig::CONFIG["LIBRUBYARG"]
93
+ end
94
+ @page_debug = false
63
95
 
64
96
  def strip_emojis!(string)
65
97
  string.gsub!(@emoji_build, @replace_with)
98
+ string.gsub!(@emoji_library, @replace_with)
99
+ string.gsub!(@emoji_license, @replace_with)
66
100
  string.gsub!(@emoji_clean, @replace_with)
67
101
  string.gsub!(@emoji_debug, @replace_with)
68
102
  string.gsub!(@emoji_install, @replace_with)
@@ -83,42 +117,32 @@ def notify(string)
83
117
  STDERR.puts(@pipe.pipetext(string))
84
118
  end
85
119
 
86
- # Used by both example and oreo to show options
87
- settingsrb = <<-END_OF_STRING
88
- # Uncomment to use / override
89
- #
90
- =begin
91
- @silent = false
92
- @compiler = "clang"
93
- @prefix = "/usr/local/bin/"
94
- @library_prefix = "/usr/lib64/"
95
- @emojis = false
96
- @replace_with = "|b*|n"
97
- @libraries << "-lc"
98
- @flags << "-ansi -pedantic -D_DEFAULT_SOURCE"
99
- @linux_flags << "-static" # clang
100
- @linux_flags << "-static -static-libgcc"
101
- @x86_64_flags << "-msse2 -mssse3 -msse4.1 -msha"
102
- @aarch64_flags << "-march=armv8-a+crypto"
103
- @windows_flags << ""
104
- @freebsd_flags << ""
105
- @darwin_flags << "-bundle"
106
- @debug_flags << "-Wpedantic -Wdeprecated-declarations -Wdiv-by-zero " +
107
- "-Wimplicit-function-declaration -Wimplicit-int " +
108
- "-Wpointer-arith -Wwrite-strings -Wold-style-definition " +
109
- "-Wmissing-noreturn -Wno-cast-function-type " +
110
- "-Wno-constant-logical-operand -Wno-long-long " +
111
- "-Wno-missing-field-initializers -Wno-overlength-strings " +
112
- "-Wno-packed-bitfield-compat -Wno-parentheses-equality " +
113
- "-Wno-self-assign -Wno-tautological-compare " +
114
- "-Wno-unused-parameter -Wno-unused-value " +
115
- "-Wsuggest-attribute=format -Wsuggest-attribute=noreturn"
116
- @flags = "-g -Wall"
117
- # No default flags (use only flags in the line above)
118
- $flags_override = true
119
- =end
120
- notify("#{@emoji_success} |gdemake/settings.rb is present|n")
121
- END_OF_STRING
120
+ @lib_data = File.join(File.expand_path("../..", __FILE__), "lib", "data")
121
+ @lib_dir = File.join(File.expand_path("../..", __FILE__), "lib")
122
+
123
+ if(ARGV[0] == "help" || ARGV[0] == "--help" || ARGV[0] == "-h" ||
124
+ ARGV[0] == "?" || ARGV[0] == "-?")
125
+ program = File.basename($0)
126
+ notify("Command syntax:\n\n")
127
+ notify("|y#{program}|n - Create or update Makefile\n")
128
+ notify("|y#{program} example|n - Create an example application\n")
129
+ notify("|y#{program} oreo|n - Create a different sample application\n\n")
130
+ exit!
131
+ end
132
+
133
+ def file_open_write_close(filename, data)
134
+ File.open(filename, 'w') do |f|
135
+ f.write(data)
136
+ end
137
+ end
138
+
139
+ def file_open_read_close(filename)
140
+ data = String.new
141
+ File.open(filename, 'r') do |f|
142
+ data = f.read
143
+ end
144
+ return(data)
145
+ end
122
146
 
123
147
  @example = false
124
148
  if(ARGV[0] =~ /^example$/)
@@ -128,92 +152,39 @@ if(ARGV[0] =~ /^example$/)
128
152
  exit!
129
153
  end
130
154
  @example = true
131
- # C code files used by the example
132
- helloc = <<-END_OF_STRING
133
- /*
134
- The most basic multiple executable example using a shared object/header file.
135
-
136
- hello.c will generate an executable named hello which that prints hello, world
137
- */
138
- #include "string/string.h"
139
-
140
- int main(void)
141
- {
142
- out("hello, world");
143
- return 0;
144
- }
145
- END_OF_STRING
146
-
147
- goodbyec = <<-END_OF_STRING
148
- /*
149
- The most basic multiple executable example using a shared object/header file.
150
-
151
- goodbye.c will generate an executable named hello which that prints goodbye, world
152
- */
153
- #include "string/string.h"
154
-
155
- int main(void)
156
- {
157
- out("goodbye, world");
158
- return 0;
159
- }
160
- END_OF_STRING
161
-
162
- stringh = <<-END_OF_STRING
163
- /*
164
- The most basic multiple executable example using a shared object/header file.
165
-
166
- string.h includes a simple shared function named out which prints output
167
- */
168
-
169
- void out(const char *in);
170
- END_OF_STRING
171
-
172
- stringc = <<-END_OF_STRING
173
- /*
174
- The most basic multiple executable example using a shared object/header file.
175
-
176
- string.c creates a simple shared function named out which prints output
177
- */
178
- #include <stdio.h>
179
- #include "string.h"
180
-
181
- void out(const char *in)
182
- {
183
- printf("%s\\n", in);
184
- }
185
- END_OF_STRING
186
-
187
- testtargetrb = <<-END_OF_STRING
188
- test_target << "\\t@echo\\n"
189
- test_target << "\\t@echo \\"|YTesting command hello:|n\\"\\n"
190
- test_target << "\\tbin/hello\\n"
191
- test_target << "\\t@echo \\"|YTesting command goodbye:|n\\"\\n"
192
- test_target << "\\tbin/goodbye\\n"
193
- END_OF_STRING
155
+ # Code files used by the example
156
+ example_settings_rb = file_open_read_close(@lib_data + '/example/demake/settings.rb')
157
+ hello_c = file_open_read_close(@lib_data + '/example/src/hello.c')
158
+ goodbye_c = file_open_read_close(@lib_data + '/example/src/goodbye.c')
159
+ string_h = file_open_read_close(@lib_data + '/example/src/string/string.h')
160
+ string_c = file_open_read_close(@lib_data + '/example/src/string/string.c')
161
+ testtarget_rb = file_open_read_close(@lib_data + '/example/demake/test-target.rb')
162
+ license = file_open_read_close(@lib_data + '/example/demake/license')
194
163
 
195
164
  Dir.mkdir('example')
196
165
  notify("#{@emoji_success} Created directory: |gexample|n |[open file folder]\n")
197
166
  Dir.mkdir('example/src')
198
167
  notify("#{@emoji_success} Created directory: |gexample|n/|gsrc|n |[open file folder]\n")
199
- File.open('example/src/hello.c', 'w').write(helloc)
168
+ file_open_write_close('example/src/hello.c', hello_c)
200
169
  notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|yhello.c|n |[page facing up]\n")
201
- File.open('example/src/goodbye.c', 'w').write(goodbyec)
170
+ file_open_write_close('example/src/goodbye.c', goodbye_c)
202
171
  notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|ygoodbye.c|n |[page facing up]\n")
203
172
  Dir.mkdir('example/src/string')
204
173
  notify("#{@emoji_success} Created directory: |gexample|n/|gsrc|n/|gstring|n |[open file folder]\n")
205
- File.open('example/src/string/string.h', 'w').write(stringh)
174
+ file_open_write_close('example/src/string/string.h', string_h)
206
175
  notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|gstring|n/|ystring.h|n |[page facing up]\n")
207
- File.open('example/src/string/string.c', 'w').write(stringc)
176
+ file_open_write_close('example/src/string/string.c', string_c)
208
177
  notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|gstring|n/|ystring.c|n |[page facing up]\n")
209
178
  Dir.mkdir('example/demake')
210
179
  notify("#{@emoji_success} Created directory: |gexample|n/|gdemake|n |[open file folder]\n")
211
- File.open('example/demake/applications', 'w').write("hello string\ngoodbye string\n")
180
+ file_open_write_close('example/demake/applications', "hello string\ngoodbye string\n")
212
181
  notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|yapplications|n |[page facing up]\n")
213
- File.open('example/demake/settings.rb', 'w').write(settingsrb)
182
+ file_open_write_close('example/demake/settings.rb', example_settings_rb)
214
183
  notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|ysettings.rb|n |[page facing up]\n")
215
- File.open('example/demake/test-target.rb', 'w').write(testtargetrb)
184
+ file_open_write_close('example/demake/test-target.rb', testtarget_rb)
216
185
  notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|ytest-target.rb|n |[page facing up]\n")
186
+ file_open_write_close('example/demake/license', license)
187
+ notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|ylicense|n |[page facing up]\n")
217
188
  Dir.chdir('example')
218
189
  @working_directory = Dir.pwd
219
190
  end
@@ -226,176 +197,78 @@ if(ARGV[0] =~ /^oreo$/)
226
197
  exit!
227
198
  end
228
199
  @oreo = true
229
- # C code file used by oreo
230
- oreoc = <<-END_OF_STRING
231
- /*
232
- oreo.c -- A simple c program that reads data piped in, issued as arguments or from a file and echos output
233
-
234
- Program main entry point: main/_start
235
- */
236
-
237
- #include <stdio.h>
238
- #include <stdlib.h>
239
- #include <string.h>
240
- #ifndef __WIN32__
241
- #include <sys/ioctl.h>
242
- #else
243
- #include <windows.h>
244
- #endif
245
-
246
- #define FALSE 0
247
- #define TRUE 1
248
-
249
- #define READ_BUFFER_SIZE 4096
250
-
251
- /* Read all the text from a file and put it into a string */
252
- char *read_file(FILE *file, unsigned int *total_bytes)
253
- {
254
- size_t bytes = 0, count = 0;
255
- char buffer[READ_BUFFER_SIZE + 1], *text = NULL;
256
-
257
- *total_bytes = 0;
258
-
259
- if(file == NULL)
260
- return NULL;
261
-
262
- bytes = fread(buffer, sizeof(char), READ_BUFFER_SIZE, file);
263
- while(bytes) {
264
- if(text) {
265
- text = realloc(text, *total_bytes + bytes + 1);
266
- count = 0;
267
- while(count < bytes) {
268
- *(text + *total_bytes + count) = buffer[count];
269
- count++;
270
- }
271
- } else {
272
- text = calloc(bytes + 1, sizeof(char));
273
- count = 0;
274
- while(count < bytes) {
275
- *(text + *total_bytes + count) = buffer[count];
276
- count++;
277
- }
278
- }
279
- *total_bytes += (unsigned int)bytes;
280
- *(text + *total_bytes) = '\\0';
281
- bytes = fread(buffer, sizeof(char), READ_BUFFER_SIZE, file);
282
- }
283
- return text;
284
- }
285
-
286
- int main(int argc, char **argv)
287
- {
288
- FILE *file = NULL;
289
- unsigned int total_bytes = 0, l = 0;
290
- int n = 0;
291
- unsigned char *string = NULL, displayed = FALSE;
292
- #ifdef __WIN32__
293
- HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
294
- DWORD bytes;
295
-
296
- if(PeekNamedPipe(stdin_handle, NULL, 0, NULL, &bytes, NULL) && bytes > 0) {
297
- #else
298
- if(ioctl(0, FIONREAD, &n) == 0 && n > 0) {
299
- #endif
300
- string = (unsigned char *)read_file(stdin, &total_bytes);
301
- #ifdef DEBUG
302
- printf("From stdin:\\r\\n");
303
- #endif
304
- printf("oreo: %s\\r\\n", string);
305
- free(string);
306
- string = NULL;
307
- displayed = TRUE;
308
- }
309
- if(argv[1] != NULL) {
310
- file = fopen(argv[1], "r");
311
- if(file == NULL) {
312
- /* We need to manually recreate the command input based on arguments with spaces */
313
- for(n = 1; n < argc; n++) {
314
- if(string != NULL) {
315
- l = (unsigned int)strlen(argv[n]);
316
- total_bytes += l + 1; /* +1 for space */
317
- string = realloc(string, (size_t)total_bytes + 1); /* +1 for \\0 */
318
- strncat((char *)string, " ", (size_t)2); /* 2 for space and \\0 */
319
- strncat((char *)string, argv[n], l);
320
- } else {
321
- total_bytes = (unsigned int)strlen(argv[n]);
322
- string = calloc(total_bytes + 1, sizeof(char)); /* +1 for \\0 */
323
- strncpy((char *)string, argv[n], total_bytes);
324
- }
325
- }
326
- #ifdef DEBUG
327
- printf("From argument:\\r\\n");
328
- #endif
329
- printf("oreo: %s\\r\\n", string);
330
- free(string);
331
- string = NULL;
332
- } else {
333
- #ifdef DEBUG
334
- printf("From file: %s\\r\\n", argv[1]);
335
- #endif
336
- string = (unsigned char *)read_file(file, &total_bytes);
337
- printf("oreo: %s\\r\\n", string);
338
- free(string);
339
- string = NULL;
340
- }
341
- } else if(!displayed) {
342
- #ifdef DEBUG
343
- printf("No input provided.\\r\\n");
344
- #endif
345
- }
346
-
347
- return 0;
348
- }
349
- END_OF_STRING
350
-
351
- testtargetrb = <<-END_OF_STRING
352
- test_target << "\\t@echo\\n"
353
- test_target << "\\t@echo \\"|YBasic functional testing of command oreo:|n\\"\\n"
354
- test_target << "\\tbin/oreo Test 1\\n"
355
- test_target << "\\techo -n \\"Test 2\\" || bin/oreo\\n"
356
- test_target << "\\techo -n \\"Test 3\\" || bin/oreo Test 4\\n"
357
- END_OF_STRING
200
+ # Code file used by oreo
201
+ oreo_settings_rb = file_open_read_close(@lib_data + '/oreo/demake/settings.rb')
202
+ defines_h = file_open_read_close(@lib_data + '/oreo/src/defines.h')
203
+ typedefs_h = file_open_read_close(@lib_data + '/oreo/src/typedefs.h')
204
+ fast_read_file_h = file_open_read_close(@lib_data + '/oreo/src/fast_read_file.h')
205
+ oreo_c = file_open_read_close(@lib_data + '/oreo/src/oreo.c')
206
+ testtarget_rb = file_open_read_close(@lib_data + '/oreo/demake/test-target.rb')
207
+ oreo_test_txt = file_open_read_close(@lib_data + '/oreo/oreo_test.txt')
208
+ license = file_open_read_close(@lib_data + '/oreo/demake/license')
358
209
 
359
210
  Dir.mkdir('oreo')
360
211
  notify("#{@emoji_success} Created directory: |goreo|n |[open file folder]\n")
361
212
  Dir.mkdir('oreo/src')
362
213
  notify("#{@emoji_success} Created directory: |goreo|n/|gsrc|n |[open file folder]\n")
363
- File.open('oreo/src/oreo.c', 'w').write(oreoc)
214
+ file_open_write_close('oreo/src/defines.h', defines_h)
215
+ notify("#{@emoji_success} Created file: |goreo|n/|gsrc|n/|ydefines.h|n |[page facing up]\n")
216
+ file_open_write_close('oreo/src/typedefs.h', typedefs_h)
217
+ notify("#{@emoji_success} Created file: |goreo|n/|gsrc|n/|ytypedefs.h|n |[page facing up]\n")
218
+ file_open_write_close('oreo/src/fast_read_file.h', fast_read_file_h)
219
+ notify("#{@emoji_success} Created file: |goreo|n/|gsrc|n/|yfast_read_file.h|n |[page facing up]\n")
220
+ file_open_write_close('oreo/src/oreo.c', oreo_c)
364
221
  notify("#{@emoji_success} Created file: |goreo|n/|gsrc|n/|yoreo.c|n |[page facing up]\n")
365
222
  Dir.mkdir('oreo/demake')
366
223
  notify("#{@emoji_success} Created directory: |goreo|n/|gdemake|n |[open file folder]\n")
367
- File.open('oreo/demake/applications', 'w').write("oreo\n")
224
+ file_open_write_close('oreo/demake/applications', "oreo\n")
368
225
  notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|yapplications|n |[page facing up]\n")
369
- File.open('oreo/demake/settings.rb', 'w').write(settingsrb)
226
+ file_open_write_close('oreo/demake/settings.rb', oreo_settings_rb)
370
227
  notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|ysettings.rb|n |[page facing up]\n")
371
- File.open('oreo/demake/test-target.rb', 'w').write(testtargetrb)
228
+ file_open_write_close('oreo/demake/test-target.rb', testtarget_rb)
372
229
  notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|ytest-target.rb|n |[page facing up]\n")
230
+ file_open_write_close('oreo/demake/license', license)
231
+ notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|ylicense|n |[page facing up]\n")
373
232
  Dir.chdir('oreo')
233
+ file_open_write_close('oreo_test.txt', oreo_test_txt)
234
+ notify("#{@emoji_success} Created file: |goreo|n/|yoreo_text.txt|n |[page facing up]\n")
374
235
  @working_directory = Dir.pwd
375
236
  end
376
237
 
377
238
  @applications = Hash.new
378
239
  @build_libraries = Hash.new
379
240
 
380
- if(@example == false && @oreo == false)
381
- # Check for settings override
382
- begin
383
- code = File.open('demake/settings.rb').read
384
- if(@emojis == false)
385
- strip_emojis!(code)
386
- end
387
- eval code
388
- rescue Errno::ENOENT
389
- rescue
390
- notify("\n|YWARNING|n: #{$!}\n\n")
241
+ # Check for settings / default override
242
+ begin
243
+ if(@example == false && @oreo == false)
244
+ code = file_open_read_close('demake/settings.rb')
245
+ elsif(@example == true)
246
+ code = example_settings_rb
247
+ elsif(@oreo == true)
248
+ code = oreo_settings_rb
249
+ end
250
+ if(@emojis == false)
251
+ strip_emojis!(code)
391
252
  end
253
+ eval code
254
+ rescue Errno::ENOENT
255
+ rescue
256
+ notify("\n|YWARNING|n: #{$!}\n\n")
257
+ end
392
258
 
259
+ if(@library_compiler_flags =~ /-static/)
260
+ @library_extension = '.a'
261
+ else
262
+ @library_extension = '.so'
263
+ end
264
+
265
+ if(@example == false && @oreo == false)
393
266
  # Applications to build
394
267
  no_applications_file = true
395
268
  begin
396
269
  # The expected format is the application followed by a list of its dependencies
397
270
  # all on the same line separated by space, : or tab and # for comments
398
- application_and_dependencies = File.open('demake/applications').read.split(/\n/)
271
+ application_and_dependencies = file_open_read_close('demake/applications').split(/\n/)
399
272
  no_applications_file = false
400
273
  application_and_dependencies.each do |app|
401
274
  if(app !~ /^#/ && app !~ /^[ \t]*#/)
@@ -416,7 +289,7 @@ if(@example == false && @oreo == false)
416
289
  begin
417
290
  # The expected format is the application followed by a list of its dependencies
418
291
  # all on the same line separated by space, : or tab and # for comments
419
- libraries_and_dependencies = File.open('demake/libraries').read.split(/\n/)
292
+ libraries_and_dependencies = file_open_read_close('demake/libraries').split(/\n/)
420
293
  no_libraries_file = false
421
294
  libraries_and_dependencies.each do |lib|
422
295
  if(lib !~ /^#/ && lib !~ /^[ \t]*#/)
@@ -467,10 +340,11 @@ CC = #{@compiler}
467
340
  OS := $(shell uname)
468
341
  PROCESSOR := $(shell uname -p)
469
342
  MACHINE := $(shell uname -m)
343
+ STRIP := strip
344
+ STRIP_ARGS := --strip-unneeded
470
345
  PREFIX = #{@prefix}
471
346
  LIBRARY_PREFIX = #{@library_prefix}
472
347
  END_OF_STRING
473
-
474
348
  @output << compiler_settings
475
349
 
476
350
  compiler_flags = "FLAGS = #{@flags}\n"
@@ -488,6 +362,12 @@ if(@windows_flags != "")
488
362
  compiler_flags << "ifeq '$(OS)' 'Windows_NT'\n"
489
363
  compiler_flags << " FLAGS += #{@windows_flags}\n"
490
364
  compiler_flags << "endif\n"
365
+ compiler_flags << "ifneq ($(filter CYGWIN_NT%,$(OS)),)\n"
366
+ compiler_flags << " FLAGS += #{@windows_flags}\n"
367
+ compiler_flags << "endif\n"
368
+ compiler_flags << "ifneq ($(filter MINGW64_NT%,$(OS)),)\n"
369
+ compiler_flags << " FLAGS += #{@windows_flags}\n"
370
+ compiler_flags << "endif\n"
491
371
  end
492
372
  if(@darwin_flags != "")
493
373
  compiler_flags << "ifeq '$(OS)' 'Darwin'\n"
@@ -499,41 +379,41 @@ if(@aarch64_flags != "")
499
379
  compiler_flags << " FLAGS += #{@aarch64_flags}\n"
500
380
  compiler_flags << "endif\n"
501
381
  end
382
+ if(@riscv64_flags != "")
383
+ compiler_flags << "ifeq '$(MACHINE)' 'riscv64'\n"
384
+ compiler_flags << " FLAGS += #{@riscv64_flags}\n"
385
+ compiler_flags << "endif\n"
386
+ end
502
387
  if(@x86_64_flags != "")
503
388
  compiler_flags << "ifeq '$(MACHINE)' 'x86_64'\n"
504
389
  compiler_flags << " FLAGS += #{@x86_64_flags}\n"
505
390
  compiler_flags << "endif\n"
391
+ compiler_flags << "ifeq '$(MACHINE)' 'amd64'\n"
392
+ compiler_flags << " FLAGS += #{@x86_64_flags}\n"
393
+ compiler_flags << "endif\n"
506
394
  end
507
395
  compiler_flags += <<-END_OF_STRING
508
396
  DEBUG_FLAGS = #{@debug_flags}
509
- FLAGS += -O2
510
- CFLAGS = $(FLAGS)
397
+ OFLAGS = #{@optimize_flags}
398
+ CFLAGS = #{@compiler_flags} $(FLAGS)
399
+ LDFLAGS = #{@linker_flags}
400
+ LIB_CFLAGS = #{@library_compiler_flags} $(FLAGS)
401
+ LIB_LDFLAGS = #{@library_linker_flags}
402
+ BUILD_FLAGS = $(CFLAGS)
511
403
  END_OF_STRING
512
- if(defined?($flags_override))
513
- notify("|ROverriding compiler flags|n:")
514
- notify("|RFLAGS|n = #{@flags}")
515
- compiler_flags = "FLAGS = #{@flags}\nCFLAGS = $(FLAGS)\n"
516
- end
517
404
  @output << compiler_flags
518
405
 
519
- if(compiler_flags =~ /-static/)
520
- @library_extension = '.a'
521
- else
522
- @library_extension = '.so'
523
- end
524
-
525
406
  compiler_directories = <<-END_OF_STRING
526
407
  LIBS = #{@libraries}
408
+ LDLIBS = $(LIBS) #{@linker_libraries}
409
+ LIB_LDLIBS = $(LIBS) #{@library_linker_libraries}
527
410
  BINARY = #{@binary_directory}
411
+ LIBRARY = #{@library_directory}
528
412
  SOURCE = #{@source_directory}
529
413
  OBJECT = #{@object_directory}
530
414
  END_OF_STRING
531
-
532
415
  @output << compiler_directories
533
416
 
534
- #SOURCES = $(wildcard $(SOURCE)/*.c $(SOURCE)/*.h)
535
- #OBJECTS = $(patsubst $(SOURCE)/%.c, $(OBJECT)/%.o, $(SOURCES))
536
-
537
417
  counter = 0
538
418
  file_list = String.new
539
419
  debug_file_list = String.new
@@ -643,28 +523,81 @@ debug_file_list = String.new
643
523
  @output << debug_file_list
644
524
  end
645
525
 
526
+ @output << "\nRUBY := $(shell command -v ruby 2> /dev/null)\n\n"
527
+
528
+ license = file_open_read_close('demake/license')
529
+ if(license != "")
530
+ longest_line = 0
531
+ license.lines.each do |l|
532
+ if(l.length > longest_line)
533
+ longest_line = l.length
534
+ end
535
+ end
536
+ line_length = longest_line + 2
537
+ include_license = "\n\t@echo \"|=!|29 #{@emoji_license} |blicense|n|;!|O\""
538
+ @output << "define LICENSE\n"
539
+ text = license.gsub(/^/, "|-!|O ").gsub(/\n/, "|;|-!|O\n")
540
+ text = text.sub("|-!|O", "|-!|O|b").sub("|;|-!|O\n", "|n|;|-!|O\n")
541
+ @output << @pipe.pipetext("|]#{line_length}\n|-[|#{line_length - 1}-]|O\n" +
542
+ "#{text}|-{|#{line_length - 1}-}|O\n\n")
543
+ @output << "endef\n"
544
+ @output << "export LICENSE\n"
545
+ @output << "define LICENSE_FILE\n"
546
+ @output << license
547
+ @output << "endef\n"
548
+ @output << "export LICENSE_FILE\n"
549
+ else
550
+ include_license = ""
551
+ end
552
+
553
+ if(@build_libraries != {})
554
+ include_libraries = "\n\t@echo \"|=!|29 #{@emoji_library} |mlibrary|n|;!|O\""
555
+ else
556
+ include_libraries = ""
557
+ end
558
+ if(@debug_enabled == true)
559
+ include_debug = "\n\t@echo \"|=!|29 #{@emoji_debug} |Ydebug|n|;!|O\""
560
+ else
561
+ include_debug = ""
562
+ end
563
+ if(include_license != "")
564
+ LICENSE = "LICENSE"
565
+ else
566
+ LICENSE = ""
567
+ end
646
568
  menu_target = <<-END_OF_STRING
647
569
  .PHONY : menu
648
- menu :
570
+ menu : #{LICENSE}
649
571
  \t@echo "|]#{BOX_WIDTH}|=[|#{SHORT_WIDTH}-]|O"
650
572
  \t@echo "|=!|;!|O"
651
573
  \t@echo "|=!|27 Make targets:|;!|O"
652
574
  \t@echo "|=!|;!|O"
653
- \t@echo "|=!|29 #{@emoji_build} |cbuild|n|;!|O"
654
- \t@echo "|=!|29 #{@emoji_clean} |cclean|n|;!|O"
655
- \t@echo "|=!|29 #{@emoji_debug} |cdebug|n|;!|O"
575
+ \t@echo "|=!|29 #{@emoji_build} |ybuild|n|;!|O"#{include_libraries}#{include_license}
576
+ \t@echo "|=!|29 #{@emoji_clean} |rclean|n|;!|O"#{include_debug}
656
577
  \t@echo "|=!|29 #{@emoji_install} |cinstall|n|;!|O"
657
578
  \t@echo "|=!|29 #{@emoji_uninstall} |cuninstall|n|;!|O"
658
- \t@echo "|=!|29 #{@emoji_test} |ctest|n|;!|O"
579
+ \t@echo "|=!|29 #{@emoji_test} |gtest|n|;!|O"
659
580
  \t@echo "|=!|;!|O"
660
581
  \t@echo "|=>|#{SHORT_WIDTH}-<|O"
661
582
  END_OF_STRING
662
583
  @applications.each do |app|
663
- menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} Executable: bin/|O|g#{app[0]}|n|=|;!|O\"\n"
584
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|yBuild|n Executable: #{@binary_directory}/|g#{app[0]}|n|=|;!|O\"\n"
664
585
  end
665
586
  @build_libraries.each do |lib|
666
- menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} Library: bin/|O|g#{lib[0]}#{@library_extension}|n|=|;!|O\"\n"
587
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|mLibrary|n File: #{@library_directory}/|g#{lib[0]}#{@library_extension}|n|=|;!|O\"\n"
588
+ end
589
+ menu_target << "\t@echo \"|=>|#{SHORT_WIDTH}-<|O\"\n"
590
+ if(@debug_enabled == true)
591
+ @applications.each do |app|
592
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|YDebug|n Executable: #{@binary_directory}/|Y#{app[0]}_debug|n|=|;!|O\"\n"
593
+ end
594
+ @build_libraries.each do |lib|
595
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|YDebug|n |mLibrary|n File: #{@library_directory}/|Y#{lib[0]}_debug#{@library_extension}|n|=|;!|O\"\n"
596
+ end
597
+ menu_target << "\t@echo \"|=>|#{SHORT_WIDTH}-<|O\"\n"
667
598
  end
599
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|cInstall|n |yBinary|n Directory: |g#{@prefix}|n|=|;!|O\"\n"
600
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|cInstall|n |mLibrary|n Directory: |g#{@library_prefix}|n|=|;!|O\"\n"
668
601
  menu_target << "\t@echo \"|={|#{SHORT_WIDTH}-}|O\"\n"
669
602
  @output << "\n"
670
603
  if(@emojis == false)
@@ -672,55 +605,111 @@ if(@emojis == false)
672
605
  end
673
606
  @output << @pipe.pipetext(menu_target)
674
607
 
675
- build_target = <<-END_OF_STRING
608
+ if(@build_libraries != {} && @debug_enabled == true)
609
+ all_target = ".PHONY : all\nall : #{LICENSE} build library debug\n\n"
610
+ elsif(@debug_enabled == true)
611
+ all_target = ".PHONY : all\nall : #{LICENSE} build debug\n\n"
612
+ elsif(@build_libraries != {})
613
+ all_target = ".PHONY : all\nall : #{LICENSE} build library\n\n"
614
+ else
615
+ all_target = ".PHONY : all\nall : #{LICENSE} build\n\n"
616
+ end
617
+ @output << all_target
618
+ #
619
+ # Rather than lots of Makefile heredocs in main source, most have been
620
+ # split up into lib/template/*.rb though a few are still inline
621
+ #
622
+ def load_with_template(template)
623
+ begin
624
+ code = file_open_read_close(@lib_dir + '/template/' + template + '.rb')
625
+ if(@emojis == false)
626
+ strip_emojis!(code)
627
+ end
628
+ if(block_given?)
629
+ yield(code)
630
+ else
631
+ eval(code)
632
+ end
633
+ rescue Errno::ENOENT
634
+ rescue
635
+ notify("\n|YWARNING|n: #{$!}\n\n")
636
+ end
637
+ end
638
+
639
+ if(include_license != "")
640
+ load_with_template("license_target") do |code|
641
+ eval(code)
642
+ end
643
+ @output << "\n"
644
+ if(@emojis == false)
645
+ strip_emojis!(@license_target)
646
+ end
647
+ @output << @pipe.pipetext(@license_target)
648
+ end
649
+
650
+ build_targets = <<-END_OF_STRING
676
651
  .PHONY : build
677
- build :
652
+ build : #{LICENSE}
678
653
  END_OF_STRING
679
654
 
680
655
  @applications.each do |app|
681
- executable_target = <<-END_OF_STRING
682
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
683
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_build} Building executable: bin/|O|g#{app[0]}|n|=|;!|O"
684
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
685
- \t@$(MAKE) $(BINARY)/#{app[0]}
686
- END_OF_STRING
656
+ load_with_template("build_target") do |code|
657
+ eval(code)
658
+ end
687
659
  if(@emojis == false)
688
- strip_emojis!(executable_target)
660
+ strip_emojis!(@build_target)
661
+ end
662
+ build_targets << @pipe.pipetext(@build_target)
663
+ if(@strip == true)
664
+ load_with_template("strip_build") do |code|
665
+ eval(code)
666
+ end
667
+ build_targets << @pipe.pipetext(@strip_build)
689
668
  end
690
- build_target << @pipe.pipetext(executable_target)
691
669
  end
692
670
 
693
- @build_libraries.each do |lib|
694
- library_target = <<-END_OF_STRING
695
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
696
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_build} Building library: bin/|O|g#{lib[0]}|n|=|;!|O"
697
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
698
- \t@$(MAKE) $(BINARY)/#{lib[0]}#{@library_extension}
671
+ @output << "\n"
672
+ @output << build_targets
673
+
674
+ library_targets = <<-END_OF_STRING
675
+ .PHONY : library
676
+ library : #{LICENSE}
699
677
  END_OF_STRING
678
+
679
+ @build_libraries.each do |lib|
680
+ load_with_template("library_target") do |code|
681
+ eval(code)
682
+ end
700
683
  if(@emojis == false)
701
- strip_emojis!(library_target)
684
+ strip_emojis!(@library_target)
702
685
  end
703
- build_target << @pipe.pipetext(library_target)
686
+ library_targets << @pipe.pipetext(@library_target)
704
687
  end
705
688
 
706
689
  @output << "\n"
707
- @output << build_target
690
+ @output << library_targets
708
691
 
709
692
  def add_dependencies_from_file(dependencies, filename, path)
710
693
  File.readlines(filename).each do |line|
711
- if(line =~ /#include \"(.*)\"/)
712
- included_filename = @working_directory + '/' + @source_directory + path + $1
713
- begin
714
- File.open(included_filename)
715
- add_dependencies_from_file(dependencies, included_filename, path)
716
- rescue Errno::ENOENT
717
- notify("|YWARNING|n: included dependency does not exist - Removing #{filename}:#{included_filename}\n")
718
- next
719
- rescue
720
- notify("|YWARNING|n: #{$!} - Removing #{filename}:#{included_filename}\n")
721
- next
694
+ begin
695
+ if(line =~ /#include \"(.*)\"/)
696
+ include = $1
697
+ if(filename !~ /#{include}$/)
698
+ included_filename = @working_directory + '/' + @source_directory + path + include
699
+ begin
700
+ File.open(included_filename)
701
+ add_dependencies_from_file(dependencies, included_filename, path)
702
+ rescue Errno::ENOENT
703
+ notify("|YWARNING|n: included dependency does not exist - Removing #{filename}:#{included_filename}\n")
704
+ next
705
+ rescue
706
+ notify("|YWARNING|n: #{$!} - Removing #{filename}:#{included_filename}\n")
707
+ next
708
+ end
709
+ dependencies << "\t\\\n\t$(SOURCE)#{path}#{include}"
710
+ end
722
711
  end
723
- dependencies << "\t\\\n\t$(SOURCE)#{path}#{$1}"
712
+ rescue ArgumentError
724
713
  end
725
714
  end
726
715
  end
@@ -730,30 +719,13 @@ def add_dependencies(filename, path)
730
719
  dependencies = String.new
731
720
  add_dependencies_from_file(dependencies, filename, path)
732
721
  if(dependencies != "")
733
- dependency_targets = <<-END_OF_STRING
734
- # Dependencies
735
- $(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '.o')} : $(SOURCE)#{path}#{filename}#{dependencies}
736
- \t@echo "|=!|O #{@emoji_compile} Compiling... |Y$(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '.o')}|n"
737
- ifeq '$(OS)' 'Windows_NT'
738
- \t@test -d $(OBJECT)#{path} |||| mkdir $(OBJECT)#{path}
739
- else
740
- \t@mkdir -p $(OBJECT)#{path}
741
- endif
742
- \t$(CC) $(LIBS) $(CFLAGS) -c $(SOURCE)#{path}#{filename} -o $(OBJECT)#{path}#{filename.gsub(/\.cp?p?$/, '.o')}
743
- # Dependencies for debug
744
- $(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '_debug.o')} : $(SOURCE)#{path}#{filename}#{dependencies}
745
- \t@echo "|=!|O #{@emoji_debug} #{@emoji_compile} Compiling... |Y$(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '_debug.o')}|n"
746
- ifeq '$(OS)' 'Windows_NT'
747
- \t@test -d $(OBJECT)#{path} |||| mkdir $(OBJECT)#{path}
748
- else
749
- \t@mkdir -p $(OBJECT)#{path}
750
- endif
751
- \t$(CC) $(LIBS) $(DEBUG_FLAGS) -c $(SOURCE)#{path}#{filename} -o $(OBJECT)#{path}#{filename.gsub(/\.cp?p?$/, '_debug.o')}
752
- END_OF_STRING
722
+ load_with_template("dependency_targets") do |code|
723
+ eval(code)
724
+ end
753
725
  if(@emojis == false)
754
- strip_emojis!(dependency_targets)
726
+ strip_emojis!(@dependency_targets)
755
727
  end
756
- @output << "\n" + @pipe.pipetext(dependency_targets)
728
+ @output << "\n" + @pipe.pipetext(@dependency_targets)
757
729
  end
758
730
  rescue
759
731
  notify("|YWARNING|n: #{$!}")
@@ -788,181 +760,122 @@ add_all_dependencies(@source_directory, '/')
788
760
  counter = 0
789
761
  @applications.each do |app|
790
762
  counter += 1
791
- executable_target = <<-END_OF_STRING
792
- $(BINARY)/#{app[0]} : $(OL#{counter})
793
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
794
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_link} Linking Files...|O bin/|g#{app[0]}|=|n|;!|O"
795
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
796
- ifeq '$(OS)' 'Windows_NT'
797
- \t@test -d $(BINARY) |||| mkdir $(BINARY)
798
- else
799
- \t@mkdir -p $(BINARY)
800
- endif
801
- \t$(CC) $(LIBS) $(CFLAGS) -o $(BINARY)/#{app[0]} $(OL#{counter})#{@raw_binary_files}
802
- END_OF_STRING
763
+ load_with_template("executable_target") do |code|
764
+ eval(code)
765
+ end
803
766
  @output << "\n"
804
767
  if(@emojis == false)
805
- strip_emojis!(executable_target)
768
+ strip_emojis!(@executable_target)
806
769
  end
807
- @output << @pipe.pipetext(executable_target)
808
- end
809
-
810
- if(@library_extension == ".so")
811
- shared = " -shared"
812
- else
813
- shared = String.new
770
+ @output << @pipe.pipetext(@executable_target)
814
771
  end
815
772
 
816
773
  @build_libraries.each do |lib|
817
774
  counter += 1
818
- library_target = <<-END_OF_STRING
819
- $(BINARY)/#{lib[0]}#{@library_extension} : $(OL#{counter})
820
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
821
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_link} Linking Files...|O bin/|g#{lib[0]}#{@library_extension}|=|n|;!|O"
822
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
823
- ifeq '$(OS)' 'Windows_NT'
824
- \t@test -d $(BINARY) |||| mkdir $(BINARY)
825
- else
826
- \t@mkdir -p $(BINARY)
827
- endif
828
- \t$(CC)#{shared} $(LIBS) $(CFLAGS) -o $(BINARY)/#{lib[0]}#{@library_extension} $(OL#{counter})#{@raw_binary_files}
829
- END_OF_STRING
775
+ load_with_template("link_library_target") do |code|
776
+ eval(code)
777
+ end
830
778
  @output << "\n"
831
779
  if(@emojis == false)
832
- strip_emojis!(library_target)
780
+ strip_emojis!(@link_library_target)
833
781
  end
834
- @output << @pipe.pipetext(library_target)
782
+ @output << @pipe.pipetext(@link_library_target)
835
783
  end
836
784
 
837
- # Debug
838
- counter = 0
839
- @applications.each do |app|
840
- counter += 1
841
- debug_executable_target = <<-END_OF_STRING
842
- $(BINARY)/#{app[0]}_debug : $(DOL#{counter})
843
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
844
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_debug} #{@emoji_link} Linking Files...|O bin/|g#{app[0]}_debug|=|n|;!|O"
845
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
846
- ifeq '$(OS)' 'Windows_NT'
847
- \t@test -d $(BINARY) |||| mkdir $(BINARY)
848
- else
849
- \t@mkdir -p $(BINARY)
850
- endif
851
- \t$(CC) $(LIBS) $(DEBUG_FLAGS) -o $(BINARY)/#{app[0]}_debug $(DOL#{counter})#{@raw_binary_files}
852
- END_OF_STRING
853
- @output << "\n"
854
- if(@emojis == false)
855
- strip_emojis!(debug_executable_target)
785
+ if(@debug_enabled == true)
786
+ counter = 0
787
+ @applications.each do |app|
788
+ counter += 1
789
+ load_with_template("debug_executable_target") do |code|
790
+ eval(code)
791
+ end
792
+ @output << "\n"
793
+ if(@emojis == false)
794
+ strip_emojis!(@debug_executable_target)
795
+ end
796
+ @output << @pipe.pipetext(@debug_executable_target)
856
797
  end
857
- @output << @pipe.pipetext(debug_executable_target)
858
- end
859
798
 
860
- @build_libraries.each do |lib|
861
- counter += 1
862
- debug_library_target = <<-END_OF_STRING
863
- $(BINARY)/#{lib[0]}_debug#{@library_extension} : $(DOL#{counter})
864
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
865
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_debug} #{@emoji_link} Linking Files...|O bin/|g#{lib[0]}_debug#{@library_extension}|=|n|;!|O"
866
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
867
- ifeq '$(OS)' 'Windows_NT'
868
- \t@test -d $(BINARY) |||| mkdir $(BINARY)
869
- else
870
- \t@mkdir -p $(BINARY)
871
- endif
872
- \t$(CC)#{shared} $(LIBS) $(DEBUG_FLAGS) -o $(BINARY)/#{lib[0]}_debug#{@library_extension} $(DOL#{counter})#{@raw_binary_files}
873
- END_OF_STRING
874
- @output << "\n"
875
- if(@emojis == false)
876
- strip_emojis!(debug_library_target)
799
+ @build_libraries.each do |lib|
800
+ counter += 1
801
+ load_with_template("debug_library_target") do |code|
802
+ eval(code)
803
+ end
804
+ @output << "\n"
805
+ if(@emojis == false)
806
+ strip_emojis!(@debug_library_target)
807
+ end
808
+ @output << @pipe.pipetext(@debug_library_target)
877
809
  end
878
- @output << @pipe.pipetext(debug_library_target)
879
810
  end
880
811
 
881
- dependency_targets = <<-END_OF_STRING
882
- # General Auto-Dependencies
883
- $(OBJECT)/%.o : $(SOURCE)/%.c
884
- \t@echo "|=!|O #{@emoji_compile} Compiling... |Y$(@)|n"
885
- ifeq '$(OS)' 'Windows_NT'
886
- \t@test -d $(BINARY) |||| mkdir $(BINARY)
887
- \t@test -d $(OBJECT) |||| mkdir $(OBJECT)
888
- else
889
- \t@mkdir -p $(BINARY)
890
- \t@mkdir -p $(OBJECT)
891
- endif
892
- \t$(CC) $(LIBS) $(CFLAGS) -c $< -o $@
893
- # General Auto-Dependencies for debug
894
- $(OBJECT)/%_debug.o : $(SOURCE)/%.c
895
- \t@echo "|=!|O #{@emoji_debug} #{@emoji_compile} Compiling... |Y$(@)|n"
896
- ifeq '$(OS)' 'Windows_NT'
897
- \t@test -d $(BINARY) |||| mkdir $(BINARY)
898
- \t@test -d $(OBJECT) |||| mkdir $(OBJECT)
899
- else
900
- \t@mkdir -p $(BINARY)
901
- \t@mkdir -p $(OBJECT)
902
- endif
903
- \t$(CC) $(LIBS) $(DEBUG_FLAGS) -c $< -o $@
904
- END_OF_STRING
812
+ load_with_template("generic_dependency_targets") do |code|
813
+ eval(code)
814
+ end
905
815
  if(@emojis == false)
906
- strip_emojis!(dependency_targets)
816
+ strip_emojis!(@generic_dependency_targets)
907
817
  end
908
- @output << "\n" + @pipe.pipetext(dependency_targets)
818
+ @output << "\n" + @pipe.pipetext(@generic_dependency_targets)
909
819
 
910
- clean_target = <<-END_OF_STRING
911
- .PHONY : clean
912
- clean :
913
- \t@echo "#{@emoji_clean} Removed |Yeverything|n from |R$(OBJECT)|n and |R$(BINARY)|n directories"
914
- \t@rm -rf $(OBJECT) $(BINARY)
915
- END_OF_STRING
820
+ load_with_template("clean_target") do |code|
821
+ eval(code)
822
+ end
916
823
  if(@emojis == false)
917
- strip_emojis!(clean_target)
824
+ strip_emojis!(@clean_target)
918
825
  end
919
- @output << "\n" + @pipe.pipetext(clean_target)
826
+ @output << "\n" + @pipe.pipetext(@clean_target)
920
827
 
921
- debug_target = <<-END_OF_STRING
922
- .PHONY : debug
923
- debug :
924
- END_OF_STRING
828
+ if(@debug_enabled == true)
829
+ load_with_template("debug_target") do |code|
830
+ eval(code)
831
+ end
925
832
 
926
- @applications.each do |app|
927
- executable_debug_target = <<-END_OF_STRING
928
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
929
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_debug} #{@emoji_build} |nBuilding executable:|O bin/|g#{app[0]}_debug|=|n|;!|O"
930
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
931
- \t@$(MAKE) $(BINARY)/#{app[0]}_debug
932
- END_OF_STRING
933
- if(@emojis == false)
934
- strip_emojis!(executable_debug_target)
833
+ if(@page_debug == true)
834
+ @pager = " 2>&1 | less -F -R -X -e"
835
+ else
836
+ @pager = ""
935
837
  end
936
- debug_target << @pipe.pipetext(executable_debug_target)
937
- end
938
838
 
939
- @build_libraries.each do |lib|
940
- library_debug_target = <<-END_OF_STRING
941
- \t@echo "|=[|#{SHORT_WIDTH}-]|O"
942
- \t@echo "|]#{BOX_WIDTH}|=! #{@emoji_debug} #{@emoji_build} Building library:|O bin/|g#{lib[0]}_debug#{@library_extension}|=|n|;!|O"
943
- \t@echo "|={|#{SHORT_WIDTH}-}|O"
944
- \t@$(MAKE) $(BINARY)/#{lib[0]}_debug#{@library_extension}
945
- END_OF_STRING
946
- if(@emojis == false)
947
- strip_emojis!(library_debug_target)
839
+ @applications.each do |app|
840
+ load_with_template("executable_debug_target") do |code|
841
+ eval(code)
842
+ end
843
+ if(@emojis == false)
844
+ strip_emojis!(@executable_debug_target)
845
+ end
846
+ @debug_target << @pipe.pipetext(@executable_debug_target)
948
847
  end
949
- debug_target << @pipe.pipetext(library_debug_target)
950
- end
951
848
 
952
- @output << "\n"
953
- @output << debug_target
849
+ @build_libraries.each do |lib|
850
+ load_with_template("library_debug_target") do |code|
851
+ eval(code)
852
+ end
853
+ if(@emojis == false)
854
+ strip_emojis!(@library_debug_target)
855
+ end
856
+ @debug_target << @pipe.pipetext(@library_debug_target)
857
+ end
858
+ @output << "\n"
859
+ @output << @debug_target
860
+ end
954
861
 
955
862
  def default_test_target(test_target)
956
863
  test_target << "\t@echo\n"
957
864
  test_target << "\t@echo \"#{@emoji_fail} |rWARNING: No tests have been created!|n\""
958
865
  end
959
866
 
867
+ if(@build_libraries != {})
868
+ test_dependencies = "test : #{LICENSE} build library"
869
+ else
870
+ test_dependencies = "test : #{LICENSE} build"
871
+ end
872
+
960
873
  test_target = <<-END_OF_STRING
961
- test :
962
- \t@echo -n "#{@emoji_test} Running tests"
874
+ #{test_dependencies}
875
+ \t@echo -n "#{@emoji_test}Running tests:"
963
876
  END_OF_STRING
964
877
  begin
965
- code = File.open('demake/test-target.rb').read
878
+ code = file_open_read_close('demake/test-target.rb')
966
879
  if(@emojis == false)
967
880
  strip_emojis!(code)
968
881
  end
@@ -978,27 +891,31 @@ end
978
891
 
979
892
  def default_install_target(install_target)
980
893
  if(@applications != {})
981
- install_target << "\tinstall -d $(PREFIX)\n"
894
+ install_target << "\t@test -d $(PREFIX) || install -d $(PREFIX)\n"
982
895
  end
983
896
  @applications.each do |app|
984
- install_target << "\tinstall -m 755 bin/#{app[0]} $(PREFIX)\n"
897
+ install_target << "\t@test -f #{@binary_directory}/#{app[0]} && install -v -m 755 #{@binary_directory}/#{app[0]} $(PREFIX) |||| \\\n"
898
+ install_target << "\t\t(echo \"Executable file #{@binary_directory}/|g#{app[0]}|n not found.\"; \\\n"
899
+ install_target << "\t\techo \"Please type '|ymake build|n' first, if you wish to install.\")\n"
985
900
  end
986
901
  if(@build_libraries != {})
987
- install_target << "\tinstall -d $(LIBRARY_PREFIX)\n"
902
+ install_target << "\t@test -d $(LIBRARY_PREFIX) || install -d $(LIBRARY_PREFIX)\n"
988
903
  end
989
904
  @build_libraries.each do |lib|
990
- install_target << "\tinstall -m 644 bin/#{lib[0]}#{@library_extension} $(LIBRARY_PREFIX)\n"
905
+ install_target << "\t@test -f #{@library_directory}/#{lib[0]}#{@library_extension} && install -v -m 755 #{@library_directory}/#{lib[0]}#{@library_extension} $(LIBRARY_PREFIX) |||| \\\n"
906
+ install_target << "\t\t(echo \"Library file #{@library_directory}/|g#{lib[0]}#{@library_extension}|n not found.\"; \\\n"
907
+ install_target << "\t\techo \"Please type '|mmake library|n' first, if you wish to install.\")\n"
991
908
  end
992
909
  install_target << "\t@echo \"#{@emoji_install} #{@emoji_success} |gInstallation Finished|n\"\n"
993
910
  end
994
911
 
995
912
  install_target = <<-END_OF_STRING
996
913
  .PHONY : install
997
- install :
914
+ install : #{LICENSE}
998
915
  \t@echo "#{@emoji_install} Starting install..."
999
916
  END_OF_STRING
1000
917
  begin
1001
- code = File.open('demake/install-target.rb').read
918
+ code = file_open_read_close('demake/install-target.rb')
1002
919
  if(@emojis == false)
1003
920
  strip_emojis!(code)
1004
921
  end
@@ -1039,7 +956,7 @@ uninstall :
1039
956
  \t@echo "#{@emoji_uninstall} Starting uninstall..."
1040
957
  END_OF_STRING
1041
958
  begin
1042
- code = File.open('demake/uninstall-target.rb').read
959
+ code = file_open_read_close('demake/uninstall-target.rb')
1043
960
  if(@emojis == false)
1044
961
  strip_emojis!(code)
1045
962
  end
@@ -1065,5 +982,25 @@ if(@example || @oreo)
1065
982
  end
1066
983
  Dir.chdir('..')
1067
984
  else
1068
- puts @output
985
+ if(File.exist?('Makefile'))
986
+ lines = file_open_read_close('Makefile').split("\n")
987
+ if(lines[1] =~ /^# Makefile automatically generated by Ruby Gem - demake [0-9]*\.[0-9]*\.[0-9]*$/)
988
+ File.open('Makefile', 'w').write(@output)
989
+ else
990
+ match = lines.find do |e|
991
+ e =~ /^# Makefile automatically generated by Ruby Gem - demake [0-9]*\.[0-9]*\.[0-9]*$/
992
+ end
993
+ if(match != nil)
994
+ print(@pipe.pipetext("|yMakefile|n already exists, |Rbut has been modified|n overwrite anyway (y/n)? "))
995
+ else
996
+ print(@pipe.pipetext("|yMakefile|n already exists, |Rand is unrecognized|n overwrite anyway (y/n)? "))
997
+ end
998
+ if(STDIN.getc == ?y)
999
+ File.open('Makefile', 'w').write(@output)
1000
+ end
1001
+ end
1002
+ else
1003
+ File.open('Makefile', 'w').write(@output)
1004
+ # puts @output
1005
+ end
1069
1006
  end