demake 0.0.3 → 0.1.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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/demake +865 -175
  3. metadata +22 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e635ec0a30c148dc71c4aa8bb14e12cd0f45e62346fca6918e9164eef07b153
4
- data.tar.gz: ca1693da772c3417751021bf9a436119af069a18becbb6882ad438fdb1e5fcaa
3
+ metadata.gz: ad64570b38ff8a61ee1a0707c671e207443422c403048971107ecb88a8b397bf
4
+ data.tar.gz: a8ec76e1e656f91b352c5f4207da9727f887d71ad69127f028405153c56789fd
5
5
  SHA512:
6
- metadata.gz: 354c414bfae2e7e9138dfd7bf7facc0b09f4b3aa71e420a305c2dda6330e9e7846de943f3ba9296014f1658d6638d2586442aa9d32a26c725e841619444ffb33
7
- data.tar.gz: ccab035b4f0477e8b2d2b9676936bf28bcfe400a7997e88b11bd1ff623214d7a19734466850f1af3175bf57803982224cbeb0b3f0239392c730e9869e0a113de
6
+ metadata.gz: 92df21acfb3f996384d3e6284f4c75ae4a0807b75deba072a4d88473c9f6adb22b8348b1b6c8c2c6d7ccdd56880ebe8b904c88b610e72adf3da41d32496136ad
7
+ data.tar.gz: 433713d18c06f6ce22aa64f819d5acf98d55f6581dafb57affcb3b0e57e76cf8001703ae6499833dfd4ec1ccd01c2bad2b4752c4999681dc1c3f8d17bee50288
data/bin/demake CHANGED
@@ -1,141 +1,528 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  #
4
3
  # demake - Single self-contained executeable script which uses Ruby to generate decorated make files
5
4
  # for multiple related applications.
6
-
5
+ #
7
6
  require 'pipetext'
8
7
 
9
- demake_version = "0.0.3"
10
-
11
- debug = true
12
- quiet = false
13
- compiler = "gcc"
14
- #compiler = "clang"
15
- #compiler = "arm-none-eabi-gcc"
16
- #compiler = "arm-linux-gnu-gcc"
17
-
18
- flags = String.new
19
- linux_flags = String.new
20
- x86_64_flags = String.new
21
- aarch64_flags = String.new
22
- darwin_flags = String.new
23
- libraries = String.new
24
- @raw_binary_files = String.new
8
+ demake_version = "0.1.1"
9
+
10
+ @silent = false
11
+ @compiler = "gcc"
12
+ #@compiler = "clang"
13
+ #@compiler = "arm-none-eabi-gcc"
14
+ #@compiler = "arm-linux-gnu-gcc"
15
+
16
+ # Raise if you have more cores and a long compile time
17
+ @num_threads = 8
18
+
19
+ # Where to install binaries
20
+ @prefix = "/usr/local/bin/"
21
+ @library_prefix = "/usr/local/lib64/"
22
+
23
+ # Contains code, does not get touched
24
+ @source_directory = "src"
25
25
 
26
- binary_directory = "bin"
27
- source_directory = "src"
28
- object_directory = "obj"
26
+ # Both of these get completely blown away with make clean
27
+ @binary_directory = "bin"
28
+ @object_directory = "obj"
29
+
30
+ @working_directory = Dir.pwd
31
+
32
+ # If you change this to false, emojis are replaced using @replace_with
33
+ @emojis = true
34
+ @replace_with = "|mo|n"
35
+ # The space at the end helps with some fonts that cut the emoji with the next letter
36
+ @emoji_build = "|Y|[construction]|n "
37
+ @emoji_clean = "|r|[fire]|n "
38
+ @emoji_debug = "|n|[bug] "
39
+ @emoji_install = "|s|[nut and bolt]|n "
40
+ @emoji_uninstall = "|y|[wrench]|n "
41
+ @emoji_test = "|R|[red question mark]|n "
42
+ @emoji_compile = "|s|[hammer and wrench]|n "
43
+ @emoji_link = "|B|[link]|n "
44
+ @emoji_fail = "|R|[cross mark]|n "
45
+ @emoji_success = "|g|[check mark]|n "
29
46
 
30
47
  @pipe = Class.new.extend(PipeText)
31
48
 
49
+ @flags = String.new
50
+ @debug_flags = "-DDEBUG -g -Wall -Wextra -Wunused-variable -Wundef -Wconversion -Wshadow -Wcast-qual -Wwrite-strings "
51
+ @linux_flags = String.new
52
+ @x86_64_flags = String.new
53
+ @aarch64_flags = String.new
54
+ @darwin_flags = String.new
55
+ @windows_flags = String.new
56
+ @freebsd_flags = String.new
57
+ @libraries = String.new
58
+ @raw_binary_files = String.new
59
+
60
+ def strip_emojis!(string)
61
+ string.gsub!(@emoji_build, @replace_with)
62
+ string.gsub!(@emoji_clean, @replace_with)
63
+ string.gsub!(@emoji_debug, @replace_with)
64
+ string.gsub!(@emoji_install, @replace_with)
65
+ string.gsub!(@emoji_uninstall, @replace_with)
66
+ string.gsub!(@emoji_test, @replace_with)
67
+ string.gsub!(@emoji_compile, @replace_with)
68
+ string.gsub!(@emoji_link, @replace_with)
69
+ string.gsub!(@emoji_fail, @replace_with)
70
+ string.gsub!(@emoji_success, @replace_with)
71
+ # Everything else
72
+ string.gsub!(/\|\[.*\]/, @replace_with)
73
+ end
74
+
75
+ def notify(string)
76
+ if(@emojis == false)
77
+ strip_emojis!(string)
78
+ end
79
+ STDERR.puts(@pipe.pipetext(string))
80
+ end
81
+
82
+ # Used by both example and oreo to show options
83
+ settingsrb = <<-END_OF_STRING
84
+ # Uncomment to use / override
32
85
  #
