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.
- checksums.yaml +4 -4
- data/bin/demake +503 -579
- data/lib/apps/example/Makefile +374 -0
- data/lib/apps/example/demake/applications +3 -0
- data/lib/apps/example/demake/brief_description +1 -0
- data/lib/apps/example/demake/license +19 -0
- data/lib/apps/example/demake/settings.rb +62 -0
- data/lib/apps/example/demake/suggestion +1 -0
- data/lib/apps/example/demake/test-target.rb +8 -0
- data/lib/apps/example/src/goodbye.c +12 -0
- data/lib/apps/example/src/hello.c +12 -0
- data/lib/apps/example/src/string/string.c +12 -0
- data/lib/apps/example/src/string/string.h +7 -0
- data/lib/apps/oreo/Makefile +260 -0
- data/lib/apps/oreo/demake/applications +1 -0
- data/lib/apps/oreo/demake/brief_description +1 -0
- data/lib/apps/oreo/demake/license +19 -0
- data/lib/apps/oreo/demake/settings.rb +62 -0
- data/lib/apps/oreo/demake/suggestion +1 -0
- data/lib/apps/oreo/demake/test-target.rb +9 -0
- data/lib/apps/oreo/oreo_test.txt +1 -0
- data/lib/apps/oreo/src/defines.h +29 -0
- data/lib/apps/oreo/src/fast_read_file.h +259 -0
- data/lib/apps/oreo/src/oreo.c +102 -0
- data/lib/apps/oreo/src/typedefs.h +61 -0
- data/lib/data/libsrc/auto_bits.h +33 -0
- data/lib/data/libsrc/base.h +10 -0
- data/lib/data/libsrc/cpu_mark_check.h +267 -0
- data/lib/data/libsrc/defines.h +29 -0
- data/lib/data/libsrc/fast_read_file.h +259 -0
- data/lib/data/libsrc/fast_sha2.h +1840 -0
- data/lib/data/libsrc/parse_arguments.h +0 -0
- data/lib/data/libsrc/rb_library.c +140 -0
- data/lib/data/libsrc/typedefs.h +61 -0
- data/lib/template/build_target.rb +6 -0
- data/lib/template/clean_target.rb +6 -0
- data/lib/template/debug_executable_target.rb +14 -0
- data/lib/template/debug_library_target.rb +14 -0
- data/lib/template/debug_target.rb +4 -0
- data/lib/template/dependency_targets.rb +22 -0
- data/lib/template/executable_debug_target.rb +6 -0
- data/lib/template/executable_target.rb +14 -0
- data/lib/template/generic_dependency_targets.rb +26 -0
- data/lib/template/library_debug_target.rb +6 -0
- data/lib/template/library_target.rb +6 -0
- data/lib/template/license_target.rb +10 -0
- data/lib/template/link_library_target.rb +14 -0
- data/lib/template/strip_build.rb +8 -0
- metadata +54 -7
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Makefile automatically generated by Ruby Gem - demake 0.2.0
|
|
3
|
+
#
|
|
4
|
+
MAKE += -j 8
|
|
5
|
+
CC = gcc
|
|
6
|
+
OS := $(shell uname)
|
|
7
|
+
PROCESSOR := $(shell uname -p)
|
|
8
|
+
MACHINE := $(shell uname -m)
|
|
9
|
+
STRIP := strip
|
|
10
|
+
STRIP_ARGS := --strip-unneeded
|
|
11
|
+
PREFIX = /usr/local/bin/
|
|
12
|
+
LIBRARY_PREFIX = /usr/local/lib/
|
|
13
|
+
FLAGS = -ansi -pedantic -D_POSIX_C_SOURCE=200809L
|
|
14
|
+
ifeq '$(MACHINE)' 'riscv64'
|
|
15
|
+
FLAGS +=
|
|
16
|
+
endif
|
|
17
|
+
DEBUG_FLAGS = -DOREO_DEBUG -g -Wall -Wextra -Wunused-variable -Wundef -Wconversion -Wshadow -Wcast-qual -Wwrite-strings
|
|
18
|
+
OFLAGS = -O2
|
|
19
|
+
CFLAGS = $(FLAGS)
|
|
20
|
+
LDFLAGS =
|
|
21
|
+
LIB_CFLAGS = $(FLAGS)
|
|
22
|
+
LIB_LDFLAGS =
|
|
23
|
+
BUILD_FLAGS = $(CFLAGS)
|
|
24
|
+
LIBS =
|
|
25
|
+
LDLIBS = $(LIBS)
|
|
26
|
+
LIB_LDLIBS = $(LIBS)
|
|
27
|
+
BINARY = bin
|
|
28
|
+
LIBRARY = lib
|
|
29
|
+
SOURCE = src
|
|
30
|
+
OBJECT = obj
|
|
31
|
+
#
|
|
32
|
+
# oreo - File List (FL1)
|
|
33
|
+
#
|
|
34
|
+
FL1 = oreo.o
|
|
35
|
+
#
|
|
36
|
+
# oreo - Object List (OL1)
|
|
37
|
+
#
|
|
38
|
+
OL1 = $(patsubst %.o, $(OBJECT)/%.o, $(FL1))
|
|
39
|
+
#
|
|
40
|
+
# oreo_debug - Debug File List (DFL1)
|
|
41
|
+
#
|
|
42
|
+
DFL1 = oreo_debug.o
|
|
43
|
+
#
|
|
44
|
+
# oreo_debug - Debug Object List (DOL1)
|
|
45
|
+
#
|
|
46
|
+
DOL1 = $(patsubst %.o, $(OBJECT)/%.o, $(DFL1))
|
|
47
|
+
|
|
48
|
+
RUBY := $(shell command -v ruby 2> /dev/null)
|
|
49
|
+
|
|
50
|
+
define LICENSE
|
|
51
|
+
|
|
52
|
+
┌────────────────────────────────────────────────────────────────────────────────┐
|
|
53
|
+
│[0;34m MIT License[0;37m │
|
|
54
|
+
│ │
|
|
55
|
+
│ Permission is hereby granted, free of charge, to any person obtaining a copy │
|
|
56
|
+
│ of this software and associated documentation files (the "Software"), to deal │
|
|
57
|
+
│ in the Software without restriction, including without limitation the rights │
|
|
58
|
+
│ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell │
|
|
59
|
+
│ copies of the Software, and to permit persons to whom the Software is │
|
|
60
|
+
│ furnished to do so, subject to the following conditions: │
|
|
61
|
+
│ │
|
|
62
|
+
│ The above copyright notice and this permission notice shall be included in all │
|
|
63
|
+
│ copies or substantial portions of the Software. │
|
|
64
|
+
│ │
|
|
65
|
+
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR │
|
|
66
|
+
│ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, │
|
|
67
|
+
│ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE │
|
|
68
|
+
│ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER │
|
|
69
|
+
│ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, │
|
|
70
|
+
│ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE │
|
|
71
|
+
│ SOFTWARE. │
|
|
72
|
+
└────────────────────────────────────────────────────────────────────────────────┘
|
|
73
|
+
|
|
74
|
+
endef
|
|
75
|
+
export LICENSE
|
|
76
|
+
define LICENSE_FILE
|
|
77
|
+
MIT License
|
|
78
|
+
|
|
79
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
80
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
81
|
+
in the Software without restriction, including without limitation the rights
|
|
82
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
83
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
84
|
+
furnished to do so, subject to the following conditions:
|
|
85
|
+
|
|
86
|
+
The above copyright notice and this permission notice shall be included in all
|
|
87
|
+
copies or substantial portions of the Software.
|
|
88
|
+
|
|
89
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
90
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
91
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
92
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
93
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
94
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
95
|
+
SOFTWARE.
|
|
96
|
+
endef
|
|
97
|
+
export LICENSE_FILE
|
|
98
|
+
|
|
99
|
+
.PHONY : menu
|
|
100
|
+
menu : LICENSE
|
|
101
|
+
@echo "╔═════════════════════════════════════════════════════════════════════════╗"
|
|
102
|
+
@echo "║ ║"
|
|
103
|
+
@echo "║ Make targets: ║"
|
|
104
|
+
@echo "║ ║"
|
|
105
|
+
@echo "║ [1;33m🚧[0;37m [0;33mbuild[0;37m ║"
|
|
106
|
+
@echo "║ [0;34m📜[0;37m [0;34mlicense[0;37m ║"
|
|
107
|
+
@echo "║ [0;31m🔥[0;37m [0;31mclean[0;37m ║"
|
|
108
|
+
@echo "║ [0;37m🐛 [1;33mdebug[0;37m ║"
|
|
109
|
+
@echo "║ [1;30m🔩[0;37m [0;36minstall[0;37m ║"
|
|
110
|
+
@echo "║ [0;33m🔧[0;37m [0;36muninstall[0;37m ║"
|
|
111
|
+
@echo "║ [1;31m❓[0;37m [0;32mtest[0;37m ║"
|
|
112
|
+
@echo "║ ║"
|
|
113
|
+
@echo "╠═════════════════════════════════════════════════════════════════════════╣"
|
|
114
|
+
@echo "║ [0;33mBuild[0;37m Executable: bin/[0;32moreo[0;37m ║"
|
|
115
|
+
@echo "╠═════════════════════════════════════════════════════════════════════════╣"
|
|
116
|
+
@echo "║ [1;33mDebug[0;37m Executable: bin/[1;33moreo_debug[0;37m ║"
|
|
117
|
+
@echo "╠═════════════════════════════════════════════════════════════════════════╣"
|
|
118
|
+
@echo "║ [0;36mInstall[0;37m [0;33mBinary[0;37m Directory: [0;32m/usr/local/bin/[0;37m ║"
|
|
119
|
+
@echo "║ [0;36mInstall[0;37m [0;35mLibrary[0;37m Directory: [0;32m/usr/local/lib/[0;37m ║"
|
|
120
|
+
@echo "╚═════════════════════════════════════════════════════════════════════════╝"
|
|
121
|
+
.PHONY : all
|
|
122
|
+
all : LICENSE build debug
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
.PHONY : license
|
|
126
|
+
license:
|
|
127
|
+
@echo "$$LICENSE_FILE" > LICENSE
|
|
128
|
+
@echo "$$LICENSE" | less -F -R -X -e
|
|
129
|
+
|
|
130
|
+
LICENSE:
|
|
131
|
+
@echo "$$LICENSE_FILE" > LICENSE
|
|
132
|
+
@echo "$$LICENSE" | less -R -X -e
|
|
133
|
+
|
|
134
|
+
.PHONY : build
|
|
135
|
+
build : LICENSE
|
|
136
|
+
@echo "╔═════════════════════════════════════════════════════════════════════════╗"
|
|
137
|
+
@echo "║ [1;33m🚧[0;37m Building executable: bin/[0;32moreo[0;37m ║"
|
|
138
|
+
@echo "╚═════════════════════════════════════════════════════════════════════════╝"
|
|
139
|
+
@$(MAKE) $(BINARY)/oreo
|
|
140
|
+
@if command -v $(STRIP) >/dev/null 2>&1 ; then echo "Stripping $(BINARY)/oreo"; $(STRIP) $(STRIP_ARGS) $(BINARY)/oreo || echo "Warning: strip failed for $(BINARY)/oreo"; else echo "strip not found; skipping strip step"; fi
|
|
141
|
+
|
|
142
|
+
.PHONY : library
|
|
143
|
+
library : LICENSE
|
|
144
|
+
|
|
145
|
+
# Dependencies
|
|
146
|
+
$(OBJECT)/oreo.o : $(SOURCE)/oreo.c \
|
|
147
|
+
$(SOURCE)/defines.h \
|
|
148
|
+
$(SOURCE)/typedefs.h \
|
|
149
|
+
$(SOURCE)/fast_read_file.h
|
|
150
|
+
@echo "║ [1;30m🛠[0;37m Compiling... [1;33m$(OBJECT)/oreo.o[0;37m"
|
|
151
|
+
ifeq '$(OS)' 'Windows_NT'
|
|
152
|
+
@test -d $(OBJECT)/ || mkdir $(OBJECT)/
|
|
153
|
+
else
|
|
154
|
+
@mkdir -p $(OBJECT)/
|
|
155
|
+
endif
|
|
156
|
+
$(CC) $(BUILD_FLAGS) $(LIBS) -c $(SOURCE)/oreo.c -o $(OBJECT)/oreo.o
|
|
157
|
+
# Dependencies for debug
|
|
158
|
+
# $(OBJECT)/oreo_debug.o : BUILD_FLAGS := $(DEBUG_FLAGS) $(CFLAGS)
|
|
159
|
+
#
|
|
160
|
+
$(OBJECT)/oreo_debug.o : $(SOURCE)/oreo.c \
|
|
161
|
+
$(SOURCE)/defines.h \
|
|
162
|
+
$(SOURCE)/typedefs.h \
|
|
163
|
+
$(SOURCE)/fast_read_file.h
|
|
164
|
+
@echo "║ [0;37m🐛 [1;30m🛠[0;37m Compiling... [1;33m$(OBJECT)/oreo_debug.o[0;37m"
|
|
165
|
+
ifeq '$(OS)' 'Windows_NT'
|
|
166
|
+
@test -d $(OBJECT)/ || mkdir $(OBJECT)/
|
|
167
|
+
else
|
|
168
|
+
@mkdir -p $(OBJECT)/
|
|
169
|
+
endif
|
|
170
|
+
$(CC) $(BUILD_FLAGS) $(LIBS) -c $(SOURCE)/oreo.c -o $(OBJECT)/oreo_debug.o
|
|
171
|
+
|
|
172
|
+
$(BINARY)/oreo : BUILD_FLAGS := $(OFLAGS) $(CFLAGS) $(LDFLAGS)
|
|
173
|
+
|
|
174
|
+
$(BINARY)/oreo : $(OL1)
|
|
175
|
+
@echo "╔═════════════════════════════════════════════════════════════════════════╗"
|
|
176
|
+
@echo "║ [1;34m🔗[0;37m Linking Files... bin/[0;32moreo[0;37m ║"
|
|
177
|
+
@echo "╚═════════════════════════════════════════════════════════════════════════╝"
|
|
178
|
+
ifeq '$(OS)' 'Windows_NT'
|
|
179
|
+
@test -d $(BINARY) || mkdir $(BINARY)
|
|
180
|
+
else
|
|
181
|
+
@mkdir -p $(BINARY)
|
|
182
|
+
endif
|
|
183
|
+
$(CC) $(BUILD_FLAGS) $(OL1) $(LDLIBS) -o $(BINARY)/oreo
|
|
184
|
+
|
|
185
|
+
$(BINARY)/oreo_debug : BUILD_FLAGS := $(DEBUG_FLAGS) $(CFLAGS) $(LDFLAGS)
|
|
186
|
+
|
|
187
|
+
$(BINARY)/oreo_debug : LICENSE $(DOL1)
|
|
188
|
+
@echo "╔═════════════════════════════════════════════════════════════════════════╗"
|
|
189
|
+
@echo "║ [0;37m🐛 [1;34m🔗[0;37m Linking Files... bin/[1;33moreo_debug[0;37m ║"
|
|
190
|
+
@echo "╚═════════════════════════════════════════════════════════════════════════╝"
|
|
191
|
+
ifeq '$(OS)' 'Windows_NT'
|
|
192
|
+
@test -d $(BINARY) || mkdir $(BINARY)
|
|
193
|
+
else
|
|
194
|
+
@mkdir -p $(BINARY)
|
|
195
|
+
endif
|
|
196
|
+
$(CC) $(BUILD_FLAGS) $(LIBS) -o $(BINARY)/oreo_debug $(DOL1)
|
|
197
|
+
|
|
198
|
+
# General Auto-Dependencies
|
|
199
|
+
$(OBJECT)/%.o : $(SOURCE)/%.c
|
|
200
|
+
@echo "║ [1;30m🛠[0;37m Compiling... [1;33m$(@)[0;37m"
|
|
201
|
+
ifeq '$(OS)' 'Windows_NT'
|
|
202
|
+
@test -d $(BINARY) || mkdir $(BINARY)
|
|
203
|
+
@test -d $(OBJECT) || mkdir $(OBJECT)
|
|
204
|
+
else
|
|
205
|
+
@mkdir -p $(BINARY)
|
|
206
|
+
@mkdir -p $(OBJECT)
|
|
207
|
+
endif
|
|
208
|
+
$(CC) $(BUILD_FLAGS) $(LIBS) -c $< -o $@
|
|
209
|
+
# General Auto-Dependencies for debug
|
|
210
|
+
# $(OBJECT)/%_debug.o : BUILD_FLAGS := $(DEBUG_FLAGS) $(CFLAGS)
|
|
211
|
+
#
|
|
212
|
+
$(OBJECT)/%_debug.o : $(SOURCE)/%.c
|
|
213
|
+
@echo "║ [0;37m🐛 [1;30m🛠[0;37m Compiling... [1;33m$(@)[0;37m"
|
|
214
|
+
ifeq '$(OS)' 'Windows_NT'
|
|
215
|
+
@test -d $(BINARY) || mkdir $(BINARY)
|
|
216
|
+
@test -d $(OBJECT) || mkdir $(OBJECT)
|
|
217
|
+
else
|
|
218
|
+
@mkdir -p $(BINARY)
|
|
219
|
+
@mkdir -p $(OBJECT)
|
|
220
|
+
endif
|
|
221
|
+
$(CC) $(BUILD_FLAGS) $(LIBS) -c $< -o $@
|
|
222
|
+
|
|
223
|
+
.PHONY : clean
|
|
224
|
+
clean :
|
|
225
|
+
@echo "[0;31m🔥[0;37m Removed [1;33meverything[0;37m from [1;31m$(OBJECT)[0;37m, [1;31m$(BINARY)[0;37m, and [1;31m$(LIBRARY)[0;37m directories"
|
|
226
|
+
@rm -rf $(OBJECT) $(BINARY) $(LIBRARY)
|
|
227
|
+
|
|
228
|
+
.PHONY : debug
|
|
229
|
+
debug : LICENSE
|
|
230
|
+
@echo "╔═════════════════════════════════════════════════════════════════════════╗"
|
|
231
|
+
@echo "║ [0;37m🐛 [1;33m🚧[0;37m [0;37mBuilding executable: bin/[1;33moreo_debug[0;37m ║"
|
|
232
|
+
@echo "╚═════════════════════════════════════════════════════════════════════════╝"
|
|
233
|
+
@$(MAKE) $(BINARY)/oreo_debug
|
|
234
|
+
|
|
235
|
+
test : LICENSE build
|
|
236
|
+
@echo -n "[1;31m❓[0;37m Running tests:"
|
|
237
|
+
@echo
|
|
238
|
+
@echo "[1;33mBasic functional testing of command oreo:[0;37m"
|
|
239
|
+
bin/oreo Test 1
|
|
240
|
+
echo -n "Test 2" | bin/oreo
|
|
241
|
+
echo -n "Test 3" | bin/oreo Test 4
|
|
242
|
+
bin/oreo oreo_test.txt
|
|
243
|
+
|
|
244
|
+
.PHONY : install
|
|
245
|
+
install : LICENSE
|
|
246
|
+
@echo "[1;30m🔩[0;37m Starting install..."
|
|
247
|
+
@test -d $(PREFIX) | install -d $(PREFIX)
|
|
248
|
+
@test -f bin/oreo && install -v -m 755 bin/oreo $(PREFIX) || \
|
|
249
|
+
(echo "Executable file bin/[0;32moreo[0;37m not found."; \
|
|
250
|
+
echo "Please type '[0;33mmake build[0;37m' first, if you wish to install.")
|
|
251
|
+
@echo "[1;30m🔩[0;37m [0;32m✔[0;37m [0;32mInstallation Finished[0;37m"
|
|
252
|
+
|
|
253
|
+
.PHONY : uninstall
|
|
254
|
+
uninstall :
|
|
255
|
+
@echo "[0;33m🔧[0;37m Starting uninstall..."
|
|
256
|
+
rm -f $(PREFIX)oreo
|
|
257
|
+
ifneq '$(OS)' 'FreeBSD'
|
|
258
|
+
rmdir --ignore-fail-on-non-empty $(PREFIX)
|
|
259
|
+
endif
|
|
260
|
+
@echo "[0;33m🔧[0;37m [0;32m✔[0;37m [0;32mUninstall Finished[0;37m"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
oreo
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Create a different sample application
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Uncomment to use / override
|
|
2
|
+
# # Default Setting | none = ""
|
|
3
|
+
#@silent = true # false
|
|
4
|
+
#@strip = false # true
|
|
5
|
+
#@debug_enabled = false # true
|
|
6
|
+
#@compiler = "clang" # "gcc"
|
|
7
|
+
#@num_threads = 16 # 8
|
|
8
|
+
#@prefix = "/usr/local/bin64/" # "/usr/local/bin/"
|
|
9
|
+
#@library_prefix = "/usr/local/lib64/" # "/usr/local/lib/"
|
|
10
|
+
#
|
|
11
|
+
# ** demake never makes changes **
|
|
12
|
+
#
|
|
13
|
+
#@source_directory = "source" # "src"
|
|
14
|
+
#
|
|
15
|
+
# ** make clean deletes all files in these directories **
|
|
16
|
+
#
|
|
17
|
+
#@binary_directory = "binary" # "bin"
|
|
18
|
+
#@library_directory = "library" # "lib"
|
|
19
|
+
#@object_directory = "object" # "obj"
|
|
20
|
+
#
|
|
21
|
+
#@emojis = false # true
|
|
22
|
+
#@replace_with = "|b*|n" # "|mo|n"
|
|
23
|
+
# Both compiler & linker
|
|
24
|
+
@flags = "-ansi -pedantic -D_POSIX_C_SOURCE=200809L"
|
|
25
|
+
@optimize_flags = "-O2"
|
|
26
|
+
#@compiler_flags = "-fPIE"
|
|
27
|
+
#@linker_flags = "-fPIE"
|
|
28
|
+
#@linker_libraries = "-lc"
|
|
29
|
+
# Platform based
|
|
30
|
+
#@linux_flags = "-static"
|
|
31
|
+
#@linux_flags = "-static -static-libgcc"
|
|
32
|
+
#@x86_64_flags = "-msse2 -mssse3 -msse4.1 -msha"
|
|
33
|
+
#@aarch64_flags = "-march=armv8-a+crypto"
|
|
34
|
+
#@riscv64_flags = "-march=native"
|
|
35
|
+
#@windows_flags = "-target x86_64-w64-windows-gnu"
|
|
36
|
+
#@freebsd_flags = ""
|
|
37
|
+
#@darwin_flags = "-bundle"
|
|
38
|
+
# Both compiler & linker
|
|
39
|
+
#@libraries = "-lc"
|
|
40
|
+
#@libraries = "-I/usr/include/ruby-3.4"
|
|
41
|
+
# Used for building libraries
|
|
42
|
+
#@library_compiler_flags = "-fPIC"
|
|
43
|
+
#@library_linker_flags = "-fPIC"
|
|
44
|
+
#@library_linker_libraries = "-lruby340"
|
|
45
|
+
# Debugging
|
|
46
|
+
@debug_flags = "-DOREO_DEBUG -g -Wall -Wextra -Wunused-variable -Wundef " +
|
|
47
|
+
"-Wconversion -Wshadow -Wcast-qual -Wwrite-strings"
|
|
48
|
+
=begin
|
|
49
|
+
@debug_flags << "-Wpedantic -Wdeprecated-declarations -Wdiv-by-zero " +
|
|
50
|
+
"-Wimplicit-function-declaration -Wimplicit-int " +
|
|
51
|
+
"-Wpointer-arith -Wwrite-strings -Wold-style-definition " +
|
|
52
|
+
"-Wmissing-noreturn -Wno-cast-function-type " +
|
|
53
|
+
"-Wno-constant-logical-operand -Wno-long-long " +
|
|
54
|
+
"-Wno-missing-field-initializers -Wno-overlength-strings " +
|
|
55
|
+
"-Wno-packed-bitfield-compat -Wno-parentheses-equality " +
|
|
56
|
+
"-Wno-self-assign -Wno-tautological-compare " +
|
|
57
|
+
"-Wno-unused-parameter -Wno-unused-value " +
|
|
58
|
+
"-Wsuggest-attribute=format -Wsuggest-attribute=noreturn"
|
|
59
|
+
=end
|
|
60
|
+
# Manually include (relative to Makefile) other raw binaries in linking
|
|
61
|
+
#@raw_binary_files = "myfile/hello.o myfile/goodbye.o"
|
|
62
|
+
notify("#{@emoji_success} demake/settings.rb is present")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cd oreo ; make ; make build ; make test
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test 5
|
|
@@ -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 */
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
fast_read_file.h -- *Full Library* Header File
|
|
4
|
+
|
|
5
|
+
For reading the entire contents of a file into 64-bit aligned memory.
|
|
6
|
+
|
|
7
|
+
See the end of this file for examples.
|
|
8
|
+
|
|
9
|
+
Public Functions: ** DON'T FORGET TO FREE YOUR MEMORY AFTER USE **
|
|
10
|
+
|
|
11
|
+
c8 *fast_read_all_file_mapped(FILE *file, u64 *total_bytes); ** READ ONLY **
|
|
12
|
+
void free_all_mapped_read_memory(c8 *data, u64 *total_bytes);
|
|
13
|
+
|
|
14
|
+
c8 *fast_read_all_file_aligned(FILE *file, u64 *total_bytes); ** READ/WRITE **
|
|
15
|
+
void free_all_aligned_read_memory(c8 *data);
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#ifndef FAST_READ_FILE_H_Minaswan /* Prevent multiple inclusions */
|
|
20
|
+
#define FAST_READ_FILE_H_Minaswan
|
|
21
|
+
#define FAST_READ_FILE_VERSION "0.1.0"
|
|
22
|
+
#ifndef TYPEDEFS_H_Minaswan /* Header guard for typedefs.h */
|
|
23
|
+
#define TYPEDEFS_H_Minaswan
|
|
24
|
+
#include <stdint.h>
|
|
25
|
+
typedef uint8_t b8; /* Booleans */
|
|
26
|
+
typedef uint16_t b16;
|
|
27
|
+
typedef uint32_t b32;
|
|
28
|
+
typedef uint64_t b64;
|
|
29
|
+
|
|
30
|
+
typedef char c8; /* Characters */
|
|
31
|
+
typedef unsigned char uc8;
|
|
32
|
+
|
|
33
|
+
typedef uint8_t u8; /* Unsigned Numbers */
|
|
34
|
+
typedef uint16_t u16;
|
|
35
|
+
typedef uint32_t u32;
|
|
36
|
+
typedef uint64_t u64;
|
|
37
|
+
|
|
38
|
+
typedef int8_t i8; /* Signed Numbers */
|
|
39
|
+
typedef int16_t i16;
|
|
40
|
+
typedef int32_t i32;
|
|
41
|
+
typedef int64_t i64;
|
|
42
|
+
|
|
43
|
+
typedef float f32; /* Floating Point Numbers */
|
|
44
|
+
typedef double f64;
|
|
45
|
+
#endif /* TYPEDEFS_H_Minaswan */
|
|
46
|
+
|
|
47
|
+
#include <stdio.h>
|
|
48
|
+
|
|
49
|
+
/* Public Functions */
|
|
50
|
+
void free_all_mapped_read_memory(c8 *data, u64 *total_bytes);
|
|
51
|
+
void free_all_aligned_read_memory(c8 *data);
|
|
52
|
+
c8 *fast_read_all_file_mapped(FILE *file, u64 *total_bytes);
|
|
53
|
+
c8 *fast_read_all_file_aligned(FILE *file, u64 *total_bytes);
|
|
54
|
+
|
|
55
|
+
#ifdef FAST_READ_FILE_IMPLEMENTATION /* Effectively read_all_file.c */
|
|
56
|
+
#include <stdlib.h>
|
|
57
|
+
#include <string.h>
|
|
58
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
59
|
+
#include <windows.h>
|
|
60
|
+
#else
|
|
61
|
+
#include <sys/mman.h>
|
|
62
|
+
#include <sys/stat.h>
|
|
63
|
+
#include <fcntl.h>
|
|
64
|
+
#include <unistd.h>
|
|
65
|
+
#endif
|
|
66
|
+
|
|
67
|
+
extern i32 fileno(FILE *stream);
|
|
68
|
+
|
|
69
|
+
#define FAST_READ_FILE_BUFFER_SIZE 4096
|
|
70
|
+
|
|
71
|
+
#ifndef FALSE
|
|
72
|
+
#define FALSE 0
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
#ifndef TRUE
|
|
76
|
+
#define TRUE 1
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
#ifndef NULL
|
|
80
|
+
#define NULL ((void *) 0)
|
|
81
|
+
#endif
|
|
82
|
+
|
|
83
|
+
#ifndef MIN
|
|
84
|
+
#define MIN(a, b) ((a) < (b) ? a : b)
|
|
85
|
+
#endif
|
|
86
|
+
|
|
87
|
+
void *fast_file_align64_malloc(size_t size)
|
|
88
|
+
{
|
|
89
|
+
void *result = NULL;
|
|
90
|
+
|
|
91
|
+
if(size == 0)
|
|
92
|
+
return(NULL);
|
|
93
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
94
|
+
result = _aligned_malloc(size, 64);
|
|
95
|
+
#else
|
|
96
|
+
#if(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
|
|
97
|
+
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
|
|
98
|
+
if(posix_memalign(&result, 64, size) != 0)
|
|
99
|
+
return(NULL);
|
|
100
|
+
#else
|
|
101
|
+
result = malloc(size);
|
|
102
|
+
#endif
|
|
103
|
+
#endif
|
|
104
|
+
return(result);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void *fast_file_align64_calloc(size_t size)
|
|
108
|
+
{
|
|
109
|
+
void *result = fast_file_align64_malloc(size);
|
|
110
|
+
|
|
111
|
+
if(result)
|
|
112
|
+
memset(result, 0, size);
|
|
113
|
+
return(result);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void *fast_file_align64_realloc(void *existing_memory, size_t old_size, size_t new_size)
|
|
117
|
+
{
|
|
118
|
+
void *new_memory = fast_file_align64_calloc(new_size);
|
|
119
|
+
|
|
120
|
+
if(new_memory && existing_memory) {
|
|
121
|
+
memcpy(new_memory, existing_memory, MIN(new_size, old_size));
|
|
122
|
+
free(existing_memory);
|
|
123
|
+
return(new_memory);
|
|
124
|
+
}
|
|
125
|
+
return(NULL);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
c8 *fast_read_all_file_aligned(FILE *file, u64 *total_bytes)
|
|
129
|
+
{
|
|
130
|
+
size_t bytes = 0, count = 0;
|
|
131
|
+
c8 buffer[FAST_READ_FILE_BUFFER_SIZE + 1];
|
|
132
|
+
c8 *data = NULL;
|
|
133
|
+
|
|
134
|
+
bytes = fread(buffer, sizeof(c8), FAST_READ_FILE_BUFFER_SIZE, file);
|
|
135
|
+
while(bytes) {
|
|
136
|
+
if(data) {
|
|
137
|
+
data = fast_file_align64_realloc(data, *total_bytes + 1, *total_bytes + bytes + 1);
|
|
138
|
+
count = 0;
|
|
139
|
+
while(count < bytes) {
|
|
140
|
+
*(data + *total_bytes + count) = buffer[count];
|
|
141
|
+
count++;
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
data = fast_file_align64_calloc(bytes + 1);
|
|
145
|
+
count = 0;
|
|
146
|
+
while(count < bytes) {
|
|
147
|
+
*(data + *total_bytes + count) = buffer[count];
|
|
148
|
+
count++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
*total_bytes += (u32)bytes;
|
|
152
|
+
*(data + *total_bytes) = '\0';
|
|
153
|
+
bytes = fread(buffer, sizeof(c8), FAST_READ_FILE_BUFFER_SIZE, file);
|
|
154
|
+
}
|
|
155
|
+
return(data);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
c8 *fast_read_all_file_mapped(FILE *file, u64 *total_bytes)
|
|
159
|
+
{
|
|
160
|
+
c8 *data = NULL;
|
|
161
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
162
|
+
HANDLE windows_file_handle = {0};
|
|
163
|
+
HANDLE windows_map_handle = {0};
|
|
164
|
+
LARGE_INTEGER windows_file_size = {0};
|
|
165
|
+
#else
|
|
166
|
+
i32 file_descriptor = fileno(file);
|
|
167
|
+
struct stat st = {0};
|
|
168
|
+
#endif
|
|
169
|
+
|
|
170
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
171
|
+
windows_file_handle = (HANDLE)_get_osfhandle(fileno(file));
|
|
172
|
+
if(windows_file_handle == INVALID_HANDLE_VALUE)
|
|
173
|
+
return(NULL);
|
|
174
|
+
if(!GetFileSizeEx(windows_file_handle, &windows_file_size) ||
|
|
175
|
+
windows_file_size.QuadPart == 0) {
|
|
176
|
+
CloseHandle(windows_file_handle);
|
|
177
|
+
return(NULL);
|
|
178
|
+
}
|
|
179
|
+
*total_bytes = (u64)windows_file_size.QuadPart;
|
|
180
|
+
windows_map_handle = CreateFileMapping(windows_file_handle,
|
|
181
|
+
NULL, PAGE_READONLY, 0, 0, NULL);
|
|
182
|
+
data = MapViewOfFile(windows_map_handle, FILE_MAP_READ, 0, 0, 0);
|
|
183
|
+
CloseHandle(windows_file_handle);
|
|
184
|
+
CloseHandle(windows_map_handle);
|
|
185
|
+
#else
|
|
186
|
+
if(file_descriptor == -1)
|
|
187
|
+
return(NULL);
|
|
188
|
+
if(fstat(file_descriptor, &st) == -1 || st.st_size == 0) {
|
|
189
|
+
close(file_descriptor);
|
|
190
|
+
return(NULL);
|
|
191
|
+
}
|
|
192
|
+
*total_bytes = (u64)st.st_size;
|
|
193
|
+
data = mmap(NULL, *total_bytes, PROT_READ, MAP_PRIVATE,
|
|
194
|
+
file_descriptor, 0);
|
|
195
|
+
if(data == MAP_FAILED) {
|
|
196
|
+
close(file_descriptor);
|
|
197
|
+
return(NULL);
|
|
198
|
+
}
|
|
199
|
+
#ifdef POSIX_FADV_SEQUENTIAL
|
|
200
|
+
posix_fadvise(file_descriptor, 0, (i64)*total_bytes,
|
|
201
|
+
POSIX_FADV_SEQUENTIAL);
|
|
202
|
+
#endif
|
|
203
|
+
#ifdef MADV_SEQUENTIAL
|
|
204
|
+
madvise(data, *total_bytes, MADV_SEQUENTIAL);
|
|
205
|
+
#endif
|
|
206
|
+
close(file_descriptor);
|
|
207
|
+
#endif
|
|
208
|
+
return(data);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
void free_all_mapped_read_memory(c8 *data, u64 *total_bytes)
|
|
212
|
+
{
|
|
213
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
214
|
+
UnmapViewOfFile(data);
|
|
215
|
+
#else
|
|
216
|
+
munmap(data, *total_bytes);
|
|
217
|
+
#endif
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
void free_all_aligned_read_memory(c8 *data)
|
|
221
|
+
{
|
|
222
|
+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
223
|
+
_aligned_free(data);
|
|
224
|
+
#else
|
|
225
|
+
free(data);
|
|
226
|
+
#endif
|
|
227
|
+
}
|
|
228
|
+
#endif /* FAST_READ_FILE_IMPLEMENTATION */
|
|
229
|
+
#endif /* FAST_READ_FILE_H_Minaswan */
|
|
230
|
+
|
|
231
|
+
/*
|
|
232
|
+
|
|
233
|
+
Examples: ** DON'T FORGET TO FREE YOUR MEMORY AFTER USE **
|
|
234
|
+
|
|
235
|
+
#define FAST_READ_FILE_IMPLEMENTATION
|
|
236
|
+
#include "fast_read_file.h"
|
|
237
|
+
|
|
238
|
+
// Read everything from file example:
|
|
239
|
+
|
|
240
|
+
FILE *file = fopen(argv[1], "rb");
|
|
241
|
+
u64 total_bytes = 0;
|
|
242
|
+
c8 *data = fast_read_all_file_mapped(file, &total_bytes);
|
|
243
|
+
use(string);
|
|
244
|
+
free_all_mapped_read_memory(string); // Note: Doesn't use malloc/free
|
|
245
|
+
|
|
246
|
+
// Read everything from stdin / non-kernal mapping example:
|
|
247
|
+
|
|
248
|
+
u64 total_bytes = 0;
|
|
249
|
+
c8 *data = fast_read_all_file_aligned(stdin, &total_bytes);
|
|
250
|
+
use(string);
|
|
251
|
+
free_all_aligned_read_memory(string); // Note: Might not use malloc/free
|
|
252
|
+
|
|
253
|
+
FILE *file = fopen(argv[1], "rb");
|
|
254
|
+
u64 total_bytes = 0;
|
|
255
|
+
c8 *data = fast_read_all_file_aligned(file, &total_bytes);
|
|
256
|
+
use(string);
|
|
257
|
+
free_all_aligned_read_memory(string); // Note: Might not use malloc/free
|
|
258
|
+
|
|
259
|
+
*/
|