This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: input line is too long


Hi Tom!!! 

Op di 31-12-2002, om 00:08 schreef Tom Tromey:
> I think I compared jikes and gcj -C a year or so ago.
> As I recall they were comparable in performance.
> This was nothing scientific, just compiling some random library with
> both compilers and `time'.
> Tom
Best wishes to you and everyone the list, I finally go my system up and
running (not totally from scratch, but hey it got pretty near to it,
waiting like 2 days to get everything compiled the way I want it to) :D

As the subject is still "input line is too long" I thought I'd better
answer it. I couldn't make much make sense out of the GNU make manual (I
get the point reading it, but how to get it into practice?? Getting the
-MM -MF output into a make file is really freaking me out.) I just run
it with 

$ go <srcdir> <version>

I rewrote my bash script to be more general so you can unleash it on any
source tree, it uses some regex and some simple comparison to prevent
regenerating every single class file<erik?>, but it's kind of slow
because it uses find to look for files, should work on any *nix platform
with bash2 and find though. It just serves my basic purpose, it's not
really adequate for heavy duty use I guess. 

The strange thing is that:
1) when generating object or class files from java sources, less errors
occur
2) doesn't GCJ just need the classfiles to find the function prototypes
when generating native code? or am I missing the point? why doesn't it
suffice to just include the CNI headers?

Best wishes.
#!/bin/bash
#
# Simple script to automate porting java sources with GCJ
#
# Usage:
# 	$ go <srcdir> <soname>
#
# Info:
#		- Not meant for parallel builds
#		- The <srcdir> will be tested if it is a directory
#		- If so, the script will scan <srcdir> for .java files
#   - All directories containing at least one .java file will be put into $TREE
#		- The directories in $TREE will be recreated in obj/ cls/ cni/ jni/
#		- First, classes will be compiled from sources into cls/
#		- Second, headers are generated from the classes and put into cni/ jni/
# 	- After that the objects will be generated from the _java_ sources
#		- Libraries, both static and shared are created and put into lib/
#		- If <soname> is specified, this will be used to generate the libraries
#			and symbolic links to the soname, all libraries created will have the
#			same soname
#
#	Bugs:
#		- Any package cannot be named the same as the basedirectory of the source
#			tree
#		- Does not check for validity of input for versionnumbers
#
# date: 30-12-2002
# (c) :D dhek bhun kho
# needs: find, wc, bash 2.0


# 
# Global settings and variables
#
declare TREE
declare SRC_DIR=${1%/} JAR_DIR="jar"
declare OBJ_DIR="obj" CLS_DIR="cls" TMP_DIR="tmp" BBG_DIR="bbg"
declare CNI_DIR="cni" JNI_DIR="jni" LIB_DIR="lib" DEP_DIR="dep"
declare TARGETS="$OBJ_DIR $CLS_DIR $CNI_DIR $DEP_DIR $BBG_DIR $JNI_DIR"
declare ALL_TARGETS="$TARGETS $JNI_DIR $LIB_DIR $TMP_DIR $JAR_DIR"
declare LOCAL_CLASSPATH=$CLASSPATH

#
# GCJ settings
#
declare GCJ="gcj "
declare GCJ_OBJ_FLAGS="-g0 -fPIC -ffloat-store -falign-jumps=32 -falign-loops=32 -falign-functions=32 -Os -pipe -c -Wno-deprecated"
declare GCJ_OBJ_FLAGS_DEBUG="${GCJ_OBJ_FLAGS//g0/g1} -ggdb -pg"
declare GCJ_OBJ_FLAGS_DEBUG=${GCJ_OBJ_FLAGS_DEBUG//Os/O0}
declare GCJ_OBJ_FLAGS=${GCJ_OBJ_FLAGS_DEBUG}
declare GCJ_CLS_FLAGS="-pipe -g1 -C"

#
# CNI Header compilation
#
declare GCJH=gcjh
declare GCJH_FLAGS="-td $TMP_DIR"
declare GCJH_CNI_FLAGS="$GCJH_FLAGS"
declare GCJH_JNI_FLAGS="$GCJH_FLAGS-jni"

#
# GCJ Libraries
#
declare GCJ_LIB_FLAGS="-ggdb -g1 -shared"

#
# JAR commands
#
declare JAR="gcj-jar"
declare JAR_OPTS="cf"

#
# Main execution
#
main() {
	echo "Checking command line arguments..."
	checkArgs $@
	echo "Creating directory structure..." 
	createTree $SRC_DIR
	echo "Compiling java->class" 
	compileClass $SRC_DIR
	echo "Creating headers"
	createHeaders
	echo "Compiling java->native"
	compileObject $SRC_DIR
	echo "Jarring classfiles"
	jarClasses
	echo "Create libraries"
	createLibraries $2
}

#
# Now everything has been compiled create the libraries
#
createLibraries() {
	local DIRS FILE_CNT VERSION=$1
  DIRS=`find $OBJ_DIR -type d`
  for DIR in $DIRS
  do
    FILES=`find $DIR -maxdepth 1 -name "*.o"`;
    FILE_CNT=`find $DIR -maxdepth 1 -name "*.o" | wc -l`; FILE_CNT=${FILE_CNT// /};
    if [ $FILE_CNT != "0" ]
    then
      LIBNAME=${DIR//$OBJ_DIR\//}; LIBNAME=${LIBNAME%/}; LIBNAME=${LIBNAME//\//-}
      ar -rcs $LIB_DIR/$LIBNAME.a $FILES
      $GCJ $GCJ_LIB_FLAGS $FILES -o $LIB_DIR/$LIBNAME.so.$VERSION -Wl,-soname,$LIBNAME.so
			ln -s $LIB_DIR/$LIBNAME.so.$VERSION $LIBNAME.so
    fi
  done
}


#
# JAR: Classes -> Jar
#
jarClasses() {
	local DIRS=`find $CLS_DIR -type d` DIR CLS_CNT JAR_FILE
	for DIR in $DIRS
	do
		FILES=`find $DIR -maxdepth 1 -name "*.class"`
		PROPS=`find ${DIR//$CLS_DIR/$SRC_DIR} -maxdepth 1 -name "*.properties"`
		PROPS_CNT=`find ${DIR//$CLS_DIR/$SRC_DIR} -maxdepth 1 -name "*.properties" | wc -l`
		CLS_CNT=`find $DIR -maxdepth 1 -type f | wc -l`
		PROPS_CNT=${PROPS_CNT// /} ; CLS_CNT=${CLS_CNT// /}
		if [ $CLS_CNT != "0" ] || [ $PROPS_CNT != "0" ]
		then
			JAR_FILE=${DIR//$CLS_DIR\//}; JAR_FILE=$JAR_DIR/${JAR_FILE//\//.}.jar
			HERE=$PWD; cd $CLS_DIR
			if [ PROPS_CNT != "0" ]
			then
				if [ CLS_CNT != "0" ] 
				then
					FILES="${FILES} ${PROPS}"
				else
					FILES="${PROPS}"
				fi
			fi
			$JAR $JAR_OPTS $JAR_FILE ${FILES//$CLS_DIR\//}
			cd $HERE
		fi
	done
}


#
# GCJ: Java -> Object
#
compileObject() {
	local FILES=`find $SRC_DIR -name *.java` DEP_FILE OBJ_FILE 
	local DIR HEADER_CNT TMP HEADERS RESOURCE

	### find header directories
	HEADERS=`find $CNI_DIR -type d` ; TMP=$HEADERS; HEADERS=""

	### find all headers
	for DIR in $TMP
	do
		HEADER_CNT=`find $DIR -maxdepth 1 -type f | wc -l`
		if [ ${HEADER_CNT// /} != "0" ] 
		then
			HEADERS="$HEADERS -I$DIR"
		fi
	done
		
	### compile java sources to objects
	for FILE in $FILES
	do
		OBJ_FILE=${FILE/$SRC_DIR/$OBJ_DIR}; OBJ_FILE=${OBJ_FILE/.java/.o}
		DEP_FILE=${FILE//$SRC_DIR/$DEP_DIR}; DEP_FILE=${DEP_FILE/.java/.P}
		if [ ! -f $OBJ_FILE ] || [ $FILE -nt $OBJ_FILE ]
		then
			$GCJ $GCJ_OBJ_FLAGS $HEADERS -o $OBJ_FILE $FILE -MM -MF $DEP_FILE -B$SRC_DIR -classpath $LOCAL_CLASSPATH
		fi
	done
	
	### compile all resources
	FILES=`find $SRC_DIR -name "*.properties"`
	for FILE in $FILES
	do
		RESOURCE=${FILE#$SRC_DIR\/}; RESOURCE=${RESOURCE%_*.properties};
		RESOURCE=${RESOURCE%.properties}; RESOURCE=${RESOURCE//\//.}
		$GCJ --resource $RESOURCE $FILE -o ${FILE/.properties/_prop.o} -c
	done
}

#
# GCJ: Java -> Class 
#
compileClass() {
	local FILES=`find $1 -name *.java`
	FILES=${FILES// /\n}
	for FILE in $FILES
	do
		CLASS_FILE=${FILE//$SRC_DIR/$CLS_DIR}; 
		CLASS_FILE=${CLASS_FILE/.java/.class};
		if [ ! -f $CLASS_FILE ] || [ $FILE -nt $CLASS_FILE ]
		then
			$GCJ $GCJ_CLS_FLAGS -d $CLS_DIR $FILE -B$SRC_DIR -classpath $LOCAL_CLASSPATH 
		fi
	done
	LOCAL_CLASSPATH=$LOCAL_CLASSPATH:$CLS_DIR
}

# 
# GCJ: Class -> JNI
#
createHeaders() {
	local FILES=`find $CLS_DIR -name *.class` HEADER
	FILES=${FILES// /\n}; FILES=${FILES//$CLS_DIR\//}
	FILES=${FILES//\//.}; FILES=${FILES//.class/}
	for FILE in $FILES 
	do
		HEADER=${FILE//./\/}; HEADER=${CNI_DIR}/${HEADER}.h
		if [ ! -a $HEADER ] || [ $FILE -nt $HEADER ]
		then
			$GCJH $GCJH_CNI_FLAGS $FILE -classpath $LOCAL_CLASSPATH -d $CNI_DIR
			$GCJH $GCJH_JNI_FLAGS $FILE -classpath $LOCAL_CLASSPATH -d $JNI_DIR
		fi
	done
}
	
#
# Preparations
#
createTree() {
	local HERE=$PWD TREE COUNT
	cd $1 ; SRC_DIR=$PWD; cd $HERE
	local BASE=$SRC_DIR/..
	TREE=`find $SRC_DIR -type d`; TREE=${TREE//$SRC_DIR/} ;
	TEMP=$TREE
	### Scan the source tree for non empty directories
	echo "Scanning source tree..."
	for ITEM in $TEMP
	do
		COUNT=`find $SRC_DIR/${ITEM#/} -maxdepth 1 -type f | wc -l`
		if [ ${COUNT// /} == "0" ] 
		then
			TREE=${TREE/$ITEM/}
		fi
	done
	
  ### recreate tree in $TARGETS
	echo "Recreating tree..."
	for ITEM in $TARGETS
	do
		for TMP in $TREE
		do
			mkdir -p $BASE/$ITEM/$TMP > /dev/null
		done
	done
	for ITEM in $ALL_TARGETS
	do
		mkdir -p $BASE/$ITEM
	done
	
  ### rewrite the directory structure
	JNI_DIR=$BASE/$JNI_DIR ;	TMP_DIR=$BASE/$TMP_DIR
	OBJ_DIR=$BASE/$OBJ_DIR ;	LIB_DIR=$BASE/$LIB_DIR
	CNI_DIR=$BASE/$CNI_DIR ; 	CLS_DIR=$BASE/$CLS_DIR
	DEP_DIR=$BASE/$DEP_DIR ;  BBG_DIR=$BASE/$BBG_DIR
	JAR_DIR=$BASE/$JAR_DIR ;
  
  LOCAL_CLASSPATH=$LOCAL_CLASSPATH:$SRC_DIR
}

#
# Simple scripts just takes one argument, check if this is a directory
#
checkArgs() {
	if [ ! $# -eq 2 ]  || [ ! -d $1 ]
	then 
		echo "Usage:"
		echo "$0 <srcdir> <version>"
		exit 1
	fi 
}

main $@

# vim: ts=2 sw=2 noai

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]