rendered paste body.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
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := img2dsf
BUILD := build
SOURCES := source
INCLUDES := include
##---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
DEBUGFLAGS :=
CFLAGS := $(DEBUGFLAGS) -Wall -O2\
CFLAGS += $(INCLUDE)
LDFLAGS = $(DEBUGFLAGS)
UNAME := $(shell uname -s)
ifneq (,$(findstring MINGW,$(UNAME)))
EXEEXT := .exe
endif
ifneq (,$(findstring Linux,$(UNAME)))
LDFLAGS += -static
endif
ifneq (,$(findstring Darwin,$(UNAME)))
SDK := /Developer/SDKs/MacOSX10.4u.sdk
OSXCFLAGS := -mmacosx-version-min=10.4 -isysroot $(SDK) -arch i386 -arch ppc
OSXCXXFLAGS := $(OSXCFLAGS)
CXXFLAGS += -fvisibility=hidden
LDFLAGS += -mmacosx-version-min=10.4 -arch i386 -arch ppc -Wl,-syslibroot,$(SDK)
endif
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lfreeimage
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# 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 OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
export CC := gcc
export CXX := g++
export AS := as
export AR := ar
export OBJCOPY := objcopy
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
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) $(TARGET)
#---------------------------------------------------------------------------------
install:
cp $(OUTPUT)$(EXEEXT) $(PREFIX)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
$(OUTPUT)$(EXEEXT): $(OFILES)
$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
%.o : %.cpp
@echo $(notdir $<)
$(CXX) -E -MMD $(CXXFLAGS) $< > /dev/null
$(CXX) $(OSXCXXFLAGS) $(CXXFLAGS) -o $@ -c $<
#---------------------------------------------------------------------------------
%.o : %.c
@echo $(notdir $<)
$(CC) -E -MMD $(CFLAGS) $< > /dev/null
$(CC) $(OSXCFLAGS) $(CFLAGS) -o $@ -c $<
endif