View Javadoc
1 /* 2 AntMake 3 4 Copyright (C) 2004 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsanleandro@yahoo.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: ConfigureInTemplate.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Template to generate configure.in files. 37 * 38 * Last modified by: $Author: chous $ at $Date: 2004/02/01 17:21:28 $ 39 * 40 * File version: $Revision: 1.5 $ 41 * 42 * Project version: $Name: $ 43 * 44 * $Id: ConfigureInTemplate.java,v 1.5 2004/02/01 17:21:28 chous Exp $ 45 * 46 */ 47 package org.acmsl.antmake; 48 49 /* 50 * Importing some JDK classes. 51 */ 52 import java.io.File; 53 import java.text.MessageFormat; 54 import java.util.ArrayList; 55 import java.util.Iterator; 56 import java.util.Collection; 57 58 /*** 59 * Template to generate <i>configure.in</i> files. 60 * @author <a href="mailto:jsanleandro@yahoo.es" 61 >Jose San Leandro</a> 62 * @version $Revision: 1.5 $ 63 */ 64 public abstract class ConfigureInTemplate 65 { 66 /*** 67 * The default header. 68 */ 69 public static final String DEFAULT_HEADER = 70 "#\n" 71 + "# AntMake\n" 72 + "#\n" 73 + "# Copyright (C) 2004 Jose San Leandro Armend?riz\n" 74 + "# jsanleandro@yahoo.es\n" 75 + "# chousz@yahoo.com\n" 76 + "#\n" 77 + "# This library is free software; you can redistribute it and/or\n" 78 + "# modify it under the terms of the GNU General Public\n" 79 + "# License as published by the Free Software Foundation; either\n" 80 + "# version 2 of the License, or (at your option) any later " 81 + "version.\n" 82 + "#\n" 83 + "# This library is distributed in the hope that it will be " 84 + "useful,\n" 85 + "# but WITHOUT ANY WARRANTY; without even the implied warranty " 86 + "of\n" 87 + "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " 88 + "GNU\n" 89 + "# General Public License for more details.\n" 90 + "#\n" 91 + "# You should have received a copy of the GNU General Public\n" 92 + "# License along with this library; if not, write to the Free " 93 + "Software\n" 94 + "# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA " 95 + "02111-1307 USA\n" 96 + "#\n" 97 + "# Thanks to ACM S.L. for distributing this library under the GPL " 98 + "license.\n" 99 + "# Contact info: jsanleandro@yahoo.es\n" 100 + "# Postal Address: c/Playa de Lagoa, 1\n" 101 + "# Urb. Valdecaba?as\n" 102 + "# Boadilla del monte\n" 103 + "# 28660 Madrid\n" 104 + "# Spain\n" 105 + " #################################################################" 106 + "#############\n" 107 + " #\n" 108 + " # Filename: $" + "RCSfile: $\n" 109 + " #\n" 110 + " # Author: AntMake\n" 111 + " #\n" 112 + " # Description: Defines the macros required to configure the make\n" 113 + " # process in order to successfully build the project\n" 114 + " # in any supported platform.\n" 115 + " #\n" 116 + " # Last modified by: $" + "Author: $ at $" + "Date: $\n" 117 + " #\n" 118 + " # File version: $" + "Revision: $\n" 119 + " #\n" 120 + " # Project version: $" + "Name: $\n" 121 + " #\n" 122 + " # $" + "Id: $\n" 123 + " #\n\n"; 124 125 /*** 126 * The default Make-Rules body. 127 */ 128 public static final String DEFAULT_BODY = 129 "dnl Process this with autoconf to create configure\n" 130 + "AC_INIT()\n\n" 131 + "AM_MAINTAINER_MODE\n" 132 + "AC_CANONICAL_SYSTEM\n" 133 + "\n" 134 + "AM_INIT_AUTOMAKE({0}, {1})\n" 135 // project name - project version 136 + "\n" 137 + "AC_PROG_INSTALL\n" 138 + "AC_PROG_LN_S\n" 139 + "\n" 140 + "AC_EXEEXT\n" 141 + "AC_OBJEXT\n" 142 + "\n" 143 + "AC_ARG_WITH(gcj,\n" 144 + " [ --with-gcj Compile {0} using GCJ (GNU Compiler for Java)])\n" 145 + "\n" 146 + "AC_PROG_CC\n" 147 + "AC_PROG_CXX\n" 148 + "dnl AC_PROG_INSTALL\n" 149 + "#AC_PROG_MAKE_SET\n" 150 + "\n" 151 + "# AM_PROG_GCJ is not good enough, we have to roll our own.\n" 152 + "# AC_CHECK_TOOL(GCJ, gcj)\n" 153 + "LT_AC_PROG_GCJ\n" 154 + "test -z \"$GCJ\" && AC_MSG_ERROR([no acceptable gcj found in //$PATH])\n" 155 + "if test \"x$'{'GCJFLAGS-unset'}'\" = xunset; then\n" 156 + " GCJFLAGS=\"-g -O2\"\n" 157 + "fi\n" 158 + "\n" 159 + "# dnl AC_SUBST(GCJFLAGS)\n" 160 + "\n" 161 + "dnl We must have the absolute path to the build directory.\n" 162 + "\n" 163 + "TOP_BUILDDIR=`pwd`\n" 164 + "\n" 165 + "AC_PROG_LIBTOOL\n" 166 + "\n" 167 + "case $'{'with_gcj'}' in\n" 168 + " yes)\n" 169 + " GCJ_COMPILED_SELECTED=ENABLE_GCJ_COMPILED\n" 170 + " GCJ_SELECTED=WITH_GCJ\n" 171 + " JAVA=$'{'JAVA-gij'}'\n" 172 + " JAVAC=$'{'JAVAC-\"gcj -C\"'}'\n" 173 + "\n" 174 + " # AM_PROG_GCJ is not good enough, we have to roll our own.\n" 175 + " # AC_CHECK_TOOL(GCJ, gcj)\n" 176 + " LT_AC_PROG_GCJ\n" 177 + " test -z \"$GCJ\" && AC_MSG_ERROR([no acceptable gcj found in //$PATH])\n" 178 + " if test \"x$'{'GCJFLAGS-unset'}'\" = xunset; then\n" 179 + " GCJFLAGS=\"-g -O2\"\n" 180 + " fi\n" 181 + " AC_SUBST(GCJFLAGS)\n" 182 + " AC_LIBTOOL_GCJ\n" 183 + "\n" 184 + " _AM_DEPENDENCIES(GCJ)\n" 185 + " AC_SUBST(LIBTOOL_DEPS)\n" 186 + " ;;\n" 187 + " *)\n" 188 + " GCJ_COMPILED_SELECTED=DISABLE_GCJ_COMPILED\n" 189 + " GCJ_SELECTED=WITHOUT_GCJ\n" 190 + " JAVA=$'{'JAVA-java'}'\n" 191 // Work-around due to problems escaping "JAVA-java". 192 + " JAVAC=$'{'JAVAC-javac'}'\n" 193 // Work-around due to problems escaping "JAVAC-javac". 194 + " ;;\n" 195 + "esac\n" 196 + "\n" 197 + "AM_CONDITIONAL(WITH_GCJ, test \"$with_gcj\" = \"yes\")\n" 198 + "\n" 199 + "pathsep='':''\n" 200 + "filesep=''/''\n" 201 + "AC_SUBST(pathsep)\n" 202 + "AC_SUBST(filesep)\n" 203 + "\n" 204 + "AC_SUBST(JAVA)\n" 205 + "AC_SUBST(JAVAC)\n" 206 + "#These do not do anything, because Make-rules cannot contain autoconf\n" 207 + "#substitutions. Perhaps fix when new automake is out.\n" 208 + "AC_SUBST(GCJ_COMPILED_SELECTED)\n" 209 + "AC_SUBST(GCJ_SELECTED)\n" 210 + "AC_SUBST(extra_java)\n" 211 + "AC_SUBST(TOP_BUILDDIR)\n" 212 + "AC_SUBST(CC)\n" 213 + "AC_SUBST(CFLAGS)\n" 214 + "AC_SUBST(PACKAGE)\n" 215 + "AC_SUBST(VERSION)\n" 216 + "AC_SUBST(SHELL)\n" 217 + "Make_rules=\"$srcdir/Make-rules\"\n" 218 + "AC_SUBST_FILE(Make_rules)\n" 219 + "\n" 220 + "AC_OUTPUT(Makefile{2})\n"; 221 222 /*** 223 * The default makefile subtemplate. 224 */ 225 public static final String DEFAULT_MAKEFILE_SUBTEMPLATE = 226 " {0}/Makefile"; 227 228 /*** 229 * The header. 230 */ 231 private String m__strHeader; 232 233 /*** 234 * The Make-Rules body. 235 */ 236 private String m__strBody; 237 238 /*** 239 * The makefile subtemplate. 240 */ 241 private String m__strMakefileSubtemplate; 242 243 /*** 244 * The project name. 245 */ 246 private String m__strProjectName; 247 248 /*** 249 * The project version. 250 */ 251 private String m__strProjectVersion; 252 253 /*** 254 * The package list. 255 */ 256 private Collection m__cPackages; 257 258 /*** 259 * Builds a ConfigureInTemplate using given information. 260 * @param header the header. 261 * @param body the body. 262 * @param makefileSubtemplate the makefile subtemplate. 263 * @param projectName the project name. 264 * @param projectVersion the project version. 265 */ 266 public ConfigureInTemplate( 267 String header, 268 String body, 269 String makefileSubtemplate, 270 String projectName, 271 String projectVersion) 272 { 273 inmutableSetHeader(header); 274 inmutableSetBody(body); 275 inmutableSetMakefileSubtemplate(makefileSubtemplate); 276 inmutableSetProjectName(projectName); 277 inmutableSetProjectVersion(projectVersion); 278 } 279 280 /*** 281 * Builds a ConfigureInTemplate using given information. 282 * @param projectName the project name. 283 * @param projectVersion the project version. 284 */ 285 public ConfigureInTemplate(String projectName, String projectVersion) 286 { 287 this( 288 DEFAULT_HEADER, 289 DEFAULT_BODY, 290 DEFAULT_MAKEFILE_SUBTEMPLATE, 291 projectName, 292 projectVersion); 293 } 294 295 /*** 296 * Specifies the header. 297 * @param header the new header. 298 */ 299 private void inmutableSetHeader(String header) 300 { 301 m__strHeader = header; 302 } 303 304 /*** 305 * Specifies the header. 306 * @param header the new header. 307 */ 308 protected void setHeader(String header) 309 { 310 inmutableSetHeader(header); 311 } 312 313 /*** 314 * Retrieves the header. 315 * @return such information. 316 */ 317 public String getHeader() 318 { 319 return m__strHeader; 320 } 321 322 /*** 323 * Specifies the body. 324 * @param body the new body. 325 */ 326 private void inmutableSetBody(String body) 327 { 328 m__strBody = body; 329 } 330 331 /*** 332 * Specifies the body. 333 * @param body the new body. 334 */ 335 protected void setBody(String body) 336 { 337 inmutableSetBody(body); 338 } 339 340 /*** 341 * Retrieves the body. 342 * @return such information. 343 */ 344 public String getBody() 345 { 346 return m__strBody; 347 } 348 349 /*** 350 * Specifies the makefile subtemplate. 351 * @param makefileSubtemplate the new makefile subtemplate. 352 */ 353 private void inmutableSetMakefileSubtemplate(String makefileSubtemplate) 354 { 355 m__strMakefileSubtemplate = makefileSubtemplate; 356 } 357 358 /*** 359 * Specifies the makefile subtemplate. 360 * @param makefileSubtemplate the new makefile subtemplate. 361 */ 362 protected void setMakefileSubtemplate(String makefileSubtemplate) 363 { 364 inmutableSetMakefileSubtemplate(makefileSubtemplate); 365 } 366 367 /*** 368 * Retrieves the makefile subtemplate. 369 * @return such information. 370 */ 371 public String getMakefileSubtemplate() 372 { 373 return m__strMakefileSubtemplate; 374 } 375 376 /*** 377 * Specifies the project name. 378 * @param projectName the new project name. 379 */ 380 private void inmutableSetProjectName(String projectName) 381 { 382 m__strProjectName = projectName; 383 } 384 385 /*** 386 * Specifies the project name. 387 * @param projectName the new project name. 388 */ 389 protected void setProjectName(String projectName) 390 { 391 inmutableSetProjectName(projectName); 392 } 393 394 /*** 395 * Retrieves the project name. 396 * @return such information. 397 */ 398 public String getProjectName() 399 { 400 return m__strProjectName; 401 } 402 403 /*** 404 * Specifies the project version. 405 * @param projectVersion the new project version. 406 */ 407 private void inmutableSetProjectVersion(String projectVersion) 408 { 409 m__strProjectVersion = projectVersion; 410 } 411 412 /*** 413 * Specifies the project version. 414 * @param projectVersion the new project version. 415 */ 416 protected void setProjectVersion(String projectVersion) 417 { 418 inmutableSetProjectVersion(projectVersion); 419 } 420 421 /*** 422 * Retrieves the project version. 423 * @return such information. 424 */ 425 public String getProjectVersion() 426 { 427 return m__strProjectVersion; 428 } 429 430 /*** 431 * Specifies the packages. 432 * @param packagees the package list. 433 */ 434 protected void setPackages(Collection packages) 435 { 436 m__cPackages = packages; 437 } 438 439 /*** 440 * Retrieves the packages. 441 * @return such collection. 442 */ 443 protected Collection getPackages() 444 { 445 return m__cPackages; 446 } 447 448 /*** 449 * Adds a package. 450 * @param concretePackage the package to add. 451 */ 452 public void addPackage(String concretePackage) 453 { 454 if (concretePackage != null) 455 { 456 Collection t_cPackages = getPackages(); 457 458 if (t_cPackages == null) 459 { 460 t_cPackages = new ArrayList(); 461 setPackages(t_cPackages); 462 } 463 464 if (!t_cPackages.contains(concretePackage)) 465 { 466 t_cPackages.add(concretePackage); 467 } 468 } 469 } 470 471 /*** 472 * Retrieves the weaved configure.in file contents. 473 * @return such contents. 474 */ 475 public String toString() 476 { 477 StringBuffer t_sbResult = new StringBuffer(); 478 479 String t_strProjectName = getProjectName(); 480 481 String t_strProjectVersion = getProjectVersion(); 482 483 Collection t_cPackages = getPackages(); 484 485 StringBuffer t_sbPackages = new StringBuffer(); 486 487 if ( (t_strProjectName != null) 488 && (t_strProjectVersion != null)) 489 { 490 MessageFormat t_Formatter = null; 491 492 t_sbResult.append(getHeader()); 493 494 if (t_cPackages != null) 495 { 496 t_Formatter = new MessageFormat(getMakefileSubtemplate()); 497 498 Iterator t_itPackages = t_cPackages.iterator(); 499 500 while (t_itPackages.hasNext()) 501 { 502 t_sbPackages.append( 503 t_Formatter.format( 504 new Object[] 505 { 506 t_itPackages.next() 507 })); 508 } 509 } 510 511 t_Formatter = new MessageFormat(getBody()); 512 513 t_sbResult.append( 514 t_Formatter.format( 515 new Object[] 516 { 517 t_strProjectName, 518 t_strProjectVersion, 519 t_sbPackages 520 })); 521 } 522 523 return t_sbResult.toString(); 524 } 525 }

This page was automatically generated by Maven