Pype.Clicker wrote:
(what if i have a variable named 'x' in two distinct included makefiles ... which one will apply in include-all pattern ? for recursive makes, at least, the locally-defined variable is ... well ... local.
Well, if you actually need the variables, you might try a package prefix setup. Instead of 'x', use 'module_x'.
For my own (non-OS) development, I started breaking out the common parts of programs into separate directories under ~/src/mods/, each with a module.mk file similar to the following:
Code: Select all
#
# module.mk for mods/emu/snd/sn76489
#
SRCS += sn76489.c
# EOF
The toplevel makefile (~/src/playmod/Makefile, for example) is as follows:
Code: Select all
#
# Makefile for playmod
#
include ~/src/supp/prgpre.mk
USES_MODS = unix/snd
SRCS = playmod.c
TARGET = playmod
include ~/src/supp/prgpost.mk
# EOF
Then ~/src/supp/prgpre.mk and ~/src/supp/prgpost.mk have all of the magic bits (and there's not much magic there).
Module inclusion is handled by the following in prgpost.mk:
Code: Select all
ifdef USES_MODS
include $(addprefix $(MODSRC), $(addsuffix /module.mk, $(USES_MODS)))
VPATH += $(addprefix $(MODSRC), $(USES_MODS))
IPATH += $(addprefix -I$(MODSRC), $(USES_MODS))
endif
CFLAGS += $(IPATH)
prgpost.mk also has the basic build rules for .c, .cpp, and .S files, automatic .o file list building, autodep handling, the clean and realclean rules, etc. I haven't put in the changes to make it work with the xmingw cross-compilers yet, but that shouldn't be too hard (even to the point of using something like $(TARGET_OS) in place of unix in the USES_MODS list and having it just work out).
In the end, all of the .o files end up in the toplevel project directory along with the final executable.
Problem is, I figured all of this stuff out, implemented a sizable chunk of it, and then haven't really started a project complex enough to warrant it since. Nor have I done anything about source-control integration, source distribution packaging, multiple-target setups, or anything.
--Jamethiel