I want to set up a development environment for httpd(8) on OpenBSD with CLion (I'm using the Remote Project feature of CLion, but this isn't very different from working at an OpenBSD box). However, CLion forces me to use CMake, and I'm having some problem porting the Makefile
into a CMakeLists.txt
.
This is the Makefile
from the original repo
# $OpenBSD: Makefile,v 1.30 2017/07/03 22:21:47 espie Exp $
PROG= httpd
SRCS= parse.y
SRCS+= config.c control.c httpd.c log.c logger.c proc.c
SRCS+= server.c server_http.c server_file.c server_fcgi.c
MAN= httpd.8 httpd.conf.5
SRCS+= patterns.c
MAN+= patterns.7
LDADD= -levent -ltls -lssl -lcrypto -lutil
DPADD= ${LIBEVENT} ${LIBTLS} ${LIBSSL} ${LIBCRYPTO} ${LIBUTIL}
#DEBUG= -g -DDEBUG=3 -O0
CFLAGS+= -Wall -I${.CURDIR}
CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
CFLAGS+= -Wmissing-declarations
CFLAGS+= -Wshadow -Wpointer-arith
CFLAGS+= -Wsign-compare -Wcast-qual
YFLAGS=
.include <bsd.prog.mk>
Despite the arcane syntax, it works perfectly on OpenBSD, and here is the output
openbsd$ uname -a
OpenBSD openbsd.my.domain 6.4 GENERIC#10 amd64
openbsd$ make
===> httpd
yacc -o parse.c parse.y
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c parse.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c config.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c control.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c httpd.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c log.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c logger.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c proc.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c server.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c server_http.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c server_file.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c server_fcgi.c
cc -O2 -pipe -Wall -I/home/nalzok/httpd/httpd -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wsign-compare -Wcast-qual -MD -MP -c patterns.c
cc -o httpd parse.o config.o control.o httpd.o log.o logger.o proc.o server.o server_http.o server_file.o server_fcgi.o patterns.o -levent -ltls -lssl -lcrypto -lutil
As @Tsyvarev wisely pointed out in a comment, I must build parse.c
from parse.y
before linking everything together to produce an executable. Among others, bison(1)
is a popular tool for making *.c
from *.y
, so my attempt looks like this. You must also install bison(1)
and pass -DBISON_EXECUTABLE=/usr/local/bin/bison
to CMake.
cmake_minimum_required(VERSION 3.10)
project(httpd)
find_package(BISON REQUIRED)
bison_target(parse httpd/parse.y "${CMAKE_CURRENT_BINARY_DIR}/parse.c")
set(CMAKE_C_FLAGS
"-Wall -Wstrict-prototypes -Wmissing-prototypes"
"-Wmissing-declarations -Wshadow -Wpointer-arith"
"-Wsign-compare -Wcast-qual")
add_executable(httpd
"${CMAKE_CURRENT_BINARY_DIR}/parse.c"
httpd/config.c httpd/control.c httpd/httpd.c httpd/log.c httpd/logger.c httpd/proc.c
httpd/server.c httpd/server_http.c httpd/server_file.c httpd/server_fcgi.c
httpd/patterns.c)
target_link_libraries(httpd event tls ssl crypto util)
This problem is, CMake only provides a FindBISON module for bison(1)
, but what I really need to call is OpenBSD's stock yacc(1)
. Note that these two utilities are not perfectly interchangeable. For example, the yacc
doesn't support the --version
flag, whereas bison
does. How do I instruct CMake to use yacc
?
As a side note, this project is only intended to be deployed on OpenBSD, so feel free to use any unportable hack.