0

Recently I took it upon myself to see if I could get devd from the FreeBSD project to build and run on OpenBSD. In doing so, I found that the application itself was not fairly large, so it was not too much work to go through and find what I needed to do in order to make up for the missing system calls. All was well and good. However, it did not seem to link. Except for a few things relating to configuration files which I deemed seemingly discardable within this context, the Makefile of the project is exactly that which is present in the directory in the FreeBSD source. I have seen this kind of this happen with yacc before, but I do not have the knowledge necessary to know how to resolve this. This is seemingly the only thing preventing me from testing it at this point.

Well, there was one include in the Makefile which was FreeBSD specific. I commented it out to see what that would do. It appeared to me that the include was necessary for a conditional statement about configuration files to theoretically be used by the daemon after it is already in production. Nothing to do fundamentally with the build process. After that, I did what any person trying to port software would do - I began the compilation process and started looking at all of the errors that the compiler was shooting back at me, and seeing if I could refactor it to work with the system being ported to. That part work fairly well, and I was able to eliminate all compiler errors and warning. I was expecting the Makefile provided would be sufficient to build the application for me.

Here is the error I was left with:

foo$ make devd
c++ -O2 -pipe   -MD -MP   -o devd devd.cc 
ld: error: undefined symbol: yyin
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::parse_one_file(char const*))

ld: error: undefined symbol: lineno
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::parse_one_file(char const*))
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(new_match)

ld: error: undefined symbol: yyparse
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::parse_one_file(char const*))

ld: error: undefined symbol: pidfilefoo$ make devd
c++ -O2 -pipe   -MD -MP   -o devd devd.cc 
ld: error: undefined symbol: yyin
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::parse_one_file(char const*))

ld: error: undefined symbol: lineno
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::parse_one_file(char const*))
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(new_match)

ld: error: undefined symbol: yyparse
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::parse_one_file(char const*))

ld: error: undefined symbol: pidfile
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::open_pidfile())
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(main)
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(main)
c++: error: linker command failed with exit code 1 (use -v to see invocation)
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(config::open_pidfile())
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(main)
>>> referenced by devd.cc
>>>               /tmp/devd-e407ee.o:(main)
c++: error: linker command failed with exit code 1 (use -v to see invocation)

And here is the BSD-style Makefile I was using to attempt to build this

# $FreeBSD$

#.include <src.opts.mk>

WARNS?= 3
PACKAGE=devd
CONFGROUPS= CONFS DEVD
CONFS=  devd.conf
DEVD=   devmatch.conf
DEVDDIR=    /etc/devd
#.if ${MK_ACPI} != "no"
#DEVD+= asus.conf
#.endif

#.if ${MK_HYPERV} != "no"
#CONFGROUPS+=   HYPERV
#HYPERVDIR=${DEVDDIR}
#HYPERV+=   hyperv.conf
#HYPERVPACKAGE= hyperv-tools
#.endif

#.if ${MK_USB} != "no"
#DEVD+= uath.conf ulpt.conf
#.endif

#.if ${MACHINE_ARCH} == "powerpc"
#DEVD+= apple.conf
#.endif

#.if ${MK_ZFS} != "no"
#DEVD+= zfs.conf
#.endif

PROG_CXX=devd
SRCS=   devd.cc token.l parse.y y.tab.h
MAN=    devd.8 devd.conf.5

LIBADD= util

YFLAGS+=-v
CFLAGS+=-I. -I${.CURDIR}
CFLAGS.clang += -Wno-missing-variable-declarations
CFLAGS.gcc = -Wno-redundant-decls
CXXFLAGS.gcc = -Wno-redundant-decls

CLEANFILES= y.output y.tab.i

HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests

.include <bsd.prog.mk>

You can find the project's source on GitHub here

Thank you all very much in advance for your time, attention, effort, and thoughtful answers. Community is important!

  • I took a look at it, but I think you have not provided nearly enough information to provide an informed answer. I'm reasonably certain that the problem is that you are not using the FreeBSD makefile infrastructure. The command `c++ -O2 -pipe -MD -MP -o devd devd.cc ` is completely wrong; the intent of the FreeBSD build system is to first produce an object file from each source, and link them together at the end. If you just compile `devd.cc`, you don't have the parser and lexer, so naturally you'll get linker errors. – rici Jan 30 '23 at 17:03
  • I'm puzzled by the error on `pidfile`, which is an OpenBSD system call AIUI, so there's no obvious reason why it would be missing, assuming that you are building on an OpenBSD system. But I couldn't help but note that your use of OpenBSD's `pidfile` function is basically wrong from start to end. Read the manpage. The function writes the pid to the file itself, so you don't have to, and anyway you can't because the file is no longer open. `pidfile` doesn't return an fd; it returns an error indication, 0 for success. So your test is inverted. And `atexit` is used to delete the pidfile. – rici Jan 30 '23 at 17:07
  • Thank you for that useful information. I will try to manually compile and link them and see if I can end up with a makefile that works. I will also go through and try and make the necessary changes with the information provided. I have not work with such subsystems on OPBSD, but I figured I could debug once it would at least build. Thank you very much!! – ToCodeABluejay Jan 30 '23 at 20:29

1 Answers1

0

Since I knew that the system binary 'config' in the '/sbin' directory of the OpenBSD source tree also uses YACC, I decided that I would try simple making a very simple replicate Makefile out of the useful information gained from that Makefile. That proved successful in this case...

.include <bsd.own.mk>

PROG= devd

SRCS= devd.cc parse.y token.l

DPADD += ${LIBUTIL}
LDADD += -lutil

MAN= devd.8 devd.conf.5

.include <bsd.prog.mk>

As one can see, it is relatively short, simple, sweet, and straight to the point. It did not require much at all to be successful. However, I think the problem here simply lied in the slight difference in the 'make' systems between FreeBSD and OpenBSD. In any case, this build, and the pidfile handling should be all squared away, in line with the OpenBSD process. All other systems call conflicts have been resolved. Now all that is left to do with is is install and test!