Another tiny patch for Linux GNUmakefile.in
Not logged in

Another tiny patch for Linux GNUmakefile.in

(1) By brickviking on 2024-09-14 08:09:03 [link] [source]

Hi there. Thanks for the work you're doing for reworking the Makefiles. I've provided the patch I wanted to add for compiling under Linux.

This is for the build-rework branch, NOT the trunk, and is the output directly from the fnc program, as I can't figure out how to get fossil diff or f-vdiff to give me the hash for the current repository revision.

Fossil revision 181490a1c (branch build-rework):

diff 181490a1c091d9e8a4a25a63c7a1fe07325145ea /home/viking/src/c/libfossil/libfossil           5.26%[~] GNUmakefile.in  |  3  3  0 +++ 
1 file changed, 3 insertions(+), 0 deletions(-)

Index: GNUmakefile.in
=======================================================================
hash - 587a115444ede43fb966537ca9b61ab60eab5f26f3ba3cf62b8e4eab18ed8010
hash + 71c27026597745f7c357d5425d6f0f4ccb3bf2029848929a17f22d9e28669ee9
--- GNUmakefile.in
+++ GNUmakefile.in
@@ -518,4 +518,7 @@ ifeq (1,$(BUILD_CLIENT_FNC))
   ifneq ($(filter $(PLATFORM_UNAME),Darwin),)
     $(_fnc).BIN.LDFLAGS += -liconv
+  endif
+  ifneq ($(filter $(PLATFORM_UNAME),Linux),)
+    $(_fnc).BIN.LDFLAGS += -lbsd
   endif
   $(eval $(call ShakeNMake.CALL.RULES.BIN,$(_fnc)))

Feel free to amend if needed.

I've also noticed I can't build the f-apps on OpenBSD any more, as it claims that sqlite3.h is missing, though it is in extsrc/include and is in my /usr/local/include as well. The f-apps build fine over on Fedora and Ubuntu, so I'm scratching my head a bit about that, as everything built fine before the recent shuffle-about aside from the missing include statement and the linker correction above.

Cheers, brickviking
(Post 4 of some)

(2) By Stephan Beal (stephan) on 2024-09-14 09:28:21 in reply to 1 [link] [source]

I can't figure out how to get fossil diff or f-vdiff to give me the hash for the current repository revision.

f-status will show you that. Also: f-resolve current

The version name "current" works only in checkouts and resolves to the current hash. Fossil has that feature, too.

I've also noticed I can't build the f-apps on OpenBSD any more, as it claims that sqlite3.h is missing,

That was fixed just before i went to bed, i thought. Speaking of...

i'm still in bed but will look at this, and your libbsd patch, as soon as i'm up and around.

Thank you for the continued feedback!

(5) By brickviking on 2024-09-14 12:32:26 in reply to 2 [link] [source]

When I last posted, it was at revision 181490a1c, and definitely showing up, but seems to have been fixed since. As of repo revision 08f28aa79f3f, compiling seems to work on Fedora, Ubuntu and OpenBSD with or without libbsd present in the case of the Linux machines. Thanks for that - I've been trying to fight with that one for about five hours and not really winning. I'll look and see what I missed.

Here's some points I discovered along the way.

  • As for compiling, at least on Ubuntu and Fedora, libbsd is not required. The changes you made render my libbsd patch redundant.

  • I tested this quickly by renaming both the /usr/include/bsd directory and /usr/lib/x86_64-gnu-linux/libbsd.so to something not obviously a library. I then reran the configure, and then the make. Both completed with a resulting fnc binary and f-apps. This was true for Ubuntu 22.04 and Fedora 36, and is likely to hold true for future releases of both.

  • Compiling with libbsd and the relevant includes present also runs to completion for both Linuxes.

  • Compiling for OpenBSD 7.5 runs to completion as well.

I'll also poke about and see what few grammar/spelling errors I can find, though I doubt I'll find (m)any.

Cheers, brickviking
(Post 6)

(6) By Stephan Beal (stephan) on 2024-09-14 12:39:28 in reply to 5 [link] [source]

