From a7d5a272ecab8d7d9e24751d6c474516af984aeb Mon Sep 17 00:00:00 2001
From: "Theodore A. Roth" <troth@openavr.org>
Date: Fri, 14 Feb 2003 20:34:03 +0000
Subject: [PATCH] These changes add basic support for a autoconf/automake based
 build system.

	* .cvsignore: Ignore autoconf files.
	* AUTHORS: New file.
	* ChangeLog: New file.
	* Makefile: Removed file.
	* Makefile.am: New file.
	* NEWS: New file.
	* README: New file.
	* bootstrap: New file.
	* configure.ac: New file.
	* avr.c: Include ac_cfg.h (generated by autoconf).
	* config.c: Include ac_cfg.h.
	Include config_gram.h instead of y.tab.h.
	* config.h: If HAS_YYSTYPE is not defined, define YYSTYPE.
	* config_gram.y: Include ac_cfg.h.
	* fileio.c: Include ac_cfg.h.
	* lexer.l: Include config_gram.h instead of y.tab.h.
	* lists.c: Include ac_cfg.h.
	* main.c: Include ac_cfg.h.
	* par.c: Include ac_cfg.h.
	* pgm.c: Include ac_cfg.h.
	* ppi.c: Include ac_cfg.h.
	* stk500.c: Include ac_cfg.h.
	* term.c: Include ac_cfg.h.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@192 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 avrdude/.cvsignore    |  12 +++++
 avrdude/AUTHORS       |   0
 avrdude/ChangeLog     |   0
 avrdude/Makefile      | 115 ------------------------------------------
 avrdude/Makefile.am   |  63 +++++++++++++++++++++++
 avrdude/NEWS          |   0
 avrdude/README        |   0
 avrdude/avr.c         |   2 +
 avrdude/bootstrap     |  30 +++++++++++
 avrdude/config.c      |   4 +-
 avrdude/config.h      |   2 +-
 avrdude/config_gram.y |   2 +
 avrdude/configure.ac  |  32 ++++++++++++
 avrdude/fileio.c      |   2 +
 avrdude/lexer.l       |   2 +-
 avrdude/lists.c       |   3 ++
 avrdude/main.c        |   2 +
 avrdude/par.c         |   2 +
 avrdude/pgm.c         |   2 +
 avrdude/ppi.c         |   2 +
 avrdude/stk500.c      |   2 +
 avrdude/term.c        |   1 +
 22 files changed, 162 insertions(+), 118 deletions(-)
 create mode 100644 avrdude/AUTHORS
 create mode 100644 avrdude/ChangeLog
 delete mode 100644 avrdude/Makefile
 create mode 100644 avrdude/Makefile.am
 create mode 100644 avrdude/NEWS
 create mode 100644 avrdude/README
 create mode 100755 avrdude/bootstrap
 create mode 100644 avrdude/configure.ac

diff --git a/avrdude/.cvsignore b/avrdude/.cvsignore
index 66beb274..5fd94e38 100644
--- a/avrdude/.cvsignore
+++ b/avrdude/.cvsignore
@@ -6,3 +6,15 @@ lexer.c
 config_gram.c
 .cvsignore
 .depend
