Using m4 macros with Eclipse & Java

删除回忆录丶 提交于 2019-12-18 09:07:13

问题


Is there a way to use m4 macros when developing in Java for Eclipse, ie. making sure the preprocessor is automatically invoked before Eclipse compiles?

Or has anyone used another preprocessor successfully with Eclipse?


回答1:


You can specify an arbitrary builder on an Eclipse project, and order the builder so that it is executed before the Java builder is run.

To define the new builder, open the project properties (right click->Properties or alt-enter), select Builders then New.... Select Program, then in the dialog configure the builder (hopefully you know what needs to be done here) and select OK. Back in the Builders page you can then select your new builder and select Up until it is before the Java Builder




回答2:


I think I have a way.

I just now got it working with the c preprocessor in eclipse on windows. I'm sure it could be adapted to M4, but I DO use gnu CPP's ability to create make files expressing the dependencies of a file. Doing that for m4 would be up to you. It has a few problems. If there's an error during preprocessing eclipse ignores it and keeps going. Also if you built with "run" the preprocessor's console output disappears as soon as the program starts.

Since I don't understand ant, and I don't have time to learn, my version is based on using Ruby for glue. I wrote a little automake in Ruby that takes a list of files that have been touched before the last make, filters out the ones that are preprocessed files, and those that are preprocessor includes, scans untouched preprocessor files to see if they depend on anything that has been changed, then processes them all.

These all depend on using Eclipse's "builders" which only seem to work in Juno. In my case the setting for the project are: create a builder for the project settings that runs before the java builder set the location to: C:\Ruby192\bin\ruby.exe set the working directory to C:\Ruby192\bin\ set the arguments to: C:\preprocessors\mymake.rb ${build_project} ${build_files:acf} this passes the directory of the project followed by the file that have been touched set "refresh" to "project containing the selected resource" and "recursively include subfolder" set build options to: Allocate console Run the builder: after clean,during manual builds, and during autobuilds

Note that according to my simple make ".jpp" files will be processed into ".java" files and ".jpp" files can #include ".jph" files (and only .jph files) ".jph" files can also #include ".jph" files and only ".jph" files

All of these files have to be under the /src/ directory (recursively in directories under /src/ which is how eclipse organizes java code and packages).

Here's the Ruby code:

require 'set'
$path = (ARGV[0].gsub('\\','/')+'/src')
$process=(ARGV[1..-1]||[]).map{ |a| a.gsub('\\','/') }
def pending(ending)
    ($process.select do |a| 
        a[0..$path.length-1]==$path && a[-4..-1].downcase == ending
    end).to_set
end
def read_make_dependencies(filename)
    ((File.open(filename).read.
        split("\n")[1..-1].
        map do |a|
            if a[-2..-1]==' \\'
                a=a[0..-3]
            end
            a.lstrip.gsub('\\/','/').gsub('\\','/').rstrip
        end)||[]).to_set
end
$pendingJph=pending('.jph')
$pendingJpp=pending('.jpp')

Dir.chdir($path)

$untouchedJph=Dir['**/*.jph'].map{|a| $path+'/'+a}.to_set - $pendingJph
$untouchedJpp=Dir['**/*.jpp'].map{|a| $path+'/'+a}.to_set - $pendingJpp

Dir.chdir('C:/MinGW/bin')

$pendingJph.each do|a|
    o = a[0..-4]+'depend'
    system "cpp -MM \"#{a}\" -o \"#{o}\""
    $pendingJph = $pendingJph + read_make_dependencies(o)
end

$untouchedJpp.each do|a|
    o = a[0..-4]+'depend'
    system "cpp -MM \"#{a}\" -o \"#{o}\""
    if not (read_make_dependencies(o) & $pendingJph).empty?
        puts "touching #{a}"
        $pendingJpp << a
    end
end

$pendingJpp.each do|a|
    o = a[0..-4]+'java'
    puts "processing #{a}"
    system "cpp -w -P -C -x c \"#{a}\" -o \"#{o}\""
end


来源:https://stackoverflow.com/questions/1533340/using-m4-macros-with-eclipse-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!