33
- # !!! If there is a demake/settings.rb file that gets executed NOW as raw code !!!
34
- #
35
- # !!! Incredibly convenient, but potentially a security nightmare -- secure your environment !!!
36
- #
37
- begin
38
- code = File.open('demake/settings.rb').read
39
- eval code
40
- rescue Errno::ENOENT
41
- rescue
42
- STDERR.puts(@pipe.pipetext("\n|YWARNING|n: #{$!}\n\n"))
86
+ =begin
87
+ @silent = false
88
+ @compiler = "clang"
89
+ @prefix = "/usr/local/bin/"
90
+ @library_prefix = "/usr/lib64/"
91
+ @emojis = false
92
+ @replace_with = "|b*|n"
93
+ @libraries << "-lc"
94
+ @flags << "-ansi -pedantic -D_DEFAULT_SOURCE"
95
+ @linux_flags << "-static" # clang
96
+ @linux_flags << "-static -static-libgcc"
97
+ @x86_64_flags << "-msse2 -mssse3 -msse4.1 -msha"
98
+ @aarch64_flags << "-march=armv8-a+crypto"
99
+ @windows_flags << ""
100
+ @freebsd_flags << ""
101
+ @darwin_flags << "-bundle"
102
+ @debug_flags << "-Wpedantic -Wdeprecated-declarations -Wdiv-by-zero " +
103
+ "-Wimplicit-function-declaration -Wimplicit-int " +
104
+ "-Wpointer-arith -Wwrite-strings -Wold-style-definition " +
105
+ "-Wmissing-noreturn -Wno-cast-function-type " +
106
+ "-Wno-constant-logical-operand -Wno-long-long " +
107
+ "-Wno-missing-field-initializers -Wno-overlength-strings " +
108
+ "-Wno-packed-bitfield-compat -Wno-parentheses-equality " +
109
+ "-Wno-self-assign -Wno-tautological-compare " +
110
+ "-Wno-unused-parameter -Wno-unused-value " +
111
+ "-Wsuggest-attribute=format -Wsuggest-attribute=noreturn"
112
+ @flags = "-g -Wall"
113
+ # No default flags (use only flags in the line above)
114
+ $flags_override = true
115
+ =end
116
+ notify("#{@emoji_success} |gdemake/settings.rb is present|n")
117
+ END_OF_STRING
118
+
119
+ @example = false
120
+ if(ARGV[0] =~ /^example$/)
121
+ if(File.directory?('example') == true)
122
+ notify("\n#{@emoji_fail}|RError|n: |Ydirectory example |Ralready exists, aborting creation|n\n\n" +
123
+ "Delete the directory and try again if you wish to recreate it.\n\n")
124
+ exit!
125
+ end
126
+ @example = true
127
+ # C code files used by the example
128
+ helloc = <<-END_OF_STRING
129
+ /*
130
+ The most basic multiple executable example using a shared object/header file.
131
+
132
+ hello.c will generate an executable named hello which that prints hello, world
133
+ */
134
+ #include "string/string.h"
135
+
136
+ int main(void)
137
+ {
138
+ out("hello, world");
139
+ return 0;
140
+ }
141
+ END_OF_STRING
142
+
143
+ goodbyec = <<-END_OF_STRING
144
+ /*
145
+ The most basic multiple executable example using a shared object/header file.
146
+
147
+ goodbye.c will generate an executable named hello which that prints goodbye, world
148
+ */
149
+ #include "string/string.h"
150
+
151
+ int main(void)
152
+ {
153
+ out("goodbye, world");
154
+ return 0;
155
+ }
156
+ END_OF_STRING
157
+
158
+ stringh = <<-END_OF_STRING
159
+ /*
160
+ The most basic multiple executable example using a shared object/header file.
161
+
162
+ string.h includes a simple shared function named out which prints output
163
+ */
164
+
165
+ void out(const char *in);
166
+ END_OF_STRING
167
+
168
+ stringc = <<-END_OF_STRING
169
+ /*
170
+ The most basic multiple executable example using a shared object/header file.
171
+
172
+ string.c creates a simple shared function named out which prints output
173
+ */
174
+ #include <stdio.h>
175
+ #include "string.h"
176
+
177
+ void out(const char *in)
178
+ {
179
+ printf("%s\\n", in);
180
+ }
181
+ END_OF_STRING
182
+
183
+ testtargetrb = <<-END_OF_STRING
184
+ test_target << "\\t@echo\\n"
185
+ test_target << "\\t@echo \\"|YTesting command hello:|n\\"\\n"
186
+ test_target << "\\tbin/hello\\n"
187
+ test_target << "\\t@echo \\"|YTesting command goodbye:|n\\"\\n"
188
+ test_target << "\\tbin/goodbye\\n"
189
+ END_OF_STRING
190
+
191
+ Dir.mkdir('example')
192
+ notify("#{@emoji_success} Created directory: |gexample|n |[open file folder]\n")
193
+ Dir.mkdir('example/src')
194
+ notify("#{@emoji_success} Created directory: |gexample|n/|gsrc|n |[open file folder]\n")
195
+ File.open('example/src/hello.c', 'w').write(helloc)
196
+ notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|yhello.c|n |[page facing up]\n")
197
+ File.open('example/src/goodbye.c', 'w').write(goodbyec)
198
+ notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|ygoodbye.c|n |[page facing up]\n")
199
+ Dir.mkdir('example/src/string')
200
+ notify("#{@emoji_success} Created directory: |gexample|n/|gsrc|n/|gstring|n |[open file folder]\n")
201
+ File.open('example/src/string/string.h', 'w').write(stringh)
202
+ notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|gstring|n/|ystring.h|n |[page facing up]\n")
203
+ File.open('example/src/string/string.c', 'w').write(stringc)
204
+ notify("#{@emoji_success} Created file: |gexample|n/|gsrc|n/|gstring|n/|ystring.c|n |[page facing up]\n")
205
+ Dir.mkdir('example/demake')
206
+ notify("#{@emoji_success} Created directory: |gexample|n/|gdemake|n |[open file folder]\n")
207
+ File.open('example/demake/applications', 'w').write("hello string\ngoodbye string\n")
208
+ notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|yapplications|n |[page facing up]\n")
209
+ File.open('example/demake/settings.rb', 'w').write(settingsrb)
210
+ notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|ysettings.rb|n |[page facing up]\n")
211
+ File.open('example/demake/test-target.rb', 'w').write(testtargetrb)
212
+ notify("#{@emoji_success} Created file: |gexample|n/|gdemake|n/|ytest-target.rb|n |[page facing up]\n")
213
+ Dir.chdir('example')
214
+ @working_directory = Dir.pwd
43
215
  end
44
216
 
45
- begin
46
- # The expected format is the application followed by a list of its dependencies
47
- # all on the same line separated by space, : or tab.
48
- application_and_dependencies = File.open('demake/applications').read.split(/\n/)
49
- @applications = Hash.new
50
- application_and_dependencies.each do |app|
51
- if(app =~ /([^ :\t]*)[ :\t]*(.*)/)
52
- @applications[$1] = Hash.new
53
- @applications[$1]['dependencies'] = $2.split(/[ :\t]/)
54
- else
55
- @applications[app] = Hash.new
56
- end
217
+ @oreo = false
218
+ if(ARGV[0] =~ /^oreo$/)
219
+ if(File.directory?('oreo') == true)
220
+ notify("\n#{@emoji_fail}|RError|n: |Ydirectory oreo |Ralready exists, aborting creation|n\n\n" +
221
+ "Delete the directory and try again if you wish to recreate it.\n\n")
222
+ exit!
57
223
  end
