]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
A main program is compiled.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 3 Jan 2007 10:42:32 +0000 (10:42 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 3 Jan 2007 10:42:32 +0000 (10:42 +0000)
git-svn-id: file:///svn/unbound/trunk@5 be551aaa-1e26-0410-a405-d3ace91eadb9

Makefile.in
configure.ac
daemon/unbound.c [new file with mode: 0644]
doc/Changelog
testcode/unitmain.c [new file with mode: 0644]
util/log.c [new file with mode: 0644]
util/log.h [new file with mode: 0644]

index 9978f89298eb26f7fdb8964a48d011a4609e1cbc..199af4ac08de4c6306a9961e87a60209da6c1174 100644 (file)
@@ -1,5 +1,17 @@
-# Standard installation pathnames
+# Copyright 2007 NLnet Labs
 # See the file LICENSE for the license
+# 
+# Standard installation pathnames
+
+QUIET=yes
+ifeq "$(QUIET)" "yes"
+  Q=@
+  INFO=@echo
+else
+  Q=
+  INFO=@:
+endif
+
 SHELL=@SHELL@
 VERSION=@PACKAGE_VERSION@
 srcdir=@srcdir@
@@ -21,6 +33,9 @@ LIBOBJS=@LIBOBJS@
 RUNTIME_PATH=@RUNTIME_PATH@
 DATE=$(shell date +%Y%m%d)
 LIBTOOL=$(libtool)
+ifeq "$(QUIET)" "yes"
+  LIBTOOL+=--quiet
+endif
 BUILD=build/
 
 LINT=splint
@@ -28,24 +43,35 @@ LINTFLAGS=+quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsigned
 
 INSTALL=$(srcdir)/install-sh 
 
-COMMON_SRC=$(wildcard *.c)
+COMMON_SRC=$(wildcard services/*.c util/*.c)
 COMMON_OBJ=$(addprefix $(BUILD),$(COMMON_SRC:.c=.o) $(LIBOBJS))
-ALL_SOURCES=$(COMMON_SRC)
+UNITTEST_SRC=$(wildcard testcode/*.c)
+UNITTEST_OBJ=$(addprefix $(BUILD),$(UNITTEST_SRC:.c=.o))
+DAEMON_SRC=$(wildcard daemon/*.c)
+DAEMON_OBJ=$(addprefix $(BUILD),$(DAEMON_SRC:.c=.o))
+ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC)
+ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.o) $(LIBOBJS))
 
 COMPILE=$(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS)
 LINK=$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS)
 LINK_LIB=$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -release $(VERSION)
 
 $(BUILD)%.o:    $(srcdir)/%.c 
-       @if test ! -d $(BUILD); then mkdir $(BUILD); fi
-       $(COMPILE) -c $< -o $@
+       $(INFO) Build $<
+       @if test ! -d $(dir $@); then $(INSTALL) -d $(patsubst %/,%,$(dir $@)); fi
+       $Q$(COMPILE) -c $< -o $@
 
 .PHONY:        clean realclean doc lint all 
 
-all:   $(COMMON_OBJ) main
+all:   $(COMMON_OBJ) unbound unittest
+
+unbound:       $(COMMON_OBJ) $(DAEMON_OBJ)
+       $(INFO) Link $@
+       $Q$(LINK) -o $@ $^
 
-main:  $(COMMON_OBJ)
-       $(LINK) -o $@ $<
+unittest:      $(COMMON_OBJ) $(UNITTEST_OBJ)
+       $(INFO) Link $@
+       $Q$(LINK) -o $@ $^
 
 clean:
        rm -f *.o *.d *.lo *~ tags
@@ -57,7 +83,7 @@ realclean: clean
        rm -f Makefile 
 
 lint:
-       for i in $(SOURCES); do \
+       for i in $(ALL_SRC); do \
                $(LINT) $(LINTFLAGS) -I. -I$(srcdir) $(srcdir)/$$i ; \
                if [ $$? -ne 0 ] ; then exit 1 ; fi ; \
        done
@@ -67,9 +93,10 @@ tags:        $(srcdir)/*.c ldns/*.[ch]
 
 # Automatic dependencies.
 $(BUILD)%.d: $(srcdir)/%.c
-       @if test ! -d $(BUILD); then mkdir $(BUILD); fi
-       $(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \
+       $(INFO) Depend $<
+       @if test ! -d $(dir $@); then $(INSTALL) -d $(patsubst %/,%,$(dir $@)); fi
+       $Q$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \
                      | sed '\''s!\(.*\)\.o[ :]*!$(dir $@)\1.o $@ : !g'\'' > $@; \
                      [ -s $@ ] || rm -f $@'
 
--include $(addprefix $(BUILD),$(ALL_SOURCES:.c=.d))
+-include $(addprefix $(BUILD),$(ALL_SRC:.c=.d))
index 3f7ae03804317d01a7dd5a56f1027d4deb0d9a56..a75d212924c231f3b79fc0baa94139b03b8916ff 100644 (file)
@@ -208,6 +208,8 @@ AC_ARG_WITH(ldns,
 
 AC_CHECK_LIB(ldns, ldns_rr_new,, [AC_MSG_ERROR([Can't find ldns library])])
 
+AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [512], [Define to the maximum message length to pass to syslog.])
+
 AH_BOTTOM([
 #include <stdio.h>
 #include <string.h>
@@ -238,6 +240,21 @@ AH_BOTTOM([
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif
+
+#ifdef HAVE_ATTR_FORMAT
+#  define ATTR_FORMAT(archetype, string_index, first_to_check) \
+    __attribute__ ((format (archetype, string_index, first_to_check)))
+#else /* !HAVE_ATTR_FORMAT */
+#  define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
+#endif /* !HAVE_ATTR_FORMAT */
+#if defined(__cplusplus)
+#  define ATTR_UNUSED(x)
+#elif defined(HAVE_ATTR_UNUSED)
+#  define ATTR_UNUSED(x)  x __attribute__((unused))
+#else /* !HAVE_ATTR_UNUSED */
+#  define ATTR_UNUSED(x)  x
+#endif /* !HAVE_ATTR_UNUSED */
+
 ])
 
 AC_CONFIG_FILES([Makefile])