tested this quickly by renaming both the /usr/include/bsd directory and /usr/lib/x86_64-gnu-linux/libbsd.so to something not obviously a library. I then reran the configure, and then the make.

The configure script now simply attempts to link some dummy app against -lbsd. If it works, that flag is added for fnc, else it doesn't add that flag. If fnc doesn't need it, but has the flag, no harm done.

I'll also poke about and see what few grammar/spelling errors I can find, though I doubt I'll find (m)any.

Oh, don't be so certain!

Thank you for the tests! i'll merge this into trunk sometime today.

(7) By Stephan Beal (stephan) on 2024-09-14 14:03:21 in reply to 6 [link] [source]

Thank you for the tests! i'll merge this into trunk sometime today.

FYI: the build-rework branch has been merged into the trunk. Please report any new problems here.

(8) By brickviking on 2024-09-15 09:14:26 in reply to 7 [source]

Please report any new problems here.

Great! I can't say whether the problems I struck are new, after all, I haven't compiled under NetBSD until now. I've also tried the compiles over on FreeBSD 13.2 (worked fine) and NetBSD 10 (didn't quite work). It has three small problems that I found.

  • -D_OPENBSD_SOURCE needed for strtonum
  • cast to unsigned char for tolower(*t)
  • complaints about alloca from libc in NetBSD being used in sqlite3.c (presumably the included amalgamation).

I'll cover them individually, though I don't exactly expect a fix for the last problem to be easy. This is NetBSD, after all...

-D_OPENBSD_SOURCE needed for strtonum

NetBSD10 seems to want an extra define set for fnc to include the definition for strtonum(3) to work - the man page says this:

STRTONUM(3)                Library Functions Manual                STRTONUM(3)

NAME
     strtonum - reliably convert string value to an integer

SYNOPSIS
     #define _OPENBSD_SOURCE

     #include <stdlib.h>

     long long
     strtonum(const char *nptr, long long minval, long long maxval,
         const char **errstr);

DESCRIPTION
     The strtonum() function converts the string in nptr to a long long value.
...

The error I got from gmake and the gcc compiler was this:

+ cc -fPIC -gdwarf-4 -DDEBUG -O0 -Wall -Werror -Wsign-compare -pedantic -std=c99 -fPIE -I./include -I./include/fossil-scm -I./extsrc -D_NETBSD_SOURCE -DNCURSES_WIDECHAR -I/usr/pkg/include/ncurses -I/usr/pkg/include -c -o client/fnc/fnc.o client/fnc/fnc.c
client/fnc/fnc.c: In function 'view_width':
client/fnc/fnc.c:7905:12: error: implicit declaration of function 'strtonum'; did you mean 'xstrtonum'? [-Werror=implicit-function-declaration]
 7905 |    ncols = strtonum(c, 0, UINT32_MAX, &e);
      |            ^~~~~~~~
      |            xstrtonum
cc1: all warnings being treated as errors
gmake: *** [shakenmake.make:392: client/fnc/fnc.o] Error 1

When I reran the compile of fnc.o manually, adding -D_OPENBSD_SOURCE, it completed.

cast to unsigned char for tolower(*t)

In addition, I've found that the native compiler for NetBSD gets its knickers in a knot about the arg to tolower(3), apparently the fix here is to cast the arg to an unsigned char pointer. None of the other operating systems I have direct access to seem to complain, as long as the arg can be represented by an unsigned char. Seemingly it doesn't complain about being fed a signed char for an integer.

Again, here's a short excerpt of tolower(3)'s man page for NetBSD:

TOLOWER(3)                 Library Functions Manual                 TOLOWER(3)

NAME
     tolower - upper case to lower case letter conversion

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <ctype.h>

     int
     tolower(int c);

... elided ...
CAVEATS
     The argument to tolower() must be EOF or representable as an unsigned
     char; otherwise, the behavior is undefined.  See the CAVEATS section of
     ctype(3) for more details.

A potential fix is below, but eyeball it with some suspicion, as there may be better ways of solving this.