58
- rescue Errno::ENOENT
59
- STDERR.puts(@pipe.pipetext("\n|RError|n: |Yapplications file|n |Rdoes not exist|n\n\n" +
60
- "You must create a file named |Yapplications|n which contains a list of\n" +
61
- "executeable application names and any dependencies to be compiled.\n\n"))
62
- exit!
63
- rescue
64
- puts $!.inspect
224
+ @oreo = true
225
+ # C code file used by oreo
226
+ oreoc = <<-END_OF_STRING
227
+ /*
228
+ oreo.c -- A simple c program that reads data piped in, issued as arguments or from a file and echos output
229
+
230
+ Program main entry point: main/_start
231
+ */
232
+
233
+ #include <stdio.h>
234
+ #include <stdlib.h>
235
+ #include <string.h>
236
+ #ifndef __WIN32__
237
+ #include <sys/ioctl.h>
238
+ #else
239
+ #include <windows.h>
240
+ #endif
241
+
242
+ #define FALSE 0
243
+ #define TRUE 1
244
+
245
+ #define READ_BUFFER_SIZE 4096
246
+
247
+ /* Read all the text from a file and put it into a string */
248
+ char *read_file(FILE *file, unsigned int *total_bytes)
249
+ {
250
+ size_t bytes = 0, count = 0;
251
+ char buffer[READ_BUFFER_SIZE + 1], *text = NULL;
252
+
253
+ *total_bytes = 0;
254
+
255
+ if(file == NULL)
256
+ return NULL;
257
+
258
+ bytes = fread(buffer, sizeof(char), READ_BUFFER_SIZE, file);
259
+ while(bytes) {
260
+ if(text) {
261
+ text = realloc(text, *total_bytes + bytes + 1);
262
+ count = 0;
263
+ while(count < bytes) {
264
+ *(text + *total_bytes + count) = buffer[count];
265
+ count++;
266
+ }
267
+ } else {
268
+ text = calloc(bytes + 1, sizeof(char));
269
+ count = 0;
270
+ while(count < bytes) {
271
+ *(text + *total_bytes + count) = buffer[count];
272
+ count++;
273
+ }
274
+ }
275
+ *total_bytes += (unsigned int)bytes;
276
+ *(text + *total_bytes) = '\\0';
277
+ bytes = fread(buffer, sizeof(char), READ_BUFFER_SIZE, file);
278
+ }
279
+ return text;
280
+ }
281
+
282
+ int main(int argc, char **argv)
283
+ {
284
+ FILE *file = NULL;
285
+ unsigned int total_bytes = 0, l = 0;
286
+ int n = 0;
287
+ unsigned char *string = NULL, displayed = FALSE;
288
+ #ifdef __WIN32__
289
+ HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
290
+ DWORD bytes;
291
+
292
+ if(PeekNamedPipe(stdin_handle, NULL, 0, NULL, &bytes, NULL) && bytes > 0) {
293
+ #else
294
+ if(ioctl(0, FIONREAD, &n) == 0 && n > 0) {
295
+ #endif
296
+ string = (unsigned char *)read_file(stdin, &total_bytes);
297
+ #ifdef DEBUG
298
+ printf("From stdin:\\r\\n");
299
+ #endif
300
+ printf("oreo: %s\\r\\n", string);
301
+ free(string);
302
+ string = NULL;
303
+ displayed = TRUE;
304
+ }
305
+ if(argv[1] != NULL) {
306
+ file = fopen(argv[1], "r");
307
+ if(file == NULL) {
308
+ /* We need to manually recreate the command input based on arguments with spaces */
309
+ for(n = 1; n < argc; n++) {
310
+ if(string != NULL) {
311
+ l = (unsigned int)strlen(argv[n]);
312
+ total_bytes += l + 1; /* +1 for space */
313
+ string = realloc(string, (size_t)total_bytes + 1); /* +1 for \\0 */
314
+ strncat((char *)string, " ", (size_t)2); /* 2 for space and \\0 */
315
+ strncat((char *)string, argv[n], l);
316
+ } else {
317
+ total_bytes = (unsigned int)strlen(argv[n]);
318
+ string = calloc(total_bytes + 1, sizeof(char)); /* +1 for \\0 */
319
+ strncpy((char *)string, argv[n], total_bytes);
320
+ }
321
+ }
322
+ #ifdef DEBUG
323
+ printf("From argument:\\r\\n");
324
+ #endif
325
+ printf("oreo: %s\\r\\n", string);
326
+ free(string);
327
+ string = NULL;
328
+ } else {
329
+ #ifdef DEBUG
330
+ printf("From file: %s\\r\\n", argv[1]);
331
+ #endif
332
+ string = (unsigned char *)read_file(file, &total_bytes);
333
+ printf("oreo: %s\\r\\n", string);
334
+ free(string);
335
+ string = NULL;
336
+ }
337
+ } else if(!displayed) {
338
+ #ifdef DEBUG
339
+ printf("No input provided.\\r\\n");
340
+ #endif
341
+ }
342
+
343
+ return 0;
344
+ }
345
+ END_OF_STRING
346
+
347
+ testtargetrb = <<-END_OF_STRING
348
+ test_target << "\\t@echo\\n"
349
+ test_target << "\\t@echo \\"|YBasic functional testing of command oreo:|n\\"\\n"
350
+ test_target << "\\tbin/oreo Test 1\\n"
351
+ test_target << "\\techo -n \\"Test 2\\" || bin/oreo\\n"
352
+ test_target << "\\techo -n \\"Test 3\\" || bin/oreo Test 4\\n"
353
+ END_OF_STRING
354
+
355
+ Dir.mkdir('oreo')
356
+ notify("#{@emoji_success} Created directory: |goreo|n |[open file folder]\n")
357
+ Dir.mkdir('oreo/src')
358
+ notify("#{@emoji_success} Created directory: |goreo|n/|gsrc|n |[open file folder]\n")
359
+ File.open('oreo/src/oreo.c', 'w').write(oreoc)
360
+ notify("#{@emoji_success} Created file: |goreo|n/|gsrc|n/|yoreo.c|n |[page facing up]\n")
361
+ Dir.mkdir('oreo/demake')
362
+ notify("#{@emoji_success} Created directory: |goreo|n/|gdemake|n |[open file folder]\n")
363
+ File.open('oreo/demake/applications', 'w').write("oreo\n")
364
+ notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|yapplications|n |[page facing up]\n")
365
+ File.open('oreo/demake/settings.rb', 'w').write(settingsrb)
366
+ notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|ysettings.rb|n |[page facing up]\n")
367
+ File.open('oreo/demake/test-target.rb', 'w').write(testtargetrb)
368
+ notify("#{@emoji_success} Created file: |goreo|n/|gdemake|n/|ytest-target.rb|n |[page facing up]\n")
369
+ Dir.chdir('oreo')
370
+ @working_directory = Dir.pwd
65
371
  end
66
372
 
67
- if(@applications == {})
68
- STDERR.puts(@pipe.pipetext("\n|RError|n: |Yapplications file|n |Rcannot be empty|n\n\n" +
69
- "You must create a file named |Yapplications|n which contains a list of\n" +
70
- "executeable application names and any dependencies to be compiled.\n\n"))
71
- exit!
373
+ @applications = Hash.new
374
+ @build_libraries = Hash.new
375
+
376
+ if(@example == false && @oreo == false)
377
+ # Check for settings override
378
+ begin
379
+ code = File.open('demake/settings.rb').read
380
+ if(@emojis == false)
381
+ strip_emojis!(code)
382
+ end
383
+ eval code
384
+ rescue Errno::ENOENT
385
+ rescue
386
+ notify("\n|YWARNING|n: #{$!}\n\n")
387
+ end
388
+
389
+ # Applications to build
390
+ no_applications_file = true
391
+ begin
392
+ # The expected format is the application followed by a list of its dependencies
393
+ # all on the same line separated by space, : or tab and # for comments
394
+ application_and_dependencies = File.open('demake/applications').read.split(/\n/)
395
+ no_applications_file = false
396
+ application_and_dependencies.each do |app|
397
+ if(app !~ /^#/ && app !~ /^[ \t]*#/)
398
+ if(app =~ /([^ :\t]*)[ :\t]*(.*)[ \t]*#?.*/)
399
+ application = $1
400
+ dependencies = $2.sub(/#.*$/, '').split(/[ :\t]/)
401
+ @applications[application] = dependencies
402
+ else
403
+ @applications[app] = Array.new
404
+ end
405
+ end
406
+ end
407
+ rescue
408
+ end
409
+
410
+ # Libraries to build
411
+ no_libraries_file = true
412
+ begin
413
+ # The expected format is the application followed by a list of its dependencies
414
+ # all on the same line separated by space, : or tab and # for comments
415
+ libraries_and_dependencies = File.open('demake/libraries').read.split(/\n/)
416
+ no_libraries_file = false
417
+ libraries_and_dependencies.each do |lib|
418
+ if(lib !~ /^#/ && lib !~ /^[ \t]*#/)
419
+ if(lib =~ /([^ :\t]*)[ :\t]*(.*)[ \t]*#?.*/)
420
+ library = $1
421
+ dependencies = $2.sub(/#.*$/, '').split(/[ :\t]/)
422
+ @build_libraries[library] = dependencies
423
+ else
424
+ @build_libraries[lib] = Array.new
425
+ end
426
+ end
427
+ end
428
+ rescue
429
+ end
430
+ if(no_applications_file && no_libraries_file)
431
+ notify("\n#{@emoji_fail}|RError|n: |Yapplications file|n |Rdoes not exist|n\n\n" +
432
+ "You must create a file named |Yapplications|n which contains a list of\n" +
433
+ "executeable application names and any dependencies to be compiled.\n\n")
434
+ exit!
435
+ elsif(@applications == {} && @build_libraries == {})
436
+ notify("\n#{@emoji_fail}|RError|n: |Yapplications file|n |Rcannot be empty|n\n\n" +
437
+ "You must create a file named |Yapplications|n which contains a list of\n" +
438
+ "executeable application names and any dependencies to be compiled.\n\n")
439
+ exit!
440
+ end
441
+ elsif(@oreo == true)
442
+ @applications['oreo'] = Array.new
443
+ elsif(@example == true)
444
+ @applications['hello'] = ['string']
445
+ @applications['goodbye'] = ['string']
72
446
  end
73
447
 
74
448
  @output = <<-END_OF_STRING
75
449
  #
76
- # Makefile automatically generated by demake #{demake_version}
450
+ # Makefile automatically generated by Ruby Gem - demake #{demake_version}
77
451
  #
78
452
  END_OF_STRING
79
453
 
80
- if(debug)
81
- @output << "DEBUG = true\n"
82
- else
83
- @output << "DEBUG = false\n"
84
- end
85
- if(quiet)
454
+ if(@silent == true)
86
455
  @output << "MAKE += -s\n"
87
456
  end
457
+ if(@num_threads > 1)
458
+ @output << "MAKE += -j #{@num_threads}\n"
459
+ end
88
460
 
89
461
  compiler_settings = <<-END_OF_STRING
90
- CC = #{compiler}
462
+ CC = #{@compiler}
91
463
  OS := $(shell uname)
92
464
  PROCESSOR := $(shell uname -p)
93
465
  MACHINE := $(shell uname -m)
466
+ PREFIX = #{@prefix}
467
+ LIBRARY_PREFIX = #{@library_prefix}
94
468
  END_OF_STRING
95
469
 
96
470
  @output << compiler_settings
97
471
 
98
- compiler_flags = "FLAGS = #{flags}\n"
99
- if(linux_flags != "")
472
+ compiler_flags = "FLAGS = #{@flags}\n"
473
+ if(@linux_flags != "")
100
474
  compiler_flags << "ifeq '$(OS)' 'Linux'\n"
101
- compiler_flags << " FLAGS += #{linux_flags}\n"
475
+ compiler_flags << " FLAGS += #{@linux_flags}\n"
476
+ compiler_flags << "endif\n"
477
+ end
478
+ if(@freebsd_flags != "")
479
+ compiler_flags << "ifeq '$(OS)' 'FreeBSD'\n"
480
+ compiler_flags << " FLAGS += #{@freebsd_flags}\n"
481
+ compiler_flags << "endif\n"
482
+ end
483
+ if(@windows_flags != "")
484
+ compiler_flags << "ifeq '$(OS)' 'Windows_NT'\n"
485
+ compiler_flags << " FLAGS += #{@windows_flags}\n"
102
486
  compiler_flags << "endif\n"
103
487
  end
104
- if(darwin_flags != "")
488
+ if(@darwin_flags != "")
105
489
  compiler_flags << "ifeq '$(OS)' 'Darwin'\n"
106
- compiler_flags << " FLAGS += #{darwin_flags}\n"
490
+ compiler_flags << " FLAGS += #{@darwin_flags}\n"
107
491
  compiler_flags << "endif\n"
108
492
  end
109
- if(aarch64_flags != "")
493
+ if(@aarch64_flags != "")
110
494
  compiler_flags << "ifeq '$(MACHINE)' 'aarch64'\n"
111
- compiler_flags << " FLAGS += #{aarch64_flags}\n"
495
+ compiler_flags << " FLAGS += #{@aarch64_flags}\n"
112
496
  compiler_flags << "endif\n"
113
497
  end
114
- if(x86_64_flags != "")
498
+ if(@x86_64_flags != "")
115
499
  compiler_flags << "ifeq '$(MACHINE)' 'x86_64'\n"
116
- compiler_flags << " FLAGS += #{x86_64_flags}\n"
500
+ compiler_flags << " FLAGS += #{@x86_64_flags}\n"
117
501
  compiler_flags << "endif\n"
118
502
  end
119
503
  compiler_flags += <<-END_OF_STRING
120
- ifeq '$(DEBUG)' 'true'
121
- FLAGS += -g -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings
122
- else
123
- FLAGS += -O2
124
- endif
504
+ DEBUG_FLAGS = #{@debug_flags}
505
+ FLAGS += -O2
125
506
  CFLAGS = $(FLAGS)
126
507
  END_OF_STRING
127
508
  if(defined?($flags_override))
128
- STDERR.puts("Overriding compiler flags")
129
- compiler_flags = "FLAGS = #{flags}\nCFLAGS = $(FLAGS)\n"
509
+ notify("|ROverriding compiler flags|n:")
510
+ notify("|RFLAGS|n = #{@flags}")
511
+ compiler_flags = "FLAGS = #{@flags}\nCFLAGS = $(FLAGS)\n"
130
512
  end
131
-
132
513
  @output << compiler_flags
133
514
 
515
+ if(compiler_flags =~ /-static/)
516
+ @library_extension = '.a'
517
+ else
518
+ @library_extension = '.so'
519
+ end
520
+
134
521
  compiler_directories = <<-END_OF_STRING
135
- LIBS = #{libraries}
136
- BINARY = #{binary_directory}
137
- SOURCE = #{source_directory}
138
- OBJECT = #{object_directory}
522
+ LIBS = #{@libraries}
523
+ BINARY = #{@binary_directory}
524
+ SOURCE = #{@source_directory}
525
+ OBJECT = #{@object_directory}
139
526
  END_OF_STRING
140
527
 
141
528
  @output << compiler_directories
@@ -144,90 +531,172 @@ END_OF_STRING
144
531
  #OBJECTS = $(patsubst $(SOURCE)/%.c, $(OBJECT)/%.o, $(SOURCES))
145
532
 
146
533
  counter = 0
534
+ file_list = String.new
535
+ debug_file_list = String.new
147
536
  @applications.each do |app|
148
537
  counter += 1
149
- @output << "#\n# #{app[0]} - File List (FL#{counter})\n#\n"
538
+ file_list << "#\n# #{app[0]} - File List (FL#{counter})\n#\n"
539
+ debug_file_list << "#\n# #{app[0]}_debug - Debug File List (DFL#{counter})\n#\n"
150
540
  # test to see if there is a app.c and we need app.o
151
541
  begin
152
- File.open(source_directory + '/' + "#{app[0]}.c")
153
- @output << "FL#{counter} = #{app[0]}.o"
542
+ File.open(@source_directory + '/' + "#{app[0]}.c")
543
+ file_list << "FL#{counter} = #{app[0]}.o"
544
+ debug_file_list << "DFL#{counter} = #{app[0]}_debug.o"
154
545
  rescue Errno::ENOENT
155
- @output << "FL#{counter} ="
546
+ file_list << "FL#{counter} ="
547
+ debug_file_list << "DFL#{counter} ="
156
548
  end
157
- if(File.directory?(source_directory + '/' + app[0]) == true)
158
- Dir.entries(source_directory + '/' + app[0]).each do |e|
549
+ if(File.directory?(@source_directory + '/' + app[0]) == true)
550
+ Dir.entries(@source_directory + '/' + app[0]).each do |e|
159
551
  if(e != '.' && e != '..' && e =~ /(.*)\.cp?p?$/)
160
- Dir.chdir(source_directory + '/' + app[0]) do
552
+ Dir.chdir(@source_directory + '/' + app[0]) do
161
553
  if(File.directory?(e) == false)
162
- @output << " " + app[0] + '/' + $1 + '.o'
554
+ file_list << " " + app[0] + '/' + $1 + '.o'
555
+ debug_file_list << " " + app[0] + '/' + $1 + '_debug.o'
163
556
  end
164
557
  end
165
558
  end
166
559
  end
167
560
  end
168
- app[1]['dependencies'].each do |dep|
169
- if(File.directory?(source_directory + '/' + dep) == true)
170
- Dir.entries(source_directory + '/' + dep).each do |e|
561
+ @applications[app[0]].each do |dep|
562
+ if(File.directory?(@source_directory + '/' + dep) == true)
563
+ Dir.entries(@source_directory + '/' + dep).each do |e|
171
564
  if(e != '.' && e != '..' && e =~ /(.*)\.cp?p?$/)
172
- Dir.chdir(source_directory + '/' + dep) do
565
+ Dir.chdir(@source_directory + '/' + dep) do
173
566
  if(File.directory?(e) == false)
174
- @output << " " + dep + '/' + $1 + '.o'
567
+ file_list << " " + dep + '/' + $1 + '.o'
568
+ debug_file_list << " " + dep + '/' + $1 + '_debug.o'
175
569
  end
176
570
  end
177
571
  end
178
572
  end
179
573
  else
180
- @output << " " + dep.sub(/\.cp?p?$/, '.o')
574
+ file_list << " " + dep.sub(/\.cp?p?$/, '.o')
575
+ debug_file_list << " " + dep.sub(/\.o$/, '_debug.o').sub(/\.cp?p?$/, '_debug.o')
181
576
  end
182
577
  end
183
- @output << "\n"
184
- @output << "#\n# #{app[0]} - Object List (OL#{counter})\n#\n"
185
- @output << "OL#{counter} = $(patsubst %.o, $(OBJECT)/%.o, $(FL#{counter}))\n"
578
+ file_list << "\n"
579
+ file_list << "#\n# #{app[0]} - Object List (OL#{counter})\n#\n"
580
+ file_list << "OL#{counter} = $(patsubst %.o, $(OBJECT)/%.o, $(FL#{counter}))\n"
581
+ @output << file_list
582
+ debug_file_list << "\n"
583
+ debug_file_list << "#\n# #{app[0]}_debug - Debug Object List (DOL#{counter})\n#\n"
584
+ debug_file_list << "DOL#{counter} = $(patsubst %.o, $(OBJECT)/%.o, $(DFL#{counter}))\n"
585
+ @output << debug_file_list
586
+ end
587
+
588
+ file_list = String.new
589
+ debug_file_list = String.new
590
+ @build_libraries.each do |lib|
591
+ counter += 1
592
+ file_list << "#\n# #{lib[0]}#{@library_extension} - File List (FL#{counter})\n#\n"
593
+ debug_file_list << "#\n# #{lib[0]}_debug#{@library_extension} - Debug File List (DFL#{counter})\n#\n"
594
+ # test to see if there is a lib.c and we need lib.o
595
+ begin
596
+ File.open(@source_directory + '/' + "#{lib[0]}.c")
597
+ file_list << "FL#{counter} = #{lib[0]}.o"
598
+ debug_file_list << "DFL#{counter} = #{lib[0]}_debug.o"
599
+ rescue Errno::ENOENT
600
+ file_list << "FL#{counter} ="
601
+ debug_file_list << "DFL#{counter} ="
602
+ end
603
+ if(File.directory?(@source_directory + '/' + lib[0]) == true)
604
+ Dir.entries(@source_directory + '/' + lib[0]).each do |e|
605
+ if(e != '.' && e != '..' && e =~ /(.*)\.cp?p?$/)
606
+ Dir.chdir(@source_directory + '/' + lib[0]) do
607
+ if(File.directory?(e) == false)
608
+ file_list << " " + lib[0] + '/' + $1 + '.o'
609
+ debug_file_list << " " + lib[0] + '/' + $1 + '_debug.o'
610
+ end
611
+ end
612
+ end
613
+ end
614
+ end
615
+ @build_libraries[lib[0]].each do |dep|
616
+ if(File.directory?(@source_directory + '/' + dep) == true)
617
+ Dir.entries(@source_directory + '/' + dep).each do |e|
618
+ if(e != '.' && e != '..' && e =~ /(.*)\.cp?p?$/)
619
+ Dir.chdir(@source_directory + '/' + dep) do
620
+ if(File.directory?(e) == false)
621
+ file_list << " " + dep + '/' + $1 + '.o'
622
+ debug_file_list << " " + dep + '/' + $1 + '_debug.o'
623
+ end
624
+ end
625
+ end
626
+ end
627
+ else
628
+ file_list << " " + dep.sub(/\.cp?p?$/, '.o')
629
+ debug_file_list << " " + dep.sub(/\.o$/, '_debug.o').sub(/\.cp?p?$/, '_debug.o')
630
+ end
631
+ end
632
+ file_list << "\n"
633
+ file_list << "#\n# #{lib[0]}#{@library_extension} - Object List (OL#{counter})\n#\n"
634
+ file_list << "OL#{counter} = $(patsubst %.o, $(OBJECT)/%.o, $(FL#{counter}))\n"
635
+ @output << file_list
636
+ debug_file_list << "\n"
637
+ debug_file_list << "#\n# #{lib[0]}_debug#{@library_extension} - Debug Object List (DOL#{counter})\n#\n"
638
+ debug_file_list << "DOL#{counter} = $(patsubst %.o, $(OBJECT)/%.o, $(DFL#{counter}))\n"
639
+ @output << debug_file_list
186
640
  end
187
641
 
188
642
  menu_target = <<-END_OF_STRING
643
+ .PHONY : menu
189
644
  menu :
190
- \t@echo "|-[|23-]|o"
191
- \t@echo "|-! Make targets:|9 !|o"
192
- \t@echo "|-!|23 !|o"
193
- \t@echo "|-! |g|[wrench]|n |Cbuild|n|14 !|o"
194
- \t@echo "|-! |B|[droplet]|n |Cclean|n|14 !|o"
195
- \t@echo "|-! |s|[nut and bolt]|n |Cinstall|n|12 !|o"
196
- \t@echo "|-! |m|[counterclockwise arrows button]|n |Ctest|n|15 !|o"
197
- \t@echo "|-{|23-}|o"
645
+ \t@echo "|]78|=[|70-]|O"
646
+ \t@echo "|=!|;!|O"
647
+ \t@echo "|=!|26 Make targets:|;!|O"
648
+ \t@echo "|=!|;!|O"
649
+ \t@echo "|=!|28 #{@emoji_build} |cbuild|n|;!|O"
650
+ \t@echo "|=!|28 #{@emoji_clean} |cclean|n|;!|O"
651
+ \t@echo "|=!|28 #{@emoji_debug} |cdebug|n|;!|O"
652
+ \t@echo "|=!|28 #{@emoji_install} |cinstall|n|;!|O"
653
+ \t@echo "|=!|28 #{@emoji_uninstall} |cuninstall|n|;!|O"
654
+ \t@echo "|=!|28 #{@emoji_test} |ctest|n|;!|O"
655
+ \t@echo "|=!|;!|O"
656
+ \t@echo "|=>|70-<|O"
198
657
  END_OF_STRING
199
- @output << "\n"
200
- @output << @pipe.pipetext(menu_target)
201
-
202
- default_target = <<-END_OF_STRING
203
- default :
204
- END_OF_STRING
205
-
206
658
  @applications.each do |app|
207
- execute_target = <<-END_OF_STRING
208
- \t@echo "|-[|50-]|o"
209
- \t@echo "|-! |g|[wrench] |nBuilding executable: |g#{app[0]}|n|17 !|o"
210
- \t@echo "|-{|50-}|o"
211
- \t@$(MAKE) #{app[0]}
212
- END_OF_STRING
213
- default_target << @pipe.pipetext(execute_target)
659
+ menu_target << "\t@echo \"|=!|]78 Executable: bin/|g#{app[0]}|n|;!|O\"\n"
214
660
  end
215
-
661
+ @build_libraries.each do |lib|
662
+ menu_target << "\t@echo \"|=!|]78 Library: bin/|g#{lib[0]}#{@library_extension}|n|;!|O\"\n"
663
+ end
664
+ menu_target << "\t@echo \"|={|70-}|O\"\n"
216
665
  @output << "\n"
217
- @output << default_target
666
+ if(@emojis == false)
667
+ strip_emojis!(menu_target)
668
+ end
669
+ @output << @pipe.pipetext(menu_target)
218
670
 
219
671
  build_target = <<-END_OF_STRING
672
+ .PHONY : build
220
673
  build :
221
674
  END_OF_STRING
222
675
 
223
676
  @applications.each do |app|
224
- execute_target = <<-END_OF_STRING
225
- \t@echo "|-[|50-]|o"
226
- \t@echo "|-! |g|[wrench] |nBuilding executable: |g#{app[0]}|n|17 !|o"
227
- \t@echo "|-{|50-}|o"
228
- \t@$(MAKE) #{app[0]}
677
+ executable_target = <<-END_OF_STRING
678
+ \t@echo "|=[|70-]|O"
679
+ \t@echo "|]78|=! #{@emoji_build} Building executable: bin/|g#{app[0]}|n|;!|O"
680
+ \t@echo "|={|70-}|O"
681
+ \t@$(MAKE) $(BINARY)/#{app[0]}
682
+ END_OF_STRING
683
+ if(@emojis == false)
684
+ strip_emojis!(executable_target)
685
+ end
686
+ build_target << @pipe.pipetext(executable_target)
687
+ end
688
+
689
+ @build_libraries.each do |lib|
690
+ library_target = <<-END_OF_STRING
691
+ \t@echo "|=[|70-]|O"
692
+ \t@echo "|]78|=! #{@emoji_build} Building library: bin/|g#{lib[0]}|n|;!|O"
693
+ \t@echo "|={|70-}|O"
694
+ \t@$(MAKE) $(BINARY)/#{lib[0]}#{@library_extension}
229
695
  END_OF_STRING
230
- build_target << @pipe.pipetext(execute_target)
696
+ if(@emojis == false)
697
+ strip_emojis!(library_target)
698
+ end
699
+ build_target << @pipe.pipetext(library_target)
231
700
  end
232
701
 
233
702
  @output << "\n"
@@ -238,6 +707,16 @@ def add_dependencies(filename, path)
238
707
  dependencies = String.new
239
708
  File.readlines(filename).each do |line|
240
709
  if(line =~ /^#include \"(.*)\"/)
710
+ file_name = @working_directory + '/' + @source_directory + path + $1
711
+ begin
712
+ File.open(file_name)
713
+ rescue Errno::ENOENT
714
+ notify("|YWARNING|n: included dependency does not exist - Removing #{filename}:#{file_name}\n")
715
+ next
716
+ rescue
717
+ notify("|YWARNING|n: #{$!} - Removing #{filename}:#{file_name}\n")
718
+ next
719
+ end
241
720
  dependencies << "\t\\\n\t$(SOURCE)#{path}#{$1}"
242
721
  end
243
722
  end
@@ -245,19 +724,31 @@ def add_dependencies(filename, path)
245
724
  dependency_targets = <<-END_OF_STRING
246
725
  # Dependencies
247
726
  $(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '.o')} : $(SOURCE)#{path}#{filename}#{dependencies}
248
- \t@echo "|=!|O |R|[fire]|n Compiling... |Y$(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '.o')}|n"
249
- ifeq '$(OS)' 'Linux'
727
+ \t@echo "|=!|O #{@emoji_compile} Compiling... |Y$(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '.o')}|n"
728
+ ifeq '$(OS)' 'Windows_NT'
729
+ \t@test -d $(OBJECT)#{path} |||| mkdir $(OBJECT)#{path}
730
+ else
250
731
  \t@mkdir -p $(OBJECT)#{path}
732
+ endif
733
+ \t$(CC) $(LIBS) $(CFLAGS) -c $(SOURCE)#{path}#{filename} -o $(OBJECT)#{path}#{filename.gsub(/\.cp?p?$/, '.o')}
734
+ # Dependencies for debug
735
+ $(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '_debug.o')} : $(SOURCE)#{path}#{filename}#{dependencies}
736
+ \t@echo "|=!|O #{@emoji_debug} #{@emoji_compile} Compiling... |Y$(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '_debug.o')}|n"
737
+ ifeq '$(OS)' 'Windows_NT'
738
+ \t@test -d $(OBJECT)#{path} |||| mkdir $(OBJECT)#{path}
251
739
  else
252
- \t@if not exist $(OBJECT)#{path} @mkdir $(OBJECT)#{path}
740
+ \t@mkdir -p $(OBJECT)#{path}
253
741
  endif
254
- \t$(CC) $(CFLAGS) -c $(SOURCE)#{path}#{filename} -o $(OBJECT)#{path}#{filename.gsub(/\.cp?p?$/, '.o')}
742
+ \t$(CC) $(LIBS) $(DEBUG_FLAGS) -c $(SOURCE)#{path}#{filename} -o $(OBJECT)#{path}#{filename.gsub(/\.cp?p?$/, '_debug.o')}
255
743
  END_OF_STRING
744
+ if(@emojis == false)
745
+ strip_emojis!(dependency_targets)
746
+ end
256
747
  @output << "\n" + @pipe.pipetext(dependency_targets)
257
748
  end
258
749
  rescue
259
- STDERR.puts(@pipe.pipetext("|YWARNING|n: #{$!}"))
260
- STDERR.puts(@pipe.pipetext("|YWARNING|n: including #{path}#{$1}#{filename} as raw binary"))
750
+ notify("|YWARNING|n: #{$!}")
751
+ notify("|YWARNING|n: including #{path}#{$1}#{filename} as raw binary")
261
752
  @raw_binary_files << " $(SOURCE)#{path}#{$1}#{filename}"
262
753
  end
263
754
  end
@@ -283,88 +774,287 @@ def add_all_dependencies(directory, path)
283
774
  end
284
775
  end
285
776
 
286
- add_all_dependencies(source_directory, '/')
777
+ add_all_dependencies(@source_directory, '/')
287
778
 
288
779
  counter = 0
289
780
  @applications.each do |app|
290
781
  counter += 1
291
- execute_target = <<-END_OF_STRING
292
- #{app[0]} : $(OL#{counter})
293
- \t@echo "|-[|50-]|o"
294
- \t@echo "|-! |B|[link]|n Linking Files... |g#{app[0]}|n|21 !|o"
295
- \t@echo "|-{|50-}|o"
296
- ifeq '$(OS)' 'Linux'
782
+ executable_target = <<-END_OF_STRING
783
+ $(BINARY)/#{app[0]} : $(OL#{counter})
784
+ \t@echo "|=[|70-]|O"
785
+ \t@echo "|]78|=! #{@emoji_link} Linking Files...|O bin/|g#{app[0]}|=|n|;!|O"
786
+ \t@echo "|={|70-}|O"
787
+ ifeq '$(OS)' 'Windows_NT'
788
+ \t@test -d $(BINARY) |||| mkdir $(BINARY)
789
+ else
790
+ \t@mkdir -p $(BINARY)
791
+ endif
792
+ \t$(CC) $(LIBS) $(CFLAGS) -o $(BINARY)/#{app[0]} $(OL#{counter})#{@raw_binary_files}
793
+ END_OF_STRING
794
+ @output << "\n"
795
+ if(@emojis == false)
796
+ strip_emojis!(executable_target)
797
+ end
798
+ @output << @pipe.pipetext(executable_target)
799
+ end
800
+
801
+ if(@library_extension == ".so")
802
+ shared = " -shared"
803
+ else
804
+ shared = String.new
805
+ end
806
+
807
+ @build_libraries.each do |lib|
808
+ counter += 1
809
+ library_target = <<-END_OF_STRING
810
+ $(BINARY)/#{lib[0]}#{@library_extension} : $(OL#{counter})
811
+ \t@echo "|=[|70-]|O"
812
+ \t@echo "|]78|=! #{@emoji_link} Linking Files...|O bin/|g#{lib[0]}#{@library_extension}|=|n|;!|O"
813
+ \t@echo "|={|70-}|O"
814
+ ifeq '$(OS)' 'Windows_NT'
815
+ \t@test -d $(BINARY) |||| mkdir $(BINARY)
816
+ else
817
+ \t@mkdir -p $(BINARY)
818
+ endif
819
+ \t$(CC)#{shared} $(LIBS) $(CFLAGS) -o $(BINARY)/#{lib[0]}#{@library_extension} $(OL#{counter})#{@raw_binary_files}
820
+ END_OF_STRING
821
+ @output << "\n"
822
+ if(@emojis == false)
823
+ strip_emojis!(library_target)
824
+ end
825
+ @output << @pipe.pipetext(library_target)
826
+ end
827
+
828
+ # Debug
829
+ counter = 0
830
+ @applications.each do |app|
831
+ counter += 1
832
+ debug_executable_target = <<-END_OF_STRING
833
+ $(BINARY)/#{app[0]}_debug : $(DOL#{counter})
834
+ \t@echo "|=[|70-]|O"
835
+ \t@echo "|]78|=! #{@emoji_debug} #{@emoji_link} Linking Files...|O bin/|g#{app[0]}_debug|=|n|;!|O"
836
+ \t@echo "|={|70-}|O"
837
+ ifeq '$(OS)' 'Windows_NT'
838
+ \t@test -d $(BINARY) |||| mkdir $(BINARY)
839
+ else
297
840
  \t@mkdir -p $(BINARY)
841
+ endif
842
+ \t$(CC) $(LIBS) $(DEBUG_FLAGS) -o $(BINARY)/#{app[0]}_debug $(DOL#{counter})#{@raw_binary_files}
843
+ END_OF_STRING
844
+ @output << "\n"
845
+ if(@emojis == false)
846
+ strip_emojis!(debug_executable_target)
847
+ end
848
+ @output << @pipe.pipetext(debug_executable_target)
849
+ end
850
+
851
+ @build_libraries.each do |lib|
852
+ counter += 1
853
+ debug_library_target = <<-END_OF_STRING
854
+ $(BINARY)/#{lib[0]}_debug#{@library_extension} : $(DOL#{counter})
855
+ \t@echo "|=[|70-]|O"
856
+ \t@echo "|]78|=! #{@emoji_debug} #{@emoji_link} Linking Files...|O bin/|g#{lib[0]}_debug#{@library_extension}|=|n|;!|O"
857
+ \t@echo "|={|70-}|O"
858
+ ifeq '$(OS)' 'Windows_NT'
859
+ \t@test -d $(BINARY) |||| mkdir $(BINARY)
298
860
  else
299
- \t@if not exist $(BINARY) @mkdir $(BINARY)
861
+ \t@mkdir -p $(BINARY)
300
862
  endif
301
- \t$(CC) $(CFLAGS) $(LIBS) -o $(BINARY)/#{app[0]} $(OL#{counter})#{@raw_binary_files}
863
+ \t$(CC)#{shared} $(LIBS) $(DEBUG_FLAGS) -o $(BINARY)/#{lib[0]}_debug#{@library_extension} $(DOL#{counter})#{@raw_binary_files}
302
864
  END_OF_STRING
303
865
  @output << "\n"
304
- @output << @pipe.pipetext(execute_target)
866
+ if(@emojis == false)
867
+ strip_emojis!(debug_library_target)
868
+ end
869
+ @output << @pipe.pipetext(debug_library_target)
305
870
  end
306
871
 
307
872
  dependency_targets = <<-END_OF_STRING
308
873
  # General Auto-Dependencies
309
874
  $(OBJECT)/%.o : $(SOURCE)/%.c
310
- \t@echo "|=!|o |R|[fire]|n Compiling... |Y$(@)|n"
311
- ifeq '$(OS)' 'Linux'
875
+ \t@echo "|=!|O #{@emoji_compile} Compiling... |Y$(@)|n"
876
+ ifeq '$(OS)' 'Windows_NT'
877
+ \t@test -d $(BINARY) |||| mkdir $(BINARY)
878
+ \t@test -d $(OBJECT) |||| mkdir $(OBJECT)
879
+ else
312
880
  \t@mkdir -p $(BINARY)
313
881
  \t@mkdir -p $(OBJECT)
882
+ endif
883
+ \t$(CC) $(LIBS) $(CFLAGS) -c $< -o $@
884
+ # General Auto-Dependencies for debug
885
+ $(OBJECT)/%_debug.o : $(SOURCE)/%.c
886
+ \t@echo "|=!|O #{@emoji_debug} #{@emoji_compile} Compiling... |Y$(@)|n"
887
+ ifeq '$(OS)' 'Windows_NT'
888
+ \t@test -d $(BINARY) |||| mkdir $(BINARY)
889
+ \t@test -d $(OBJECT) |||| mkdir $(OBJECT)
314
890
  else
315
- \t@if not exist $(BINARY) @mkdir $(BINARY)
316
- \t@if not exist $(OBJECT) @mkdir $(OBJECT)
891
+ \t@mkdir -p $(BINARY)
892
+ \t@mkdir -p $(OBJECT)
317
893
  endif
318
- \t$(CC) $(CFLAGS) -c $< -o $@
894
+ \t$(CC) $(LIBS) $(DEBUG_FLAGS) -c $< -o $@
319
895
  END_OF_STRING
896
+ if(@emojis == false)
897
+ strip_emojis!(dependency_targets)
898
+ end
320
899
  @output << "\n" + @pipe.pipetext(dependency_targets)
321
900
 
322
901
  clean_target = <<-END_OF_STRING
902
+ .PHONY : clean
323
903
  clean :
324
- \t@echo "|B|[droplet]|n Removed |Yeverything|n from |R$(OBJECT)|n and |R$(BINARY)|n directories"
325
- ifeq '$(OS)' 'Linux'
904
+ \t@echo "#{@emoji_clean} Removed |Yeverything|n from |R$(OBJECT)|n and |R$(BINARY)|n directories"
326
905
  \t@rm -rf $(OBJECT) $(BINARY)
327
- else
328
- \t@if exist $(OBJECT)\*.* erase /Q $(OBJECT)\*.*
329
- \t@if exist $(OBJECT) rmdir $(OBJECT)
330
- \t@if exist $(BINARY)\*.* erase /Q $(BINARY)\*.*
331
- \t@if exist $(BINARY) rmdir $(BINARY)
332
- endif
333
906
  END_OF_STRING
334
- @output << @pipe.pipetext(clean_target + "\n")
907
+ if(@emojis == false)
908
+ strip_emojis!(clean_target)
909
+ end
910
+ @output << "\n" + @pipe.pipetext(clean_target)
911
+
912
+ debug_target = <<-END_OF_STRING
913
+ .PHONY : debug
914
+ debug :
915
+ END_OF_STRING
916
+
917
+ @applications.each do |app|
918
+ executable_debug_target = <<-END_OF_STRING
919
+ \t@echo "|=[|70-]|O"
920
+ \t@echo "|]78|=! #{@emoji_debug} #{@emoji_build} |nBuilding executable:|O bin/|g#{app[0]}_debug|=|n|;!|O"
921
+ \t@echo "|={|70-}|O"
922
+ \t@$(MAKE) $(BINARY)/#{app[0]}_debug
923
+ END_OF_STRING
924
+ if(@emojis == false)
925
+ strip_emojis!(executable_debug_target)
926
+ end
927
+ debug_target << @pipe.pipetext(executable_debug_target)
928
+ end
929
+
930
+ @build_libraries.each do |lib|
931
+ library_debug_target = <<-END_OF_STRING
932
+ \t@echo "|=[|70-]|O"
933
+ \t@echo "|]78|=! #{@emoji_debug} #{@emoji_build} Building library:|O bin/|g#{lib[0]}_debug#{@library_extension}|=|n|;!|O"
934
+ \t@echo "|={|70-}|O"
935
+ \t@$(MAKE) $(BINARY)/#{lib[0]}_debug#{@library_extension}
936
+ END_OF_STRING
937
+ if(@emojis == false)
938
+ strip_emojis!(library_debug_target)
939
+ end
940
+ debug_target << @pipe.pipetext(library_debug_target)
941
+ end
942
+
943
+ @output << "\n"
944
+ @output << debug_target
945
+
946
+ def default_test_target(test_target)
947
+ test_target << "\t@echo\n"
948
+ test_target << "\t@echo \"#{@emoji_fail} |rWARNING: No tests have been created!|n\""
949
+ end
335
950
 
336
951
  test_target = <<-END_OF_STRING
337
952
  test :
338
- \t@echo -n "|m|[counterclockwise arrows button]|n Running tests"
953
+ \t@echo -n "#{@emoji_test} Running tests"
339
954
  END_OF_STRING
340
955
  begin
341
956
  code = File.open('demake/test-target.rb').read
957
+ if(@emojis == false)
958
+ strip_emojis!(code)
959
+ end
342
960
  eval code
343
961
  rescue Errno::ENOENT
344
- test_targets = <<-END_OF_STRING
345
- \t@echo "|R|[cross mark]|n |rNo tests have been executed|n"
346
- END_OF_STRING
347
- test_target << test_targets
348
962
  rescue
349
- STDERR.puts(@pipe.pipetext("\n|YWARNING|n: #{$!}\n\n"))
963
+ notify("\n|YWARNING|n: #{$!}\n\n")
964
+ end
965
+ if(@emojis == false)
966
+ strip_emojis!(test_target)
967
+ end
968
+ @output << "\n" + @pipe.pipetext(test_target)
969
+
970
+ def default_install_target(install_target)
971
+ if(@applications != {})
972
+ install_target << "\tinstall -d $(PREFIX)\n"
973
+ end
974
+ @applications.each do |app|
975
+ install_target << "\tinstall -m 755 bin/#{app[0]} $(PREFIX)\n"
976
+ end
977
+ if(@build_libraries != {})
978
+ install_target << "\tinstall -d $(LIBRARY_PREFIX)\n"
979
+ end
980
+ @build_libraries.each do |lib|
981
+ install_target << "\tinstall -m 644 bin/#{lib[0]}#{@library_extension} $(LIBRARY_PREFIX)\n"
982
+ end
983
+ install_target << "\t@echo \"#{@emoji_install} #{@emoji_success} |gInstallation Finished|n\"\n"
350
984
  end
351
- @output << @pipe.pipetext(test_target)
352
985
 
353
986
  install_target = <<-END_OF_STRING
987
+ .PHONY : install
354
988
  install :
355
- \t@echo "|s|[nut and bolt]|n Starting install..."
989
+ \t@echo "#{@emoji_install} Starting install..."
356
990
  END_OF_STRING
357
991
  begin
358
992
  code = File.open('demake/install-target.rb').read
993
+ if(@emojis == false)
994
+ strip_emojis!(code)
995
+ end
359
996
  eval code
360
997
  rescue Errno::ENOENT
361
- install_targets = <<-END_OF_STRING
362
- \t@echo "|R|[cross mark]|n |rNo install scripts have been executed|n"
998
+ default_install_target(install_target)
999
+ rescue
1000
+ notify("\n|YWARNING|n: #{$!}\n\n")
1001
+ end
1002
+ if(@emojis == false)
1003
+ strip_emojis!(install_target)
1004
+ end
1005
+ @output << "\n" + @pipe.pipetext(install_target)
1006
+
1007
+ def default_uninstall_target(uninstall_target)
1008
+ @applications.each do |app|
1009
+ uninstall_target << "\trm -f $(PREFIX)#{app[0]}\n"
1010
+ end
1011
+ if(@applications != {})
1012
+ uninstall_target << "ifneq '$(OS)' 'FreeBSD'\n"
1013
+ uninstall_target << "\trmdir --ignore-fail-on-non-empty $(PREFIX)\n"
1014
+ uninstall_target << "endif\n"
1015
+ end
1016
+ @build_libraries.each do |lib|
1017
+ uninstall_target << "\trm -f $(LIBRARY_PREFIX)#{lib[0]}#{@library_extension}\n"
1018
+ end
1019
+ if(@build_libraries != {})
1020
+ uninstall_target << "ifneq '$(OS)' 'FreeBSD'\n"
1021
+ uninstall_target << "\trmdir --ignore-fail-on-non-empty $(LIBRARY_PREFIX)\n"
1022
+ uninstall_target << "endif\n"
1023
+ end
1024
+ uninstall_target << "\t@echo \"#{@emoji_uninstall} #{@emoji_success} |gUninstall Finished|n\"\n"
1025
+ end
1026
+
1027
+ uninstall_target = <<-END_OF_STRING
1028
+ .PHONY : uninstall
1029
+ uninstall :
1030
+ \t@echo "#{@emoji_uninstall} Starting uninstall..."
363
1031
  END_OF_STRING
364
- install_target << install_targets
1032
+ begin
1033
+ code = File.open('demake/uninstall-target.rb').read
1034
+ if(@emojis == false)
1035
+ strip_emojis!(code)
1036
+ end
1037
+ eval code
1038
+ rescue Errno::ENOENT
1039
+ default_uninstall_target(uninstall_target)
365
1040
  rescue
366
- STDERR.puts(@pipe.pipetext("\n|YWARNING|n: #{$!}\n\n"))
1041
+ notify("\n|YWARNING|n: #{$!}\n\n")
1042
+ end
1043
+ if(@emojis == false)
1044
+ strip_emojis!(uninstall_target)
367
1045
  end
368
- @output << @pipe.pipetext(install_target)
1046
+ @output << "\n" + @pipe.pipetext(uninstall_target)
369
1047
 
370
- puts @output
1048
+ if(@example || @oreo)
1049
+ File.open('Makefile', 'w').write(@output)
1050
+ if(@example)
1051
+ notify("#{@emoji_success} Created file: |gexample|n/|yMakefile|n |[page facing up]\n\n" +
1052
+ "Suggestion: |Ccd example ; make ; make build ; make test|n\n")
1053
+ elsif(@oreo)
1054
+ notify("#{@emoji_success} Created file: |goreo|n/|yMakefile|n |[page facing up]\n\n" +
1055
+ "Suggestion: |Ccd oreo ; make ; make build ; make test|n\n")
1056
+ end
1057
+ Dir.chdir('..')
1058
+ else
1059
+ puts @output
1060
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -30,15 +30,27 @@ dependencies:
30
30
  - !ruby/object:Gem::Version
31
31
  version: 0.1.3
32
32
  description: |
33
- == Develop, Decorate and manage Dependencies for C Makefiles easily with a Ruby script.
33
+ == Develop, Decorate and manage Dependencies for C (GNU) Makefiles easily with a Ruby script.
34
34
 
35
35
  Install using the Ruby Gem:
36
36
 
37
37
  > gem install demake
38
38
 
39
+ To create an example with multiple sample applications:
40
+
41
+ > demake example
42
+
43
+ This will create a directory named example containing the example.
44
+
45
+ To create an example with a single sample application:
46
+
47
+ > demake oreo
48
+
49
+ This will create a directory named oreo containing the example.
50
+
39
51
  It requires a demake directory and application file containing the application
40
52
  names followed by depencencies separated by spaces and with a new line to indicate
41
- a different application. Something like:
53
+ a different application. Something like (from the example):
42
54
 
43
55
  > mkdir demake
44
56
  > echo "hello string" > demake/applications
@@ -48,21 +60,17 @@ description: |
48
60
  For customization, optionally include (see example):
49
61
  demake/settings.rb, demake/test-target.rb, demake/install-target.rb
50
62
 
51
- The gem uses a command line interface:
63
+ The output of the command by itself is a (GNU style) Makefile:
52
64
 
53
65
  > demake > Makefile
54
66
 
55
67
  You can also clone from git for a more complete example:
56
68
 
57
69
  > git clone https://github.com/MinaswanNakamoto/demake.git
58
- > cd demake/bin
59
- > chmod +x demake
60
- > cd ../example
61
- > ../bin/demake > Makefile
62
- > make
63
- > make build
64
- > bin/hello
65
- > bin/goodbye
70
+ > chmod +x demake/bin/demake
71
+ > cd demake
72
+ > bin/demake example
73
+ > cd example ; make ; make build ; make test
66
74
 
67
75
  If you have an existing C application and you want to generate a Makefile for it,
68
76
  you might try the gen_application shell script.
@@ -95,6 +103,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
103
  requirements: []
96
104
  rubygems_version: 3.6.9
97
105
  specification_version: 4
98
- summary: Develop, Decorate and manage Dependencies for C Makefiles easily with a Ruby
99
- script.
106
+ summary: Develop, Decorate and manage Dependencies for C (GNU) Makefiles easily with
107
+ a Ruby script.
100
108
  test_files: []