demake 0.0.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 +7 -0
  2. data/bin/demake +345 -0
  3. metadata +98 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bd006764cbdf45c025cd9d0a10eada888b3a4f042e3482b474bf665c136ca985
4
+ data.tar.gz: a393eec65c429d5dc9067f1e867870c5377a971e369f5cd19bf66bb6d01190aa
5
+ SHA512:
6
+ metadata.gz: d47c284b90c784a4e27a5543b7a5f63362d72944cbb2a5d21bc6a4963e9b447b7612d29d274bbd8730f4894bd00a701c85bb96fc989cb2d799296822ddf9b09c
7
+ data.tar.gz: 94ed99765ca34c0bd95e5e052501695605e469f4b9733b8d75868f3fbb21d704d2c9a158d0fa94f60db2151f5d642b438f73c104b7f68fe422252c8c4b4482cd
data/bin/demake ADDED
@@ -0,0 +1,345 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # demake - Executeable script which uses Ruby to generate decorated make files
5
+ # for multiple related applications.
6
+
7
+ require 'pipetext'
8
+
9
+ debug = true
10
+ quiet = false
11
+ compiler = "gcc"
12
+ #compiler = "clang"
13
+ #compiler = "arm-none-eabi-gcc"
14
+ #compiler = "arm-linux-gnu-gcc"
15
+ binary_directory = "bin"
16
+ source_directory = "src"
17
+ object_directory = "obj"
18
+ @raw_binary_files = String.new
19
+
20
+ flags = "-ansi -pedantic -D_DEFAULT_SOURCE"
21
+ #flags = "-ansi -pedantic -static -static-libgcc"
22
+
23
+ libraries = "-lc"
24
+
25
+ @pipe = Class.new.extend(PipeText)
26
+
27
+ begin
28
+ code = File.open('demake/settings.rb').read
29
+ eval code
30
+ rescue Errno::ENOENT
31
+ rescue
32
+ STDERR.puts(@pipe.pipetext("\n|YWARNING|n: #{$!}\n\n"))
33
+ end
34
+
35
+ begin
36
+ # The expected format is the application followed by a list of its dependencies
37
+ # all on the same line separated by space, : or tab.
38
+ application_and_dependencies = File.open('demake/applications').read.split(/\n/)
39
+ @applications = Hash.new
40
+ application_and_dependencies.each do |app|
41
+ if(app =~ /([^ :\t]*)[ :\t]*(.*)/)
42
+ @applications[$1] = Hash.new
43
+ @applications[$1]['dependencies'] = $2.split(/[ :\t]/)
44
+ else
45
+ @applications[app] = Hash.new
46
+ end
47
+ end
48
+ rescue Errno::ENOENT
49
+ STDERR.puts(@pipe.pipetext("\n|RError|n: |Yapplications file|n |Rdoes not exist|n\n\n" +
50
+ "You must create a file named |Yapplications|n which contains a list of\n" +
51
+ "executeable application names and any dependencies to be compiled.\n\n"))
52
+ exit!
53
+ rescue
54
+ puts $!.inspect
55
+ end
56
+
57
+ if(@applications == {})
58
+ STDERR.puts(@pipe.pipetext("\n|RError|n: |Yapplications file|n |Rcannot be empty|n\n\n" +
59
+ "You must create a file named |Yapplications|n which contains a list of\n" +
60
+ "executeable application names and any dependencies to be compiled.\n\n"))
61
+ exit!
62
+ end
63
+
64
+ @output = <<-END_OF_STRING
65
+ #
66
+ # Makefile automatically generated by demake
67
+ #
68
+ END_OF_STRING
69
+
70
+ if(debug)
71
+ @output << "DEBUG = true\n"
72
+ else
73
+ @output << "DEBUG = false\n"
74
+ end
75
+ if(quiet)
76
+ @output << "MAKE += -s\n"
77
+ end
78
+
79
+ compiler_settings = <<-END_OF_STRING
80
+ CC = #{compiler}
81
+ OS := $(shell uname)
82
+ PROCESSOR := $(shell uname -p)
83
+ MACHINE := $(shell uname -m)
84
+ END_OF_STRING
85
+
86
+ @output << compiler_settings
87
+
88
+ compiler_flags = <<-END_OF_STRING
89
+ FLAGS = #{flags}
90
+ ifeq '$(OS)' 'Linux'
91
+ ifeq '$(CC)' 'gcc'
92
+ FLAGS += -static -static-libgcc
93
+ else
94
+ FLAGS += -static
95
+ endif
96
+ endif
97
+ ifeq '$(OS)' 'Darwin'
98
+ FLAGS += -bundle
99
+ endif
100
+ ifeq '$(MACHINE)' 'aarch64'
101
+ FLAGS += -march=native
102
+ endif
103
+ ifeq '$(DEBUG)' 'true'
104
+ FLAGS += -g -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings
105
+ else
106
+ FLAGS += -O2
107
+ endif
108
+ CFLAGS = $(FLAGS)
109
+ END_OF_STRING
110
+
111
+ if(defined?($flags_override))
112
+ STDERR.puts("Overriding compiler flags")
113
+ compiler_flags = "FLAGS = #{flags}\nCFLAGS = $(FLAGS)\n"
114
+ end
115
+ @output << compiler_flags
116
+
117
+ compiler_directories = <<-END_OF_STRING
118
+ LIBS = #{libraries}
119
+ BINARY = #{binary_directory}
120
+ SOURCE = #{source_directory}
121
+ OBJECT = #{object_directory}
122
+ END_OF_STRING
123
+
124
+ @output << compiler_directories
125
+
126
+ #SOURCES = $(wildcard $(SOURCE)/*.c $(SOURCE)/*.h)
127
+ #OBJECTS = $(patsubst $(SOURCE)/%.c, $(OBJECT)/%.o, $(SOURCES))
128
+
129
+ counter = 0
130
+ @applications.each do |app|
131
+ counter += 1
132
+ @output << "#\n# #{app[0]} - File List (FL#{counter})\n#\n"
133
+ # test to see if there is a app.c and we need app.o
134
+ begin
135
+ File.open(source_directory + '/' + "#{app[0]}.c")
136
+ @output << "FL#{counter} = #{app[0]}.o"
137
+ rescue Errno::ENOENT
138
+ @output << "FL#{counter} ="
139
+ end
140
+ app[1]['dependencies'].each do |dep|
141
+ if(File.directory?(source_directory + '/' + dep) == true)
142
+ Dir.entries(source_directory + '/' + dep).each do |e|
143
+ if(e != '.' && e != '..' && e =~ /(.*)\.cp?p?$/)
144
+ Dir.chdir(source_directory + '/' + dep) do
145
+ if(File.directory?(e) == false)
146
+ @output << " " + dep + '/' + $1 + '.o'
147
+ end
148
+ end
149
+ end
150
+ end
151
+ else
152
+ @output << " " + dep.sub(/\.cp?p?$/, '.o')
153
+ end
154
+ end
155
+ @output << "\n"
156
+ @output << "#\n# #{app[0]} - Object List (OL#{counter})\n#\n"
157
+ @output << "OL#{counter} = $(patsubst %.o, $(OBJECT)/%.o, $(FL#{counter}))\n"
158
+ end
159
+
160
+ menu_target = <<-END_OF_STRING
161
+ menu :
162
+ \t@clear
163
+ \t@echo "|-[|20-]|o"
164
+ \t@echo "|]28|-! Make targets:|;!|o"
165
+ \t@echo "|]28|-!|;!|o"
166
+ \t@echo "|]27|-! |g|[wrench]|n |Cbuild|n|;!|o"
167
+ \t@echo "|]27|-! |B|[droplet]|n |Cclean|n|;!|o"
168
+ \t@echo "|]27|-! |s|[nut and bolt]|n |Cinstall|n|;!|o"
169
+ \t@echo "|]27|-! |m|[counterclockwise arrows button]|n |Ctest|n|;!|o"
170
+ \t@echo "|-{|20-}|o"
171
+ END_OF_STRING
172
+ @output << "\n"
173
+ @output << @pipe.pipetext(menu_target)
174
+
175
+ default_target = <<-END_OF_STRING
176
+ default :
177
+ @clear
178
+ END_OF_STRING
179
+
180
+ @applications.each do |app|
181
+ execute_target = <<-END_OF_STRING
182
+ \t@echo "|-[|50-]|o"
183
+ \t@echo "|]57|-! |g|[wrench] |nBuilding executable: |g#{app[0]}|n|;!|o"
184
+ \t@echo "|-{|50-}|o"
185
+ \t@$(MAKE) #{app[0]}
186
+ END_OF_STRING
187
+ default_target << @pipe.pipetext(execute_target)
188
+ end
189
+
190
+ @output << "\n"
191
+ @output << default_target
192
+
193
+ build_target = <<-END_OF_STRING
194
+ build :
195
+ @clear
196
+ END_OF_STRING
197
+
198
+ @applications.each do |app|
199
+ execute_target = <<-END_OF_STRING
200
+ \t@echo "|-[|50-]|o"
201
+ \t@echo "|]57|-! |g|[wrench] |nBuilding executable: |g#{app[0]}|n|;!|o"
202
+ \t@echo "|-{|50-}|o"
203
+ \t@$(MAKE) #{app[0]}
204
+ END_OF_STRING
205
+ build_target << @pipe.pipetext(execute_target)
206
+ end
207
+
208
+ @output << "\n"
209
+ @output << build_target
210
+
211
+ def add_dependencies(filename, path)
212
+ begin
213
+ dependencies = String.new
214
+ File.readlines(filename).each do |line|
215
+ if(line =~ /^#include \"(.*)\"/)
216
+ dependencies << "\t\\\n\t$(SOURCE)#{path}#{$1}"
217
+ end
218
+ end
219
+ if(dependencies != "")
220
+ dependency_targets = <<-END_OF_STRING
221
+ # Dependencies
222
+ $(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '.o')} : $(SOURCE)#{path}#{filename}#{dependencies}
223
+ \t@echo "|=!|O |R|[fire]|n Compiling... |c$(OBJECT)#{path}#{filename.sub(/\.cp?p?$/, '.o')}|n"
224
+ ifeq '$(OS)' 'Linux'
225
+ \t@mkdir -p $(OBJECT)#{path}
226
+ else
227
+ \t@if not exist $(OBJECT)#{path} @mkdir $(OBJECT)#{path}
228
+ endif
229
+ \t$(CC) $(CFLAGS) -c $(SOURCE)#{path}#{filename} -o $(OBJECT)#{path}#{filename.gsub(/\.cp?p?$/, '.o')}
230
+ END_OF_STRING
231
+ @output << "\n" + @pipe.pipetext(dependency_targets)
232
+ end
233
+ rescue
234
+ STDERR.puts(@pipe.pipetext("|YWARNING|n: #{$!}"))
235
+ STDERR.puts(@pipe.pipetext("|YWARNING|n: including #{path}#{$1}#{filename} as raw binary"))
236
+ @raw_binary_files << " $(SOURCE)#{path}#{$1}#{filename}"
237
+ end
238
+ end
239
+
240
+ def add_all_dependencies(directory, path)
241
+ Dir.entries(directory).each do |e|
242
+ if(e != '.' && e != '..')
243
+ Dir.chdir(directory) do
244
+ if(File.directory?(e) == true)
245
+ add_all_dependencies(e, path + e + '/')
246
+ end
247
+ end
248
+ end
249
+ end
250
+ Dir.entries(directory).each do |e|
251
+ if(e != '.' && e != '..')
252
+ Dir.chdir(directory) do
253
+ if(File.directory?(e) == false)
254
+ add_dependencies(e, path)
255
+ end
256
+ end
257
+ end
258
+ end
259
+ end
260
+
261
+ add_all_dependencies(source_directory, '/')
262
+
263
+ counter = 0
264
+ @applications.each do |app|
265
+ counter += 1
266
+ execute_target = <<-END_OF_STRING
267
+ #{app[0]} : $(OL#{counter})
268
+ \t@echo "|-[|50-]|o"
269
+ \t@echo "|]57|-! |B|[link]|n Linking Files... |g#{app[0]}|n|;!|o"
270
+ \t@echo "|-{|50-}|o"
271
+ ifeq '$(OS)' 'Linux'
272
+ \t@mkdir -p $(BINARY)
273
+ else
274
+ \t@if not exist $(BINARY) @mkdir $(BINARY)
275
+ endif
276
+ \t$(CC) $(LIBS) -o $(BINARY)/#{app[0]} $(OL#{counter})#{@raw_binary_files}
277
+ END_OF_STRING
278
+ @output << "\n"
279
+ @output << @pipe.pipetext(execute_target)
280
+ end
281
+
282
+ dependency_targets = <<-END_OF_STRING
283
+ # General Auto-Dependencies
284
+ $(OBJECT)/%.o : $(SOURCE)/%.c
285
+ \t@echo "|=!|o |R|[fire]|n Compiling... |c$(@)|n"
286
+ ifeq '$(OS)' 'Linux'
287
+ \t@mkdir -p $(BINARY)
288
+ \t@mkdir -p $(OBJECT)
289
+ else
290
+ \t@if not exist $(BINARY) @mkdir $(BINARY)
291
+ \t@if not exist $(OBJECT) @mkdir $(OBJECT)
292
+ endif
293
+ \t$(CC) $(CFLAGS) -c $< -o $@
294
+ END_OF_STRING
295
+ @output << "\n" + @pipe.pipetext(dependency_targets)
296
+
297
+ clean_target = <<-END_OF_STRING
298
+ clean :
299
+ \t@echo "|B|[droplet]|n Removed |Yeverything|n from |R$(OBJECT)|n and |R$(BINARY)|n directories"
300
+ ifeq '$(OS)' 'Linux'
301
+ \t@rm -rf $(OBJECT) $(BINARY)
302
+ else
303
+ \t@if exist $(OBJECT)\*.* erase /Q $(OBJECT)\*.*
304
+ \t@if exist $(OBJECT) rmdir $(OBJECT)
305
+ \t@if exist $(BINARY)\*.* erase /Q $(BINARY)\*.*
306
+ \t@if exist $(BINARY) rmdir $(BINARY)
307
+ endif
308
+ END_OF_STRING
309
+ @output << @pipe.pipetext(clean_target + "\n")
310
+
311
+ test_target = <<-END_OF_STRING
312
+ test :
313
+ \t@echo "|m|[counterclockwise arrows button]|n Starting tests..."
314
+ END_OF_STRING
315
+ begin
316
+ code = File.open('demake/test-target.rb').read
317
+ eval code
318
+ rescue Errno::ENOENT
319
+ test_targets = <<-END_OF_STRING
320
+ \t@echo "|R|[cross mark]|n |rNo tests have been executed|n"
321
+ END_OF_STRING
322
+ test_target << test_targets
323
+ rescue
324
+ STDERR.puts(@pipe.pipetext("\n|YWARNING|n: #{$!}\n\n"))
325
+ end
326
+ @output << @pipe.pipetext(test_target)
327
+
328
+ install_target = <<-END_OF_STRING
329
+ install :
330
+ \t@echo "|s|[nut and bolt]|n Starting install..."
331
+ END_OF_STRING
332
+ begin
333
+ code = File.open('demake/install-target.rb').read
334
+ eval code
335
+ rescue Errno::ENOENT
336
+ install_targets = <<-END_OF_STRING
337
+ \t@echo "|R|[cross mark]|n |rNo install scripts have been executed|n"
338
+ END_OF_STRING
339
+ install_target << install_targets
340
+ rescue
341
+ STDERR.puts(@pipe.pipetext("\n|YWARNING|n: #{$!}\n\n"))
342
+ end
343
+ @output << @pipe.pipetext(install_target)
344
+
345
+ puts @output
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: demake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Minaswan Nakamoto
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: pipetext
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.1'
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '0.1'
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.1.3
32
+ description: |
33
+ == Develop, Decorate and manage Dependencies for C Makefiles easily with a Ruby script.
34
+
35
+ Install using the Ruby Gem:
36
+
37
+ > gem install demake
38
+
39
+ If you have an existing C application and you want to generate a Makefile for it,
40
+ you might try the gen_application shell script.
41
+
42
+ > ./gen_application myapp
43
+
44
+ It requires a demake directory and application file containing the application
45
+ names followed by depencencies separated by spaces and with a new line to indicate
46
+ a different application. Something like:
47
+
48
+ > mkdir demake
49
+ > echo "hello string" > demake/applications
50
+ > echo "goodbye string" >> demake/applications
51
+ > demake > Makefile
52
+
53
+ For customization, optionally include (see example):
54
+ demake/settings.rb, demake/test-target.rb, demake/install-target.rb
55
+
56
+ The gem uses a command line interface:
57
+
58
+ > demake > Makefile
59
+
60
+ You can also clone from git for a more complete example:
61
+
62
+ > git clone https://github.com/MinaswanNakamoto/demake.git
63
+ > cd demake/bin
64
+ > chmod +x demake
65
+ > cd ../example
66
+ > ../bin/demake > Makefile
67
+ > make
68
+ > make build
69
+ email: minaswan.nakamoto@onionmail.org
70
+ executables:
71
+ - demake
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - bin/demake
76
+ homepage: https://github.com/MinaswanNakamoto/demake
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.6.9
95
+ specification_version: 4
96
+ summary: Develop, Decorate and manage Dependencies for C Makefiles easily with a Ruby
97
+ script.
98
+ test_files: []