in a makefile, declaring a phony target as a wildcard - linux

I want to declare my wildcard target as phony, but phony doesn't support wildcards:
My makefile:
%.config:
gcc <<compile>>
I want the user to be able to use my makefile to compile the project, using a specific configuration file:
make something.config
make something_else.config
obviously, I need my target to be phony, becuase the target files exist, but simply writing:
.PHONY: %.config
doesn't work.
I've seen here that makeapp supports another syntax, that would help:
$(phony %.config): ...
but I can only use make, and not makeapp.
Is there any way to do it with make?

These are conflicting aims. A phony target is one that doesn't correspond to a real file. In your case, the file exists, but it's not really a target.
I would suggest not using the name of the config file as the target. Instead, construct a system based on one of the following:
make something_else
make CONFIG=something_else.config

Related

linux kernel make tag variable

Linux kernel source can use make tags to get the tag for editor.
In scripts/tags.sh, line7 and line8 say that "Uses the following environment variables: ARCH, SUBARCH, SRCARCH, srctree, src, obj"
I want to ask What are these variable meaning?
I already read this article,but it just mention the two vairables, SRCARCH and SUBARCH.
Variables you should use
Next variables can be passed to tags.sh (actually you should pass them to make tags cscope command, and Makefile will pass them to tags.sh for you).
ARCH: which architecture to index. You can see all architectures list just by doing ls -l arch/ in your kernel source tree.
SUBARCH: the meaning of this variable depends on your architecture:
if ARCH=arm, SUBARCH will be used to determine arch/arm/mach-* and arch/arm/plat-* directories, and these directories will be indexed
if ARCH=um, use SUBARCH to specify which architecture you actually want to use in your User-Mode Linux (like SUBARCH=arm or SUBARCH=x86)
for the rest of architectures, you can omit this variable
ALLSOURCE_ARCHS: use this to index more than one architecture. Like ALLSOURCE_ARCHS="x86 mips arm" or ALLSOURCE_ARCHS="all". If you only want to index one architecture, omit this variable and use ARCH instead.
COMPILED_SOURCE: set this variable to 1 if you want to index only actually compiled source files. If you want to index all source files, omit setting this variable.
O= (this is actually Makefile parameter): use absolute paths (useful if you want to load created cscope/ctags index files outside of kernel directory, e.g. for development of out-of-tree kernel modules). If you want to use relative paths (i.e. you're gonna do development only in kernel dir), just omit that parameter.
Variables you don't need to touch
SRCARCH: being set from ARCH variable in Makefile and then passed to script. You probably don't need to mess with it, just set ARCH variable correctly
srctree: kernel source tree path. This variable will be passed from Makefile automatically if you're using this script via make cscope tags.
src and obj variables: those are not used by scripts/tags.sh anymore. It was replaced by utilizing KBUILD_SRC variable, which is provided from Makefile automatically, when you provide O=... parameter to it.
Usage
Basically, I'd recommend to only use scripts/tags.sh via make invocation. Example:
$ make O=. ARCH=arm SUBARCH=omap2 COMPILED_SOURCE=1 cscope tags
or
$ make ARCH=x86 cscope tags

mapping kernel config variables to modules

In general, how do I know what set of kernel config options are necessary to have some .ko file built?
For example, I need 'xt_conntrack.ko'. What resources are there that let me know whether or not enabling CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m in my kernel config is necessary or even sufficient to result in my built .ko file? How do I find the full set of kconfig options required to yield a kernel module?
http://cateee.net/lkddb/web-lkddb/NETFILTER_XT_MATCH_CONNTRACK.html indicates it will build "xt_conntrack", but I am not seeing it when I =m it and all of its dependencies.
On the other side, there is no set of kconfig flags visible here (http://modules.libres.ch/browse/linux/v3.0/x86_64/xt_conntrack/)
How do I find the full set of kconfig options required to yield a kernel module?
In general, determining set of options for building a kernel module is complex process. Steps described below may guide in that process.
1. Find a Makefile
Find a Makefile which builds a kernel module. This file is located in the same directory, where .ko file is produced; this directory usually coincides with a directory of module's source files. This Makefile contains a line which builds a module:
obj-${CONFIG_...} := <module_name>.o
Example:
A module xt_conntrack.ko is built by the line
obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
in file net/netfilter/Makefile.
2. Determine final option
There are several ways how configuration options may affect on building a module.
The option is used directly in the line, produced the module:
obj-${CONFIG_X} := <module_name>.o
means that option CONFIG_X should be set for the module to be built.
Given Makefile is conditionally included into the upper one:
obj-${CONFIG_Y} := <dir>/
The line produced the module is guarded by "if" clause:
ifeq ($(CONFIG_F),y)
obj-m := <module_name>.o
endif
Alternatively, guard may protect inclusion of the Makefile from the upper one:
ifeq ($(CONFIG_F),y)
obj-m := <dir>/
endif
Example:
A module xt_conntrack depends by rule 1 from CONFIG_NETFILTER_XT_MATCH_CONNTRACK option.
Also it depends by rule 2 from CONFIG_NETFILTER option, because outer net/Makefile includes net/netfilter/Makefile via
obj-$(CONFIG_NETFILTER) += netfilter/
3. Find definition of the option and determine its availability
Note: This is the most complicated step, mainly because availability of the option is expressed in terms of other options. It is recommended to use ready-made tools for that. E.g., make menuconfig tool may search options and show their definition.
Every configuration option is defined in one of Kconfig files.
Definition determines:
availability of the option (when the option can be used),
possible values of the option (y/n - boolean, y/m/n - tristate, etc.),
whether the option can be set by a user.
Example:
Option NETFILTER_XT_MATCH_CONNTRACK is defined in net/netfilter/Kconfig as
config NETFILTER_XT_MATCH_CONNTRACK
tristate '"conntrack" connection tracking match support'
depends on NF_CONNTRACK
default m if NETFILTER_ADVANCED=n
help
This is a general conntrack match module, a superset of the state match.
It allows matching on additional conntrack information, which is
useful in complex configurations, such as NAT gateways with multiple
internet links or tunnels.
To compile it as a module, choose M here. If unsure, say N.
That is, the option is available (can be set) only when NF_CONNTRACK option is set.
Documentation for format of Kconfig files is located at Documentation/kbuild/kconfig-language.txt.

How to prevent scons from cleaning parent and sibling directories?

I'm working on implementing a build system using scons for a somewhat large software project. There is a directory structure which separates the code for individual libraries and programs into their own directories. With our existing make system, I can do a "make clean" in a single program directory and it will only clean the files associated with the source in that directory. If I do an "scons -c" though, it recognizes that the program depends on a slew of libraries that are in sibling (or cousin) directories and cleans all of the files for those as well. This is not what I want since I then have to rebuild all of these libraries which can take several minutes.
I have tried playing with the "NoClean()" command, but have not gotten it to work in the way I need. Given the size of the code base and complexity of the directory structure, I can't realistically have a NoClean() line for every file in every library.
Is there any way to tell scons to ignore any dependencies above the current directory when doing a clean (i.e. scons -c) ?
I'd love to have a good answer to this myself.
The only solution that I can offer for now is that you get Noclean working.
So in your library, you should have something like this
lib_objs = SharedObject(source_list)
mylib = SharedLibrary('libname', lib_objs)
So for this we want to protect the library and the sources from being cleaned.
NoClean([mylib, lib_objs])
Notice that I had to split the building of the object files from the library because I want to be able to pass them to NoClean as well.
Try using the target name when cleaning.
scons -c aTargetName
You can use the SCons Alias() function to simplify the target name and to also group several target names into one alias.
With this approach you'll have to add an alias in each appropriate subdir, which isn't necessarily a bad thing :)

Automake flex output naming

If if use, for example
foo_SOURCES = bar.l
then, automake generates via flex file bar.c. But, if I provide prefix AM_LFLAGS=-Psome_prefix, it generates lex.some_prefix.c, which is not known by other
compilation rules, so it fails with bar.c: No such file or directory. Where is my mistake and how can I work around it? I really need prefix.
I think the only way around this is to write your own rule for the .l->.c translation. Something like:
x_SOURCES = lex.some_prefix.c
lex.some_prefix.c: lex.l
... rule here
You may also need a tweak to ensure you distribute the .l file.

makefile: how to call macros in macros

I have the following macros in my make file:
pdf:
// do something
clean:
// just another fancy thing
No I want to declare a macro all: which include (or call) the macros above. The following thing doesn't work:
all:
pdf:
clean:
I don't want to repeat the code from pdf: and clean: in order not to rebel against DRY principle.
Thanks for your help.
Those are not macros, they are targets.
Makefiles take the syntax of [target]: [dependent target 1] [dependent target 2]
Try:
all: pdf clean
executing make without argument is
same as calling make all.
That's not correct. The first normal target in the file is the default target. There's nothing magical about all, though it is conventional to use that as the first target.
You also can run:
make clean pdf
Any way, all is commonly used as a default make target - in other words executing make without argument is same as calling make all. This maybe very confusing for expirienced users, therefore if you want "such a shortcut", call it deferently (e.g. cpdf)

Resources