Index: client/fnc/fnc.c
==================================================================
--- client/fnc/fnc.c
+++ client/fnc/fnc.c
@@ -13820,11 +13820,11 @@
 			if (lower == NULL) {
 				free(optval);
 				return RC_ERRNO("strdup");
 			}
 			for (t = lower; *t != '\0'; ++t)
-				*t = tolower(*t);
+				*t = tolower((unsigned char)*t);
 			envval = getenv(lower);
 			free(lower);
 		}
 	}
 

complaints about alloca from libc in NetBSD being used in sqlite3.c

Frankly, I don't know how to solve this one, as NetBSD is the only platform I've tried where this happens. I'd love to know how the pkg boys had solved this one, as it might prove enlightening.

Here's some of the warnings I got; one for the libfossil.o itself, presumably when pulling in sqlite3.o:

+ cc -o libfossil.so -shared ./src/fsl.o ./src/annotate.o ./src/appendf.o ./src/auth.o ./src/bag.o ./src/buffer.o ./src/cache.o ./src/checkin.o ./src/checkout.o ./src/cli.o ./src/content.o ./src/config.o ./src/cx.o ./src/db.o ./src/deck.o ./src/delta.o ./src/dibu.o ./src/diff.o ./src/encode.o ./src/event.o ./src/foci.o ./src/fs.o ./src/forum.o ./src/glob.o ./src/io.o ./src/leaf.o ./src/list.o ./src/lookslike.o ./src/md5.o ./src/merge.o ./src/merge3.o ./src/popen.o ./src/pq.o ./src/repo.o ./src/schema.o ./src/search.o ./src/sha1.o ./src/sha3.o ./src/strftime.o ./src/tag.o ./src/ticket.o ./src/udf.o ./src/utf8.o ./src/vfile.o ./src/vpath.o ./src/wiki.o ./src/zip.o ./src/difftk_cstr.o ./src/schema_config_cstr.o ./src/schema_repo1_cstr.o ./src/schema_repo2_cstr.o ./src/schema_ckout_cstr.o ./src/schema_ticket_cstr.o ./src/schema_ticket_reports_cstr.o ./src/schema_forum_cstr.o ./extsrc/sqlite3.o -lz -lm
ld: ./extsrc/sqlite3.o: in function `sqlite3BitvecSet':
/home/viking/src/c/libfossil/libfossil/extsrc/sqlite3.c:54056: warning: Warning: reference to the libc supplied alloca(3); this most likely will not work. Please use the compiler provided version of alloca(3), by supplying the appropriate compiler flags (e.g. -std=gnu99).

And I also got the same warning when I was making the f-app binaries too:

+ cc -o f-apps/f-acat ./f-apps/f-acat.o -L. -lfossil -rdynamic
ld: ./libfossil.so: warning: Warning: reference to the libc supplied alloca(3); this most likely will not work. Please use the compiler provided version of alloca(3), by supplying the appropriate compiler flags (e.g. -std=gnu99).

This ran for practically all the f-apps.

I hope you can untangle each of these. While I'm at it, I'll go check if fnc appears in the pkg database. I know fossil does.

Cheers, brickviking
(Post 7, a very long one)

(9) By Stephan Beal (stephan) on 2024-09-15 09:57:04 in reply to 8 [link] [source]

complaints about alloca from libc in NetBSD being used in sqlite3.c

That part's fixed in the current trunk, i believe. We had the -DSQLITE_USE_ALLOCA flag there for reasons lost to history (probably copy/pasted from fossil 10 years ago). The other ones are for fnc so i'll wait for Mark to respond how he'd like to handle them (defining _OPENBSD_SOURCE directly in fnc or require it as a build flag - either works for me).

(10) By mark on 2024-09-15 10:53:02 in reply to 9 [link] [source]

Thanks, brickviking!

The tolower(3) fix is definitely correct. And I agree with Stephan
inasmuch as -DSQLITE_USE_ALLOCA should get zapped. And we'll just
conditionally define _OPENBSD_SOURCE on NetBSD builds.

diff 717276940c7c9ce6415c29802498cef432a72712 26adf1707c1a075f599a02fe04a5be08666c6104
[~] fnc.bld.mk            |  1  0  1 -
[~] include/fnc_compat.h  |  4  4  0 ++++
[~] src/fnc.c             |  2  1  1 +-

3 files changed, 5 insertions(+), 2 deletions(-)

Index: fnc.bld.mk
=======================================================================
hash - 196ddef3e7fefbacf7ae2733d247033a6b4135d792f9e8ff48504e46416cf7ff
hash + 70b4dfbe66a793778712a71a89d3f133c9d4b9ade5b585bf936b38bd322bd2f7
--- fnc.bld.mk
+++ fnc.bld.mk
@@ -24,7 +24,6 @@ SQLITE_CFLAGS =	${C
 		-DSQLITE_OMIT_SHARED_CACHE \
 		-DSQLITE_OMIT_LOAD_EXTENSION \
 		-DSQLITE_MAX_EXPR_DEPTH=0 \
-		-DSQLITE_USE_ALLOCA \
 		-DSQLITE_ENABLE_LOCKING_STYLE=0 \
 		-DSQLITE_DEFAULT_FILE_FORMAT=4 \
 		-DSQLITE_ENABLE_EXPLAIN_COMMENTS \

Index: include/fnc_compat.h
=======================================================================
hash - 85556f09ac604e1ae599d2095fbc1d047f767aa86c873558ff09aa38c5014d4e
hash + bb6f5631690c77372e00e84a5d5113d6c3acc42eca457cdea3de3646d9ba4092
--- include/fnc_compat.h
+++ include/fnc_compat.h
@@ -47,6 +47,10 @@
 
 #endif  /* __has_include */
 #endif  /* __linux__ */
+
+#ifdef __NetBSD__
+#define _OPENBSD_SOURCE		/* strtonum(3) */
+#endif
 
 #if !defined(__linux__) && !defined(__APPLE__)
 #define HAVE_REALLOCARRAY

Index: src/fnc.c
=======================================================================
hash - 703732d0398e7369f86e5ecd3771ce737ba4faa78ec9f6c21d485ccb896fd863
hash + adc4e9b42289738c496671e596680be094b7f2f7bb3ddeba1fde4a87c3fecb66
--- src/fnc.c
+++ src/fnc.c
@@ -13822,7 +13822,7 @@ fnc_conf_getopt(char **ret, enum fnc_opt_id id, bool ls
 				return RC_ERRNO("strdup");
 			}
 			for (t = lower; *t != '\0'; ++t)
-				*t = tolower(*t);
+				*t = tolower((unsigned char)*t);
 			envval = getenv(lower);
 			free(lower);
 		}

(11) By brickviking on 2024-09-15 11:06:42 in reply to 10 [link] [source]

Thanks for that. I guess I can expect those in the next time I update my BSD's copies of libfossil. It just puzzles me that everything but NetBSD shrugs and say "Well, you must know what you're doing" whereas NetBSD seems to think "Hey, you really should make sure this is only an unsigned char", and because of the -Werror, doesn't go any further.

Anyhow, cheers again.
(Post 8, very short one)

(12) By mark on 2024-09-15 11:25:39 in reply to 11 [link] [source]

Yes, I just ran a sync now: https://fossil.wanderinghorse.net/r/libfossil/info/8e0da47996461a2b

Actually, I usually do explicitly cast arguments to the character
handling functions but this one slipped by. Probably because my hard-
wired heuristic looks for isXXXXX(3) functions; so I can appreciate
NetBSD being vocal here. It's because char can be signed on some arches,
which makes tolower(c) undefined behaviour in such cases. So I very much
appreciate your report and patch :)

(3.2) By Stephan Beal (stephan) on 2024-09-14 11:50:49 edited from 3.1 in reply to 1 [link] [source]

$(_fnc).BIN.LDFLAGS += -lbsd

As of the current build-rework tip, this is determined via the configure process. If configure can link -lbsd to an app then it's used, otherwise it's not. On my system, e.g., -lbsd fails to link (cannot find, despite libbsd clearly being in the system-level library path).

Please try that out:

$ ./configure
$ grep lbsd GNUmakefile

that should show two lines of output on your system, one of them is a comment and the other is LDFLAGS_LIBBSD .... If it doesn't, the new test in auto.def is broken.

This change was tested on my main workstation (Linux, but doesn't like -lbsd) and OpenBSD 7.5 on a Raspberry Pi4 (which is dog slow but works, and doesn't need -lbsd). What i'm missing is a system which actually needs -lbsd, so i need your feedback on whether this change actually works.

(4) By mark on 2024-09-14 11:24:37 in reply to 1 [link] [source]

FYI, you can use the -o diff option (e.g., fnc diff -o) to write the
diff directly to stdout so you can pipe it to xclip(1) rather than copy
pasta the curses diff view. Alternatively, you can use the diff view P
keymap to write the currently viewed diff to file. See fnc diff -h or
the fnc(1) manual page (which is admittedly long but all the commands are
tagged so you can enter :t diff when viewing the manual page to jump
straight to the diff section).

(13) By brickviking on 2024-09-15 22:10:51 in reply to 4 [link] [source]

Come to think of it, I did notice that :t diff didn't work, as less(1) complained there was no tags file at my present location, and less (at least on my Linux) wants a ctags file, and for it to be at my current location. Clearly the TAGS file (probably from etags) that's made on my system doesn't seem to be put into the right place for less to use. And of course, tags don't work with more(1), and I don't know about any other PAGER program - I can only remember those two - more or less ;-)

Cheers, brickviking
(Post 9 of more)

(14) By Stephan Beal (stephan) on 2024-09-15 22:18:17 in reply to 13 [link] [source]

Clearly the TAGS file (probably from etags) that's made on my system doesn't seem to be put into the right place for less to use.

It's generated (if etags is found) in the top build directory. Is there a better/preferred option for that?

The first time i try to hit a tag in emacs, it asks me where the tags file is, i point it to the top dir, tap enter, and then it remembers that for the rest of the session. i only use that for jumping around files with esc-., and don't get any other use out of tags.

(15) By brickviking on 2024-09-16 08:23:36 in reply to 14 [link] [source]

That's not quite what I meant. less(1) (at least on Linux) can't use an etags-created file, only a ctags-created one (or a very close output relative). And yes, when I have a tags file (not TAGS), hitting :t diff will take me to the place in the source code where it thinks it first found "diff".

Hope that clears up things. Yes, I've used emacs with tags, though I'm still not sure how to use it exactly. I also know vim has support for tags in whichever format it supports.

You can probably tell I don't use tags or cscope much.

Cheers, brickviking
(Post 11)

(16) By Stephan Beal (stephan) on 2024-09-16 10:14:25 in reply to 15 [link] [source]

That's not quite what I meant. less(1) (at least on Linux) can't use an etags-created file, only a ctags-created one

Aha! i've always assumed (without ever having looked into it) that they were competing, but essentially compatible, products doing the same thing. Apparently my system has ctags (who knew?) so i will tinker with adding ctags support to the build, storing them as tags. If emacs can handle a ctags file, i'll default to using ctags, otherwise i'll possibly go ahead and generate both tags (ctags) and TAGS (etags), with the caveat that that won't work well on Windows, but we can skip generating those altogether on Windows.

I've used emacs with tags, though I'm still not sure how to use it exactly.

Put your cursor on some C symbol and tap (esc-.). That will, the first time, as where the tags file is (if it's not in the current dir), then will jump to the definition of that symbol. There's probably a way to jump to the decl but i've never looked into it.

You can probably tell I don't use tags or cscope much.

i tinkered with cscope once, and it's nice, but i just don't get enough use out of it to bother with it. i'm almost always working on my own trees, and know where everything is, and it's less useful in that case. If i were working on foreign trees, cscope and a "language server" would be a great help.