Question

I'm working on a build system that has bad practices piled on other bad practices for a long time and I'm in the process of re-writing the build. The languages involved are C/C++, Fortran, Ada, and Java and for the time being I'm sticking with GNU style makefiles -- though we're considering other alternatives such as SCons.

With that said, I'm looking for some specific recommendations -- not recommendations of the form "use a different build system", etc.

Whoever wrote the particular makefile I'm looking at right now had planned on a sequential build of java code that looks something like this:

LIST_OF_JAVA_FILES  = file1.java
LIST_OF_JAVA_FILES += file2.java
LIST_OF_JAVA_FILES += file3.java
...
LIST_OF_JAVA_FILES += fileN.java

all: ${LIST_OF_JAVA_FILES}

${LIST_OF_JAVA_FILES} : %.class : %.java
  ${JAVAC} ${CLASSPATH} ${<}

Provided you perform a build in serial, this works fine. However, as soon as dependencies come into the mix it becomes more problematic.

  1. C/C++ compilers have options built-in for dependency generation ... does a similar facility exist for Java?
  2. Is it necessary to use third party tools (like Jikes) to generate dependencies?
  3. Typically speaking, if a team were using makefiles for building anything java related, is it more typical to call the java compiler one time listing out all .java files in one command-line -vs- one target for each .class file?
    • If this is more common, is this strictly for simplicity sake or is there a deeper reason?
    • note: I understand that for a sequential build this would be the faster option, but I want an answer to do empirical tests for parallel builds
Was it helpful?

Solution 3

It ended up being most expedient (and the norm for java development as a whole) to just specify all source files in a single build step and allow javac to resolve all the dependencies that way.

OTHER TIPS

We had similar issue in our project. We decided to build all java code via ant and invoke ant from a makefile.

Unless you have a lot of JNI (c++ <----> java) dependencies this might work for you too.

Good luck.

Doing something like

javac -cp MY_CLASSPATH Main.java

suffices most of the time, as it resolves dependences automatically. Sometimes you may need to use more files on the command line, since some of them may get used without an explicit reference.

There are also ant and maven and ivy and whatever, but it's an overkill for something that simple.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top