aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@bordeaux-inp.fr>2024-06-17 03:14:20 +0900
committerTristan Riehs <tristan.riehs@bordeaux-inp.fr>2024-06-17 03:14:20 +0900
commitcad449dff9c50bddcce41df04c5b3be771d28d04 (patch)
tree843a10df33202e06be4aca3ad381e4de18f20137
parent2e5693e7cf1e3c408916a1af6d16dc6363b835fe (diff)
Improve build system
Add support for toggling debug on and off and for using GNU Readline or not.
-rw-r--r--configure.ac36
-rw-r--r--src/Makefile.am18
-rw-r--r--src/calculer.c4
3 files changed, 49 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 50df1af..0747857 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,10 +4,38 @@ AM_INIT_AUTOMAKE([-Wall -Werror, foreign])
AC_PROG_CC
-if [ ! -d "./linenoise/" ]
-then
- git clone --depth=1 'https://github.com/antirez/linenoise.git'
-fi
+AH_TEMPLATE([USE_READLINE], [do we use GNU Readline ?])
+AC_DEFUN([LINENOISE_URL], [https://github.com/antirez/linenoise.git])
+
+AC_CHECK_LIB([readline],
+ [readline],
+ [AC_DEFINE([USE_READLINE], [1])
+ use_readline=true
+ AC_ARG_WITH([readline],
+ AS_HELP_STRING([--without-readline],
+ [do not use GNU Readline, and use the Linenoise library
+ available at LINENOISE_URL]),
+ if test ! -d "./linenoise/"
+ then
+ git clone --depth=1 'LINENOISE_URL'
+ fi
+ AC_DEFINE([USE_READLINE], [0])
+ use_readline=false
+ )],
+ [AC_DEFINE([USE_READLINE], [0])
+ use_readline=true]
+)
+
+AM_CONDITIONAL([USE_READLINE_COND], [test x$use_readline = xtrue])
+
+AC_ARG_ENABLE([debug],
+ [AS_HELP_STRING([--enable-debug],
+ [enable debugging, only useful for development])],
+ [debug=true],
+ [debug=false]
+)
+
+AM_CONDITIONAL([DEBUG_COND], [test x$debug = xtrue])
AC_CONFIG_FILES([
Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 006ee7f..88d970c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,19 @@
bin_PROGRAMS = calculer
-AM_CFLAGS = -Wall -Wextra -I../linenoise/
-calculer_SOURCES = calculer.c linenoise.c
-BUILT_SOURCES: linenoise.c
+AM_CFLAGS = -Wall -Wextra
+AM_LDFLAGS =
+calculer_SOURCES = calculer.c
+
+if DEBUG_COND
+else
+AM_CFLAGS += -DNDEBUG -Wno-unused-variable
+endif
+if USE_READLINE_COND
+AM_LDFLAGS += -lreadline
+else
+calculer_SOURCES += linenoise.c
+AM_CFLAGS += -I../linenoise/
+BUILT_SOURCES: linenoise.c
linenoise.c:
cp ../linenoise/linenoise.c .
+endif
diff --git a/src/calculer.c b/src/calculer.c
index 8d13052..be11895 100644
--- a/src/calculer.c
+++ b/src/calculer.c
@@ -25,7 +25,7 @@
#include <time.h>
#include <unistd.h>
-#include "linenoise.h"
+#include "_readline.h"
static int lower = 0;
static int upper = 100;
@@ -169,7 +169,7 @@ main(int argc, char *argv[])
sprintf(prompt, "%d + %d = ", x, y);
void *measure_data = measure_before();
- input = linenoise(prompt);
+ input = readline(prompt);
if ((!input) || (*input == '\0'))
{