diff --git a/Makefile b/Makefile index eaee943..d59385f 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,127 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITXENON)),) +$(error "Please set DEVKITXENON in your environment. export DEVKITXENON=devkitPPC") +endif -default: xenon +include $(DEVKITXENON)/rules -all: release +#--------------------------------------------------------------------------------- +# 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 := libext2fs +BUILD := build +SOURCES := source +DATA := data +INCLUDES := -xenon: - $(MAKE) -C source PLATFORM=xenon BUILD=xenon_debug -clean: - $(MAKE) -C source clean +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- -install: xenon - $(MAKE) -C source install +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) -DXENON -DWORDS_BIGENDIAN -U__linux__ -DNO_INLINE_FUNCS +CXXFLAGS = $(CFLAGS) +LDFLAGS = -g $(MACHDEP) -Wl,--gc-sections -Wl,-Map,$(notdir $@).map +#--------------------------------------------------------------------------------- +# 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 OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# 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))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ + $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBXENON_INC) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ + -L$(LIBXENON_LIB) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).elf32 + +install: $(OUTPUT).a + mkdir -p $(DEVKITXENON)/usr/include/libext2 + cp include/ext2.h $(DEVKITXENON)/usr/include/libext2 + cp libext2fs.a $(DEVKITXENON)/usr/lib/libext2fs.a + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).a: $(OFILES) + + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/source/Makefile b/source/Makefile deleted file mode 100644 index 325df2d..0000000 --- a/source/Makefile +++ /dev/null @@ -1,110 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITXENON)),) -$(error "Please set DEVKITXENON in your environment. export DEVKITXENON=devkitPPC") -endif - -include $(DEVKITXENON)/rules - -#--------------------------------------------------------------------------------- -# 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 -#--------------------------------------------------------------------------------- -BUILD ?= xenon_release -SOURCES := . -INCLUDES := ../include -LIBDIR := ../lib - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -CFLAGS = -O2 -Wall -Wno-unused $(MACHDEP) $(INCLUDE) -DXENON -DWORDS_BIGENDIAN -U__linux__ -CXXFLAGS = $(CFLAGS) -ASFLAGS := -g -export EXT2BIN := $(LIBDIR)/$(PLATFORM)/libext2fs.a - -#--------------------------------------------------------------------------------- -# 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 DEPSDIR := $(CURDIR)/$(BUILD) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -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 OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(LIBXENON_INC) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ - -L$(LIBXENON_LIB) - -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr xenon_release $(LIBDIR) - -all: $(EXT2BIN) - -install: - mkdir -p $(DEVKITXENON)/usr/include/libext2 - cp ../include/ext2.h $(DEVKITXENON)/usr/include/libext2 - cp ../lib/xenon/libext2fs.a $(DEVKITXENON)/usr/lib/libext2fs.a - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(EXT2BIN): $(OFILES) $(LIBDIR)/$(PLATFORM) - @rm -f "../$(EXT2BIN)" - @$(AR) rcs "../$(EXT2BIN)" $(OFILES) - @echo built ... $(notdir $@) - -$(LIBDIR)/$(PLATFORM): - mkdir -p ../$(LIBDIR)/$(PLATFORM) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- - diff --git a/source/mem_allocate.h b/source/mem_allocate.h index 0aaac0c..cb4f29d 100644 --- a/source/mem_allocate.h +++ b/source/mem_allocate.h @@ -3,28 +3,10 @@ #include -extern __inline__ void* mem_alloc (size_t size) { - return malloc(size); -} - -extern __inline__ void* mem_calloc (size_t count, size_t size) { - return calloc(count, size); -} - -extern __inline__ void* mem_realloc (void *p, size_t size) { - return realloc(p, size); -} - -extern __inline__ void* mem_align (size_t a, size_t size) { - #ifdef __wii__ - return memalign(a, size); - #else - return malloc(size); - #endif -} - -extern __inline__ void mem_free (void* mem) { - free(mem); -} +#define mem_alloc(size) malloc(size) +#define mem_calloc(count, size) calloc(count, size) +#define mem_realloc(p, size) realloc(p, size) +#define mem_align(a,size) memalign(a, size) +#define mem_free(mem) free(mem) #endif /* _MEM_ALLOCATE_H */