+INSTALL
+Makefile.in
+ac_cfg.h.in
+aclocal.m4
+autom4te.cache
+configure
+depcomp
+install-sh
+missing
+mkinstalldirs
+stamp-h.in
+
diff --git a/avrdude/AUTHORS b/avrdude/AUTHORS
new file mode 100644
index 00000000..e69de29b
diff --git a/avrdude/ChangeLog b/avrdude/ChangeLog
new file mode 100644
index 00000000..e69de29b
diff --git a/avrdude/Makefile b/avrdude/Makefile
deleted file mode 100644
index 4d67530a..00000000
--- a/avrdude/Makefile
+++ /dev/null
@@ -1,115 +0,0 @@
-#
-# avrdude - A Downloader/Uploader for AVR device programmers
-# Copyright (C) 2000, 2001, 2002, 2003  Brian S. Dean <bsd@bsdhome.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.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-#
-# $Id$
-#
-
-TARGET       = avrdude
-
-PREFIX      ?= /usr/local
-BINDIR       = ${PREFIX}/bin
-MANDIR       = ${PREFIX}/man/man1
-MANUAL       = avrdude.1
-DOCDIR       = ${PREFIX}/share/doc/avrdude
-CONFIGDIR    = ${PREFIX}/etc
-
-DIRS         = ${BINDIR} ${MANDIR} ${DOCDIR} ${CONFIGDIR}
-
-INSTALL      = /usr/bin/install -c -o root -g wheel
-
-CFLAGS       += -Wall -DCONFIG_DIR=\"${CONFIGDIR}\" ${YYDEF}
-#CFLAGS       = -g -Wall -DCONFIG_DIR=\"${CONFIGDIR}\" ${YYDEF}
-LDFLAGS      =  
-YFLAGS       = -t -d -v
-
-INSTALL_PROGRAM = ${INSTALL} -m 555 -s
-INSTALL_DATA    = ${INSTALL} -m 444
-INSTALL_MANUAL  = ${INSTALL_DATA}
-
-LIBS       = -lreadline
-
-YYDEF  = -DYYSTYPE="struct token_t *"
-
-SRCS = config_gram.c avr.c config.c fileio.c lexer.c lists.c main.c par.c \
-	pgm.c ppi.c stk500.c term.c
-
-OBJS = config_gram.o avr.o config.o fileio.o lexer.o lists.o main.o par.o \
-	pgm.o ppi.o stk500.o term.o
-
-all : depend ${TARGET}
-
-
-${TARGET} : ${OBJS}
-	${CC} ${LDFLAGS} -o ${TARGET} ${OBJS} ${LIBS}
-
-clean :
-	rm -f *.o config_gram.c lexer.c ${TARGET} *~ *.core y.tab.h y.output
-
-install : dirs                             \
-	  ${BINDIR}/${TARGET}              \
-	  ${MANDIR}/${MANUAL}              \
-	  ${DOCDIR}/avrdude.pdf            \
-	  ${CONFIGDIR}/avrdude.conf.sample \
-	  ${CONFIGDIR}/avrdude.conf
-
-dirs :
-	@for dir in ${DIRS}; do \
-	  if [ ! -d $$dir ]; then \
-	    echo "creating directory $$dir"; \
-	    mkdir -p $$dir; \
-	  fi \
-	done
-
-${BINDIR}/${TARGET} : ${TARGET}
-	${INSTALL_PROGRAM} ${TARGET} $@
-
-${MANDIR}/${MANUAL} : ${MANUAL}
-	${INSTALL_MANUAL} ${MANUAL} $@
-
-${DOCDIR}/avrdude.pdf : avrdude.pdf
-	${INSTALL_DATA} avrdude.pdf $@
-
-${CONFIGDIR}/avrdude.conf.sample : avrdude.conf.sample
-	${INSTALL_DATA} avrdude.conf.sample $@
-
-${CONFIGDIR}/avrdude.conf : avrdude.conf.sample
-	@if [ -f ${CONFIGDIR}/avrdude.conf ]; then                       \
-	  export TS=`date '+%Y%m%d%H%M%S'`;                              \
-	  echo "NOTE: backing up ${CONFIGDIR}/avrdude.conf to ${CONFIGDIR}/avrdude.conf.$${TS}"; \
-	  cp -p ${CONFIGDIR}/avrdude.conf ${CONFIGDIR}/avrdude.conf.$${TS}; \
-	fi
-	${INSTALL_DATA} avrdude.conf.sample $@
-
-.SUFFIXES: .c .y .l
-
-.y.c:
-	${YACC} ${YFLAGS} -b y $<
-	mv -f y.tab.c $@
-
-.l.c:
-	${LEX} -t $< > $@
-
-depend :
-	@if [ ! -f y.tab.h ]; then touch y.tab.h; fi
-	@${MAKE} config_gram.c lexer.c
-	@${CC} ${CFLAGS} -MM ${SRCS} > .depend
-
-include .depend
-
diff --git a/avrdude/Makefile.am b/avrdude/Makefile.am
new file mode 100644
index 00000000..12a80db4
--- /dev/null
+++ b/avrdude/Makefile.am
@@ -0,0 +1,63 @@
+#
+# avrdude - A Downloader/Uploader for AVR device programmers
+# Copyright (C) 2003  Theodore A. Roth  <troth@openavr.org>
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+#
+# $Id$
+#
+
+AM_YFLAGS    = -d
+
+AM_CPPFLAGS     = -DCONFIG_DIR=\"$(sysconfdir)\"
+
+bin_PROGRAMS = avrdude
+
+avrdude_SOURCES = \
+	config_gram.y \
+	lexer.l \
+	avr.c \
+	avr.h \
+	avrpart.h \
+	config.c \
+	config.h \
+	fileio.c \
+	fileio.h \
+	linux_ppdev.h \
+	lists.c \
+	lists.h \
+	main.c \
+	par.c \
+	par.h \
+	pgm.c \
+	pgm.h \
+	pindefs.h \
+	ppi.c \
+	ppi.h \
+	stk500.c \
+	stk500.h \
+	stk500_private.h \
+	term.c \
+	term.h
+
+man_MANS = avrdude.1
+
+sysconf_DATA = avrdude.conf
+
+avrdude.conf: avrdude.conf.sample
+	cp $< $@
+
diff --git a/avrdude/NEWS b/avrdude/NEWS
new file mode 100644
index 00000000..e69de29b
diff --git a/avrdude/README b/avrdude/README
new file mode 100644
index 00000000..e69de29b
diff --git a/avrdude/avr.c b/avrdude/avr.c
index 20df82a6..55a95ca9 100644
--- a/avrdude/avr.c
+++ b/avrdude/avr.c
@@ -19,6 +19,8 @@
 
 /* $Id$ */
 
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
diff --git a/avrdude/bootstrap b/avrdude/bootstrap
new file mode 100755
index 00000000..9a5ef9d4
--- /dev/null
+++ b/avrdude/bootstrap
@@ -0,0 +1,30 @@
+#! /bin/sh
+
+# autoconf-2.57 is preferred, but >= 2.53 should be ok
+
+if [ "x${AUTOHEADER}" = "x" ]; then
+	AUTOHEADER="autoheader-2.57"
+fi
+
+if [ "x${AUTOCONF}" = "x" ]; then
+	AUTOCONF="autoconf-2.57"
+fi
+
+# automake-1.7 is preferred, but >= 1.6 should be ok
+
+if [ "x${ACLOCAL}" = "x" ]; then
+	ACLOCAL="aclocal-1.7"
+fi
+
+if [ "x${AUTOMAKE}" = "x" ]; then
+	AUTOMAKE="automake-1.7"
+fi
+
+# Bootstrap the build system.
+
+set -x
+
+${ACLOCAL}
+${AUTOHEADER}
+${AUTOCONF}
+${AUTOMAKE} -a -c
diff --git a/avrdude/config.c b/avrdude/config.c
index 0d643754..618850c8 100644
--- a/avrdude/config.c
+++ b/avrdude/config.c
@@ -19,6 +19,8 @@
 
 /* $Id$ */
 
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -26,7 +28,7 @@
 
 #include "avr.h"
 #include "config.h"
