Charles Maria
Charles Maria

Reputation: 2195

Creating frege.jar and including intermediate .java files (for use with J2ObjC)

Is there a way to compile the Frege runtime and libraries to just their .java intermediates? I'm trying to use Frege as part of an iOS app via J2ObjC, which can't parse .class files.

Upvotes: 1

Views: 172

Answers (2)

Charles Maria
Charles Maria

Reputation: 2195

Ingo's answer works just fine for creating Java intermediary files. Just wanted to add my own answer in order to clarify that Frege has a lot of dependencies that are incompatible with J2ObjC and as such, cannot work with J2ObjC.

Upvotes: 0

Ingo
Ingo

Reputation: 36349

According to some tests, the following will work:

# get the project
git clone https://github.com/Frege/frege.git
cd frege
# make a current frege compiler available and build a new one
cp ~/Downloads/frege3.23.370*.jar fregec.jar
make runtime fregec.jar
# optionally, remove the class files
find build/ -type f -name '*.class' -exec rm {} ';'

At this point, you have a runnable compiler in fregec.jar and the java sources corresponding to the classes in that jar under build/frege/ It is important that you use this compiler only with your self-made java sources. For, suppose, foo has been replaced with bar in some module, and your frege source code references foo. Then you can compile it with an older fregec.jar, but you cannot compile the generated java file (which still has the foo in it) together with your java sources where there is no foo, only bar.

Apart from that, you can now use those ressources as often as you want to create a standalone frege library/application.

In the following I show how to make a standalone console application, please adapt for your needs. Assumptions are:

  • the project is in a sibling directory standalone
  • main function is in module my.fine.App

Here we go:

# go to project directory and make a directory for the generated code
cd ../standalone
mkdir -p generated
# compile the Frege code into generated/
java -jar ../fregec.jar -d generated -O -make my/fine/App.fr
# at this point, we could already run it, but had to supply fregec.jar
# in the classpath.
java -cp generated/:../fregec.jar my.fine.App
# remove class files
find generated/ -type f -name '*.class' -exec rm {} ';'
# now generate minimal standalone code, the idea being that javac
# gets the source files it needs automatically
javac -d bin -sourcepath generated:../frege:../frege/build generated/my/fine/App.java
java -cp bin my.fine.App
# jar it up
jar -cvf App.jar -C bin .
jar -uvfe App.jar my.fine.App
java -jar App.jar

Upvotes: 1

Related Questions