all: preparations for out-of-tree build

- Makefile: Prepare for out-of-tree build
  - Define CONFIG_MARS_BIGMODULE if build out-of-tree
  - Adjusted target for buildtag.h generation
  - Added target for mars_config.h generation (depends on Kconfig)
  - Commits 949c64e 3e1d566 167dd73 rebased on eaba743
- Added script gen_config.pl to generate mars_config.h from Kconfig
  (Commits f373687 dc92c2f bf863f2 rebased on eaba743)
- Include mars_config.h in mars.h/brick.h/brick_say.h
  (Commits 6f14e02 8f1b7d6 rebased on eaba743)

Signed-off-by: Thomas Schoebel-Theuer <tst@1und1.de>
This commit is contained in:
Daniel Hermann 2013-04-09 15:35:00 +02:00 committed by Thomas Schoebel-Theuer
parent dfeb8e6bbb
commit 176be50435
6 changed files with 175 additions and 6 deletions

3
.gitignore vendored
View File

@ -7,7 +7,8 @@ modules.*
*.ko
\#*
.#*
buildtag.h
kernel/buildtag.h
kernel/mars_config.h
*.orig
*.rej

124
gen_config.pl Executable file
View File

@ -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 = <STDIN>) {
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 */
%;

View File

@ -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 > $@;

View File

@ -9,6 +9,9 @@
#include <asm/atomic.h>
// include default config
#include "mars_config.h"
#include "brick_locks.h"
#include "meta.h"

View File

@ -2,6 +2,9 @@
#ifndef BRICK_SAY_H
#define BRICK_SAY_H
// include default config
#include "mars_config.h"
/////////////////////////////////////////////////////////////////////////
extern int brick_say_logging;

View File

@ -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