demake 0.1.2 → 0.2.1

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/bin/demake +503 -579
  3. data/lib/apps/example/Makefile +374 -0
  4. data/lib/apps/example/demake/applications +3 -0
  5. data/lib/apps/example/demake/brief_description +1 -0
  6. data/lib/apps/example/demake/license +19 -0
  7. data/lib/apps/example/demake/settings.rb +62 -0
  8. data/lib/apps/example/demake/suggestion +1 -0
  9. data/lib/apps/example/demake/test-target.rb +8 -0
  10. data/lib/apps/example/src/goodbye.c +12 -0
  11. data/lib/apps/example/src/hello.c +12 -0
  12. data/lib/apps/example/src/string/string.c +12 -0
  13. data/lib/apps/example/src/string/string.h +7 -0
  14. data/lib/apps/oreo/Makefile +260 -0
  15. data/lib/apps/oreo/demake/applications +1 -0
  16. data/lib/apps/oreo/demake/brief_description +1 -0
  17. data/lib/apps/oreo/demake/license +19 -0
  18. data/lib/apps/oreo/demake/settings.rb +62 -0
  19. data/lib/apps/oreo/demake/suggestion +1 -0
  20. data/lib/apps/oreo/demake/test-target.rb +9 -0
  21. data/lib/apps/oreo/oreo_test.txt +1 -0
  22. data/lib/apps/oreo/src/defines.h +29 -0
  23. data/lib/apps/oreo/src/fast_read_file.h +259 -0
  24. data/lib/apps/oreo/src/oreo.c +102 -0
  25. data/lib/apps/oreo/src/typedefs.h +61 -0
  26. data/lib/data/libsrc/auto_bits.h +33 -0
  27. data/lib/data/libsrc/base.h +10 -0
  28. data/lib/data/libsrc/cpu_mark_check.h +267 -0
  29. data/lib/data/libsrc/defines.h +29 -0
  30. data/lib/data/libsrc/fast_read_file.h +259 -0
  31. data/lib/data/libsrc/fast_sha2.h +1840 -0
  32. data/lib/data/libsrc/parse_arguments.h +0 -0
  33. data/lib/data/libsrc/rb_library.c +140 -0
  34. data/lib/data/libsrc/typedefs.h +61 -0
  35. data/lib/template/build_target.rb +6 -0
  36. data/lib/template/clean_target.rb +6 -0
  37. data/lib/template/debug_executable_target.rb +14 -0
  38. data/lib/template/debug_library_target.rb +14 -0
  39. data/lib/template/debug_target.rb +4 -0
  40. data/lib/template/dependency_targets.rb +22 -0
  41. data/lib/template/executable_debug_target.rb +6 -0
  42. data/lib/template/executable_target.rb +14 -0
  43. data/lib/template/generic_dependency_targets.rb +26 -0
  44. data/lib/template/library_debug_target.rb +6 -0
  45. data/lib/template/library_target.rb +6 -0
  46. data/lib/template/license_target.rb +10 -0
  47. data/lib/template/link_library_target.rb +14 -0
  48. data/lib/template/strip_build.rb +8 -0
  49. metadata +54 -7
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 - Executable script which uses Ruby to generate decorated GNU Makefiles
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.1"
9
10
 
10
11
  @silent = false
11
12
  @compiler = "gcc"
@@ -13,6 +14,8 @@ 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
 
@@ -20,15 +23,16 @@ WIDTH = 75
20
23
  BOX_WIDTH = WIDTH + "\t@echo".length # To normalize for Makefile format
21
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,370 +117,193 @@ 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_apps = File.join(File.expand_path("../..", __FILE__), "lib", "apps")
122
+ @lib_dir = File.join(File.expand_path("../..", __FILE__), "lib")
123
+ @available_apps = Array.new
122
124
 
123
- @example = false
124
- if(ARGV[0] =~ /^example$/)
125
- if(File.directory?('example') == true)
126
- notify("\n#{@emoji_fail}|RError|n: |Ydirectory example |Ralready exists, aborting creation|n\n\n" +
127
- "Delete the directory and try again if you wish to recreate it.\n\n")
128
- exit!
125
+ Dir.entries(@lib_apps).each do |e|
126
+ if(e != '.' && e != '..')
127
+ @available_apps << e
129
128
  end
130
- @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
129
+ end
194
130
 
195
- Dir.mkdir('example')
196
- notify("#{@emoji_success} Created directory: |gexample|n |[open file folder]\n")
197
- Dir.mkdir('example/src')
198
- notify("#{@emoji_success} Created directory: |gexample|n/|gsrc|n |[open file folder]\n")
199
- File.open('example/src/hello.c', 'w').write(helloc)
200
- 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)
202
- notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|ygoodbye.c|n |[page facing up]\n")
203
- Dir.mkdir('example/src/string')
204
- 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)
206
- 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)
208
- notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|gstring|n/|ystring.c|n |[page facing up]\n")
209
- Dir.mkdir('example/demake')
210
- 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")
212
- 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)
214
- 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)
216
- notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|ytest-target.rb|n |[page facing up]\n")
217
- Dir.chdir('example')
218
- @working_directory = Dir.pwd
131
+ def file_open_write_close(filename, data)
132
+ begin
133
+ File.open(filename, 'w') do |f|
134
+ f.write(data)
135
+ end
136
+ rescue
137
+ notify("|RError|n: #{$!}")
138
+ end
219
139
  end
