makeconf 0.1.0 → 0.2.0
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.
- data/lib/makeconf.rb +9 -10
- data/lib/makeconf/baseproject.rb +66 -11
- data/lib/makeconf/buildable.rb +1 -1
- data/lib/makeconf/compiler.rb +27 -14
- data/lib/makeconf/linker.rb +1 -1
- metadata +3 -3
data/lib/makeconf.rb
CHANGED
@@ -95,7 +95,7 @@ class Makeconf
|
|
95
95
|
end
|
96
96
|
|
97
97
|
opts.on_tail('-V', '--version', 'Display version information and exit') do
|
98
|
-
puts "Makeconf $Id: makeconf.rb
|
98
|
+
puts "Makeconf $Id: makeconf.rb 301 2012-11-17 16:47:04Z mheily $"
|
99
99
|
exit
|
100
100
|
end
|
101
101
|
end
|
@@ -124,8 +124,14 @@ class Makeconf
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
+
# Adjust the log level to increase debugging output
|
128
|
+
def log_level=(level)
|
129
|
+
@@logger.level = level
|
130
|
+
end
|
131
|
+
|
127
132
|
# Examine the operating environment and set configuration options
|
128
|
-
def configure
|
133
|
+
def configure(project = nil)
|
134
|
+
@project = project unless project.nil?
|
129
135
|
|
130
136
|
@@logger.info 'Configuring the project'
|
131
137
|
# FIXME: once the GUI is finished, it should just be
|
@@ -142,7 +148,7 @@ class Makeconf
|
|
142
148
|
raise ArgumentError unless options.kind_of?(Hash)
|
143
149
|
options.each do |k,v|
|
144
150
|
case k
|
145
|
-
when :minimum_version
|
151
|
+
when :minimum_version, :log_level
|
146
152
|
send(k.to_s + '=',v)
|
147
153
|
else
|
148
154
|
raise ArgumentError, "Unknown argument #{k}"
|
@@ -201,13 +207,6 @@ class Makeconf
|
|
201
207
|
makefile.add_rule('install', Platform.is_windows? ?
|
202
208
|
'dir $(DESTDIR)' + Platform.dev_null :
|
203
209
|
'/usr/bin/test -e $(DESTDIR)')
|
204
|
-
|
205
|
-
# Distribute Makeconf with 'make distdir'
|
206
|
-
makefile.distribute([
|
207
|
-
'configure',
|
208
|
-
'makeconf/*.rb',
|
209
|
-
'makeconf/makeconf/*.rb',
|
210
|
-
])
|
211
210
|
end
|
212
211
|
|
213
212
|
end
|
data/lib/makeconf/baseproject.rb
CHANGED
@@ -28,6 +28,7 @@ class BaseProject
|
|
28
28
|
@license_file = nil
|
29
29
|
@author = 'Unknown author'
|
30
30
|
@config_h = 'config.h'
|
31
|
+
@config_h_rules = [] # Makefile rules to generate config.h
|
31
32
|
@header = {} # Hash of system header availablity
|
32
33
|
@build = [] # List of items to build
|
33
34
|
@distribute = [] # List of items to distribute
|
@@ -35,6 +36,7 @@ class BaseProject
|
|
35
36
|
@target = [] # List of additional Makefile targets
|
36
37
|
@decls = {} # List of declarations discovered via check_decl()
|
37
38
|
@funcs = {} # List of functions discovered via check_func()
|
39
|
+
@defs = {} # Custom preprocessor macro definitions
|
38
40
|
@packager = Packager.new(self)
|
39
41
|
@cc = nil
|
40
42
|
|
@@ -166,6 +168,17 @@ class BaseProject
|
|
166
168
|
# Add custom targets
|
167
169
|
@target.each { |t| makefile.add_target t }
|
168
170
|
|
171
|
+
# Add the config.h target
|
172
|
+
@config_h_rules.unshift \
|
173
|
+
'@echo "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */" > config.h.tmp',
|
174
|
+
'@date > config.log'
|
175
|
+
@config_h_rules.push \
|
176
|
+
'@rm -f conftest.c conftest.o',
|
177
|
+
'@mv config.h.tmp ' + @config_h
|
178
|
+
makefile.add_target Target.new('config.h', [], @config_h_rules)
|
179
|
+
|
180
|
+
makefile.distribute 'Makefile'
|
181
|
+
|
169
182
|
makefile
|
170
183
|
end
|
171
184
|
|
@@ -175,35 +188,77 @@ class BaseProject
|
|
175
188
|
@install.each { |x| @installer.install x }
|
176
189
|
end
|
177
190
|
|
191
|
+
# Check if a system header file is available
|
192
|
+
def check_header(headers)
|
193
|
+
headers = [ headers ] if headers.kind_of? String
|
194
|
+
throw ArgumentError unless headers.kind_of? Array
|
195
|
+
rc = true
|
196
|
+
|
197
|
+
headers.each do |header|
|
198
|
+
printf "checking for #{header}... "
|
199
|
+
@header[header] = @cc.check_header(header)
|
200
|
+
if @header[header]
|
201
|
+
puts 'yes'
|
202
|
+
else
|
203
|
+
puts 'no'
|
204
|
+
rc = false
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
rc
|
209
|
+
end
|
210
|
+
|
178
211
|
# Check if a system header declares a macro or symbol
|
179
|
-
def check_decl(
|
180
|
-
throw ArgumentError unless header.kind_of? String
|
212
|
+
def check_decl(decl, opt = { :include => 'stdlib.h' })
|
181
213
|
decl = [ decl ] if decl.kind_of? String
|
182
214
|
throw ArgumentError unless decl.kind_of? Array
|
183
|
-
|
184
|
-
@cc ||= CCompiler.new() #FIXME: stop this
|
215
|
+
rc = true
|
185
216
|
|
186
217
|
decl.each do |x|
|
187
218
|
next if @decls.has_key? x
|
188
219
|
printf "checking whether #{x} is declared... "
|
189
|
-
|
190
|
-
|
220
|
+
source = [
|
221
|
+
"#define _GNU_SOURCE",
|
222
|
+
"#include <#{opt[:include]}>",
|
223
|
+
"int main() { #{x}; }"
|
224
|
+
].join("\n")
|
225
|
+
@decls[x] = @cc.test_compile(source)
|
226
|
+
if @decls[x]
|
227
|
+
puts 'yes'
|
228
|
+
else
|
229
|
+
puts 'no'
|
230
|
+
rc = false
|
231
|
+
end
|
191
232
|
end
|
233
|
+
|
234
|
+
rc
|
192
235
|
end
|
193
236
|
|
194
237
|
# Check if a function is available in the standard C library
|
195
238
|
# TODO: probably should add :ldadd when checking..
|
196
|
-
def
|
239
|
+
def check_function(func, *arg)
|
197
240
|
func = [ func ] if func.kind_of? String
|
198
241
|
throw ArgumentError unless func.kind_of? Array
|
242
|
+
rc = true
|
199
243
|
|
200
|
-
@cc ||= CCompiler.new() #FIXME: stop this
|
201
244
|
func.each do |x|
|
202
245
|
next if @funcs.has_key? x
|
203
246
|
printf "checking for #{x}... "
|
204
247
|
@funcs[x] = @cc.test_link "void *#{x}();\nint main() { void *p;\np = &#{x}; }"
|
205
|
-
|
248
|
+
if @funcs[x]
|
249
|
+
puts 'yes'
|
250
|
+
else
|
251
|
+
puts 'no'
|
252
|
+
rc = false
|
253
|
+
end
|
206
254
|
end
|
255
|
+
|
256
|
+
rc
|
257
|
+
end
|
258
|
+
|
259
|
+
# Define a C preprocessor symbol
|
260
|
+
def define(id,value)
|
261
|
+
@defs[id] = value
|
207
262
|
end
|
208
263
|
|
209
264
|
def add_binary(options)
|
@@ -343,6 +398,7 @@ class BaseProject
|
|
343
398
|
@header.keys.sort.each { |k| buf["HAVE_#{k}".upcase] = @header[k] }
|
344
399
|
@decls.keys.sort.each { |x| buf["HAVE_DECL_#{x}".upcase] = @decls[x] }
|
345
400
|
@funcs.keys.sort.each { |x| buf["HAVE_#{x}".upcase] = @funcs[x] }
|
401
|
+
@defs.keys.sort.each { |x| buf[x] = @defs[x] }
|
346
402
|
|
347
403
|
puts 'creating ' + ofile
|
348
404
|
f = File.open(ofile, 'w')
|
@@ -353,7 +409,7 @@ class BaseProject
|
|
353
409
|
if v == true
|
354
410
|
f.printf "#define #{id} 1\n"
|
355
411
|
else
|
356
|
-
f.printf "#undef #{id}
|
412
|
+
f.printf "/* #undef #{id} */\n"
|
357
413
|
end
|
358
414
|
end
|
359
415
|
f.close
|
@@ -382,5 +438,4 @@ class BaseProject
|
|
382
438
|
end
|
383
439
|
return false
|
384
440
|
end
|
385
|
-
|
386
441
|
end
|
data/lib/makeconf/buildable.rb
CHANGED
@@ -180,7 +180,7 @@ class Buildable
|
|
180
180
|
@ldadd = [ @ldadd ] if @ldadd.kind_of?(String)
|
181
181
|
@ldadd.each { |lib| ld.library lib }
|
182
182
|
|
183
|
-
makefile.add_target(obj, [src, localdep[src]].flatten, cc.rule)
|
183
|
+
makefile.add_target(obj, [@project.config_h, src, localdep[src]].flatten, cc.rule)
|
184
184
|
makefile.clean(obj)
|
185
185
|
objs.push obj
|
186
186
|
end
|
data/lib/makeconf/compiler.rb
CHANGED
@@ -4,7 +4,7 @@ class Compiler
|
|
4
4
|
|
5
5
|
require 'tempfile'
|
6
6
|
|
7
|
-
attr_accessor :sysroot
|
7
|
+
attr_accessor :sysroot, :output
|
8
8
|
attr_reader :ld
|
9
9
|
|
10
10
|
def initialize(language, extension)
|
@@ -55,11 +55,6 @@ class Compiler
|
|
55
55
|
@quiet = b
|
56
56
|
end
|
57
57
|
|
58
|
-
def output=(s)
|
59
|
-
@output = s
|
60
|
-
ld.output = s
|
61
|
-
end
|
62
|
-
|
63
58
|
def makefile
|
64
59
|
m = Makefile.new
|
65
60
|
m.define_variable('CC', ':=', @path)
|
@@ -69,7 +64,7 @@ class Compiler
|
|
69
64
|
|
70
65
|
# Return the command formatted as a Makefile rule
|
71
66
|
def rule
|
72
|
-
[ '$(CC)', '-
|
67
|
+
[ '$(CC)', '-DHAVE_CONFIG_H', flags, '$(CFLAGS)', '-c', @sources ].flatten.join(' ')
|
73
68
|
end
|
74
69
|
|
75
70
|
# Return the complete command line to compile an object
|
@@ -99,7 +94,7 @@ class Compiler
|
|
99
94
|
# return [ @path, cflags, '-combine', ldflags, inputs, ldadd ].flatten.join(' ')
|
100
95
|
#
|
101
96
|
|
102
|
-
cmd = [ @path, '-
|
97
|
+
cmd = [ @path, '-DHAVE_CONFIG_H', flags, '-c', @sources ].flatten.join(' ')
|
103
98
|
|
104
99
|
cmd += Platform.dev_null if @quiet
|
105
100
|
|
@@ -197,31 +192,49 @@ class Compiler
|
|
197
192
|
# Run the compilation command
|
198
193
|
def compile
|
199
194
|
cmd = self.command
|
195
|
+
#puts ' + ' + cmd
|
200
196
|
log.debug "Invoking the compiler"
|
201
197
|
rc = Platform.execute cmd
|
202
198
|
log.debug "Compilation complete; rc=#{rc.to_s}"
|
199
|
+
rc
|
200
|
+
end
|
201
|
+
|
202
|
+
# Run the link command
|
203
|
+
def link
|
204
|
+
throw 'Invalid linker' unless @ld.is_a?(Linker)
|
205
|
+
throw 'One or more source files are required' unless @sources.length > 0
|
206
|
+
cmd = @ld.command
|
207
|
+
log.debug "Invoking the linker: " + cmd
|
208
|
+
rc = Platform.execute cmd
|
209
|
+
log.debug "Linking complete; rc=#{rc.to_s}"
|
210
|
+
rc
|
203
211
|
end
|
204
212
|
|
205
213
|
# Compile a test program
|
206
214
|
def test_compile(code, stage = :compile)
|
215
|
+
log.debug "Testing compilation of:\n" + code
|
207
216
|
|
208
217
|
# Write the code to a temporary source file
|
209
218
|
f = Tempfile.new(['test_compile', @extension]);
|
210
219
|
f.print code
|
211
220
|
f.flush
|
212
|
-
###objfile = f.path + '.out'
|
213
221
|
|
214
222
|
# Run the compiler
|
215
223
|
cc = self.clone
|
216
224
|
cc.sources = f.path
|
217
|
-
|
218
|
-
cc.flags += '-o /dev/null' #FIXME: /dev/null not portable
|
225
|
+
cc.output = f.path.sub(/\.c$/, '.o')
|
219
226
|
cc.quiet = true
|
220
227
|
rc = cc.compile
|
221
228
|
|
222
|
-
#
|
223
|
-
|
224
|
-
|
229
|
+
# (Optional) Run the linker
|
230
|
+
if (rc == true and stage == :combined)
|
231
|
+
cc.ld.quiet = true
|
232
|
+
rc = cc.link
|
233
|
+
File.unlink(cc.ld.output) if File.exist? cc.ld.output
|
234
|
+
end
|
235
|
+
|
236
|
+
# Delete the output file(s)
|
237
|
+
File.unlink(cc.output) if File.exist? cc.output
|
225
238
|
|
226
239
|
return rc
|
227
240
|
end
|
data/lib/makeconf/linker.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: makeconf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: An alternative to GNU autoconf/automake/libtool/etc
|
15
15
|
email: mark@heily.com
|
@@ -37,7 +37,7 @@ files:
|
|
37
37
|
- lib/makeconf/externalproject.rb
|
38
38
|
- lib/makeconf/systemtype.rb
|
39
39
|
- lib/makeconf/androidproject.rb
|
40
|
-
homepage: http://
|
40
|
+
homepage: http://sourceforge.net/p/makeconf
|
41
41
|
licenses: []
|
42
42
|
post_install_message:
|
43
43
|
rdoc_options: []
|