makefile
2004-10-26 by Abdul R Rafiq
Hi,
I am trying to setup my dev. environment using gnuarm and newlib3. the
makefiles in newlib3 makes the entire lib. Is there a sample makefile that
compiles one or two c files? I tried to create makefile based on the one
that came with newlib, but the test2 program created using my makefile does
not work. If I compile the entire newlib using its own makefile, then all
test programs work fine.
below is my makefile. my target is TinyArm50 LPC2119.
thank you in advance.
Abdul
####################################
mdl = ARM
# GCC ARM
#cfgl are link/load parameters passed to ld
#-s means strip all symbols
#-v means verbose output
#-o $@ means use $@ as output filename
#$+ copies dependancies to link line
GNUARM_DIR = c:/gnuarm/
LPC_NEWLIB_DIR = c:/dvp/LPClib/
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
# Figure out where the libraries are
#SYS_LDFLAGS = ${shell arm-elf-gcc -print-search-dirs | grep ^libraries |
sed -e "s/^libraries:.*=/:/g" -e "s/ /\\\\ /g" -e "s/:/ -L /g"}
SYS_LDFLAGS = -L ${GNUARM_DIR}lib/gcc/arm-elf/3.4.1/ -L
${GNUARM_DIR}lib/gcc/ -L ${GNUARM_DIR}arm-elf/lib/arm-elf/3.4.1/ -L
${GNUARM_DIR}arm-elf/lib/ -L ${LPC_NEWLIB_DIR}
cfgl_arm = -v -o$@ -L. ${SYS_LDFLAGS} ${LPC_NEWLIB_DIR}crt0.o $+
# Compile command.
cfg_arm_gc = -c -I ${LPC_NEWLIB_DIR} -Os -o $@
###### The list of targets.
all: gccversion dep test9.hex test9.bin
###### List of all the sources.
sources = test9.c
# Build dependencies for the link phase for all the test programs.
test9.prg: $(sources:.c=.o)
@echo
@echo $(MSG_LINKING) $@
$(cl) $(linkfile_LPC2119)
@echo
$(csize) $@
#
# GNU Compiler ARM
#
ifeq ($(mdl),ARM)
submdl = LPC210X
endif
ifeq ($(submdl),LPC210X)
ar = arm-elf-ar
cc = arm-elf-gcc
cl = arm-elf-ld $(cfgl_arm)
chex = arm-elf-objcopy -O ihex $< $@
cbin = arm-elf-objcopy -O binary $< $@
csize = arm-elf-size
# Providing a named linkfile option here allows programs for
# multiple variants to be built using the same makefile.
linkfile_LPC210X = -Tlpc210x.ld
linkfile_LPC2119 = -Tlpc2119.ld
### Rules for building ###
# Build a dependancy file from a C file. Uses the C compiler to
# determine what files are included and filters the result to
# produce a makefile target: dependancy list
%.d: %.c
@set -e; rm -f $@; \
$(cc) -I ${LPC_NEWLIB_DIR} -M $(clags) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
# How to add an object file to a library.
(%):
$(ar) cr $@ $%
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(cc) $(cfg_arm_gc) $<
# How to build an object file from an assembly file
%.o: %.s
$(cc) $(cfg_arm_gc) $<
# How to create a hex file from the result produced by the
# linker.
%.hex: %.prg
@echo
$(chex)
# How to create a bin file from the result produced by the
# linker.
%.bin: %.prg
$(cbin)
endif
dep : $(sources:.c=.d)
@touch .depend
# Display compiler version information.
gccversion :
@$(cc) --version
clean:
rm -f *.o
rm -f *.a
rm -f *.hex
rm -f *.prg
rm -f *.d
rm -f *.d.[0-9]*
rm -f .depend
# Include dependancies for all the the C source.
ifneq ($(wildward .depend),)
include $(sources:.c=.d)
endif