From cb2eddfc812e546ee898a464c989e999679cb96b Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 2 May 2024 10:33:10 +0200 Subject: [PATCH] add missing scconfig/src/tty/ dir --- scconfig/src/tty/INIT.c | 2 + scconfig/src/tty/INIT.h | 1 + scconfig/src/tty/Makefile.plugin | 35 +++++ scconfig/src/tty/find_gpm.c | 86 +++++++++++ scconfig/src/tty/find_gpm.h | 1 + scconfig/src/tty/find_ioctl.c | 78 ++++++++++ scconfig/src/tty/find_ioctl.h | 1 + scconfig/src/tty/find_ncurses.c | 244 +++++++++++++++++++++++++++++++ scconfig/src/tty/find_ncurses.h | 5 + scconfig/src/tty/find_pty.c | 110 ++++++++++++++ scconfig/src/tty/find_pty.h | 2 + scconfig/src/tty/find_readline.c | 107 ++++++++++++++ scconfig/src/tty/find_readline.h | 2 + scconfig/src/tty/find_slang.c | 87 +++++++++++ scconfig/src/tty/find_slang.h | 1 + scconfig/src/tty/find_term.c | 101 +++++++++++++ scconfig/src/tty/find_term.h | 2 + scconfig/src/tty/tty.c | 36 +++++ 18 files changed, 901 insertions(+) create mode 100644 scconfig/src/tty/INIT.c create mode 100644 scconfig/src/tty/INIT.h create mode 100644 scconfig/src/tty/Makefile.plugin create mode 100644 scconfig/src/tty/find_gpm.c create mode 100644 scconfig/src/tty/find_gpm.h create mode 100644 scconfig/src/tty/find_ioctl.c create mode 100644 scconfig/src/tty/find_ioctl.h create mode 100644 scconfig/src/tty/find_ncurses.c create mode 100644 scconfig/src/tty/find_ncurses.h create mode 100644 scconfig/src/tty/find_pty.c create mode 100644 scconfig/src/tty/find_pty.h create mode 100644 scconfig/src/tty/find_readline.c create mode 100644 scconfig/src/tty/find_readline.h create mode 100644 scconfig/src/tty/find_slang.c create mode 100644 scconfig/src/tty/find_slang.h create mode 100644 scconfig/src/tty/find_term.c create mode 100644 scconfig/src/tty/find_term.h create mode 100644 scconfig/src/tty/tty.c diff --git a/scconfig/src/tty/INIT.c b/scconfig/src/tty/INIT.c new file mode 100644 index 00000000..a1e48cee --- /dev/null +++ b/scconfig/src/tty/INIT.c @@ -0,0 +1,2 @@ + deps_tty_init(); + diff --git a/scconfig/src/tty/INIT.h b/scconfig/src/tty/INIT.h new file mode 100644 index 00000000..be5f2717 --- /dev/null +++ b/scconfig/src/tty/INIT.h @@ -0,0 +1 @@ +void deps_tty_init(); diff --git a/scconfig/src/tty/Makefile.plugin b/scconfig/src/tty/Makefile.plugin new file mode 100644 index 00000000..7b1a6321 --- /dev/null +++ b/scconfig/src/tty/Makefile.plugin @@ -0,0 +1,35 @@ +TTY_CFLAGS = -DPLUGIN_TTY +TTY_OBJS = \ + $(BIN)/tty/find_ncurses.o \ + $(BIN)/tty/find_slang.o \ + $(BIN)/tty/find_gpm.o \ + $(BIN)/tty/find_pty.o \ + $(BIN)/tty/find_ioctl.o \ + $(BIN)/tty/find_term.o \ + $(BIN)/tty/find_readline.o \ + $(BIN)/tty/tty.o + +$(BIN)/tty/find_ncurses.o: $(SRC)/tty/find_ncurses.c + $(CC) $(CFLAGS) -c $(SRC)/tty/find_ncurses.c -o $(BIN)/tty/find_ncurses.o + +$(BIN)/tty/find_slang.o: $(SRC)/tty/find_slang.c + $(CC) $(CFLAGS) -c $(SRC)/tty/find_slang.c -o $(BIN)/tty/find_slang.o + +$(BIN)/tty/tty.o: $(SRC)/tty/tty.c + $(CC) $(CFLAGS) -c $(SRC)/tty/tty.c -o $(BIN)/tty/tty.o + +$(BIN)/tty/find_gpm.o: $(SRC)/tty/find_gpm.c + $(CC) $(CFLAGS) -c $(SRC)/tty/find_gpm.c -o $(BIN)/tty/find_gpm.o + +$(BIN)/tty/find_pty.o: $(SRC)/tty/find_pty.c + $(CC) $(CFLAGS) -c $(SRC)/tty/find_pty.c -o $(BIN)/tty/find_pty.o + +$(BIN)/tty/find_ioctl.o: $(SRC)/tty/find_ioctl.c + $(CC) $(CFLAGS) -c $(SRC)/tty/find_ioctl.c -o $(BIN)/tty/find_ioctl.o + +$(BIN)/tty/find_term.o: $(SRC)/tty/find_term.c + $(CC) $(CFLAGS) -c $(SRC)/tty/find_term.c -o $(BIN)/tty/find_term.o + +$(BIN)/tty/find_readline.o: $(SRC)/tty/find_readline.c + $(CC) $(CFLAGS) -c $(SRC)/tty/find_readline.c -o $(BIN)/tty/find_readline.o + diff --git a/scconfig/src/tty/find_gpm.c b/scconfig/src/tty/find_gpm.c new file mode 100644 index 00000000..4e47b138 --- /dev/null +++ b/scconfig/src/tty/find_gpm.c @@ -0,0 +1,86 @@ +/* + scconfig - tty lib detection - ncurses + Copyright (C) 2017 Tibor Palinkas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Project page: http://repo.hu/projects/scconfig + Contact (email and IRC): http://igor2.repo.hu/contact.html +*/ +#include +#include +#include +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +int find_gpm(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/gpm"; + const char *test_c = + NL "#include " + NL "int main()" + NL "{" + NL " Gpm_Connect conn;" + NL " conn.eventMask = ~GPM_MOVE;" + NL " conn.defaultMask = GPM_MOVE;" + NL " conn.minMod = conn.maxMod = 0;" + NL " Gpm_Open(&conn, 0);" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + if (require("cc/cc", logdepth, fatal)) + return 1; + + report("Checking for gpm... "); + logprintf(logdepth, "find_gpm:\n"); + logdepth++; + + { + char *cflags = NULL, *ldflags = NULL; + /* rely on pkgconfig when available */ + if (run_pkg_config(logdepth, "gpm", &cflags, &ldflags) == 0) { + if (try_icl(logdepth, node, test_c, "#include ", cflags, ldflags) != 0) { + free(cflags); + free(ldflags); + return 0; + } + } + free(cflags); + free(ldflags); + } + + { + char **incs, *incs_arr[] = {"#include ", NULL } ; + char **cflags, *cflags_arr[] = {"", NULL}; + char **ldflags, *ldflags_arr[] = {"-lgpm", NULL}; + + /* fall back on guessing */ + for(incs = incs_arr; *incs != NULL; incs++) { + for(cflags = cflags_arr; *cflags != NULL; cflags++) { + for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { + if (try_icl(logdepth, node, test_c, *incs, *cflags, *ldflags) != 0) { + return 0; + } + } + } + } + } + + return try_fail(logdepth, node); +} + diff --git a/scconfig/src/tty/find_gpm.h b/scconfig/src/tty/find_gpm.h new file mode 100644 index 00000000..04cb4e02 --- /dev/null +++ b/scconfig/src/tty/find_gpm.h @@ -0,0 +1 @@ +int find_gpm(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/tty/find_ioctl.c b/scconfig/src/tty/find_ioctl.c new file mode 100644 index 00000000..9097939e --- /dev/null +++ b/scconfig/src/tty/find_ioctl.c @@ -0,0 +1,78 @@ +/* + scconfig - tty lib detection - termios + Copyright (C) 2017 Tibor Palinkas + Copyright (C) 2018 Aron Barath + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Project page: http://repo.hu/projects/scconfig + Contact (email and IRC): http://igor2.repo.hu/contact.html +*/ +#include +#include +#include +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +int find_tty_ioctl(const char *name, int logdepth, int fatal) +{ + char node[128]; + char* nodeend; + const char *test_c_template = + NL "#include " + NL "int main()" + NL "{" + NL " %s buf;" + NL " if (sizeof(buf) > 0 && %s > 0) {" + NL " puts(\"OK\");" + NL " return 0;" + NL " }" + NL " return 1;" + NL "}" + NL; + char test_c[1024]; + const char **ioc, *ioctls[] = {"TIOCGWINSZ", "TCGETA", "TIOCGETP", NULL}; + const char **typ, *types[] = {"struct winsize", "struct termio", "struct sgttyb", NULL}; + const char **inc, *includes[] = {"#include ", "#include \n#include ", "#include \n#include ", NULL } ; + + if (require("cc/cc", logdepth, fatal)) + return 1; + + strcpy(node, "libs/tty/ioctl/"); + nodeend = node + strlen(node); + + report("Checking for TTY ioctls...\n"); + logprintf(logdepth, "find_tty_ioctl:\n"); + logdepth++; + + for(ioc = ioctls, typ = types; *ioc != NULL; ++ioc, ++typ) { + report(" %s... ", *ioc); + strcpy(nodeend, *ioc); + sprintf(test_c, test_c_template, *typ, *ioc); + for(inc = includes; *inc != NULL; ++inc) { + if (try_icl(logdepth, node, test_c, *inc, NULL, NULL)) { + goto next_ioc; + } + } + strcat(nodeend, "/presents"); + put(node, sfalse); + report("not found\n"); + next_ioc:; + } + + return 0; +} diff --git a/scconfig/src/tty/find_ioctl.h b/scconfig/src/tty/find_ioctl.h new file mode 100644 index 00000000..620976dc --- /dev/null +++ b/scconfig/src/tty/find_ioctl.h @@ -0,0 +1 @@ +int find_tty_ioctl(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/tty/find_ncurses.c b/scconfig/src/tty/find_ncurses.c new file mode 100644 index 00000000..d3827147 --- /dev/null +++ b/scconfig/src/tty/find_ncurses.c @@ -0,0 +1,244 @@ +/* + scconfig - tty lib detection - ncurses + Copyright (C) 2017 Tibor Palinkas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Project page: http://repo.hu/projects/scconfig + Contact (email and IRC): http://igor2.repo.hu/contact.html +*/ +#include +#include +#include +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +/* Need to look for a unique string because ncurses may write arbitrary + terminal control sequences to stdout during initialization */ + +#define SAFE_OK "{{{scconfig:OK}}}" + +int end_ok(char *stdout_str) +{ + return (strstr(stdout_str, SAFE_OK) != NULL); +} + +static const char *nucrses_test_c = + NL "#include " + NL "#include " + NL "int main()" + NL "{" + NL " WINDOW *mainwin = initscr();" + NL " endwin();" + NL " if (mainwin != NULL)" + NL " puts(\"" SAFE_OK "\");" + NL " return 0;" + NL "}" + NL; + + +int find_ncurses(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/ncurses"; + const char *inc = "#include "; + + if (require("cc/cc", logdepth, fatal)) + return 1; + + report("Checking for ncurses... "); + logprintf(logdepth, "find_ncurses:\n"); + logdepth++; + + { + char *cflags = NULL, *ldflags = NULL; + /* rely on pkgconfig when available */ + if (run_pkg_config(logdepth, "ncurses", &cflags, &ldflags) == 0) { + if (try_icl_(logdepth, node, nucrses_test_c, inc, cflags, ldflags, 1, end_ok) != 0) { + free(cflags); + free(ldflags); + return 0; + } + } + free(cflags); + free(ldflags); + } + + { + char **cflags, *cflags_arr[] = {"", NULL}; + char **ldflags, *ldflags_arr[] = {"-lncurses", NULL}; + + /* fall back on guessing */ + for(cflags = cflags_arr; *cflags != NULL; cflags++) { + for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { + if (try_icl_(logdepth, node, nucrses_test_c, inc, *cflags, *ldflags, 1, end_ok) != 0) { + return 0; + } + } + } + } + + return try_fail(logdepth, node); +} + +int find_ncursesw(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/ncursesw"; + const char *inc = "#include "; + + if (require("cc/cc", logdepth, fatal)) + return 1; + + report("Checking for ncursesw... "); + logprintf(logdepth, "find_ncursesw:\n"); + logdepth++; + + { + char *cflags = NULL, *ldflags = NULL; + /* rely on pkgconfig when available */ + if (run_pkg_config(logdepth, "ncursesw", &cflags, &ldflags) == 0) { + if (try_icl_(logdepth, node, nucrses_test_c, inc, cflags, ldflags, 1, end_ok) != 0) { + free(cflags); + free(ldflags); + return 0; + } + } + free(cflags); + free(ldflags); + } + + { + char **cflags, *cflags_arr[] = {"", NULL}; + char **ldflags, *ldflags_arr[] = {"-lncursesw", NULL}; + + /* fall back on guessing */ + for(cflags = cflags_arr; *cflags != NULL; cflags++) { + for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { + if (try_icl_(logdepth, node, nucrses_test_c, inc, *cflags, *ldflags, 1, end_ok) != 0) { + return 0; + } + } + } + } + + return try_fail(logdepth, node); +} + + +int find_ncurses_escdelay(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/ncurses/escdelay"; + const char *test_c = + NL "#include " + NL "#include " + NL "int main()" + NL "{" + NL " if (ESCDELAY >= 0)" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + + if (require("cc/cc", logdepth, fatal) || require("libs/tty/ncurses/presents", logdepth, fatal)) + return 1; + + report("Checking for ncurses ESCDELAY... "); + logprintf(logdepth, "find_ncurses ESCDELAY:\n"); + logdepth++; + + if (try_icl(logdepth, node, test_c, get("libs/tty/ncurses/includes"), get("libs/tty/ncurses/cflags"), get("libs/tty/ncurses/ldflags")) != 0) + return 0; + + return try_fail(logdepth, node); +} + + +int find_ncurses_cur_term(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/ncurses/cur_term"; + char *inc, *inc1; + const char *test_c = + NL "#include " + NL "#include " + NL "int main()" + NL "{" + NL " if (&cur_term != NULL)" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + + if (require("cc/cc", logdepth, fatal) || require("libs/tty/ncurses/presents", logdepth, fatal)) + return 1; + + report("Checking for ncurses cur_term... "); + logprintf(logdepth, "find_ncurses cur_term:\n"); + logdepth++; + + if (try_icl(logdepth, node, test_c, get("libs/tty/ncurses/includes"), get("libs/tty/ncurses/cflags"), get("libs/tty/ncurses/ldflags")) != 0) + return 0; + + inc1 = str_subsn(get("libs/tty/ncurses/includes")); + + inc = str_concat("\n", inc1, "#include ", NULL); + if (try_icl(logdepth, node, test_c, inc, get("libs/tty/ncurses/cflags"), get("libs/tty/ncurses/ldflags")) != 0) { + free(inc); + free(inc1); + return 0; + } + free(inc); + + inc = str_concat("\n", inc1, "#include ", NULL); + if (try_icl(logdepth, node, test_c, inc, get("libs/tty/ncurses/cflags"), get("libs/tty/ncurses/ldflags")) != 0) { + free(inc); + free(inc1); + return 0; + } + free(inc); + + free(inc1); + return try_fail(logdepth, node); +} + + +int find_ncurses_resizeterm(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/ncurses/resizeterm"; + const char *test_c = + NL "#include " + NL "#include " + NL "int main()" + NL "{" + NL " if (0) resizeterm(80, 25);" + NL " if (resizeterm != NULL)" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + + if (require("cc/cc", logdepth, fatal) || require("libs/tty/ncurses/presents", logdepth, fatal)) + return 1; + + report("Checking for ncurses resizeterm... "); + logprintf(logdepth, "find_ncurses resizeterm:\n"); + logdepth++; + + if (try_icl(logdepth, node, test_c, get("libs/tty/ncurses/includes"), get("libs/tty/ncurses/cflags"), get("libs/tty/ncurses/ldflags")) != 0) + return 0; + + return try_fail(logdepth, node); +} + diff --git a/scconfig/src/tty/find_ncurses.h b/scconfig/src/tty/find_ncurses.h new file mode 100644 index 00000000..f982abc5 --- /dev/null +++ b/scconfig/src/tty/find_ncurses.h @@ -0,0 +1,5 @@ +int find_ncurses(const char *name, int logdepth, int fatal); +int find_ncursesw(const char *name, int logdepth, int fatal); +int find_ncurses_escdelay(const char *name, int logdepth, int fatal); +int find_ncurses_cur_term(const char *name, int logdepth, int fatal); +int find_ncurses_resizeterm(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/tty/find_pty.c b/scconfig/src/tty/find_pty.c new file mode 100644 index 00000000..0908126d --- /dev/null +++ b/scconfig/src/tty/find_pty.c @@ -0,0 +1,110 @@ +/* + scconfig - tty lib detection - ncurses + Copyright (C) 2017 Tibor Palinkas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Project page: http://repo.hu/projects/scconfig + Contact (email and IRC): http://igor2.repo.hu/contact.html +*/ +#include +#include +#include +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +int find_grantpt(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/grantpt"; + const char *test_c = + NL "#include " + NL "int main()" + NL "{" + NL " if (grantpt(-1) == -1)" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + if (require("cc/cc", logdepth, fatal)) + return 1; + + report("Checking for grantpt... "); + logprintf(logdepth, "find_grantpt:\n"); + logdepth++; + + { + char **incs, *incs_arr[] = {"#include ", NULL } ; + char **cflags, *cflags_arr[] = {"", NULL}; + char **ldflags, *ldflags_arr[] = {"", NULL}; + + /* fall back on guessing */ + for(incs = incs_arr; *incs != NULL; incs++) { + for(cflags = cflags_arr; *cflags != NULL; cflags++) { + for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { + if (try_icl(logdepth, node, test_c, *incs, *cflags, *ldflags) != 0) { + return 0; + } + } + } + } + } + + return try_fail(logdepth, node); +} + + +int find_posix_openpt(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/posix_openpt"; + const char *test_c = + NL "#include " + NL "#include " + NL "#include " + NL "int main()" + NL "{" + NL " if (posix_openpt(0) >= 0)" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + if (require("cc/cc", logdepth, fatal)) + return 1; + + report("Checking for posix_openpt... "); + logprintf(logdepth, "find_posix_openpt:\n"); + logdepth++; + + { + char **incs, *incs_arr[] = {"", "#define _XOPEN_SOURCE 600", NULL } ; + char **cflags, *cflags_arr[] = {"", NULL}; + char **ldflags, *ldflags_arr[] = {"", NULL}; + + /* fall back on guessing */ + for(incs = incs_arr; *incs != NULL; incs++) { + for(cflags = cflags_arr; *cflags != NULL; cflags++) { + for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { + if (try_icl(logdepth, node, test_c, *incs, *cflags, *ldflags) != 0) { + return 0; + } + } + } + } + } + + return try_fail(logdepth, node); +} + diff --git a/scconfig/src/tty/find_pty.h b/scconfig/src/tty/find_pty.h new file mode 100644 index 00000000..be924a3c --- /dev/null +++ b/scconfig/src/tty/find_pty.h @@ -0,0 +1,2 @@ +int find_grantpt(const char *name, int logdepth, int fatal); +int find_posix_openpt(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/tty/find_readline.c b/scconfig/src/tty/find_readline.c new file mode 100644 index 00000000..0057594c --- /dev/null +++ b/scconfig/src/tty/find_readline.c @@ -0,0 +1,107 @@ +/* + scconfig - tty lib detection - readline + Copyright (C) 2017 Tibor Palinkas + Copyright (C) 2018 Aron Barath + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Project page: http://repo.hu/projects/scconfig + Contact (email and IRC): http://igor2.repo.hu/contact.html +*/ +#include +#include +#include +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +int find_tty_readline(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/readline"; + const char *test_c = + NL "int my_puts(const char* s);" + NL "int main()" + NL "{" + NL " if (rl_set_prompt(\"x\") == 0)" + NL " my_puts(\"OK\");" + NL " return 0;" + NL "}" + NL "#include " + NL "int my_puts(const char* s) {" + NL " puts(s);" + NL "}" + NL; + const char **ldflag, *ldflags[] = {"-lreadline", NULL }; + const char **inc, *includes[] = {"#include ", "#include \n#include ", NULL }; + + if (require("cc/cc", logdepth, fatal)) + return try_fail(logdepth, node); + + report("Checking for readline library... "); + logprintf(logdepth, "find_tty_readline: check for readline library\n"); + logdepth++; + + for(ldflag = ldflags; *ldflag != NULL; ++ldflag) { + for(inc = includes; *inc != NULL; ++inc) { + if (try_icl(logdepth, node, test_c, *inc, NULL, *ldflag)) { + return 0; + } + } + } + + return try_fail(logdepth, node); +} + +int find_tty_history(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/history"; + const char *test_c = + NL "int my_puts(const char* s);" + NL "int main()" + NL "{" + NL " HIST_ENTRY **list;" + NL " using_history();" + NL " add_history(\"thing\");" + NL " list = history_list();" + NL " if (list != NULL && (*list) != NULL)" + NL " my_puts(\"OK\");" + NL " return 0;" + NL "}" + NL "#include " + NL "int my_puts(const char* s) {" + NL " puts(s);" + NL "}" + NL; + const char **ldflag, *ldflags[] = {"-lhistory", NULL }; + const char **inc, *includes[] = {"#include ", "#include \n#include ", NULL }; + + if (require("cc/cc", logdepth, fatal)) + return try_fail(logdepth, node); + + report("Checking for history library... "); + logprintf(logdepth, "find_tty_history: check for history library\n"); + logdepth++; + + for(ldflag = ldflags; *ldflag != NULL; ++ldflag) { + for(inc = includes; *inc != NULL; ++inc) { + if (try_icl(logdepth, node, test_c, *inc, NULL, *ldflag)) { + return 0; + } + } + } + + return try_fail(logdepth, node); +} diff --git a/scconfig/src/tty/find_readline.h b/scconfig/src/tty/find_readline.h new file mode 100644 index 00000000..7fce83bf --- /dev/null +++ b/scconfig/src/tty/find_readline.h @@ -0,0 +1,2 @@ +int find_tty_readline(const char *name, int logdepth, int fatal); +int find_tty_history(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/tty/find_slang.c b/scconfig/src/tty/find_slang.c new file mode 100644 index 00000000..e03f1936 --- /dev/null +++ b/scconfig/src/tty/find_slang.c @@ -0,0 +1,87 @@ +/* + scconfig - tty lib detection - slang + Copyright (C) 2017 Tibor Palinkas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Project page: http://repo.hu/projects/scconfig + Contact (email and IRC): http://igor2.repo.hu/contact.html +*/ +#include +#include +#include +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +int find_slang(const char *name, int logdepth, int fatal) +{ + const char *node = "libs/tty/slang"; + const char *test_c = + NL "#include " + NL "#include " + NL "int main()" + NL "{" + NL " if (SLtt_initialize(\"this should not work\") == 0)" + NL " puts(\"SLtt_initialize() does not fail on invalid term string\");" + NL " else if (SLtt_initialize(\"vt100\") != 0)" + NL " puts(\"SLtt_initialize() fails to init on vt100\");" + NL " else" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + if (require("cc/cc", logdepth, fatal)) + return 1; + + report("Checking for slang... "); + logprintf(logdepth, "find_slang:\n"); + logdepth++; + + { + char *cflags = NULL, *ldflags = NULL; + /* rely on pkgconfig when available */ + if (run_pkg_config(logdepth, "slang", &cflags, &ldflags) == 0) { + if (try_icl(logdepth, node, test_c, "#include ", cflags, ldflags) != 0) { + free(cflags); + free(ldflags); + return 0; + } + } + free(cflags); + free(ldflags); + } + + { + char **incs, *incs_arr[] = {"#include ", "#include ", NULL } ; + char **cflags, *cflags_arr[] = {"", NULL}; + char **ldflags, *ldflags_arr[] = {"-lslang", NULL}; + + /* fall back on guessing */ + for(incs = incs_arr; *incs != NULL; incs++) { + for(cflags = cflags_arr; *cflags != NULL; cflags++) { + for(ldflags = ldflags_arr; *ldflags != NULL; ldflags++) { + if (try_icl(logdepth, node, test_c, *incs, *cflags, *ldflags) != 0) { + return 0; + } + } + } + } + } + + return try_fail(logdepth, node); +} + diff --git a/scconfig/src/tty/find_slang.h b/scconfig/src/tty/find_slang.h new file mode 100644 index 00000000..36f4aa7b --- /dev/null +++ b/scconfig/src/tty/find_slang.h @@ -0,0 +1 @@ +int find_slang(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/tty/find_term.c b/scconfig/src/tty/find_term.c new file mode 100644 index 00000000..9a809691 --- /dev/null +++ b/scconfig/src/tty/find_term.c @@ -0,0 +1,101 @@ +/* + scconfig - tty lib detection - terminal related functionality + Copyright (C) 2017 Tibor Palinkas + Copyright (C) 2018 Aron Barath + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Project page: http://repo.hu/projects/scconfig + Contact (email and IRC): http://igor2.repo.hu/contact.html +*/ +#include +#include +#include +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +int find_tty_cfmakeraw(const char *name, int logdepth, int fatal) +{ + const char *key = "libs/tty/cfmakeraw"; + const char *test_c = + NL "#include " + NL "int main()" + NL "{" + NL " struct termios t;" + NL no_implicit(void, "cfmakeraw", "cfmakeraw") + NL " cfmakeraw(&t);" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + const char **inc; + const char *incs[] = { + "#include ", + "#include \n#include ", + "#define _DEFAULT_SOURCE\n#define _BSD_SOURCE\n#include ", + "#define _DEFAULT_SOURCE\n#define _BSD_SOURCE\n#include \n#include ", + NULL + }; + + require("cc/cc", logdepth, fatal); + + report("Checking for cfmakeraw()... "); + logprintf(logdepth, "find_tty_cfmakeraw: trying to find cfmakeraw()...\n"); + logdepth++; + + for (inc = incs; *inc != NULL; ++inc ) + if (try_icl(logdepth, key, test_c, *inc, NULL, NULL)) + return 0; + + return try_fail(logdepth, key); +} + +int find_tty_cfsetspeed(const char *name, int logdepth, int fatal) +{ + const char *key = "libs/tty/cfsetspeed"; + const char *test_c = + NL "#include " + NL "int main()" + NL "{" + NL " struct termios t;" + NL no_implicit(int, "cfsetspeed", "cfsetspeed") + NL " if (cfsetspeed(&t, B9600) == 0)" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + const char **inc; + const char *incs[] = { + "#include ", + "#include \n#include ", + "#define _DEFAULT_SOURCE\n#define _BSD_SOURCE\n#include ", + "#define _DEFAULT_SOURCE\n#define _BSD_SOURCE\n#include \n#include ", + NULL + }; + + require("cc/cc", logdepth, fatal); + + report("Checking for cfsetspeed()... "); + logprintf(logdepth, "find_tty_cfsetspeed: trying to find cfsetspeed()...\n"); + logdepth++; + + for (inc = incs; *inc != NULL; ++inc ) + if (try_icl(logdepth, key, test_c, *inc, NULL, NULL)) + return 0; + + return try_fail(logdepth, key); +} diff --git a/scconfig/src/tty/find_term.h b/scconfig/src/tty/find_term.h new file mode 100644 index 00000000..fbdd9c74 --- /dev/null +++ b/scconfig/src/tty/find_term.h @@ -0,0 +1,2 @@ +int find_tty_cfmakeraw(const char *name, int logdepth, int fatal); +int find_tty_cfsetspeed(const char *name, int logdepth, int fatal); diff --git a/scconfig/src/tty/tty.c b/scconfig/src/tty/tty.c new file mode 100644 index 00000000..cda34563 --- /dev/null +++ b/scconfig/src/tty/tty.c @@ -0,0 +1,36 @@ +#include "libs.h" +#include "log.h" +#include "db.h" +#include "dep.h" + +#include "find_ncurses.h" +#include "find_slang.h" +#include "find_gpm.h" +#include "find_pty.h" +#include "find_ioctl.h" +#include "find_term.h" +#include "find_readline.h" + +void deps_tty_init() +{ + dep_add("libs/tty/slang/*", find_slang); + + dep_add("libs/tty/gpm/*", find_gpm); + + dep_add("libs/tty/grantpt/*", find_grantpt); + dep_add("libs/tty/posix_openpt/*", find_posix_openpt); + + dep_add("libs/tty/ncurses/escdelay/*", find_ncurses_escdelay); + dep_add("libs/tty/ncurses/cur_term/*", find_ncurses_cur_term); + dep_add("libs/tty/ncurses/resizeterm/*",find_ncurses_resizeterm); + dep_add("libs/tty/ncurses/*", find_ncurses); + dep_add("libs/tty/ncursesw/*", find_ncursesw); + + dep_add("libs/tty/ioctl/*", find_tty_ioctl); + + dep_add("libs/tty/cfmakeraw/*", find_tty_cfmakeraw); + dep_add("libs/tty/cfsetspeed/*", find_tty_cfsetspeed); + + dep_add("libs/tty/readline/*", find_tty_readline); + dep_add("libs/tty/history/*", find_tty_history); +}