Skip to content

Commit

Permalink
Change SDR libraries to be installed under gps_pvt/sdr
Browse files Browse the repository at this point in the history
  • Loading branch information
fenrir-naru committed Jan 11, 2025
1 parent cf5c948 commit b9cf048
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 302 deletions.
47 changes: 27 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,36 @@ end

desc "Generate SWIG wrapper codes"
task :swig do
out_base_dir = File::join(File::dirname(__FILE__), 'ext', 'gps_pvt')
[
mods = Hash[*([ # {mod_name => [src.i, mod_path=[...]], ...}
File::join(File::dirname(__FILE__), 'ext', 'ninja-scan-light', 'tool', 'swig'),
File::join(File::dirname(__FILE__), 'ext', 'sdr', 'swig'),
].each{|swig_dir|
Dir::chdir(swig_dir){
Dir::glob("*.i"){|src|
mod_name = File::basename(src, '.*')
out_dir = File::join(out_base_dir, mod_name)
sh "mkdir -p #{out_dir}"
wrapper = File::join(out_dir, "#{mod_name}_wrap.cxx")
sh [:make, :clean, wrapper,
"BUILD_DIR=#{out_dir}",
"SWIGFLAGS='-c++ -ruby -prefix \"GPS_PVT::\"#{" -D__MINGW__" if ENV["MSYSTEM"]}'"].join(' ')
open(wrapper, 'r+'){|io|
lines = io.read.lines.collect{|line|
line.sub(/rb_require\(\"([^\"]+)\"\)/){ # from camel to underscore downcase style
"rb_require(\"#{$1.sub('GPS_PVT', 'gps_pvt')}\")"
}
[File::join(File::dirname(__FILE__), 'ext', 'sdr', 'swig'), 'SDR'],
].collect{|swig_dir, extra_mod_path|
Dir::glob(File::join(swig_dir, "*.i")).collect{|src|
[
File::basename(src, '.*'),
[src, ['GPS_PVT', extra_mod_path].flatten.compact],
]
}
}.flatten(2))]
out_base_dir = File::join(File::dirname(__FILE__), 'ext')
mods.each{|mod_name, (src, mod_path)|
Dir::chdir(File::dirname(src)){
out_dir = File::join(out_base_dir, mod_path.collect{|v| v.downcase}, mod_name)
mod_prefix = mod_path.collect{|v| "#{v}::"}.join
sh "mkdir -p #{out_dir}"
wrapper = File::join(out_dir, "#{mod_name}_wrap.cxx")
sh [:make, :clean, wrapper,
"BUILD_DIR=#{out_dir}",
"SWIGFLAGS='-c++ -ruby -prefix \"#{mod_prefix}\"#{" -D__MINGW__" if ENV["MSYSTEM"]}'"].join(' ')
open(wrapper, 'r+'){|io|
lines = io.read.lines.collect{|line|
line.sub(/rb_require\(\"((?:[^\/"]+\/)*)([^"]+)\"\)/){ # from camel to underscore downcase style
src, path = mods[$2]
"rb_require(\"#{path ? File::join(path.collect{|v| v.downcase}, $2) : "#{$1}#{$2}"}\")"
}
io.rewind
io.write(lines.join)
}
io.rewind
io.write(lines.join)
}
}
}
Expand Down
36 changes: 23 additions & 13 deletions ext/gps_pvt/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require "mkmf"

extconf_dir = File::dirname(__FILE__)

{
'ninja_tool' => [File::dirname(__FILE__), '..', 'ninja-scan-light', 'tool'],
'sdr' => [File::dirname(__FILE__), '..', 'sdr'],
'ninja_tool' => [extconf_dir, '..', 'ninja-scan-light', 'tool'],
'sdr' => [extconf_dir, '..', 'sdr'],
}.each{|target, path|
path = File::join(path) if path.kind_of?(Array)
path = File::absolute_path(path)
Expand All @@ -24,30 +27,34 @@ def IO_TARGETS.mod(&b)
alias_method(:open_orig, :open)
}

Dir::glob(File::join(File::dirname(__FILE__), "*/")).each{|dir|
mod_name = File::basename(dir)

dst = File::join(Dir.getwd, mod_name)
FileUtils::mkdir_p(dst) if dir != dst

$stderr.puts "For #{mod_name} ..."
require 'pathname'

Pathname::glob(File::join(extconf_dir, "**/")){|dir|
mod_path = dir.relative_path_from(Pathname(extconf_dir))
mod_name = mod_path.basename

# @see https://stackoverflow.com/a/35842162/15992898
$srcs = Dir::glob(File::join(dir, '*.cxx')).collect{|path|
File::join(mod_name, File::basename(path))
$srcs = Pathname::glob(dir.join('*.cxx')).collect{|cxx_path|
mod_path.join(cxx_path.basename).to_s
}
next if $srcs.empty?
$objs = $srcs.collect{|path|
path.sub(/\.[^\.]+$/, '.o')
}

$stderr.puts "For #{mod_path} ..."

dst = Pathname::getwd.join(mod_path)
FileUtils::mkdir_p(dst) if dir != dst

IO_TARGETS.mod{
# rename Makefile to Makefile.#{mod_name}
define_method(:open){|*args, &b|
args[0] += ".#{mod_name}" if (args[0] && (args[0] == "Makefile"))
args[0] += ".#{mod_path.to_s.gsub('/', '.')}" if (args[0] && (args[0] == "Makefile"))
open_orig(*args, &b)
}
}
create_makefile("gps_pvt/#{mod_name}")
create_makefile(mod_path.to_s)
}

IO_TARGETS.mod{
Expand All @@ -61,6 +68,9 @@ def IO_TARGETS.mod(&b)
io.write(<<-__TOPLEVEL_MAKEFILE__)
TOPTARGETS := all clean distclean realclean install site-install
MAKEOVERRIDES := $(filter-out target_prefix=%,$(MAKEOVERRIDES))
unexport target_prefix
SUBMFS := $(wildcard Makefile.*)
$(TOPTARGETS): $(SUBMFS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ static swig_module_info swig_module = {swig_types, 20, 0, 0, 0, 0};
/* -------- TYPES TABLE (END) -------- */

#define SWIG_init Init_Replica
#define SWIG_name "GPS_PVT::Replica"
#define SWIG_name "GPS_PVT::SDR::Replica"

static VALUE mReplica;

Expand Down Expand Up @@ -2703,7 +2703,7 @@ struct GPS_CA_Code : public TimeBasedSignalGenerator<int, tick_t> {
static swig_class SwigClassGC_VALUE;

/*
Document-method: GPS_PVT::Replica::GC_VALUE.inspect
Document-method: GPS_PVT::SDR::Replica::GC_VALUE.inspect
call-seq:
inspect -> VALUE
Expand All @@ -2730,7 +2730,7 @@ _wrap_GC_VALUE_inspect(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::GC_VALUE.to_s
Document-method: GPS_PVT::SDR::Replica::GC_VALUE.to_s
call-seq:
to_s -> VALUE
Expand All @@ -2757,9 +2757,9 @@ _wrap_GC_VALUE_to_s(int argc, VALUE *argv, VALUE self) {


/*
Document-class: GPS_PVT::Replica::Carrier
Document-class: GPS_PVT::SDR::Replica::Carrier
Proxy of C++ GPS_PVT::Replica::Carrier class
Proxy of C++ GPS_PVT::SDR::Replica::Carrier class
*/
Expand All @@ -2781,7 +2781,7 @@ _wrap_Carrier_allocate(int argc, VALUE *argv, VALUE self)


/*
Document-method: GPS_PVT::Replica::Carrier.new
Document-method: GPS_PVT::SDR::Replica::Carrier.new
call-seq:
Carrier.new(tick_t const & init_freq)
Expand Down Expand Up @@ -2815,7 +2815,7 @@ _wrap_new_Carrier(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::Carrier.current
Document-method: GPS_PVT::SDR::Replica::Carrier.current
call-seq:
current -> ComplexD
Expand Down Expand Up @@ -2850,7 +2850,7 @@ _wrap_Carrier_current(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::Carrier.generate
Document-method: GPS_PVT::SDR::Replica::Carrier.generate
call-seq:
generate(tick_t const & t, tick_t const & dt, tick_t const & freq) -> Complex
Expand Down Expand Up @@ -3027,7 +3027,7 @@ SWIGINTERN VALUE _wrap_Carrier_generate(int nargs, VALUE *args, VALUE self) {


/*
Document-method: GPS_PVT::Replica::Carrier.phase_cycle
Document-method: GPS_PVT::SDR::Replica::Carrier.phase_cycle
call-seq:
phase_cycle -> tick_t
Expand All @@ -3036,7 +3036,7 @@ Get value of attribute.
*/
/*
Document-method: GPS_PVT::Replica::Carrier.phase_cycle=
Document-method: GPS_PVT::SDR::Replica::Carrier.phase_cycle=
call-seq:
phase_cycle=(x) -> tick_t
Expand Down Expand Up @@ -3098,7 +3098,7 @@ _wrap_Carrier_phase_cycle_get(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::Carrier.frequency
Document-method: GPS_PVT::SDR::Replica::Carrier.frequency
call-seq:
frequency -> tick_t
Expand All @@ -3107,7 +3107,7 @@ Get value of attribute.
*/
/*
Document-method: GPS_PVT::Replica::Carrier.frequency=
Document-method: GPS_PVT::SDR::Replica::Carrier.frequency=
call-seq:
frequency=(x) -> tick_t
Expand Down Expand Up @@ -3169,7 +3169,7 @@ _wrap_Carrier_frequency_get(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::Carrier.advance
Document-method: GPS_PVT::SDR::Replica::Carrier.advance
call-seq:
advance(tick_t const & shift_cycle)
Expand Down Expand Up @@ -3209,7 +3209,7 @@ _wrap_Carrier_advance(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::Carrier.advance_time
Document-method: GPS_PVT::SDR::Replica::Carrier.advance_time
call-seq:
advance_time(tick_t const & shift_time)
Expand Down Expand Up @@ -3255,16 +3255,16 @@ free_Carrier(void *self) {
}

/*
Document-class: GPS_PVT::Replica::GPS_CA_Code
Document-class: GPS_PVT::SDR::Replica::GPS_CA_Code
Proxy of C++ GPS_PVT::Replica::GPS_CA_Code class
Proxy of C++ GPS_PVT::SDR::Replica::GPS_CA_Code class
*/
static swig_class SwigClassGPS_CA_Code;

/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.new
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.new
call-seq:
GPS_CA_Code.new(int const & sid, tick_t const & offset_cycle=0)
Expand Down Expand Up @@ -3395,7 +3395,7 @@ SWIGINTERN VALUE _wrap_new_GPS_CA_Code(int nargs, VALUE *args, VALUE self) {


/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.current
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.current
call-seq:
current -> int
Expand Down Expand Up @@ -3428,7 +3428,7 @@ _wrap_GPS_CA_Code_current(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.generate
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.generate
call-seq:
generate(tick_t const & t, tick_t const & dt) -> Int
Expand Down Expand Up @@ -3481,7 +3481,7 @@ _wrap_GPS_CA_Code_generate(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.phase_cycle
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.phase_cycle
call-seq:
phase_cycle -> tick_t
Expand All @@ -3490,7 +3490,7 @@ Get value of attribute.
*/
/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.phase_cycle=
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.phase_cycle=
call-seq:
phase_cycle=(x) -> tick_t
Expand Down Expand Up @@ -3552,7 +3552,7 @@ _wrap_GPS_CA_Code_phase_cycle_get(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.frequency
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.frequency
call-seq:
frequency -> tick_t
Expand All @@ -3561,7 +3561,7 @@ Get value of attribute.
*/
/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.frequency=
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.frequency=
call-seq:
frequency=(x) -> tick_t
Expand Down Expand Up @@ -3623,7 +3623,7 @@ _wrap_GPS_CA_Code_frequency_get(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.advance
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.advance
call-seq:
advance(tick_t const & shift_cycle)
Expand Down Expand Up @@ -3663,7 +3663,7 @@ _wrap_GPS_CA_Code_advance(int argc, VALUE *argv, VALUE self) {


/*
Document-method: GPS_PVT::Replica::GPS_CA_Code.advance_time
Document-method: GPS_PVT::SDR::Replica::GPS_CA_Code.advance_time
call-seq:
advance_time(tick_t const & shift_time)
Expand Down Expand Up @@ -4044,6 +4044,7 @@ SWIGEXPORT void Init_Replica(void) {

SWIG_InitRuntime();
mReplica = rb_define_module("GPS_PVT");
mReplica = rb_define_module_under(mReplica, "SDR");
mReplica = rb_define_module_under(mReplica, "Replica");

SWIG_InitializeModule(0);
Expand All @@ -4064,7 +4065,7 @@ SWIGEXPORT void Init_Replica(void) {
swig::SwigGCReferences::initialize();

rb_require("gps_pvt/SylphideMath");
rb_require("gps_pvt/Signal");
rb_require("gps_pvt/sdr/Signal");

#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
Expand Down
Loading

0 comments on commit b9cf048

Please sign in to comment.