-#include "y.tab.h"
+#include "config_gram.h"
 
 char string_buf[MAX_STR_CONST];
 char *string_buf_ptr;
diff --git a/avrdude/config.h b/avrdude/config.h
index 590ada5e..00fb4b91 100644
--- a/avrdude/config.h
+++ b/avrdude/config.h
@@ -54,7 +54,7 @@ extern char       * infile;
 extern LISTID       string_list;
 extern LISTID       number_list;
 
-#if 0
+#if !defined(HAS_YYSTYPE)
 #define YYSTYPE struct token_t *
 #endif
 extern YYSTYPE yylval;
diff --git a/avrdude/config_gram.y b/avrdude/config_gram.y
index 727602fc..20cfed6d 100644
--- a/avrdude/config_gram.y
+++ b/avrdude/config_gram.y
@@ -20,6 +20,8 @@
 /* $Id$ */
 %{
 
+#include "ac_cfg.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
diff --git a/avrdude/configure.ac b/avrdude/configure.ac
new file mode 100644
index 00000000..b647a196
--- /dev/null
+++ b/avrdude/configure.ac
@@ -0,0 +1,32 @@
+# Process this file with autoconf to produce a configure script.
+AC_INIT(avrdude, 3.1.0cvs, avrdude-dev@nongnu.org)
+AC_PREREQ(2.53)
+AC_CONFIG_SRCDIR([main.c])
+AM_INIT_AUTOMAKE
+AM_CONFIG_HEADER([ac_cfg.h]) 
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_YACC
+AM_PROG_LEX
+
+# Checks for libraries.
+AC_CHECK_LIB([termcap], [tputs])
+AC_CHECK_LIB([readline], [readline])
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h sys/ioctl.h sys/time.h termios.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_HEADER_TIME
+
+# Checks for library functions.
+AC_PROG_GCC_TRADITIONAL
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([memset select strcasecmp strdup strerror strncasecmp strtol strtoul])
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/avrdude/fileio.c b/avrdude/fileio.c
index cf991cfc..37dfab35 100644
--- a/avrdude/fileio.c
+++ b/avrdude/fileio.c
@@ -19,6 +19,8 @@
 
 /* $Id$ */
 
+#include "ac_cfg.h"
+
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/avrdude/lexer.l b/avrdude/lexer.l
index cea7fbf7..45651e04 100644
--- a/avrdude/lexer.l
+++ b/avrdude/lexer.l
@@ -29,7 +29,7 @@
 #include <sys/stat.h>
 
 #include "config.h"
-#include "y.tab.h"
+#include "config_gram.h"
 #include "lists.h"
 
 extern int    lineno;
diff --git a/avrdude/lists.c b/avrdude/lists.c
index e2f0592a..ab3b6972 100644
--- a/avrdude/lists.c
+++ b/avrdude/lists.c
@@ -36,6 +36,9 @@
   Author : Brian Dean
   Date   : 10 January, 1990
   ------------------------------------------------------------------------*/
+
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/avrdude/main.c b/avrdude/main.c
index f01a3986..b1d51e93 100644
--- a/avrdude/main.c
+++ b/avrdude/main.c
@@ -65,6 +65,8 @@
  * 
  */
 
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
diff --git a/avrdude/par.c b/avrdude/par.c
index 316836de..3dae6196 100644
--- a/avrdude/par.c
+++ b/avrdude/par.c
@@ -19,6 +19,8 @@
 
 /* $Id$ */
 
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/avrdude/pgm.c b/avrdude/pgm.c
index 5d12d148..21ab9bb1 100644
--- a/avrdude/pgm.c
+++ b/avrdude/pgm.c
@@ -19,6 +19,8 @@
 
 /* $Id$ */
 
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/avrdude/ppi.c b/avrdude/ppi.c
index 4aa16bbd..ce999049 100644
--- a/avrdude/ppi.c
+++ b/avrdude/ppi.c
@@ -21,6 +21,8 @@
 
 #if defined(__FreeBSD__) || defined(__linux__)
 
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/avrdude/stk500.c b/avrdude/stk500.c
index 857b8f18..858bd1eb 100644
--- a/avrdude/stk500.c
+++ b/avrdude/stk500.c
@@ -28,6 +28,8 @@
  *
  */
 
+#include "ac_cfg.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/avrdude/term.c b/avrdude/term.c
index bb4110ca..7b65fda3 100644
--- a/avrdude/term.c
+++ b/avrdude/term.c
@@ -19,6 +19,7 @@
 
 /* $Id$ */
 
+#include "ac_cfg.h"
 
 #include <stdio.h>
 #include <stdlib.h>