1: #############################################################################
     2: #############################################################################
     3: #
     4: # Makefile for gzmcpc4nds
     5: #
     6: # Copyright 2008-2009 Douglas McClendon -- dmc AT viros DOT org
     7: #
     8: #############################################################################
     9: #############################################################################
    10: 
    11: # export all make variables by default 
    12: # (until I discover a con at least)
    13: export
    14: 
    15: # these are visible during download play (and possibly other bootloaders)
    16: # note: convert -colors 8 -size 104x16 mybanner.bmp gzmcpc_banner.bmp
    17: #BANNER_IMAGE = gzmcpc_banner_dmcsig.bmp 
    18: BANNER_IMAGE = resources/bitmaps/gzmcpc_banner.bmp 
    19: # note: convert -colors 8 -size 32x32 mylogo.jpg gzmcpc_logo.bmp
    20: LOGO_IMAGE = resources/bitmaps/gzmcpc_logo.bmp 
    21: LOGO_STRING = "Guitar-ZyX MCP v.2k9.dev" 
    22: 
    23: 
    24: # define nds client sources
    25: # (could be a glob, but nah)
    26: NDS_ARM9_SOURCES = \
    27: 	cloader/arm9_loader.c \
    28: 	configfiles.c \
    29: 	debug.c \
    30: 	libdmc.c \
    31: 	graphics.c \
    32: 	input.c \
    33: 	libmcp.c \
    34: 	metrognome.c \
    35: 	modes.c \
    36: 	mode__intro__main.c \
    37: 	mode__intro__credits.c \
    38: 	mode__get_update.c \
    39: 	mode__main_menu.c \
    40: 	mode__ssid__input.c \
    41: 	mode__tpw__jam.c \
    42: 	network.c \
    43: 	rak.c \
    44: 	sound.c \
    45: 	time.c \
    46: 	main.c 
    47: 
    48: NDS_ARM7_SOURCES = \
    49: 	cloader/arm7_loader.c \
    50: 	arm7_main.c 
    51: 
    52: # where sound effects are found, all files here get linked
    53: # into the program.
    54: # TODO: load these at runtime from flash, with simplest/smallest
    55: #       of defaults, to support download play.
    56: SOUND_DIR := resources/sounds
    57: 
    58: # where splash images are found, all *.splash.*jpg files get
    59: # linked into the program.
    60: # TODO: load these at runtime from flash, with simplest/smallest
    61: #       of defaults, to support download play.
    62: BITMAPS_DIR := resources/bitmaps
    63: 
    64: 
    65: #
    66: # set a sane default for ZYXDEVSUITE, and handle errors well
    67: #
    68: ifeq ($(strip $(ZYXDEVSUITE)),)
    69: ZYXDEVSUITE := /usr/lib/ZyXdevSuite/ZyXdev_arm
    70: ifneq ($(wildcard $(ZYXDEVSUITE)),$(ZYXDEVSUITE))
    71: $(error "The default ZYXDEVSUITE directory $(ZYXDEVSUITE) does not exist, probably you want to override this by setting the ZYXDEVSUITE variable in your environment to the location where you installed it.")
    72: endif
    73: endif
    74: 
    75: ifneq ($(wildcard $(ZYXDEVSUITE)),$(ZYXDEVSUITE))
    76: $(error "ZYXDEVSUITE directory $(ZYXDEVSUITE) does not exist")
    77: endif
    78: 
    79: ZYXDEVSUITEARM := $(ZYXDEVSUITE)
    80: 
    81: # add zyxdevsuitearm to path
    82: PATH := $(ZYXDEVSUITEARM)/bin:$(PATH)
    83: 
    84: include $(ZYXDEVSUITEARM)/ds_rules
    85: 
    86: # all files in SOUND_DIR are audio files
    87: AUDIO_FILES := \
    88: 	$(foreach file, \
    89: 		$(notdir $(wildcard $(SOUND_DIR)/*.*)), \
    90: 		$(CURDIR)/$(SOUND_DIR)/$(file))
    91: 
    92: # all *.splash.*jpg files in BITMAPS_DIR are splash image files
    93: SPLASH_FILES := \
    94: 	$(foreach file, \
    95: 		$(notdir $(wildcard $(BITMAPS_DIR)/*.splash.*jpg)), \
    96: 		$(CURDIR)/$(BITMAPS_DIR)/$(file))
    97: PNG_IMAGE_FILES := \
    98: 	$(foreach file, \
    99: 		$(notdir $(wildcard $(BITMAPS_DIR)/*.png)), \
   100: 		$(CURDIR)/$(BITMAPS_DIR)/$(file))
   101: BMP_IMAGE_FILES := \
   102: 	$(foreach file, \
   103: 		$(notdir $(wildcard $(BITMAPS_DIR)/*font*.bmp)), \
   104: 		$(CURDIR)/$(BITMAPS_DIR)/$(file))
   105: 
   106: # TODO: obsolete with wfbl
   107: SERVE_NIFI := zyx-serve-nifi
   108: 
   109: # define c compiler, etc...
   110: NDS_ARM9_CC = arm-eabi-gcc 
   111: NDS_ARM9_CXX = arm-eabi-gcc 
   112: NDS_ARM9_OBJCOPY = arm-eabi-objcopy
   113: NDS_ARM7_CC = arm-eabi-gcc 
   114: NDS_ARM7_CXX = arm-eabi-gcc 
   115: NDS_ARM7_OBJCOPY = arm-eabi-objcopy
   116: 
   117: # common includes and libdirs
   118: INCLUDES :=
   119: # todo: figure out why this instead of "../load_bin.h" in 
   120: #       /cloader/arm9_loader.c causes problems
   121: #INCLUDES += $(CURDIR)
   122: LIBDIRS :=
   123: 
   124: # initialize common_cflags
   125: COMMON_CFLAGS := 
   126: COMMON_CFLAGS += -Wall
   127: 
   128: ifneq ($(strip $(FMODE)),)
   129: 	COMMON_CFLAGS += -DFMODE=$(FMODE)
   130: endif
   131: 
   132: # use this to enable compilation of the 'pro' version
   133: #COMMON_CFLAGS += -DIM_POOR_OR_LICENSED_OR_NOT
   134: COMMON_CFLAGS += -DIM_POOR_OR_LICENSED_OR_NOT
   135: 
   136: # add common cflags
   137: COMMON_CFLAGS += -O2
   138: 
   139: # perhaps some way exists to use gdb, maybe with desmume
   140: #COMMON_CFLAGS += -g
   141: 
   142: # TODO: educational comments for all these
   143: # nds arm9 flags
   144: NDS_ARM9_CFLAGS := $(COMMON_CFLAGS)
   145: NDS_ARM9_CFLAGS += -mcpu=arm9tdmi
   146: NDS_ARM9_CFLAGS += -mtune=arm9tdmi
   147: NDS_ARM9_CFLAGS += -DARM9
   148: NDS_ARM9_CFLAGS += -fomit-frame-pointer
   149: NDS_ARM9_CFLAGS += -ffast-math
   150: NDS_ARM9_CFLAGS += -mthumb
   151: NDS_ARM9_CFLAGS += -mthumb-interwork
   152: 
   153: # nds arm7 flags
   154: NDS_ARM7_CFLAGS := $(COMMON_CFLAGS)
   155: NDS_ARM7_CFLAGS += -mcpu=arm7tdmi
   156: NDS_ARM7_CFLAGS += -mtune=arm7tdmi
   157: NDS_ARM7_CFLAGS += -DARM7
   158: NDS_ARM7_CFLAGS += -fomit-frame-pointer
   159: NDS_ARM7_CFLAGS += -ffast-math
   160: NDS_ARM7_CFLAGS += -mthumb
   161: NDS_ARM7_CFLAGS += -mthumb-interwork
   162: 
   163: 
   164: NDS_ARM9_INCLUDES := $(INCLUDES)
   165: NDS_ARM7_INCLUDES := $(INCLUDES)
   166: NDS_ARM9_LIBDIRS := $(LIBDIRS)
   167: NDS_ARM7_LIBDIRS := $(LIBDIRS)
   168: 
   169: NDS_ARM9_INCLUDES += $(ZYXDEVSUITE)/include
   170: NDS_ARM7_INCLUDES += $(ZYXDEVSUITE)/include
   171: 
   172: NDS_ARM9_LIBDIRS += $(ZYXDEVSUITE)/lib
   173: NDS_ARM7_LIBDIRS += $(ZYXDEVSUITE)/lib
   174: 
   175: NDS_ARM9_INCLUDES += $(ZYXDEVSUITE)/libnds/include
   176: NDS_ARM7_INCLUDES += $(ZYXDEVSUITE)/libnds/include
   177: 
   178: NDS_ARM9_LIBDIRS += $(ZYXDEVSUITE)/libnds/lib
   179: NDS_ARM7_LIBDIRS += $(ZYXDEVSUITE)/libnds/lib
   180: 
   181: NDS_ARM9_INCLUDES += $(ZYXDEVSUITE)/arm-eabi/include
   182: NDS_ARM7_INCLUDES += $(ZYXDEVSUITE)/arm-eabi/include
   183: 
   184: NDS_ARM9_INCLUDES += $(BITMAPS_DIR)
   185: 
   186: #NDS_ARM9_INCLUDES += /usr/include
   187: #NDS_ARM7_INCLUDES += /usr/include
   188: #NDS_ARM9_LIBDIRS += /usr/lib
   189: #NDS_ARM7_LIBDIRS += /usr/lib
   190: 
   191: NDS_ARM9_LIBS :=
   192: NDS_ARM7_LIBS :=
   193: # maxmod sound library
   194: NDS_ARM9_LIBS += mm9
   195: NDS_ARM7_LIBS += mm7
   196: # flash fat filesystem access library
   197: NDS_ARM9_LIBS += fat
   198: # wifi library
   199: NDS_ARM9_LIBS += dswifi9
   200: NDS_ARM7_LIBS += dswifi7
   201: # main nds library
   202: NDS_ARM9_LIBS += nds9
   203: NDS_ARM7_LIBS += nds7
   204: 
   205: NDS_ARM9_DEPS = $(patsubst %.c,%.d,$(NDS_ARM9_SOURCES)) 
   206: NDS_ARM7_DEPS = $(patsubst %.c,%.d,$(NDS_ARM7_SOURCES)) 
   207: 
   208: NDS_ARM9_OBJECTS = $(patsubst %.c,%.o,$(NDS_ARM9_SOURCES)) 
   209: # XXX first pass is with .s, then try generating .bin's and loading from fat
   210: NDS_ARM9_OBJECTS += $(patsubst %.jpg,%.o,$(SPLASH_FILES)) 
   211: NDS_ARM9_OBJECTS += $(patsubst %.bmp,%.o,$(BMP_IMAGE_FILES)) 
   212: NDS_ARM9_OBJECTS += $(patsubst %.png,%.o,$(PNG_IMAGE_FILES)) 
   213: NDS_ARM9_OBJECTS += sounds.bin.o
   214: NDS_ARM9_OBJECTS += load.bin.o
   215: 
   216: NDS_ARM7_OBJECTS = $(patsubst %.c,%.o,$(NDS_ARM7_SOURCES)) 
   217: 
   218: NDS_ARM9_INCFLAGS := $(foreach dir,$(NDS_ARM9_INCLUDES),-I$(dir)) 
   219: NDS_ARM7_INCFLAGS := $(foreach dir,$(NDS_ARM7_INCLUDES),-I$(dir)) 
   220: 
   221: NDS_ARM9_LDFLAGS := $(foreach dir,$(NDS_ARM9_LIBDIRS),-L$(dir)) 
   222: NDS_ARM7_LDFLAGS := $(foreach dir,$(NDS_ARM7_LIBDIRS),-L$(dir)) 
   223: 
   224: NDS_ARM9_LDFLAGS += $(foreach lib,$(NDS_ARM9_LIBS),-l$(lib)) 
   225: NDS_ARM7_LDFLAGS += $(foreach lib,$(NDS_ARM7_LIBS),-l$(lib)) 
   226: 
   227: NDS_ARM9_CFLAGS += $(NDS_ARM9_INCFLAGS)
   228: NDS_ARM7_CFLAGS += $(NDS_ARM7_INCFLAGS)
   229: 
   230: # arm9 gets to use the implicit rules, while arm7 uses static rules
   231: CC = $(NDS_ARM9_CC)
   232: OBJCOPY = $(NDS_ARM9_OBJCOPY)
   233: CFLAGS = $(NDS_ARM9_CFLAGS)
   234: 
   235: #############################################################################
   236: #############
   237: # Variables #
   238: #############
   239: 
   240: ALL_TARGETS = \
   241: 	gzmcp-client.nds \
   242: 	nroot
   243: 
   244: 
   245: #############################################################################
   246: #############################################################################
   247: # Build Rules 
   248: 
   249: #############################################################################
   250: # Build Rules :: pattern rules
   251: 
   252: # the generic rule is 
   253: %.o: %.c
   254: 	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
   255: 
   256: # note: based on nds examples, this must(?) be near default as well, though
   257: #       not mentioned as such in the gnu make manual where it was copied
   258: #       from.  
   259: # note: using -MM instead of -M to ignore system headers
   260: # note: using -MG because we generate some header files (e.g. sounds.h)
   261: %.d: %.c
   262: 	set -e; rm -f $@; \
   263: 	 $(CC) -MM -MG $(CPPFLAGS) $< > $@.$$$$; \
   264: 	 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
   265: 	 rm -f $@.$$$$
   266: 
   267: # image resources via grit
   268: %.s %.h: %.bmp %.grit
   269: 	grit $< -fts -o$*.s
   270: %.s %.h: %.jpg %.grit
   271: 	grit $< -fts -o$*.s
   272: %.s %.h: %.png %.grit
   273: 	grit $< -fts -o$*.s
   274: %.o: %.s
   275: 	$(CC) -x assembler-with-cpp -c -o $*.o $<
   276: 
   277: #############################################################################
   278: # Build Rules :: special first is default
   279: 
   280: default:
   281: 	make all
   282: 	make nroot
   283: 	make tidy
   284: 
   285: all: $(ALL_TARGETS)
   286: 
   287: #############################################################################
   288: # Build Rules :: ARM7 
   289: $(NDS_ARM7_OBJECTS): %.o: %.c
   290: 	$(NDS_ARM7_CC) -c $(NDS_ARM7_CFLAGS) $(CPPFLAGS) $< -o $@
   291: 
   292: #############################################################################
   293: # Build Rules :: ARM9/rest
   294: 
   295: cloader/arm9_loader.o: load_bin.h
   296: 
   297: # desmume testing
   298: dmtest: gzmcp-client.nds
   299: 	desmume gzmcp-client.nds
   300: 
   301: # for development serving up via wmb
   302: dev: 
   303: 	make all
   304: 	make tidy
   305: 	make serve
   306: 
   307: serve: gzmcp-client.nds
   308: 	sudo $(SERVE_NIFI) gzmcp-client_r4.nds
   309: 
   310: nroot: gzmcp-client.nds
   311: 	mkdir -p nroot/gzmcp
   312: 	mkdir -p nroot/boot
   313: 	cp gzmcp-client.nds nroot/gzmcp/
   314: 	cp resources/text/example.defaults nroot/gzmcp/defaults
   315: 	cp resources/text/example.midispec nroot/gzmcp/midispec
   316: 	cp resources/text/example.presets nroot/gzmcp/presets
   317: 	cp resources/text/example.zds-boot.cfg nroot/boot/zds-boot.cfg
   318: 	cp resources/text/example.zds-boot.cfg nroot/boot/g_zds-boot.cfg
   319: 	
   320: 
   321: # generate maxmod soundbank sources that can be referenced by our sources
   322: # -d is to make it suitable for an nds project
   323: sounds.bin sounds.h: $(AUDIO_FILES)
   324: 	mmutil $^ -d -osounds.bin -hsounds.h
   325: 
   326: sounds.bin.o sounds_bin.h: sounds.bin
   327: 	$(bin2o)
   328: 
   329: load.bin.o load_bin.h: load.bin
   330: 	# bin2o needs much improvement
   331: 	$(bin2o)
   332: 
   333: # todo: specify deps as a patsubst on all files under cl/bl
   334: load.bin:
   335: 	make -C cloader/bootloader
   336: 
   337: .PHONY: tidy
   338: tidy:
   339: 	@echo removing transient files
   340: 	rm -f *~
   341: 	rm -f *.o
   342: 	rm -f *.d
   343: 	rm -f *.elf
   344: 	rm -f nds-client.arm[79]
   345: 	rm -f .builderr 
   346: 	rm -f .map
   347: 	rm -f load_bin.h
   348: 	rm -f load.bin
   349: 	rm -f sounds.h
   350: 	rm -f sounds_bin.h
   351: 	rm -f sounds.bin
   352: 	rm -f cloader/*~ 
   353: 	rm -rf cloader/bootloader/build
   354: 	rm -f cloader/bootloader/*~ 
   355: 	rm -f cloader/bootloader/source/*~ 
   356: 	rm -f cloader/*.o
   357: 	rm -f cloader/*.d
   358: 
   359: .PHONY: clean
   360: clean: tidy
   361: 	make -C cloader/bootloader clean 
   362: 	rm -rf nroot 
   363: 	rm -rf nroot 
   364: 	rm -f $(ALL_TARGETS) 
   365: 	rm -f $(NDS_ARM9_DEPS) 
   366: 	rm -f $(NDS_ARM7_DEPS) 
   367: 	rm -f $(NDS_ARM9_OBJECTS) 
   368: 	rm -f $(NDS_ARM7_OBJECTS) 
   369: 	rm -f $(BITMAPS_DIR)/*.[sh]
   370: 
   371: 
   372: nds-client.arm7: $(NDS_ARM7_OBJECTS)
   373: 
   374: 	$(NDS_ARM7_CC) \
   375: 		-specs=ds_arm7.specs \
   376: 		$(NDS_ARM7_CFLAGS) \
   377: 		$(CPPFLAGS) \
   378: 		-mno-fpu \
   379: 		-Wl,-Map,.map \
   380: 		$^ \
   381: 		$(NDS_ARM7_LDFLAGS) \
   382: 		-o $@.elf
   383: 
   384: 	$(NDS_ARM7_OBJCOPY) \
   385: 		-O binary \
   386: 		$@.elf \
   387: 		$@
   388: 
   389: # TODO: split this into at least two targets
   390: nds-client.arm9: $(NDS_ARM9_OBJECTS)
   391: 
   392: 	$(CC) \
   393: 		-specs=ds_arm9.specs \
   394: 		$(CFLAGS) \
   395: 		$(CPPFLAGS) \
   396: 		-mno-fpu \
   397: 		-Wl,-Map,.map \
   398: 		$^ \
   399: 		$(NDS_ARM9_LDFLAGS) \
   400: 		-o $@.elf
   401: 
   402: 	$(OBJCOPY) \
   403: 		-O binary \
   404: 		$@.elf \
   405: 		$@
   406: 
   407: 
   408: gzmcp-client.nds: nds-client.arm9 nds-client.arm7
   409: 	
   410: 	@echo BUILD: running ndstool to combine arm7 and arm9 executables...
   411: 	ndstool	\
   412: 		-c $@ \
   413: 		-9 nds-client.arm9 \
   414: 		-7 nds-client.arm7 \
   415: 		-o $(BANNER_IMAGE) \
   416: 		-b $(LOGO_IMAGE) \
   417: 		$(LOGO_STRING) \
   418: 		>> ./.builderr 2>&1
   419: 	
   420: 	@echo
   421: 	@echo
   422: 	@echo BUILD: shiny new nds homebrew ready to rock-n-roll!!!
   423: 	@echo
   424: 	@echo
   425: 
   426: 
   427: # include the automatically generated dependencies
   428: # note: the - means it is ok if some of the dependency files do not exist
   429: -include $(NDS_ARM9_DEPS)
   430: -include $(NDS_ARM7_DEPS)
   431: 
   432: #
   433: # END MAKEFILE
   434: #############################################################################
   435: