ibara/mg

broken build on MacOS <= 10.9

Closed this issue · 14 comments

I updated mg in macports to 20180927 and some builds failure are raised.
First of all, I read #11 #12 and one error was already present (fstatat) but without solution.

All errors are Undefined symbols

  • for 10.9,10.8,10.7 is _fstatat
  • for 10.6,10.5 are _fstatat _strndup _getline

So, what do you think about adding patches to fix those errors? at least _fstatat.
I found this https://github.com/PixarAnimationStudios/USD/pull/139/files from Pixar that fallback to lstat.

thanks

ibara commented

fstatat is either stat or lstat, depending on the flags given to it. So please check.
It probably makes sense to make fstatat a wrapper around stat or lstat. That way we don't have to alter any source code.

We can grab strndup and getline from OpenBSD.

ibara commented

I'm still not sure the best approach for fstatat yet, but strndup and getline are taken care of.

Oh, you are so fast. Thank you.
For fstatat we can include a function like this if the OS doesn't provide it

int
fstatat(int fd, const char *path, struct stat *buf, int flag)
{
	if(flag & AT_SYMLINK_NOFOLLOW) {
		return lstat(path, buf);
	} else {
		return stat(path, buf);
	}
}

in this way we don't patch upstream. We need to take into account the relative path that fstatat introduce to stat and lstat. What do you think?

ibara commented

I just looked at the source code. The only place that uses fstatat is in fileio.c:530
if (fstatat(dirfd(dirp), dent->d_name, &statbuf, 0) < 0)
So I think we can just get away with it being a stat wrapper. I'll fix it now.

ibara commented

Fixed. Thanks for reporting. OpenBSD 6.5-beta was tagged a few days ago, so expect a new release here in about a month.

Thanks. In 10.6
in getline.c change to

ssize_t *
getline(char **buf, size_t *bufsiz, FILE *fp)

in configure

echo "extern char *strndup(const char *, size_t);" >> config.h

unfortunately 10.6 doesn't have "_strnlen" (undefined symbols)

ibara commented

Fixed.

Missing the fix of strndup on configure

ibara commented

Done.

Works. thank you so much!

ibara commented

Great!
And I have a Mac OS X 10.4.11 machine now, so it should help make macOS maintenance easier.

Nice ;-)

I checked compatibility with Mac OS X 10.4.11 PPC (iBook) and the following errors need to be fixed

  • invalid initializer
dired.c:72: error: invalid initializer

add to config.h through configure

#define SLIST_HEAD_INITIALIZER(head) { NULL }

SLIST_HEAD_INITIALIZER doesn't exist on sys/queue.h

  • static declaration
fparseln.c:79: error: static declaration of 'fgetln' follows non-static declaration
/usr/include/stdio.h:315: error: previous declaration of 'fgetln' was here

stdio.h define fgetln() ifndef _POSIX_C_SOURCE. But declaring it doesn't work. Remove static works but it is bad.

  • linking
/usr/bin/ld: can't locate file for: -lutil

seems useless -lutil on MacOS. Tested version 10.4.11 and 10.14.3.

ibara commented

I've already got all this fixed. I'll commit it later.

Good. Then you can change README with Mac OS X (10.4 or later). Anyway, thank your support.