|
| 1 | +#--------------------------------------------------------------------------------- |
| 2 | +.SUFFIXES: |
| 3 | +#--------------------------------------------------------------------------------- |
| 4 | +ifeq ($(strip $(DEVKITARM)),) |
| 5 | +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM) |
| 6 | +endif |
| 7 | + |
| 8 | +include $(DEVKITARM)/gp2x_rules |
| 9 | + |
| 10 | + |
| 11 | +#--------------------------------------------------------------------------------- |
| 12 | +# BUILD is the directory where object files & intermediate files will be placed |
| 13 | +# SOURCES is a list of directories containing source code |
| 14 | +# INCLUDES is a list of directories containing extra header files |
| 15 | +# DATA is a list of directories containing binary files |
| 16 | +# LIB is where the built library will be placed |
| 17 | +# all directories are relative to this makefile |
| 18 | +#--------------------------------------------------------------------------------- |
| 19 | +BUILD ?= release |
| 20 | +SOURCES := ../source |
| 21 | +INCLUDES := ../include |
| 22 | +DATA := |
| 23 | +LIB := $(TOPDIR)/gp2x/lib |
| 24 | + |
| 25 | +#--------------------------------------------------------------------------------- |
| 26 | +# options for code generation |
| 27 | +#--------------------------------------------------------------------------------- |
| 28 | +ARCH := -mthumb -mthumb-interwork |
| 29 | + |
| 30 | +CFLAGS := -g -Wall -O2\ |
| 31 | + -mcpu=arm9tdmi -mtune=arm9tdmi\ |
| 32 | + -fomit-frame-pointer\ |
| 33 | + -ffast-math \ |
| 34 | + $(ARCH) |
| 35 | + |
| 36 | +CFLAGS += $(INCLUDE) -DGP2X |
| 37 | +CXXFLAGS := $(CFLAGS) |
| 38 | + |
| 39 | +ASFLAGS := -g $(ARCH) |
| 40 | + |
| 41 | +ifneq ($(BUILD),debug) |
| 42 | +export GP2XBIN := $(LIB)/libfat.a |
| 43 | +else |
| 44 | +export GP2XBIN := $(LIB)/libfatd.a |
| 45 | +CFLAGS += -DFAT_DEBUG |
| 46 | +endif |
| 47 | + |
| 48 | + |
| 49 | +#--------------------------------------------------------------------------------- |
| 50 | +# any extra libraries we wish to link with the project |
| 51 | +#--------------------------------------------------------------------------------- |
| 52 | +LIBS := |
| 53 | +#-lnds9 |
| 54 | + |
| 55 | +#--------------------------------------------------------------------------------- |
| 56 | +# list of directories containing libraries, this must be the top level containing |
| 57 | +# include and lib |
| 58 | +#--------------------------------------------------------------------------------- |
| 59 | +LIBDIRS := $(LIBORCUS) |
| 60 | + |
| 61 | +#--------------------------------------------------------------------------------- |
| 62 | +# no real need to edit anything past this point unless you need to add additional |
| 63 | +# rules for different file extensions |
| 64 | +#--------------------------------------------------------------------------------- |
| 65 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 66 | +#--------------------------------------------------------------------------------- |
| 67 | + |
| 68 | +export TOPDIR ?= $(CURDIR)/.. |
| 69 | + |
| 70 | +export DEPSDIR := $(CURDIR)/$(BUILD) |
| 71 | + |
| 72 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 73 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 74 | + |
| 75 | +export CC := $(PREFIX)gcc |
| 76 | +export CXX := $(PREFIX)g++ |
| 77 | +export AR := $(PREFIX)ar |
| 78 | +export OBJCOPY := $(PREFIX)objcopy |
| 79 | + |
| 80 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 81 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 82 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 83 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 84 | + |
| 85 | +#--------------------------------------------------------------------------------- |
| 86 | +# use CXX for linking C++ projects, CC for standard C |
| 87 | +#--------------------------------------------------------------------------------- |
| 88 | +ifeq ($(strip $(CPPFILES)),) |
| 89 | +#--------------------------------------------------------------------------------- |
| 90 | + export LD := $(CC) |
| 91 | +#--------------------------------------------------------------------------------- |
| 92 | +else |
| 93 | +#--------------------------------------------------------------------------------- |
| 94 | + export LD := $(CXX) |
| 95 | +#--------------------------------------------------------------------------------- |
| 96 | +endif |
| 97 | +#--------------------------------------------------------------------------------- |
| 98 | + |
| 99 | +export OFILES := $(addsuffix .o,$(BINFILES)) \ |
| 100 | + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 101 | + |
| 102 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 103 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 104 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 105 | + -I$(CURDIR)/$(BUILD) |
| 106 | + |
| 107 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) |
| 108 | + |
| 109 | +.PHONY: $(BUILD) clean |
| 110 | + |
| 111 | +#--------------------------------------------------------------------------------- |
| 112 | +$(BUILD): |
| 113 | + @[ -d $@ ] || mkdir -p $@ |
| 114 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 115 | + |
| 116 | +#--------------------------------------------------------------------------------- |
| 117 | +clean: |
| 118 | + @echo clean ... |
| 119 | + @rm -fr debug gp2x_release $(LIB) include |
| 120 | + |
| 121 | +all: $(GP2XBIN) |
| 122 | + |
| 123 | +dist-bin: |
| 124 | + @mkdir -p include |
| 125 | + @cp $(TOPDIR)/include/fat.h $(TOPDIR)/include/libfatversion.h include |
| 126 | + @tar --exclude=.svn --exclude=*CVS* -cvjf $(TOPDIR)/distribute/$(VERSTRING)/libfat-gp2x-$(VERSTRING).tar.bz2 include lib |
| 127 | + |
| 128 | +install: |
| 129 | + @mkdir -p $(DESTDIR)$(DEVKITPRO)/liborcus/lib |
| 130 | + @mkdir -p $(DESTDIR)$(DEVKITPRO)/liborcus/include |
| 131 | + @cp lib/libfat.a $(DESTDIR)$(DEVKITPRO)/liborcus/lib |
| 132 | + @cp $(TOPDIR)/include/fat.h $(TOPDIR)/include/libfatversion.h $(DESTDIR)$(DEVKITPRO)/liborcus/include |
| 133 | + |
| 134 | +#--------------------------------------------------------------------------------- |
| 135 | +else |
| 136 | + |
| 137 | +DEPENDS := $(OFILES:.o=.d) |
| 138 | + |
| 139 | +#--------------------------------------------------------------------------------- |
| 140 | +# main targets |
| 141 | +#--------------------------------------------------------------------------------- |
| 142 | +$(GP2XBIN) : $(OFILES) $(LIB) |
| 143 | + @rm -f "$(GP2XBIN)" |
| 144 | + @$(AR) rcs "$(GP2XBIN)" $(OFILES) |
| 145 | + @echo built ... $(notdir $@) |
| 146 | + |
| 147 | +$(LIB): |
| 148 | + mkdir $(LIB) |
| 149 | + |
| 150 | +#--------------------------------------------------------------------------------- |
| 151 | +# you need a rule like this for each extension you use as binary data |
| 152 | +#--------------------------------------------------------------------------------- |
| 153 | +%.bin.o : %.bin |
| 154 | +#--------------------------------------------------------------------------------- |
| 155 | + @echo $(notdir $<) |
| 156 | + @$(bin2o) |
| 157 | + |
| 158 | + |
| 159 | +-include $(DEPENDS) |
| 160 | + |
| 161 | +#--------------------------------------------------------------------------------------- |
| 162 | +endif |
| 163 | +#--------------------------------------------------------------------------------------- |
| 164 | + |
0 commit comments