#--------------------------------------------------------------------------------- .SUFFIXES: #--------------------------------------------------------------------------------- #--------------------------------------------------------------------------------- # TARGET is the name of the output # BUILD is the directory where object files & intermediate files will be placed # SOURCES is a list of directories containing source code # INCLUDES is a list of directories containing extra header files #--------------------------------------------------------------------------------- TARGET := dlditool BUILD := build SOURCES := source INCLUDES := include #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- DEBUGFLAGS := -s UNAME := $(shell uname -s) CFLAGS := $(DEBUGFLAGS) -Wall -O3 CFLAGS += $(INCLUDE) CXXFLAGS = $(CFLAGS) -fno-rtti LDFLAGS = $(DEBUGFLAGS) ifneq (,$(findstring MINGW,$(UNAME))) PLATFORM := win32 EXEEXT := .exe endif ifneq (,$(findstring CYGWIN,$(UNAME))) CFLAGS += -mno-cygwin LDFLAGS += -mno-cygwin EXEEXT := .exe endif ifneq (,$(findstring Linux,$(UNAME))) LDFLAGS += -static endif #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- LIBS := #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- LIBDIRS := #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional # rules for different file extensions #--------------------------------------------------------------------------------- ifneq ($(BUILD),$(notdir $(CURDIR))) #--------------------------------------------------------------------------------- export OUTPUTDIR:= $(CURDIR) export OUTPUT := $(CURDIR)/$(TARGET) export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ $(foreach dir,$(DATA),$(CURDIR)/$(dir)) export CC := gcc export CXX := g++ export AR := ar export OBJCOPY := objcopy #--------------------------------------------------------------------------------- # automatically build a list of object files for our project #--------------------------------------------------------------------------------- CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) export OFILES := $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(SFILES:.s=.o) #--------------------------------------------------------------------------------- # use CXX for linking C++ projects, CC for standard C #--------------------------------------------------------------------------------- ifeq ($(strip $(CPPFILES)),) #--------------------------------------------------------------------------------- export LD := $(CC) #--------------------------------------------------------------------------------- else #--------------------------------------------------------------------------------- export LD := $(CXX) #--------------------------------------------------------------------------------- endif #--------------------------------------------------------------------------------- export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ -I$(CURDIR)/$(BUILD) export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) .PHONY: $(BUILD) clean #--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile #--------------------------------------------------------------------------------- clean: @echo clean ... @rm -fr $(BUILD) $(OUTPUT) #--------------------------------------------------------------------------------- all: clean $(BUILD) #--------------------------------------------------------------------------------- run: $(OUTPUT) @echo $(OUTPUT) install: cp $(OUTPUT)$(EXEEXT) $(PREFIX) #--------------------------------------------------------------------------------- else DEPENDS := $(OFILES:.o=.d) #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- $(OUTPUT): $(OFILES) @echo linking @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $(OUTPUT)$(EXEEXT) #--------------------------------------------------------------------------------- # Compile Targets for C/C++ #--------------------------------------------------------------------------------- #--------------------------------------------------------------------------------- %.o : %.cpp @echo $(notdir $<) @$(CXX) -MMD $(CXXFLAGS) -o $@ -c $< #--------------------------------------------------------------------------------- %.o : %.c @echo $(notdir $<) @$(CC) -MMD $(CFLAGS) -o $@ -c $< #--------------------------------------------------------------------------------- %.o : %.s @echo $(notdir $<) @$(CC) -MMD $(ASFLAGS) -o $@ -c $< -include $(DEPENDS) #--------------------------------------------------------------------------------- endif #---------------------------------------------------------------------------------