Re: [cc65] Makefiles?

From: Karri Kaksonen <karri1sipo.fi>
Date: 2009-01-19 08:35:43
Oliver Schmidt kirjoitti:
> Hi,
>
>   
>> I need a *small* makefile program for WinXP and WinVista as I have a dial-up
>> internet connecion.  Can anybody tell me where to find such?  I'm having a
>> hard time googling it.
>>     
>
> After 10 seconds of googling: http://www.steve.org.uk/Software/make/
>
>   

I have some input to this discussion that is cc65 specific.

One problem with large projects is that you cannot put lots of filenames 
on the linker command line.
Therefore I use 3 makefiles to get things done. Please look at the files 
called "objlists" and "others" to get the idea.
I have used this technique in Windows and Linux and it works well in 
both environments.

In the top folder I have a Makefile like this:

/MegaPak/Makefile:
all:
    "$(MAKE)" -C resident;
    "$(MAKE)" -C intro;
    "$(MAKE)" -C abcmusic;
    "$(MAKE)" -C mygame;
    "$(MAKE)" -C music;
    "$(MAKE)" -C miniloader;
    "$(MAKE)" -C cart clean;
    "$(MAKE)" -C cart;

clean:
    "$(MAKE)" -C resident clean;
    "$(MAKE)" -C intro clean;
    "$(MAKE)" -C abcmusic clean;
    "$(MAKE)" -C mygame clean;
    "$(MAKE)" -C music clean;
    "$(MAKE)" -C miniloader clean;
    "$(MAKE)" -C cart clean;


This Makefile compiles all my subdirectories that contain all kind of stuff.

In a subdirectory I have a Makefile like this:
/MegaPak/miniloader/Makefile:
################ EDIT THESE ########################

# As we are producing a cart we want to put our code
# in a loadable segment so that we can load it in RAM
# when we need it and throw it away after use.
# Without these defines the code would go into the
# main RAM and stay there forever.
CODE_SEGMENT=MINILOADER_CODE
DATA_SEGMENT=MINILOADER_DATA
RODATA_SEGMENT=MINILOADER_RODATA
BSS_SEGMENT=MINILOADER_BSS

# These are the object files we want this makefile to produce
objects= \
    aaminiexec.o \
    minidir.o \
    minihelp.o \
    miniload.o

############### DONT EDIT BELOW THIS ############### 

# We are compiling for Atari Lynx
SYS=lynx

# These are the names of the tools we use
CO=co65
CC=cc65
AS=ca65
AR=ar65
SPRPCK=sprpck
CP=cp
RM=rm
ECHO=echo
TOUCH=touch

# The flag for adding stuff to a library
ARFLAGS=a

# The flags for compiling C-code
CFLAGS=-I . -t $(SYS) --add-source -O -Or -Cl -Os
SEGMENTS=--code-name $(CODE_SEGMENT) \
    --rodata-name $(RODATA_SEGMENT) \
    --bss-name $(BSS_SEGMENT) \
    --data-name $(DATA_SEGMENT)

# Include paths we may need for compilations
ifeq ($(CC65_INC),)
    CC65_INC=/usr/lib/cc65/include
endif
ifeq ($(CC65_ASMINC),)
    CC65_ASMINC="$(CC65_INC)/../asminc"
endif

# Rule for making a *.o file out of a *.c file
%.o: %.c
    $(CC) $(CFLAGS) $(SEGMENTS) -o $(patsubst %c, %s, $(notdir $<)) $<
    $(AS) -o $@ $(AFLAGS) $(*).s
    $(RM) $*.s

# Rule for making a *.o file out of a *.s file
%.o: %.s
    $(AS) -t lynx -I $(CC65_ASMINC) -o $@ $(AFLAGS) $<

# Rule for making a *.o file out of a *.bmp file
%.o : %.bmp
    $(SPRPCK) -t6 -p2 $<
    $(ECHO) .global _$* > $*.s
    $(ECHO) .segment \"$(RODATA_SEGMENT)\" >> $*.s
    $(ECHO) _$*: .incbin \"$*.spr\" >> $*.s
    $(AS) -t lynx -o $@ $(AFLAGS) $*.s
    $(RM) $*.s
    $(RM) $*.pal
    $(RM) $*.spr

all: $(objects)
    $(TOUCH) objlist
    $(RM) objlist
    for obj in $(objects); do $(ECHO) ../miniloader/$$obj >> objlist; done

clean :
    $(TOUCH) $(objects)
    $(RM) $(objects)
    $(TOUCH) objlist
    $(RM) objlist


The interesting thing in this Makefile is that it will list all the 
objects that are required in a file called "objlist".
This objlist file will later be used by the linker.


The last Makefile is for creating the actual target cart. In 
MegaPak/cart/Makefile:
#
# makefile to create a complete Atari Lynx cart using the
# the www.cc65.org compiler
#
# Currently the only user applications are "intro" for the startup
# and "sketch" for a drawing application.
# If you want more loadable modules you need to add them just like
# the "sketch" is created.
# Note: you need to add them to this Makefile, to the directory.s
# and you have to create a new directory for the new module.

################ EDIT THESE ########################

# These are the object files we want this makefile to produce
objects= \
    lnxhdr.o \
    encrypt1024.o \
    directory.o \
    title.o

objlists = \
    ../resident/objlist \
    ../miniloader/objlist \
    ../abcmusic/objlist \
    ../intro/objlist \
    ../mygame/objlist \
    ../music/objlist

others = \
    @../resident/objlist \
    @../miniloader/objlist \
    @../abcmusic/objlist \
    @../intro/objlist \
    @../mygame/objlist \
    @../music/objlist

target = cart.lnx

############### DONT EDIT BELOW THIS ############### 

# We are compiling for Atari Lynx
SYS=lynx

# These are the names of the tools we use
CL=cl65
CO=co65
CC=cc65
AS=ca65
AR=ar65
SPRPCK=sprpck
CP=cp
RM=rm
ECHO=echo
TOUCH=touch

# The flag for adding stuff to a library
ARFLAGS=a

# The flags for compiling C-code
CFLAGS=-I . -t $(SYS) --add-source -O -Or -Cl -Os

# Include paths we may need for compilations
ifeq ($(CC65_INC),)
    CC65_INC=/usr/lib/cc65/include
endif
ifeq ($(CC65_ASMINC),)
    CC65_ASMINC="$(CC65_INC)/../asminc"
endif

# Rule for making a *.o file out of a *.c file
%.o: %.c
    $(CC) $(CFLAGS) -o $(patsubst %c, %s, $(notdir $<)) $<
    $(AS) -o $@ $(AFLAGS) $(*).s
    $(RM) $*.s

# Rule for making a *.o file out of a *.s file
%.o: %.s
    $(AS) -t lynx -I $(CC65_ASMINC) -o $@ $(AFLAGS) $<

# Rule for making a *.o file out of a *.bmp file
%.o : %.bmp
    $(SPRPCK) -t6 -p2 $<
    $(ECHO) .global _$* > $*.s
    $(ECHO) .segment \"RODATA\" >> $*.s
    $(ECHO) _$*: .incbin \"$*.spr\" >> $*.s
    $(AS) -t lynx -o $@ $(AFLAGS) $*.s
    $(RM) $*.s
    $(RM) $*.pal
    $(RM) $*.spr

all: $(target)

title.o : songbird.bmp
    $(SPRPCK) -t6 songbird.bmp
    $(AS) -t lynx -I $(CC65_ASMINC) -o title.o $(AFLAGS) title.s
    $(RM) songbird.pal
    $(RM) songbird.spr

$(target) : $(objects) $(objlists)
    $(CL) -t $(SYS) -o $@ -m lynxcart.map -C lynxcart.cfg $(objects) 
$(others) lynx.lib
    $(RM) null

clean :
    $(TOUCH) $(objects)
    $(RM) $(objects)
    $(TOUCH) $(target)
    $(RM) $(target)
    $(TOUCH) lynxcart.map
    $(RM) lynxcart.map


----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Jan 19 08:36:00 2009

This archive was generated by hypermail 2.1.8 : 2009-01-19 08:36:03 CET