diff --git a/daemon/unbound.c b/daemon/unbound.c
new file mode 100644 (file)
index 0000000..aafb0ad
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * daemon/unbound.c - main program for unbound DNS resolver daemon.
+ *
+ * Copyright (c) 2007, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+ *
+ */
+
+#include "config.h"
+#include "util/log.h"
+
+int 
+main(int argc, char* argv[])
+{
+       if(argc != 1) {
+               printf("usage: %s\n", argv[0]);
+               printf("\tstart unbound daemon DNS resolver.\n");
+               return 1;
+       }
+       log_init();
+       log_info("Start of %s.", PACKAGE_STRING);
+       return 0;
+}
index 00bf99ae565e7ad2f5ab6d663e7e002ffb8c4fa3..753c850ca1bbc0806f94de224859b0952c4abeb8 100644 (file)
@@ -4,6 +4,8 @@
          You need a ssh login.  There is no https access yet.
        - Added LICENSE, the BSD license.
        - Added doc/README with compile help.
+       - main program stub and quiet makefile.
+       - minimal logging service (to stderr).
 
 15 December 2006: Wouter
        - Created Makefile.in and configure.ac.
diff --git a/testcode/unitmain.c b/testcode/unitmain.c
new file mode 100644 (file)
index 0000000..da04f26
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * testcode/unitmain.c - unit test main program for unbound.
+ *
+ * Copyright (c) 2007, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+ *
+ */
+
+#include "config.h"
+
+int main(int argc, char* argv[])
+{
+       if(argc != 1) {
+               printf("usage: %s\n", argv[0]);
+               printf("\tperforms unit tests.\n");
+               return 1;
+       }
+       printf("Start of %s unit test.\n", PACKAGE_STRING);
+       return 0;
+}
diff --git a/util/log.c b/util/log.c
new file mode 100644 (file)
index 0000000..56718be
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * util/log.c - implementation of the log code
+ *
+ * Copyright (c) 2007, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+ *
+ */
+
+#include "config.h"
+#include "util/log.h"
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
+void
+log_init()
+{
+}
+
+void
+log_vmsg(const char *format, va_list args)
+{
+       char message[MAXSYSLOGMSGLEN];
+       const char* ident="unbound";
+       vsnprintf(message, sizeof(message), format, args);
+       fprintf(stderr, "[%d] %s[%d]: %s\n",
+               (int)time(NULL), ident, (int)getpid(), message);
+}
+
+void
+log_info(const char *format, ...)
+{
+        va_list args;
+       va_start(args, format);
+       log_vmsg(format, args);
+       va_end(args);
+}
diff --git a/util/log.h b/util/log.h
new file mode 100644 (file)
index 0000000..4969ca2
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * util/log.h - logging service
+ *
+ * Copyright (c) 2007, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+ *
+ */
+
+#ifndef UTIL_LOG_H
+#define UTIL_LOG_H
+
+#include "config.h"
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
+/**
+ * call this to initialize logging services
+ */
+void log_init();
+
+/**
+ * Pass printf formatted arguments. No trailing newline is needed.
+ */
+void log_info(const char* format, ...) ATTR_FORMAT(printf, 1, 2);
+
+/**
+ * va_list argument version of log_info.
+ */
+void log_vmsg(const char *format, va_list args);
+
+#endif /* UTIL_LOG_H */