cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

Makefile (1938B)


      1#
      2# A Makefile that compiles all .c and .s files in "src" and "res" 
      3# subdirectories and places the output in a "obj" subdirectory
      4#
      5
      6# If you move this project you can change the directory 
      7# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/"
      8GBDK_HOME = ../../../
      9
     10LCC = $(GBDK_HOME)bin/lcc 
     11
     12# You can set flags for LCC here
     13# For example, you can uncomment the line below to turn on debug output
     14# LCCFLAGS = -debug
     15# LCCFLAGS = -v
     16
     17# You can set the name of the .gb ROM file here
     18PROJECTNAME    = Example
     19
     20SRCDIR      = src
     21OBJDIR      = obj
     22RESDIR      = res
     23BINS	    = $(OBJDIR)/$(PROJECTNAME).gb
     24CSOURCES    = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c)))
     25ASMSOURCES  = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s)))
     26OBJS       = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o)
     27
     28all:	prepare $(BINS)
     29
     30compile.bat: Makefile
     31	@echo "REM Automatically generated from Makefile" > compile.bat
     32	@make -sn | sed y/\\//\\\\/ | grep -v make >> compile.bat
     33
     34# Compile .c files in "src/" to .o object files
     35$(OBJDIR)/%.o:	$(SRCDIR)/%.c
     36	$(LCC) $(LCCFLAGS) -c -o $@ $<
     37
     38# Compile .c files in "res/" to .o object files
     39$(OBJDIR)/%.o:	$(RESDIR)/%.c
     40	$(LCC) $(LCCFLAGS) -c -o $@ $<
     41
     42# Compile .s assembly files in "src/" to .o object files
     43$(OBJDIR)/%.o:	$(SRCDIR)/%.s
     44	$(LCC) $(LCCFLAGS) -c -o $@ $<
     45
     46# If needed, compile .c files i n"src/" to .s assembly files
     47# (not required if .c is compiled directly to .o)
     48$(OBJDIR)/%.s:	$(SRCDIR)/%.c
     49	$(LCC) $(LCCFLAGS) -S -o $@ $<
     50
     51
     52$(OBJDIR)/linkfile.lk:	$(OBJS)
     53	rm -f $@
     54	@for obj in $(OBJS); do \
     55		echo $$obj >>$@; \
     56	done
     57
     58# Link the compiled object files (via linkerfile) into a .gb ROM file
     59$(BINS):	$(OBJDIR)/linkfile.lk
     60		$(LCC) $(LCCFLAGS) -o $(BINS) -Wl-f$<
     61
     62prepare:
     63	mkdir -p $(OBJDIR)
     64	mkdir -p $(RESDIR)
     65
     66clean:
     67#	rm -f  *.gb *.ihx *.cdb *.adb *.noi *.map
     68	rm -f  $(OBJDIR)/*.*
     69