I have setup several GNU-based build systems primary via cygwin.
I don't see much of a need for autoconf or automake anymore. They are legacy tools designed to support a wide range of broken POSIX systems.
I presume targeting IRIX & HP-UX are not priorities for you.
GNU make v4.0 corrects a number of subtle defects in the way make has worked in the past and it can handle complex projects pretty easy now.
I make sub-makefiles to handle stuff I resuse over-and-over.
I have a program.mk that knows how to build the current directory as a program.
I break out the toolchains into their own sub-makefiles. I target embedded stuff so this will need a bit of work for it to make sense for PC toolchains.
This is an excerpt from my program.mk file
PROGRAM=$(strip $(notdir $(CURDIR)))
# Find the source
ifeq ($(SRC_DIRS),)
SRC_DIRS=src $(patsubst %/.,%,$(wilcard src/*/.))
endif
ifeq ($(INC_DIRS),)
INC_DIRS=inc $(SRC_DIRS)
endif
CC_SRCS=$(filter-out $(XSRC_LIST),$(foreach SRC_DIR,$(SRC_DIRS), $(wildcard $(SRC_DIR)/*.c)))
AS_SRCS=$(filter-out $(XSRC_LIST),$(foreach SRC_DIR,$(SRC_DIRS), $(wildcard $(SRC_DIR)/*.s)))
SRCS=$(AS_SRCS) $(CC_SRCS)
CC_OBJS=$(subst src/,obj/,$(patsubst %.c,%.o,$(CC_SRCS)))
AS_OBJS=$(subst src/,obj/,$(patsubst %.s,%.o,$(AS_SRCS)))
OBJS=$(AS_OBJS) $(CC_OBJS)
OBJ_DIRS=$(sort $(dir $(OBJS)))
DEPS=$(patsubst obj/%.o,dep/%.dep,$(OBJS))
DEP_DIRS=$(subst obj/,dep/,$(OBJ_DIRS))
# Compiler/Toolchain selection
ifeq ($(VENDOR),)
$(warning Vendor is not set, choose from VENDOR={demo, microsoft, gnu}
include ../../sweng/toolchain/demo.mk
else
include ../../sweng/toolchain/$(VENDOR)-$(ARCH).mk
endif
OUTPUTS += $(PROGRAM).$(BINEXT): $(OBJS) OUTPUTS: $(OBJS)PHONY+=clean
XDEPGOALS+=clean
clean:
@rm -rf out obj lst log lnt dep
@printf "Cleaned $(BRED)%s$(NORMAL)/$(BGREEN)%s$(NORMAL) $(OKSTRING)\n" "$(TARGET)" "$(PROGRAM)"
build: prep $(filter clean cleanall,$(MAKECMDGOALS)) @$(MAKE) --no-print-directory $(OUTPUTS) @printf "Built $(BRED)%s$(NORMAL)/$(BGREEN)%s$(NORMAL) $(OKSTRING)\n" "$(TARGET)" "$(PROGRAM)".PHONY: $(PHONY)
.PRECIOUS: $(PRECIOUS)vpath src/%.h $(INC_DIRS) vpath src/%.c $(SRC_DIRS) vpath src/%.s $(SRC_DIRS)
Getting dependencies working well took me a bit
# For some goals it is important that dependencies are not included
# For example, if a .dep has an error in it and a 'make clean' is issued the clean will fail
# If no goal is specified on the command line we default to 'build' so we need to include dependencies if
# MAKECMDGOALS is blank!
ifeq ($(MAKECMDGOALS),)
INCDEP = build
else
INCDEP = $(filter-out $(XDEPGOALS),$(MAKECMDGOALS))
endif
# Only include dependency files that exist
ifneq ($(INCDEP),)
$(info Including dependencies)
DEPS_EXISTING = $(foreach DIR,$(DEP_DIRS),$(wildcard $(DIR)*.dep))
ifneq ($(DEPS_EXISTING),)
include $(DEPS_EXISTING)
endif #DEPS_EXISTING
endif #INCDEP
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara