diff --git a/.gitignore b/.gitignore index fdcc1e0a..b30acf10 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ modules.* *.ko \#* .#* -buildtag.h +kernel/buildtag.h +kernel/mars_config.h *.orig *.rej diff --git a/gen_config.pl b/gen_config.pl new file mode 100755 index 00000000..c2fc61e8 --- /dev/null +++ b/gen_config.pl @@ -0,0 +1,124 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use 5.010; + +use Data::Dumper; + +my $DEBUG = 0; + +## +## Parse Kconfig from STDIN +## + +my $option; +my $type; +my @default; + +while (my $line = ) { + if ($line =~ /^config\s+(\w+)\W*$/) { + $option = $1; + printf STDERR "OPTION: %s\n", $option if $DEBUG; + } + elsif ($line =~ /^\s+(tristate|bool|int|string)\s+.*$/) { + $type = $1; + printf STDERR "TYPE: %s\n", $type if $DEBUG; + } + elsif ($line =~ /^\s+default\s+(.*)$/) { + printf STDERR "DEFAULT: %s\n", $1 if $DEBUG; + push @default, { + option => $option, + type => $type, + value => $1, + } if $option; + } + elsif ($line =~ /^\s+---help---\s+$/) { + # ignore lines after this by unsetting $option + undef $option; + # Kconfig syntax allows to have directives after the help section, + # but we do not use this freedom here, for simplicity. + } +} + +print STDERR Dumper(\@default) if $DEBUG; + + +## +## Print the header +## + +print qq% +#ifndef MARS_CONFIG_H +#define MARS_CONFIG_H + +/* + * Module default settings from Kconfig + * + * If the module is built as an external module, this file provides + * reasonable default settings for configuration variables CONFIG_*. + * The defaults are extracted from Kconfig. If you want to change a + * setting, please edit Kconfig directly and regenerate this file. + * + * This file was auto-generated with $0 + * -- DO NOT EDIT MANUALLY -- + */ + +#ifndef CONFIG_MARS_HAVE_BIGMODULE +#define CONFIG_MARS_HAVE_BIGMODULE +#endif +%; + +## +## Print option defaults +## + +foreach my $opt (@default) { + + my $optname = $opt->{option}; + my $optval = $opt->{value}; + + if (!defined($optname) || !defined($optval)) { + printf(STDERR "SKIPPED option due to missing parameters: optname=%s optval=%s\n", + $optname||'', $optval||''); + next; + } + + given ($opt->{type}) { + + when ('tristate') { + # ignore tristate + } + + when ('bool') { + if ($optval eq 'n') { + print qq% +/* CONFIG_$optname is unset */ +%; + } + else { + print qq% +#ifndef CONFIG_$optname +#define CONFIG_$optname 1 +#endif +%; + } + } + + when (['int', 'string']) { + print qq% +#ifndef CONFIG_$optname +#define CONFIG_$optname $optval +#endif +%; + } + + } + +} + +print qq% + +#endif /* MARS_CONFIG_H */ +%; diff --git a/kernel/Makefile b/kernel/Makefile index cea083eb..5f1f1e07 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,6 +2,10 @@ # Makefile for MARS # +ifneq ($(KBUILD_EXTMOD),) + CONFIG_MARS_BIGMODULE := m +endif + mars-objs := \ brick_say.o \ brick_mem.o \ @@ -65,11 +69,42 @@ mars-objs += \ endif -.PHONY FORCE: block/mars/kernel/buildtag.h -block/mars/kernel/buildtag.h: - set -e; exec > $@;\ - cd block/mars;\ +# +# buildtag.h should be regenerated in every build. If a file +# 'DISTVERSION' exists (out-of-tree tarball), its content is +# used as the BUILDTAG. Otherwise, if git is available, the +# git HEAD revision is used instead. +# +extra-y += buildtag.h +$(obj)/buildtag.h: $(patsubst $(obj)/buildtag.h,,$(wildcard $(obj)/*.[ch])) $(obj)/*/*.[ch] + $(Q)$(kecho) "MARS: Generating $@" + $(Q)set -e; \ + exec > $@;\ /bin/echo -e "/* Automatically generated -- DO NOT EDIT! */";\ - /bin/echo -e "#define BUILDTAG \"$$(git log -1 --pretty='format:%H')\"";\ + cd $(src); \ + if [ -e DISTVERSION ]; then \ + BUILDTAG=$$(cat DISTVERSION); \ + elif git rev-parse --git-dir >/dev/null 2>&1; then \ + BUILDTAG="$$(git rev-parse HEAD)"; \ + else \ + BUILDTAG="no-buildtag-available"; \ + fi; \ + /bin/echo -e "#define BUILDTAG \"$$BUILDTAG\"";\ /bin/echo -e "#define BUILDHOST \"$$USER@$$HOSTNAME\"";\ /bin/echo -e "#define BUILDDATE \"$$(date '+%F %T')\"" + +# +# mars_config.h is generated by a simple Kconfig parser (gen_config.pl) +# at build time. +# It is used for out-of-tree builds. +# In-tree builds should not be disturbed due to #ifndef safeguarding. +# +extra-y += mars_config.h +$(obj)/mars_config.h: $(src)/Kconfig $(src)/../gen_config.pl + $(Q)$(kecho) "MARS: Generating $@" + $(Q)set -e; \ + if [ ! -x $(src)/../gen_config.pl ]; then \ + $(kecho) "MARS: cannot execute script $(src)/../gen_config.pl"; \ + /bin/false; \ + fi; \ + cat $< | $(src)/../gen_config.pl > $@; diff --git a/kernel/brick.h b/kernel/brick.h index 3a542422..1d178fd4 100644 --- a/kernel/brick.h +++ b/kernel/brick.h @@ -9,6 +9,9 @@ #include +// include default config +#include "mars_config.h" + #include "brick_locks.h" #include "meta.h" diff --git a/kernel/brick_say.h b/kernel/brick_say.h index 2960e054..f5acfbfa 100644 --- a/kernel/brick_say.h +++ b/kernel/brick_say.h @@ -2,6 +2,9 @@ #ifndef BRICK_SAY_H #define BRICK_SAY_H +// include default config +#include "mars_config.h" + ///////////////////////////////////////////////////////////////////////// extern int brick_say_logging; diff --git a/kernel/mars.h b/kernel/mars.h index cf4926eb..0e73c73e 100644 --- a/kernel/mars.h +++ b/kernel/mars.h @@ -7,6 +7,9 @@ //#define MARS_TRACING // write runtime trace data to /mars/trace.csv +// include default config +#include "mars_config.h" + ///////////////////////////////////////////////////////////////////////// // include the generic brick infrastructure