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
@@ -0,0 +1,102 @@
1
+ /*
2
+ oreo.c -- A simple c program that reads data piped in, issued as arguments or from a file and echos output
3
+
4
+ Program main entry point: _start/main
5
+ */
6
+
7
+ #include <stdio.h>
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+
11
+ /* Cross platform test to see if data has been piped from stdin */
12
+ #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
13
+ #include <io.h>
14
+ #define piped_from_stdin !_isatty(fileno(stdin))
15
+ #else
16
+ #include <unistd.h>
17
+ #define piped_from_stdin !isatty(fileno(stdin))
18
+ #endif
19
+
20
+ /* Cross platform test to see if data has been piped from stdin - Option 2 */
21
+ /*
22
+ #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
23
+ #include <windows.h>
24
+ #else
25
+ #include <sys/ioctl.h>
26
+ #endif
27
+ */
28
+
29
+ #include "defines.h"
30
+ #include "typedefs.h"
31
+ #define FAST_READ_FILE_IMPLEMENTATION
32
+ #include "fast_read_file.h"
33
+
34
+ i32 main(i32 argc, c8 **argv)
35
+ {
36
+ FILE *file = NULL;
37
+ u64 total_bytes = 0, l = 0;
38
+ i32 n = 0;
39
+ c8 *string = NULL;
40
+ b8 displayed = FALSE;
41
+
42
+ /* Cross platform test to see if data has been piped from stdin - Option 2 */
43
+ /*
44
+ #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
45
+ HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
46
+ DWORD bytes;
47
+
48
+ if(PeekNamedPipe(stdin_handle, NULL, 0, NULL, &bytes, NULL) && bytes > 0) {
49
+ #else
50
+ if(ioctl(0, FIONREAD, &n) == 0 && n > 0) {
51
+ #endif
52
+ */
53
+
54
+ if(piped_from_stdin) {
55
+ string = (c8 *)fast_read_all_file_aligned(stdin, &total_bytes);
56
+ #ifdef OREO_DEBUG
57
+ printf("From stdin:\r\n");
58
+ #endif
59
+ printf("oreo: %s\r\n", string);
60
+ free_all_aligned_read_memory(string);
61
+ string = NULL;
62
+ displayed = TRUE;
63
+ }
64
+ if(argv[1] != NULL) {
65
+ file = fopen(argv[1], "r");
66
+ if(file == NULL) {
67
+ /* We need to manually recreate the command input based on arguments with spaces */
68
+ for(n = 1; n < argc; n++) {
69
+ if(string != NULL) {
70
+ l = (u32)strlen(argv[n]);
71
+ total_bytes += l + 1; /* +1 for space */
72
+ string = realloc(string, (size_t)total_bytes + 1); /* +1 for \0 */
73
+ strncat((c8 *)string, " ", (size_t)2); /* 2 for space and \0 */
74
+ strncat((c8 *)string, argv[n], l);
75
+ } else {
76
+ total_bytes = (u32)strlen(argv[n]);
77
+ string = calloc(total_bytes + 1, sizeof(c8)); /* +1 for \0 */
78
+ strncpy((c8 *)string, argv[n], total_bytes);
79
+ }
80
+ }
81
+ #ifdef OREO_DEBUG
82
+ printf("From argument:\r\n");
83
+ #endif
84
+ printf("oreo: %s\r\n", string);
85
+ free(string);
86
+ string = NULL;
87
+ } else {
88
+ #ifdef OREO_DEBUG
89
+ printf("From file: %s\r\n", argv[1]);
90
+ #endif
91
+ string = (c8 *)fast_read_all_file_mapped(file, &total_bytes);
92
+ printf("oreo: %s\r\n", string);
93
+ free_all_mapped_read_memory(string, &total_bytes);
94
+ string = NULL;
95
+ }
96
+ } else if(!displayed) {
97
+ #ifdef OREO_DEBUG
98
+ printf("No input provided.\r\n");
99
+ #endif
100
+ }
101
+ exit(0);
102
+ }
@@ -0,0 +1,61 @@
1
+ /*
2
+
3
+ typedefs.h -- Include and typedefs for basic C types
4
+
5
+ These typedefs appear in all full library header files.
6
+
7
+ You can override all of them by including this file first and making your changes here.
8
+
9
+ To add text editor color highlight support for these typedefs see below.
10
+
11
+ */
12
+
13
+ #ifndef TYPEDEFS_H_Minaswan /* Prevents multiple inclusions */
14
+ #define TYPEDEFS_H_Minaswan
15
+ #define TYPEDEFS_VERSION "0.1.0"
16
+ #include <stdint.h>
17
+
18
+ typedef uint8_t b8; /* Booleans */
19
+ typedef uint16_t b16;
20
+ typedef uint32_t b32;
21
+ typedef uint64_t b64;
22
+
23
+ typedef char c8; /* Characters */
24
+ typedef unsigned char uc8;
25
+
26
+ typedef uint8_t u8; /* Unsigned Numbers */
27
+ typedef uint16_t u16;
28
+ typedef uint32_t u32;
29
+ typedef uint64_t u64;
30
+
31
+ typedef int8_t i8; /* Signed Numbers */
32
+ typedef int16_t i16;
33
+ typedef int32_t i32;
34
+ typedef int64_t i64;
35
+
36
+ typedef float f32; /* Floating Point Numbers */
37
+ typedef double f64;
38
+ #endif /* TYPEDEFS_H_Minaswan */
39
+
40
+ /*
41
+
42
+ For nvim, add to ~/.config/nvim/init.lua:
43
+
44
+ vim.cmd("syntax on")
45
+ vim.api.nvim_create_augroup("CustomCTypedefs", { clear = true })
46
+ vim.api.nvim_create_autocmd("FileType", {
47
+ group = "CustomCTypedefs",
48
+ pattern = { "c", "h", "cpp", "hpp" },
49
+ callback = function()
50
+ vim.cmd([[syntax match CustomTypedef /\<\(b8\|b16\|b32\|b64\|c8\|uc8\|i8\|i16\|i32\|i64\|u8\|u16\|u32\|u64\|f32\|f64\)\>/]])
51
+ vim.cmd([[highlight CustomTypedef guifg=green ctermfg=green]])
52
+ end,
53
+ })
54
+
55
+ For nano, add to /usr/share/nano/c.nanorc:
56
+
57
+ color green "\<(b8|b16|b32|b64|c8|uc8|i8|i16|i32|i64|u8|u16|u32|u64|f32|f64)\>"
58
+
59
+ For emacs, it would seem the magic is strong, because it just works. :)
60
+
61
+ */
@@ -0,0 +1,33 @@
1
+ /*
2
+
3
+ auto_bits.h -- *Full Library* Header File
4
+
5
+ For auto bits
6
+
7
+ See the end of this file for an example.
8
+
9
+ Public Functions:
10
+
11
+ */
12
+
13
+ #ifndef AUTO_BITS_H_Minaswan /* Prevent multiple inclusions */
14
+ #define AUTO_BITS_H_Minaswan
15
+ #ifndef TYPEDEFS_H_Minaswan /* Header guard for typedefs.h */
16
+ #define TYPEDEFS_H_Minaswan
17
+
18
+ #endif /* TYPEDEFS_H_Minaswan */
19
+
20
+ /* Public Functions */
21
+
22
+ #ifdef AUTO_BITS_IMPLEMENTATION
23
+
24
+ #endif /* AUTO_BITS_IMPLEMENTATION */
25
+ #endif /* AUTO_BITS_H_Minaswan */
26
+
27
+ /*
28
+ Example:
29
+
30
+ #define AUTO_BITS_IMPLEMENTATION
31
+ #include "auto_bits.h"
32
+
33
+ */
@@ -0,0 +1,10 @@
1
+ /*
2
+ base.h -- Light weight C Environment Setup
3
+ */
4
+
5
+ #ifndef BASE_H_Minaswan /* Header guard to prevent multiple inclusions */
6
+ #define BASE_H_Minaswan
7
+ #define BASE_VERSION "0.1.0"
8
+ #include "defines.h"
9
+ #include "typedefs.h"
10
+ #endif /* BASE_H_Minaswan */
@@ -0,0 +1,267 @@
1
+ /*
2
+
3
+ cpu_mark_check.h -- *Full Library* Header File for Inline CPU Profiling
4
+
5
+ See the end of this file for an example.
6
+
7
+ Public Functions:
8
+
9
+ i32 cpu_mark_new(const c8 *description);
10
+ void cpu_mark_check(i32 index, i32 limit);
11
+ void cpu_mark_new_description(i32 index, const c8 *description);
12
+ void cpu_mark_reset(i32 index);
13
+ void cpu_mark_remove(i32 index);
14
+
15
+ */
16
+
17
+ #ifndef CPU_MARK_CHECK_H_Minaswan /* Prevents multiple inclusions */
18
+ #define CPU_MARK_CHECK_H_Minaswan
19
+ #define CPU_MARK_CHECK_VERSION "0.1.0"
20
+ #ifndef TYPEDEFS_H_Minaswan /* Header guard for typedefs.h */
21
+ #define TYPEDEFS_H_Minaswan
22
+ #include <stdint.h>
23
+ typedef uint8_t b8; /* Booleans */
24
+ typedef uint16_t b16;
25
+ typedef uint32_t b32;
26
+ typedef uint64_t b64;
27
+
28
+ typedef char c8; /* Characters */
29
+ typedef unsigned char uc8;
30
+
31
+ typedef uint8_t u8; /* Unsigned Numbers */
32
+ typedef uint16_t u16;
33
+ typedef uint32_t u32;
34
+ typedef uint64_t u64;
35
+
36
+ typedef int8_t i8; /* Signed Numbers */
37
+ typedef int16_t i16;
38
+ typedef int32_t i32;
39
+ typedef int64_t i64;
40
+
41
+ typedef float f32; /* Floating Point Numbers */
42
+ typedef double f64;
43
+ #endif /* TYPEDEFS_H_Minaswan */
44
+
45
+ /* Public Functions */
46
+ i32 cpu_mark_new(const c8 *description);
47
+ void cpu_mark_check(i32 index, i32 limit);
48
+ void cpu_mark_new_description(i32 index, const c8 *description);
49
+ void cpu_mark_reset(i32 index);
50
+ void cpu_mark_remove(i32 index);
51
+
52
+ #ifdef CPU_MARK_CHECK_IMPLEMENTATION
53
+ #include <stdio.h>
54
+ #include <stdlib.h>
55
+ #include <string.h>
56
+ #include <time.h>
57
+ #include <sys/time.h>
58
+
59
+ #ifndef FALSE
60
+ #define FALSE 0
61
+ #endif
62
+
63
+ #ifndef TRUE
64
+ #define TRUE 1
65
+ #endif
66
+
67
+ #ifndef NULL
68
+ #define NULL ((void *) 0)
69
+ #endif
70
+
71
+ #define CPU_MARK_DEFAULT_USEC 1000
72
+
73
+ struct cpu_mark_time {
74
+ i32 index;
75
+ u64 threshold;
76
+ const c8 *description;
77
+ struct timeval last;
78
+ struct cpu_mark_time *next;
79
+ };
80
+
81
+ struct cpu_mark_time *cpu_mark_list = NULL;
82
+
83
+ i32 cpu_mark_next_index(void)
84
+ {
85
+ struct cpu_mark_time *cpu_mark = NULL;
86
+ i32 index = 0;
87
+
88
+ for(cpu_mark = cpu_mark_list; cpu_mark; cpu_mark = cpu_mark->next) {
89
+ if(cpu_mark->index >= index)
90
+ index = cpu_mark->index;
91
+ }
92
+ index++;
93
+
94
+ return(index);
95
+ }
96
+
97
+ i32 cpu_mark_new(const c8 *description)
98
+ {
99
+ struct cpu_mark_time *cpu_mark = NULL;
100
+
101
+ cpu_mark = (struct cpu_mark_time *)calloc(1, sizeof(struct cpu_mark_time));
102
+ cpu_mark->index = cpu_mark_next_index();
103
+ if(description && *description)
104
+ cpu_mark->description = description;
105
+ else
106
+ cpu_mark->description = "No Description";
107
+ cpu_mark->next = cpu_mark_list;
108
+ cpu_mark_list = cpu_mark;
109
+ gettimeofday(&cpu_mark->last, (struct timezone *) 0);
110
+
111
+ return(cpu_mark->index);
112
+ }
113
+
114
+ void cpu_mark_remove(i32 index)
115
+ {
116
+ struct cpu_mark_time *cpu_mark = NULL, *next_cpu_mark = NULL;
117
+
118
+ if(cpu_mark_list && cpu_mark_list->index == index) {
119
+ cpu_mark = cpu_mark_list;
120
+ cpu_mark_list = cpu_mark->next;
121
+ free(cpu_mark);
122
+ } else if(cpu_mark_list) {
123
+ for(cpu_mark = cpu_mark_list; cpu_mark; cpu_mark = cpu_mark->next) {
124
+ if(cpu_mark->next && cpu_mark->next->index == index) {
125
+ next_cpu_mark = cpu_mark->next;
126
+ cpu_mark->next = next_cpu_mark->next;
127
+ free(next_cpu_mark);
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ void cpu_mark_reset(i32 index)
134
+ {
135
+ struct cpu_mark_time *cpu_mark = NULL;
136
+
137
+ for(cpu_mark = cpu_mark_list; cpu_mark; cpu_mark = cpu_mark->next) {
138
+ if(cpu_mark->index == index) {
139
+ gettimeofday(&cpu_mark->last, (struct timezone *) 0);
140
+ }
141
+ }
142
+ }
143
+
144
+ struct cpu_mark_time *cpu_mark_find_by_index(i32 index)
145
+ {
146
+ struct cpu_mark_time *cpu_mark = NULL;
147
+
148
+ for(cpu_mark = cpu_mark_list; cpu_mark; cpu_mark = cpu_mark->next) {
149
+ if(cpu_mark->index == index)
150
+ return(cpu_mark);
151
+ }
152
+
153
+ return(NULL);
154
+ }
155
+
156
+ void cpu_mark_new_description(i32 index, const c8 *description)
157
+ {
158
+ struct cpu_mark_time *cpu_mark = NULL;
159
+
160
+ cpu_mark = cpu_mark_find_by_index(index);
161
+
162
+ if(cpu_mark) {
163
+ if(description && *description)
164
+ cpu_mark->description = description;
165
+ else
166
+ cpu_mark->description = "No Description";
167
+ }
168
+ }
169
+
170
+ struct timeval cpu_mark_subtract_time(struct timeval *time1, struct timeval *time2)
171
+ {
172
+ struct timeval difference, no_time;
173
+
174
+ no_time.tv_sec = 0;
175
+ no_time.tv_usec = 0;
176
+
177
+ if(time1->tv_sec < time2->tv_sec)
178
+ return no_time;
179
+ else if(time1->tv_sec == time2->tv_sec) {
180
+ if(time1->tv_usec < time2->tv_usec)
181
+ return no_time;
182
+ else {
183
+ difference.tv_sec = 0;
184
+ difference.tv_usec = time1->tv_usec - time2->tv_usec;
185
+ return difference;
186
+ }
187
+ } else {
188
+ difference.tv_sec = time1->tv_sec - time2->tv_sec;
189
+ if(time1->tv_usec < time2->tv_usec) {
190
+ difference.tv_usec = time1->tv_usec + 1000000 - time2->tv_usec;
191
+ difference.tv_sec--;
192
+ } else
193
+ difference.tv_usec = time1->tv_usec - time2->tv_usec;
194
+ return difference;
195
+ }
196
+ return no_time;
197
+ }
198
+
199
+ void cpu_mark_check(i32 index, i32 limit)
200
+ {
201
+ struct cpu_mark_time *cpu_mark = cpu_mark_find_by_index(index);
202
+ struct timeval current, spent;
203
+ c8 local_buf[1024];
204
+ c8 local_buf2[1024];
205
+
206
+ if(!cpu_mark)
207
+ return;
208
+
209
+ gettimeofday(&current, (struct timezone *) 0);
210
+ spent = cpu_mark_subtract_time(&current, &cpu_mark->last);
211
+ if(spent.tv_sec || spent.tv_usec > limit) {
212
+ sprintf(local_buf2, "CPU Threshold (%d): ", cpu_mark->index);
213
+ strcat(local_buf2, cpu_mark->description);
214
+ printf("%s\r\n", local_buf2);
215
+ sprintf(local_buf2, "CPU Threshold (%d): ", cpu_mark->index);
216
+ if(spent.tv_sec) {
217
+ sprintf(local_buf, " secs = %ld", spent.tv_sec);
218
+ strcat(local_buf2, local_buf);
219
+ }
220
+ if(spent.tv_usec) {
221
+ sprintf(local_buf, " usecs = %ld", spent.tv_usec);
222
+ strcat(local_buf2, local_buf);
223
+ }
224
+ printf("%s\r\n", local_buf2);
225
+ }
226
+ }
227
+ #endif /* CPU_MARK_CHECK_IMPLEMENTATION */
228
+ #endif /* CPU_MARK_CHECK_H_Minaswan */
229
+
230
+ /*
231
+ Example:
232
+
233
+ #define CPU_MARK_CHECK_IMPLEMENTATION
234
+ #include "cpu_mark_check.h"
235
+
236
+ i32 mark1 = cpu_mark_new("Startup");
237
+
238
+ i32 i = 0, j = 0, k = 0;
239
+ for(i = 0; i < 100000; i++) // Perform "startup" work
240
+ j += i;
241
+ k += j;
242
+ printf("k = %d\n", k); // So compiler won't optimize out testing
243
+ cpu_mark_check(mark1, 0); // If it's been more than 0 msec print mark time
244
+
245
+ cpu_mark_reset(mark1); // Reset counter to start "main" work
246
+ // Could also just create new if we wanted "startup" to keep going
247
+ // i32 mark2 = cpu_mark_new("Main Working");
248
+
249
+ cpu_mark_new_description(mark1, "Main Working");
250
+ j = 0;
251
+ for(i = 0; i < 100000; i++) // Perform "main" work
252
+ j += i;
253
+ k += j;
254
+ printf("k = %d\n", k);
255
+ cpu_mark_check(mark1, 0); // If it's been more than 0 msec print mark time
256
+
257
+ cpu_mark_new_description(mark1, "Main Still Working");
258
+ j = 0;
259
+ for(i = 0; i < 100000; i++) // Perform more "main" work
260
+ j += i;
261
+ k += j;
262
+ printf("k = %d\n", k);
263
+ cpu_mark_check(mark1, 0); // If it's been more than 0 msec print mark time
264
+
265
+ cpu_mark_remove(mark1);
266
+
267
+ */
@@ -0,0 +1,29 @@
1
+ /*
2
+ defines.h -- Basic C preprocessor macro definitions
3
+ */
4
+
5
+ #ifndef DEFINES_H_Minaswan /* Header guard to prevent multiple inclusions */
6
+ #define DEFINES_H_Minaswan
7
+ #define DEFINES_VERSION "0.1.0"
8
+ #ifndef NULL
9
+ #define NULL ((void *) 0)
10
+ #endif
11
+ #ifndef FALSE
12
+ #define FALSE 0
13
+ #endif
14
+ #ifndef TRUE
15
+ #define TRUE 1
16
+ #endif
17
+ #ifndef NO
18
+ #define NO 0
19
+ #endif
20
+ #ifndef YES
21
+ #define YES 1
22
+ #endif
23
+ #ifndef OFF
24
+ #define OFF 0
25
+ #endif
26
+ #ifndef ON
27
+ #define ON 1
28
+ #endif
29
+ #endif /* DEFINES_H_Minaswan */