220
140
 
221
- @oreo = false
222
- if(ARGV[0] =~ /^oreo$/)
223
- if(File.directory?('oreo') == true)
224
- notify("\n#{@emoji_fail}|RError|n: |Ydirectory oreo |Ralready exists, aborting creation|n\n\n" +
225
- "Delete the directory and try again if you wish to recreate it.\n\n")
226
- exit!
141
+ def file_open_read_close(filename, notify_warning=true)
142
+ data = String.new
143
+ begin
144
+ File.open(filename, 'r') do |f|
145
+ data = f.read
146
+ end
147
+ rescue
148
+ if(notify_warning == true)
149
+ notify("|YWARNING|n: #{$!.to_s.sub(/@ rb_[a-zA-Z_]* /, '')}")
150
+ end
227
151
  end
228
- @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
152
+ return(data)
153
+ end
350
154
 
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
155
+ def copy_template(filename)
156
+ if(File.directory?(filename) == true)
157
+ new_name = filename.sub(/^#{@lib_apps}./, '')
158
+ begin
159
+ if(File.directory?(new_name) != true)
160
+ Dir.mkdir(new_name)
161
+ notify("#{@emoji_success} Created directory: |g#{new_name}|n |[open file folder]\n")
162
+ end
163
+ Dir.entries(filename).each do |e|
164
+ if(e != '.' && e != '..')
165
+ copy_template(File.join(filename, e))
166
+ end
167
+ end
168
+ rescue Errno::EACCES
169
+ notify("|RError|n: #{$!.to_s.sub(/@ dir_s_mkdir /, '')}")
170
+ exit!
171
+ rescue
172
+ notify("|RError|n: #{$!}")
173
+ exit!
174
+ end
175
+ else
176
+ data = file_open_read_close(filename)
177
+ new_name = filename.sub(/^#{@lib_apps}./, '')
178
+ file_open_write_close(new_name, file_open_read_close(filename))
179
+ notify("#{@emoji_success} Created file: |y#{new_name}|n |[page facing up]\n")
180
+ end
181
+ end
182
+
183
+ @found_application = nil
184
+ @suggestion = String.new
185
+ @available_apps.sort.each do |app|
186
+ if(ARGV[0] =~ /^#{app}$/)
187
+ if(File.directory?(app) == true)
188
+ notify("\n#{@emoji_fail}|RError|n: |Ydirectory #{app} |Ralready exists, aborting creation|n\n\n" +
189
+ "Delete the directory and try again if you wish to recreate it.\n\n")
190
+ exit!
191
+ end
192
+ @found_application = app
193
+ copy_template(File.join(@lib_apps, app))
194
+ begin
195
+ File.open(File.join(@lib_apps, app, 'demake', 'suggestion'), 'r') do |f|
196
+ @suggestion = f.read.chomp
197
+ end
198
+ rescue
199
+ end
200
+ Dir.chdir(app)
201
+ @working_directory = Dir.pwd
202
+ end
203
+ end
358
204
 
359
- Dir.mkdir('oreo')
360
- notify("#{@emoji_success} Created directory: |goreo|n |[open file folder]\n")
361
- Dir.mkdir('oreo/src')
362
- notify("#{@emoji_success} Created directory: |goreo|n/|gsrc|n |[open file folder]\n")
363
- File.open('oreo/src/oreo.c', 'w').write(oreoc)
364
- notify("#{@emoji_success} Created file: |goreo|n/|gsrc|n/|yoreo.c|n |[page facing up]\n")
365
- Dir.mkdir('oreo/demake')
366
- notify("#{@emoji_success} Created directory: |goreo|n/|gdemake|n |[open file folder]\n")
367
- File.open('oreo/demake/applications', 'w').write("oreo\n")
368
- 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)
370
- 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)
372
- notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|ytest-target.rb|n |[page facing up]\n")
373
- Dir.chdir('oreo')
374
- @working_directory = Dir.pwd
205
+ need_help = false
206
+ if(ARGV[0] == "help" || ARGV[0] == "--help" || ARGV[0] == "-h" ||
207
+ ARGV[0] == "?" || ARGV[0] == "-?")
208
+ need_help = true
209
+ end
210
+ if(need_help == false && ARGV[0] != nil && @found_application == nil)
211
+ notify("Unknown argument: #{ARGV[0]}\n\n")
212
+ need_help = true
213
+ end
214
+ if(need_help == true)
215
+ program = File.basename($0)
216
+ COLUMN_WIDTH = 20
217
+ syntax = "|]#{COLUMN_WIDTH}Command syntax:\n\n" + "|y#{program}|n|; - Create or update Makefile\n"
218
+ @available_apps.sort.each do |app|
219
+ data = String.new
220
+ begin
221
+ File.open(File.join(@lib_apps, app, 'demake', 'brief_description'), 'r') do |f|
222
+ data = f.read.chomp
223
+ end
224
+ rescue
225
+ end
226
+ if(data != "")
227
+ syntax << "|y#{program} #{app}|n|; - #{data}\n"
228
+ else
229
+ syntax << "|y#{program} #{app}|n\n"
230
+ end
231
+ end
232
+ notify(syntax + "\n")
233
+ exit!
375
234
  end
376
235
 
377
236
  @applications = Hash.new
378
237
  @build_libraries = Hash.new
379
238
 
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")
239
+ # Check for settings / default override
240
+ begin
241
+ code = file_open_read_close('demake/settings.rb')
242
+ if(@emojis == false)
243
+ strip_emojis!(code)
391
244
  end
245
+ eval code
246
+ rescue
247
+ notify("\n|YWARNING|n: #{$!}\n\n")
248
+ end
392
249
 
393
- # Applications to build
394
- no_applications_file = true
395
- begin
396
- # The expected format is the application followed by a list of its dependencies
397
- # all on the same line separated by space, : or tab and # for comments
398
- application_and_dependencies = File.open('demake/applications').read.split(/\n/)
399
- no_applications_file = false
400
- application_and_dependencies.each do |app|
401
- if(app !~ /^#/ && app !~ /^[ \t]*#/)
402
- if(app =~ /([^ :\t]*)[ :\t]*(.*)[ \t]*#?.*/)
403
- application = $1
404
- dependencies = $2.sub(/#.*$/, '').split(/[ :\t]/)
405
- @applications[application] = dependencies
406
- else
407
- @applications[app] = Array.new
408
- end
250
+ if(@library_compiler_flags =~ /-static/)
251
+ @library_extension = '.a'
252
+ else
253
+ @library_extension = '.so'
254
+ end
255
+
256
+ # Applications to build
257
+ no_applications_file = true
258
+ begin
259
+ # The expected format is the application followed by a list of its dependencies
260
+ # all on the same line separated by space, : or tab and # for comments
261
+ application_and_dependencies = file_open_read_close('demake/applications').split(/\n/)
262
+ no_applications_file = false
263
+ application_and_dependencies.each do |app|
264
+ if(app !~ /^#/ && app !~ /^[ \t]*#/)
265
+ if(app =~ /([^ :\t]*)[ :\t]*(.*)[ \t]*#?.*/)
266
+ application = $1
267
+ dependencies = $2.sub(/#.*$/, '').split(/[ :\t]/)
268
+ @applications[application] = dependencies
269
+ else
270
+ @applications[app] = Array.new
409
271
  end
410
272
  end
411
- rescue
412
273
  end
274
+ rescue
275
+ end
413
276
 
414
- # Libraries to build
415
- no_libraries_file = true
416
- begin
417
- # The expected format is the application followed by a list of its dependencies
418
- # all on the same line separated by space, : or tab and # for comments
419
- libraries_and_dependencies = File.open('demake/libraries').read.split(/\n/)
420
- no_libraries_file = false
421
- libraries_and_dependencies.each do |lib|
422
- if(lib !~ /^#/ && lib !~ /^[ \t]*#/)
423
- if(lib =~ /([^ :\t]*)[ :\t]*(.*)[ \t]*#?.*/)
424
- library = $1
425
- dependencies = $2.sub(/#.*$/, '').split(/[ :\t]/)
426
- @build_libraries[library] = dependencies
427
- else
428
- @build_libraries[lib] = Array.new
429
- end
277
+ # Libraries to build
278
+ no_libraries_file = true
279
+ begin
280
+ # The expected format is the application followed by a list of its dependencies
281
+ # all on the same line separated by space, : or tab and # for comments
282
+ libraries_and_dependencies = file_open_read_close('demake/libraries', false).split(/\n/)
283
+ no_libraries_file = false
284
+ libraries_and_dependencies.each do |lib|
285
+ if(lib !~ /^#/ && lib !~ /^[ \t]*#/)
286
+ if(lib =~ /([^ :\t]*)[ :\t]*(.*)[ \t]*#?.*/)
287
+ library = $1
288
+ dependencies = $2.sub(/#.*$/, '').split(/[ :\t]/)
289
+ @build_libraries[library] = dependencies
290
+ else
291
+ @build_libraries[lib] = Array.new
430
292
  end
431
293
  end
432
- rescue
433
294
  end
434
- if(no_applications_file && no_libraries_file)
435
- notify("\n#{@emoji_fail}|RError|n: |Yapplications file|n |Rdoes not exist|n\n\n" +
436
- "You must create a file named |Yapplications|n which contains a list of\n" +
437
- "executeable application names and any dependencies to be compiled.\n\n")
438
- exit!
439
- elsif(@applications == {} && @build_libraries == {})
440
- notify("\n#{@emoji_fail}|RError|n: |Yapplications file|n |Rcannot be empty|n\n\n" +
441
- "You must create a file named |Yapplications|n which contains a list of\n" +
442
- "executeable application names and any dependencies to be compiled.\n\n")
443
- exit!
444
- end
445
- elsif(@oreo == true)
446
- @applications['oreo'] = Array.new
447
- elsif(@example == true)
448
- @applications['hello'] = ['string']
449
- @applications['goodbye'] = ['string']
295
+ rescue
296
+ end
297
+ if(no_applications_file && no_libraries_file)
298
+ notify("\n#{@emoji_fail}|RError|n: |Yapplications file|n |Rdoes not exist|n\n\n" +
299
+ "You must create a file named |Yapplications|n which contains a list of\n" +
300
+ "executable application names and any dependencies to be compiled.\n\n")
301
+ exit!
302
+ elsif(@applications == {} && @build_libraries == {})
303
+ notify("\n#{@emoji_fail}|RError|n: |Yapplications file|n |Rcannot be empty|n\n\n" +
304
+ "You must create a file named |Yapplications|n which contains a list of\n" +
305
+ "executable application names and any dependencies to be compiled.\n\n")
306
+ exit!
450
307
  end
451
308
 
452
309
  @output = <<-END_OF_STRING
@@ -467,10 +324,11 @@ CC = #{@compiler}
467
324
  OS := $(shell uname)
468
325
  PROCESSOR := $(shell uname -p)
469
326
  MACHINE := $(shell uname -m)
327
+ STRIP := strip
328
+ STRIP_ARGS := --strip-unneeded
470
329
  PREFIX = #{@prefix}
471
330
  LIBRARY_PREFIX = #{@library_prefix}
472
331
  END_OF_STRING
473
-
474
332
  @output << compiler_settings
475
333
 
476
334
  compiler_flags = "FLAGS = #{@flags}\n"
@@ -488,6 +346,12 @@ if(@windows_flags != "")
488
346
  compiler_flags << "ifeq '$(OS)' 'Windows_NT'\n"
489
347
  compiler_flags << " FLAGS += #{@windows_flags}\n"
490
348
  compiler_flags << "endif\n"
349
+ compiler_flags << "ifneq ($(filter CYGWIN_NT%,$(OS)),)\n"
350
+ compiler_flags << " FLAGS += #{@windows_flags}\n"
351
+ compiler_flags << "endif\n"
352
+ compiler_flags << "ifneq ($(filter MINGW64_NT%,$(OS)),)\n"
353
+ compiler_flags << " FLAGS += #{@windows_flags}\n"
354
+ compiler_flags << "endif\n"
491
355
  end
492
356
  if(@darwin_flags != "")
493
357
  compiler_flags << "ifeq '$(OS)' 'Darwin'\n"
@@ -499,41 +363,41 @@ if(@aarch64_flags != "")
499
363
  compiler_flags << " FLAGS += #{@aarch64_flags}\n"
500
364
  compiler_flags << "endif\n"
501
365
  end
366
+ if(@riscv64_flags != "")
367
+ compiler_flags << "ifeq '$(MACHINE)' 'riscv64'\n"
368
+ compiler_flags << " FLAGS += #{@riscv64_flags}\n"
369
+ compiler_flags << "endif\n"
370
+ end
502
371
  if(@x86_64_flags != "")
503
372
  compiler_flags << "ifeq '$(MACHINE)' 'x86_64'\n"
504
373
  compiler_flags << " FLAGS += #{@x86_64_flags}\n"
505
374
  compiler_flags << "endif\n"
375
+ compiler_flags << "ifeq '$(MACHINE)' 'amd64'\n"
376
+ compiler_flags << " FLAGS += #{@x86_64_flags}\n"
377
+ compiler_flags << "endif\n"
506
378
  end
507
379
  compiler_flags += <<-END_OF_STRING
508
380
  DEBUG_FLAGS = #{@debug_flags}
509
- FLAGS += -O2
510
- CFLAGS = $(FLAGS)
381
+ OFLAGS = #{@optimize_flags}
382
+ CFLAGS = #{@compiler_flags} $(FLAGS)
383
+ LDFLAGS = #{@linker_flags}
384
+ LIB_CFLAGS = #{@library_compiler_flags} $(FLAGS)
385
+ LIB_LDFLAGS = #{@library_linker_flags}
386
+ BUILD_FLAGS = $(CFLAGS)
511
387
  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
388
  @output << compiler_flags
518
389
 
519
- if(compiler_flags =~ /-static/)
520
- @library_extension = '.a'
521
- else
522
- @library_extension = '.so'
523
- end
524
-
525
390
  compiler_directories = <<-END_OF_STRING
526
391
  LIBS = #{@libraries}
392
+ LDLIBS = $(LIBS) #{@linker_libraries}
393
+ LIB_LDLIBS = $(LIBS) #{@library_linker_libraries}
527
394
  BINARY = #{@binary_directory}
395
+ LIBRARY = #{@library_directory}
528
396
  SOURCE = #{@source_directory}
529
397
  OBJECT = #{@object_directory}
530
398
  END_OF_STRING
531
-
532
399
  @output << compiler_directories
533
400
 
534
- #SOURCES = $(wildcard $(SOURCE)/*.c $(SOURCE)/*.h)
535
- #OBJECTS = $(patsubst $(SOURCE)/%.c, $(OBJECT)/%.o, $(SOURCES))
536
-
537
401
  counter = 0
538
402
  file_list = String.new
539
403
  debug_file_list = String.new
@@ -643,28 +507,81 @@ debug_file_list = String.new
643
507
  @output << debug_file_list
644
508
  end
645
509
 
510
+ @output << "\nRUBY := $(shell command -v ruby 2> /dev/null)\n\n"
511
+
512
+ license = file_open_read_close('demake/license')
513
+ if(license != "")
514
+ longest_line = 0
515
+ license.lines.each do |l|
516
+ if(l.length > longest_line)
517
+ longest_line = l.length
518
+ end
519
+ end
520
+ line_length = longest_line + 2
521
+ include_license = "\n\t@echo \"|=!|29 #{@emoji_license} |blicense|n|;!|O\""
522
+ @output << "define LICENSE\n"
523
+ text = license.gsub(/^/, "|-!|O ").gsub(/\n/, "|;|-!|O\n")
524
+ text = text.sub("|-!|O", "|-!|O|b").sub("|;|-!|O\n", "|n|;|-!|O\n")
525
+ @output << @pipe.pipetext("|]#{line_length}\n|-[|#{line_length - 1}-]|O\n" +
526
+ "#{text}|-{|#{line_length - 1}-}|O\n\n")
527
+ @output << "endef\n"
528
+ @output << "export LICENSE\n"
529
+ @output << "define LICENSE_FILE\n"
530
+ @output << license
531
+ @output << "endef\n"
532
+ @output << "export LICENSE_FILE\n"
533
+ else
534
+ include_license = ""
535
+ end
536
+
537
+ if(@build_libraries != {})
538
+ include_libraries = "\n\t@echo \"|=!|29 #{@emoji_library} |mlibrary|n|;!|O\""
539
+ else
540
+ include_libraries = ""
541
+ end
542
+ if(@debug_enabled == true)
543
+ include_debug = "\n\t@echo \"|=!|29 #{@emoji_debug} |Ydebug|n|;!|O\""
544
+ else
545
+ include_debug = ""
546
+ end
547
+ if(include_license != "")
548
+ LICENSE = "LICENSE"
549
+ else
550
+ LICENSE = ""
551
+ end
646
552
  menu_target = <<-END_OF_STRING
647
553
  .PHONY : menu
648
- menu :
554
+ menu : #{LICENSE}
649
555
  \t@echo "|]#{BOX_WIDTH}|=[|#{SHORT_WIDTH}-]|O"
650
556
  \t@echo "|=!|;!|O"
651
557
  \t@echo "|=!|27 Make targets:|;!|O"
652
558
  \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"
559
+ \t@echo "|=!|29 #{@emoji_build} |ybuild|n|;!|O"#{include_libraries}#{include_license}
560
+ \t@echo "|=!|29 #{@emoji_clean} |rclean|n|;!|O"#{include_debug}
656
561
  \t@echo "|=!|29 #{@emoji_install} |cinstall|n|;!|O"
657
562
  \t@echo "|=!|29 #{@emoji_uninstall} |cuninstall|n|;!|O"
658
- \t@echo "|=!|29 #{@emoji_test} |ctest|n|;!|O"
563
+ \t@echo "|=!|29 #{@emoji_test} |gtest|n|;!|O"
659
564
  \t@echo "|=!|;!|O"
660
565
  \t@echo "|=>|#{SHORT_WIDTH}-<|O"
661
566
  END_OF_STRING
662
567
  @applications.each do |app|
663
- menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} Executable: bin/|O|g#{app[0]}|n|=|;!|O\"\n"
568
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|yBuild|n Executable: #{@binary_directory}/|g#{app[0]}|n|=|;!|O\"\n"
664
569
  end
665
570
  @build_libraries.each do |lib|
666
- menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} Library: bin/|O|g#{lib[0]}#{@library_extension}|n|=|;!|O\"\n"
571
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|mLibrary|n File: #{@library_directory}/|g#{lib[0]}#{@library_extension}|n|=|;!|O\"\n"
572
+ end
573
+ menu_target << "\t@echo \"|=>|#{SHORT_WIDTH}-<|O\"\n"
574
+ if(@debug_enabled == true)
575
+ @applications.each do |app|
576
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|YDebug|n Executable: #{@binary_directory}/|Y#{app[0]}_debug|n|=|;!|O\"\n"
577
+ end
578
+ @build_libraries.each do |lib|
579
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|YDebug|n |mLibrary|n File: #{@library_directory}/|Y#{lib[0]}_debug#{@library_extension}|n|=|;!|O\"\n"
580
+ end
581
+ menu_target << "\t@echo \"|=>|#{SHORT_WIDTH}-<|O\"\n"
667
582
  end
583
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|cInstall|n |yBinary|n Directory: |g#{@prefix}|n|=|;!|O\"\n"
584
+ menu_target << "\t@echo \"|=!|]#{BOX_WIDTH} |O|cInstall|n |mLibrary|n Directory: |g#{@library_prefix}|n|=|;!|O\"\n"
668
585
  menu_target << "\t@echo \"|={|#{SHORT_WIDTH}-}|O\"\n"
669
586
  @output << "\n"
670
587
  if(@emojis == false)
@@ -672,55 +589,111 @@ if(@emojis == false)
672
589
  end
673
590
  @output << @pipe.pipetext(menu_target)
674
591
 
675
- build_target = <<-END_OF_STRING
592
+ if(@build_libraries != {} && @debug_enabled == true)
593
+ all_target = ".PHONY : all\nall : #{LICENSE} build library debug\n\n"
594
+ elsif(@debug_enabled == true)
595
+ all_target = ".PHONY : all\nall : #{LICENSE} build debug\n\n"
596
+ elsif(@build_libraries != {})
597
+ all_target = ".PHONY : all\nall : #{LICENSE} build library\n\n"
598
+ else
599
+ all_target = ".PHONY : all\nall : #{LICENSE} build\n\n"
600
+ end
601
+ @output << all_target
602
+ #
603
+ # Rather than lots of Makefile heredocs in main source, most have been
604
+ # split up into lib/template/*.rb though a few are still inline
605
+ #
606
+ def load_with_template(template)
607
+ begin
608
+ code = file_open_read_close(@lib_dir + '/template/' + template + '.rb')
609
+ if(@emojis == false)
610
+ strip_emojis!(code)
611
+ end
612
+ if(block_given?)
613
+ yield(code)
614
+ else
615
+ eval(code)
616
+ end
617
+ rescue Errno::ENOENT
618
+ rescue
619
+ notify("\n|YWARNING|n: #{$!}\n\n")
620
+ end
621
+ end
622
+
623
+ if(include_license != "")
624
+ load_with_template("license_target") do |code|
625
+ eval(code)
626
+ end
627
+ @output << "\n"
628
+ if(@emojis == false)
629
+ strip_emojis!(@license_target)
630
+ end
631
+ @output << @pipe.pipetext(@license_target)
632
+ end
633
+
634
+ build_targets = <<-END_OF_STRING
676
635
  .PHONY : build
677
- build :
636
+ build : #{LICENSE}
678
637
  END_OF_STRING
679
638
 
680
639
  @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
640
+ load_with_template("build_target") do |code|
641
+ eval(code)
642
+ end
687
643
  if(@emojis == false)
688
- strip_emojis!(executable_target)
644
+ strip_emojis!(@build_target)
645
+ end
646
+ build_targets << @pipe.pipetext(@build_target)
647
+ if(@strip == true)
648
+ load_with_template("strip_build") do |code|
649
+ eval(code)
650
+ end
651
+ build_targets << @pipe.pipetext(@strip_build)
689
652
  end
690
- build_target << @pipe.pipetext(executable_target)
691
653
  end
692
654
 
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}
655
+ @output << "\n"
656
+ @output << build_targets
657
+
658
+ library_targets = <<-END_OF_STRING
659
+ .PHONY : library
660
+ library : #{LICENSE}
699
661
  END_OF_STRING
662
+
663
+ @build_libraries.each do |lib|
664
+ load_with_template("library_target") do |code|
665
+ eval(code)
666
+ end
700
667
  if(@emojis == false)
701
- strip_emojis!(library_target)
668
+ strip_emojis!(@library_target)
702
669
  end
703
- build_target << @pipe.pipetext(library_target)
670
+ library_targets << @pipe.pipetext(@library_target)
704
671
  end
705
672
 
706
673
  @output << "\n"
707
- @output << build_target
674
+ @output << library_targets
708
675
 
709
676
  def add_dependencies_from_file(dependencies, filename, path)
710
677
  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
678
+ begin
679
+ if(line =~ /#include \"(.*)\"/)
680
+ include = $1
681
+ if(filename !~ /#{include}$/)
682
+ included_filename = @working_directory + '/' + @source_directory + path + include
683
+ begin
684
+ File.open(included_filename)
685
+ add_dependencies_from_file(dependencies, included_filename, path)
686
+ rescue Errno::ENOENT
687
+ notify("|YWARNING|n: included dependency does not exist - Removing #{filename}:#{included_filename}\n")
688
+ next
689
+ rescue
690
+ notify("|YWARNING|n: #{$!} - Removing #{filename}:#{included_filename}\n")
691
+ next
692
+ end
693
+ dependencies << "\t\\\n\t$(SOURCE)#{path}#{include}"
694
+ end
722
695
  end
723
- dependencies << "\t\\\n\t$(SOURCE)#{path}#{$1}"
696
+ rescue ArgumentError
724
697
  end
725
698
  end
726
699
  end
@@ -730,30 +703,13 @@ def add_dependencies(filename, path)
730
703
  dependencies = String.new
731
704
  add_dependencies_from_file(dependencies, filename, path)
732
705
  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
706
+ load_with_template("dependency_targets") do |code|
707
+ eval(code)
708
+ end
753
709
  if(@emojis == false)
754
- strip_emojis!(dependency_targets)
710
+ strip_emojis!(@dependency_targets)
755
711
  end
756
- @output << "\n" + @pipe.pipetext(dependency_targets)
712
+ @output << "\n" + @pipe.pipetext(@dependency_targets)
757
713
  end
758
714
  rescue
759
715
  notify("|YWARNING|n: #{$!}")
@@ -788,181 +744,122 @@ add_all_dependencies(@source_directory, '/')
788
744
  counter = 0
789
745
  @applications.each do |app|
790
746
  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
747
+ load_with_template("executable_target") do |code|
748
+ eval(code)
749
+ end
803
750
  @output << "\n"
804
751
  if(@emojis == false)
805
- strip_emojis!(executable_target)
752
+ strip_emojis!(@executable_target)
806
753
  end
807
- @output << @pipe.pipetext(executable_target)
808
- end
809
-
810
- if(@library_extension == ".so")
811
- shared = " -shared"
812
- else
813
- shared = String.new
754
+ @output << @pipe.pipetext(@executable_target)
814
755
  end
815
756
 
816
757
  @build_libraries.each do |lib|
817
758
  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
759
+ load_with_template("link_library_target") do |code|
760
+ eval(code)
761
+ end
830
762
  @output << "\n"
831
763
  if(@emojis == false)
832
- strip_emojis!(library_target)
764
+ strip_emojis!(@link_library_target)
833
765
  end
834
- @output << @pipe.pipetext(library_target)
766
+ @output << @pipe.pipetext(@link_library_target)
835
767
  end
836
768
 
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)
769
+ if(@debug_enabled == true)
770
+ counter = 0
771
+ @applications.each do |app|
772
+ counter += 1
773
+ load_with_template("debug_executable_target") do |code|
774
+ eval(code)
775
+ end
776
+ @output << "\n"
777
+ if(@emojis == false)
778
+ strip_emojis!(@debug_executable_target)
779
+ end
780
+ @output << @pipe.pipetext(@debug_executable_target)
856
781
  end
857
- @output << @pipe.pipetext(debug_executable_target)
858
- end
859
782
 
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)
783
+ @build_libraries.each do |lib|
784
+ counter += 1
785
+ load_with_template("debug_library_target") do |code|
786
+ eval(code)
787
+ end
788
+ @output << "\n"
789
+ if(@emojis == false)
790
+ strip_emojis!(@debug_library_target)
791
+ end
792
+ @output << @pipe.pipetext(@debug_library_target)
877
793
  end
878
- @output << @pipe.pipetext(debug_library_target)
879
794
  end
880
795
 
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
796
+ load_with_template("generic_dependency_targets") do |code|
797
+ eval(code)
798
+ end
905
799
  if(@emojis == false)
906
- strip_emojis!(dependency_targets)
800
+ strip_emojis!(@generic_dependency_targets)
907
801
  end
908
- @output << "\n" + @pipe.pipetext(dependency_targets)
802
+ @output << "\n" + @pipe.pipetext(@generic_dependency_targets)
909
803
 
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
804
+ load_with_template("clean_target") do |code|
805
+ eval(code)
806
+ end
916
807
  if(@emojis == false)
917
- strip_emojis!(clean_target)
808
+ strip_emojis!(@clean_target)
918
809
  end
919
- @output << "\n" + @pipe.pipetext(clean_target)
810
+ @output << "\n" + @pipe.pipetext(@clean_target)
920
811
 
921
- debug_target = <<-END_OF_STRING
922
- .PHONY : debug
923
- debug :
924
- END_OF_STRING
812
+ if(@debug_enabled == true)
813
+ load_with_template("debug_target") do |code|
814
+ eval(code)
815
+ end
925
816
 
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)
817
+ if(@page_debug == true)
818
+ @pager = " 2>&1 | less -F -R -X -e"
819
+ else
820
+ @pager = ""
935
821
  end
936
- debug_target << @pipe.pipetext(executable_debug_target)
937
- end
938
822
 
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)
823
+ @applications.each do |app|
824
+ load_with_template("executable_debug_target") do |code|
825
+ eval(code)
826
+ end
827
+ if(@emojis == false)
828
+ strip_emojis!(@executable_debug_target)
829
+ end
830
+ @debug_target << @pipe.pipetext(@executable_debug_target)
948
831
  end
949
- debug_target << @pipe.pipetext(library_debug_target)
950
- end
951
832
 
952
- @output << "\n"
953
- @output << debug_target
833
+ @build_libraries.each do |lib|
834
+ load_with_template("library_debug_target") do |code|
835
+ eval(code)
836
+ end
837
+ if(@emojis == false)
838
+ strip_emojis!(@library_debug_target)
839
+ end
840
+ @debug_target << @pipe.pipetext(@library_debug_target)
841
+ end
842
+ @output << "\n"
843
+ @output << @debug_target
844
+ end
954
845
 
955
846
  def default_test_target(test_target)
956
847
  test_target << "\t@echo\n"
957
848
  test_target << "\t@echo \"#{@emoji_fail} |rWARNING: No tests have been created!|n\""
958
849
  end
959
850
 
851
+ if(@build_libraries != {})
852
+ test_dependencies = "test : #{LICENSE} build library"
853
+ else
854
+ test_dependencies = "test : #{LICENSE} build"
855
+ end
856
+
960
857
  test_target = <<-END_OF_STRING
961
- test :
962
- \t@echo -n "#{@emoji_test} Running tests"
858
+ #{test_dependencies}
859
+ \t@echo -n "#{@emoji_test}Running tests:"
963
860
  END_OF_STRING
964
861
  begin
965
- code = File.open('demake/test-target.rb').read
862
+ code = file_open_read_close('demake/test-target.rb')
966
863
  if(@emojis == false)
967
864
  strip_emojis!(code)
968
865
  end
@@ -978,27 +875,34 @@ end
978
875
 
979
876
  def default_install_target(install_target)
980
877
  if(@applications != {})
981
- install_target << "\tinstall -d $(PREFIX)\n"
878
+ install_target << "\t@test -d $(PREFIX) || install -d $(PREFIX)\n"
982
879
  end
983
880
  @applications.each do |app|
984
- install_target << "\tinstall -m 755 bin/#{app[0]} $(PREFIX)\n"
881
+ install_target << "\t@test -f #{@binary_directory}/#{app[0]} && install -v -m 755 #{@binary_directory}/#{app[0]} $(PREFIX) |||| \\\n"
882
+ install_target << "\t\t(echo \"Executable file #{@binary_directory}/|g#{app[0]}|n not found.\"; \\\n"
883
+ install_target << "\t\techo \"Please type '|ymake build|n' first, if you wish to install.\")\n"
985
884
  end
986
885
  if(@build_libraries != {})
987
- install_target << "\tinstall -d $(LIBRARY_PREFIX)\n"
886
+ install_target << "\t@test -d $(LIBRARY_PREFIX) || install -d $(LIBRARY_PREFIX)\n"
988
887
  end
989
888
  @build_libraries.each do |lib|
990
- install_target << "\tinstall -m 644 bin/#{lib[0]}#{@library_extension} $(LIBRARY_PREFIX)\n"
889
+ install_target << "\t@test -f #{@library_directory}/#{lib[0]}#{@library_extension} && install -v -m 755 #{@library_directory}/#{lib[0]}#{@library_extension} $(LIBRARY_PREFIX) |||| \\\n"
890
+ install_target << "\t\t(echo \"Library file #{@library_directory}/|g#{lib[0]}#{@library_extension}|n not found.\"; \\\n"
891
+ install_target << "\t\techo \"Please type '|mmake library|n' first, if you wish to install.\")\n"
991
892
  end
992
893
  install_target << "\t@echo \"#{@emoji_install} #{@emoji_success} |gInstallation Finished|n\"\n"
993
894
  end
994
895
 
995
896
  install_target = <<-END_OF_STRING
996
897
  .PHONY : install
997
- install :
898
+ install : #{LICENSE}
998
899
  \t@echo "#{@emoji_install} Starting install..."
999
900
  END_OF_STRING
1000
901
  begin
1001
- code = File.open('demake/install-target.rb').read
902
+ code = String.new
903
+ File.open('demake/install-target.rb', 'r') do |f|
904
+ code = f.read
905
+ end
1002
906
  if(@emojis == false)
1003
907
  strip_emojis!(code)
1004
908
  end
@@ -1039,7 +943,10 @@ uninstall :
1039
943
  \t@echo "#{@emoji_uninstall} Starting uninstall..."
1040
944
  END_OF_STRING
1041
945
  begin
1042
- code = File.open('demake/uninstall-target.rb').read
946
+ code = String.new
947
+ File.open('demake/uninstall-target.rb', 'r') do |f|
948
+ code = f.read
949
+ end
1043
950
  if(@emojis == false)
1044
951
  strip_emojis!(code)
1045
952
  end
@@ -1054,16 +961,33 @@ if(@emojis == false)
1054
961
  end
1055
962
  @output << "\n" + @pipe.pipetext(uninstall_target)
1056
963
 
1057
- if(@example || @oreo)
964
+ if(@found_application != nil)
1058
965
  File.open('Makefile', 'w').write(@output)
1059
- if(@example)
1060
- notify("#{@emoji_success} Created file: |gexample|n/|yMakefile|n |[page facing up]\n\n" +
1061
- "Suggestion: |Ccd example ; make ; make build ; make test|n\n")
1062
- elsif(@oreo)
1063
- notify("#{@emoji_success} Created file: |goreo|n/|yMakefile|n |[page facing up]\n\n" +
1064
- "Suggestion: |Ccd oreo ; make ; make build ; make test|n\n")
966
+ notify("#{@emoji_success} Created file: |y#{@found_application}/Makefile|n |[page facing up]\n\n")
967
+ if(@suggestion != "")
968
+ notify("Suggestion: |C#{@suggestion}|n\n")
1065
969
  end
1066
970
  Dir.chdir('..')
1067
971
  else
1068
- puts @output
972
+ if(File.exist?('Makefile'))
973
+ lines = file_open_read_close('Makefile').split("\n")
974
+ if(lines[1] =~ /^# Makefile automatically generated by Ruby Gem - demake [0-9]*\.[0-9]*\.[0-9]*$/)
975
+ File.open('Makefile', 'w').write(@output)
976
+ else
977
+ match = lines.find do |e|
978
+ e =~ /^# Makefile automatically generated by Ruby Gem - demake [0-9]*\.[0-9]*\.[0-9]*$/
979
+ end
980
+ if(match != nil)
981
+ print(@pipe.pipetext("|yMakefile|n already exists, |Rbut has been modified|n overwrite anyway (y/n)? "))
982
+ else
983
+ print(@pipe.pipetext("|yMakefile|n already exists, |Rand is unrecognized|n overwrite anyway (y/n)? "))
984
+ end
985
+ if(STDIN.getc == ?y)
986
+ File.open('Makefile', 'w').write(@output)
987
+ end
988
+ end
989
+ else
990
+ File.open('Makefile', 'w').write(@output)
991
+ # puts @output
992
+ end
1069
993
  end