|
automake vs. GNU makeautomake vs. GNU makePosted Feb 7, 2008 3:04 UTC (Thu) by stevenj (subscriber, #421)In reply to: automake vs. GNU make by sward Parent article: LCA: Disintermediating distributions I have no doubt about that, if you compare hand-written recursive make with GNU make+include. I'm more doubtful if you compare to automake input files, which are pretty compact (and support a portable include directive if you have definitions you want to share between directories etc.). Of course, it's possible that Tom Tromey or someone may come up with some very clever include file that we can all use in our GNU Makefiles that gives us 95% of automake's functionality in a cleaner and faster way (at the expense of requiring GNU make to build, which in this day and age isn't too much of a burden). And then we'll just use 'include' for subdirectories. But until such a thing gets released, the alternative is to write the include files yourself, support all of the standard targets yourself, be careful to use only portable sh constructs yourself, and so on; in the vast majority of cases, automake seems a simpler and more robust solution at present. A technical question about using include instead of recursive make via automake (recursive make by hand is crazy): how do you separate the namespaces for the subdirectories? For example, if you have a source file with the same name in two subdirectories (e.g. main.c), do you have to jump through hoops to prevent it from getting confused? Or what if you want a 'make clean' target in two subdirectories? I didn't see any obvious way to handle such separation cleanly in the GNU make manual.
(Log in to post comments)
automake vs. GNU make Posted Feb 7, 2008 4:25 UTC (Thu) by masuel (guest, #28661) [Link] >For example, if you have a source file with the same name in two > subdirectories (e.g. main.c), do you have to jump through hoops to > prevent it from getting confused? The way I do it is always reference the tree from the build root. so a/main.c is never looks like b/main.c and yes I can start a build from the subdirs etc. non-recursive is the way to go. Just require gnu make don't try supporting version 8.79 (rh9) clients just make people upgrade....
automake vs. GNU make Posted Feb 7, 2008 4:41 UTC (Thu) by sward (subscriber, #6416) [Link]
Files (source or derived) in separate directories are *always* in separate namespaces, in
Miller's approach. The 'make' is run once, in the root directory, and all sources and targets
are described from that point of view. So you don't build 'main.c', you build 'foo/main.c'.
You use target-specific overrides if you need to customize things, e.g.:
# in foo/include.mk:
$(FOO_OBJ): CPPFLAGS += -Ifoo
Now, if you wanted a selective clean (for one subdir), I agree there isn't a good way to do
this in the include-based structure (other than calling it something else, e.g. 'foo/clean').
Of course, you could also include a local Makefile in the subdir just to make things more
familiar:
# in foo/Makefile:
clean:
cd ..; $(MAKE) foo/clean
Did that help, or would a more complete example be clearer?
automake vs. GNU make Posted Feb 7, 2008 4:55 UTC (Thu) by vmole (subscriber, #111) [Link] Even neater: Stick the following as GNUMakefile in each of your subdirs:
CURMOD:=$(shell pwd | sed -e 's,.*/src/\(.*\),\1,')
all :
@cd $${PWD%$(CURMOD)} && $(MAKE) --no-print-directory $(CURMOD)
% :: FORCE
@cd $${PWD%$(CURMOD)} && $(MAKE) --no-print-directory $(CURMOD)/$@
FORCE:
which automatically transfers any make command up to the top level and re-invokes with the same arguments. (You'll need to tweak the sed command to match your layout.)
automake vs. GNU make Posted Feb 7, 2008 5:18 UTC (Thu) by stevenj (subscriber, #421) [Link] That's clear enough. Yes, using foo/main.c and bar/main.c in the Makefile rules will clearly work (unless you have one of the rare compilers that doesn't support -c -o, although you can hack around that with enough effort I suppose).It seems a bit ugly to me, though, that your subdirectory Makefiles (to be included) must be written differently depending on the name of the directory they are in. The analogous thing in a programming language would be, if you had a subroutine foo(), to require that all local variables be named with a "foo_" prefix.
automake vs. GNU make Posted Feb 7, 2008 5:54 UTC (Thu) by sward (subscriber, #6416) [Link]
That isn't really necessary for variable names (that you don't need to reference later), only
the source and targets need to be qualified. A fairly typical example:
# Define sources for this component:
MY_SRC = $(wildcard foo/*.c)
MY_OBJ = $(MY_SRC:.c=.o)
MY_TGT = foo/libfoo.a
# Additional flags and dependencies for building this component:
$(MY_OBJ): CPPFLAGS += -I foo
$(MY_TGT): $(MY_OBJ)
# Add these to the master Makefile's lists:
SOURCE += $(MY_SRC)
TARGET += $(MY_TGT)
CLEAN += $(MY_OBJ)
The next component can reuse MY_SRC etc. You wouldn't even need these variables, if you had
no need for target-specific variables or dependencies. (But of course, you usually do). If
you wanted to keep a reference to 'foo/libfoo.a', for use in other Makefiles, you might
replace MY_TGT with LIBFOO.
In short, you only need unique names for global variables; local ones can be overwritten.
You do need the component path ('foo' in this example) in a few spots, but it is trivial to
change that if the directory structure changes.
|
Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds
Powered by Rackspace Managed Hosting.