File: jjrun

package info (click to toggle)
javacc 7.0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,712 kB
  • sloc: java: 27,671; xml: 2,305; cpp: 404; sh: 128; makefile: 24
file content (179 lines) | stat: -rw-r--r-- 4,466 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/sh
####################################################################
#
#   Copyright (C) 2006   Andrew Tomazos <andrew@tomazos.com>
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the GNU General Public License
#	as published by the Free Software Foundation; either version 2
#	of the License, or (at your option) any later version.
#
####################################################################
#
#	jjrun 1.0d1
#
#	- Build and execute a JavaCC .jj file in one command
#
#	- Requires javacc, java, make and sh
#
#	- TODO: If you use something other than SimpleCharStream you
#	  will need to modify the OBJECTS variable below
#
#	- TODO: Only tested on GNU/Linux
#
####################################################################

# $PROGFILE: This programs file path
PROGFILE=$0

# $VERSION: This programs version
VERSION=1.0d1

# $PROGNAME: This programs name
PROGNAME=`basename $0`

# If project not specified output usage and exit
if [ ! $1 ]
then
	echo "USAGE: $PROGNAME <jjfile>"
	exit 1
fi

# $PROJECT: The jj file to run
PROJECT=`basename $1 .jj`

# $MAKEFILE: An automatically generated makefile
MAKEFILE=$PROJECT.mk

# $FORCE: forces the regeneration of the makefile
FORCE=$2


# If the specified project does not exist than exit
if [ ! -f $PROJECT.jj ]
then
	echo ERROR: $PROGNAME: File not found $PROJECT.jj
	exit 1
fi

# If forcing makefile regeneration than delete the makefile
if [ $FORCE ]
then
	rm $MAKEFILE
fi

# If the makefile does not exist than generate it
if [ ! -f $MAKEFILE ]
then
	echo $PROGNAME: Generating $MAKEFILE...

#### START jjrun_makefile_header_here_doc
cat > $MAKEFILE <<jjrun_makefile_header_here_doc
# Automatically generated makefile for $PROJECT by $PROGNAME $VERSION

#   Copyright (C) 2006   Andrew Tomazos <andrew@tomazos.com>
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the GNU General Public License
#	as published by the Free Software Foundation; either version 2
#	of the License, or (at your option) any later version.

# ${PROJECT}: Name of the project
PROJECT=$PROJECT

# ${MAKEFILE}: Filename of this makefile
MAKEFILE=$MAKEFILE

# ${PROGFILE}: Filepath of $PROGNAME
PROGFILE=$PROGFILE

jjrun_makefile_header_here_doc
#### END jjrun_makefile_header_here_doc

#### START jjrun_makefile_main_here_doc
cat >> $MAKEFILE <<'jjrun_makefile_main_here_doc'

# ${JJ}: The original .jj file
JJ=${PROJECT}.jj

# ${AUTOGENS}: The automatically generated classed of javacc
AUTOGENS=					\
	${PROJECT}				\
	${PROJECT}Constants		\
	${PROJECT}TokenManager

# ${BOILERS}: The boilerplate classes generated by javacc
BOILERS=					\
	SimpleCharStream		\
	ParseException			\
	Token					\
	TokenMgrError

# ${OBJECTS}: The names of the classes output by javacc
OBJECTS=${AUTOGENS} ${BOILERS} 

# ${BOILERSOURCES}: The boilerplater sources files output by javacc
BOILERSOURCES=$(addsuffix .java, ${BOILERS})

# ${SOURCES}: The source files output by javacc
SOURCES=$(addsuffix .java, ${OBJECTS})

# ${CLASSES}: The class files compiled with javac from the output of javacc
CLASSES=$(addsuffix .class, ${OBJECTS})

# ${MANIFEST}: filename of the manifest for the final jar file
MANIFEST=${PROJECT}.mf

# ${JAR}: filename of the final jar file
JAR=${PROJECT}.jar

# make build rule to make JAR
build: ${JAR}

# make ${JAR}: build the jar file 
${JAR}: ${SOURCES} ${MANIFEST}
	@echo ${MAKEFILE}: Building ${JAR}...
	javac ${SOURCES}
	jar cvfm ${JAR} ${MANIFEST} ${CLASSES}
	rm ${CLASSES}

# make clean: remove all generated jar files
clean:
	@echo ${MAKEFILE}: Cleaning ${PROJECT}...
	@-rm ${JAR} ${SOURCES} ${MANIFEST}

# make ${SOURCES}: compile the jj file into java sources
${SOURCES}: ${JJ}
	@echo ${MAKEFILE}: Compiling ${JJ}...
	@javacc ${JJ}
	touch -c ${BOILERSOURCES}

# make ${MANIFEST}: rule to make
${MANIFEST}:
	@echo ${MAKEFILE}: Creating manifest...
	@echo Manifest-Version: 1.0 > ${MANIFEST}
	@echo Main-Class: ${PROJECT} >> ${MANIFEST}

${MAKEFILE}: ${PROGFILE}
	@echo ${MAKEFILE}: Regenerating ${MAKEFILE}
	@${PROGFILE} ${PROJECT} FORCE

jjrun_makefile_main_here_doc
# END jjrun_makefile_main_here_doc

fi

# If this was a forced regeneration than stop here
if [ $FORCE ]
then
	exit 0
fi

# Execute the makefile to rebuild the jar file if necessary
echo $PROGNAME: Executing $MAKEFILE...
make -f $MAKEFILE

# Execute the jar file
echo $PROGNAME: Executing $PROJECT.jar...
java -jar $PROJECT.jar