#
# MSP430 libc
#
-# $Id: Makefile,v 1.47 2008/05/17 02:44:59 cliechti Exp $
-#
-VERSION = 20050812
+VERSION = 20090126
# installation prefix (set this if you don't install by hand)
-
-#prefix = /usr
-prefix = /usr/local/msp430
+ifndef PREFIX
+PREFIX = /usr/local/msp430
+endif
# name of target architecture (used for conform naming)
target = msp430
-prefix_target = ${prefix}/${target}
-bindir = ${prefix_target}/bin
+prefix_target = $(PREFIX)/${target}
+bindir = $(PREFIX)/bin
includedir = ${prefix_target}/include
libdir = ${prefix_target}/lib
-srcdir = .
+SRC_ROOT := .
+BUILD_ROOT = ./Build
-CC = ${target}-gcc
-AS = ${target}-gcc -x assembler-with-cpp
-AR = ${target}-ar
+override CC = ${bindir}/msp430-gcc
+override AS = ${bindir}/msp430-gcc -x assembler-with-cpp
+override AR = ${bindir}/msp430-ar
RM = rm
MD = mkdir -p $@
INSTALL = install -c -m644 $^/
-ASFLAGS = -Wa,-gstabs -D_GNU_ASSEMBLER_
-CFLAGS = -Wall -O2 -g
-
+COMMON := $(LIB_OPTIONS)
# make sure we can find our header files (not the installed ones)
+COMMON += -I$(SRC_ROOT)/../include
+COMMON += -I$(SRC_ROOT)
-ALL_ASFLAGS += -I$(srcdir)/../include -I$(srcdir) ${ASFLAGS}
-ALL_CFLAGS += -I$(srcdir)/../include -I$(srcdir) ${CFLAGS}
+override ASFLAGS = $(COMMON)
+ASFLAGS += -Wa,-gdwarf-2
+#ASFLAGS += -Wa,-ahlmsd=$(<:.S=.lst)
+#ASFLAGS += -v
+override CFLAGS = $(COMMON)
+CFLAGS += -Wall -Os -gdwarf-2
-opt_speed_cflags = -O2
-# further declaration...
+# further declaration...
+SRCDIRS = .
ifdef gnu
- source_dirs = gnu
+ SRCDIRS += gnu
else
- source_dirs = bsd
+ SRCDIRS = bsd
endif
+SRCDIRS += stdlib
+SRCDIRS += string
+SRCDIRS += libm
+
+VPATH := $(addprefix $(SRC_ROOT)/, $(SRCDIRS))
+
+
+all: build
+print:
+ @$(CC) --print-multi-lib
+build: build-crt build-multilib
+install: install-crt install-headers install-multilib
+clean:
+ ${RM} -rf $(BUILD_ROOT)
-source_dirs =
-
-VPATH = $(addprefix $(srcdir)/, $(source_dirs))
-
-all: build-crt build-libc build-libm
-
-install: install-crt install-libc install-headers install-libm
-
-clean: clean-crt clean-libc clean-libm
-
-
-crt_all_objs = \
- crt430x110.o crt430x112.o \
- crt430x1101.o crt430x1111.o crt430x1121.o \
- crt430x1122.o crt430x1132.o \
- crt430x122.o crt430x123.o \
- crt430x1222.o crt430x1232.o \
- crt430x133.o crt430x135.o \
- crt430x1331.o crt430x1351.o \
- crt430x147.o crt430x148.o crt430x149.o \
- crt430x1471.o crt430x1481.o crt430x1491.o \
- crt430x155.o crt430x156.o crt430x157.o \
- crt430x167.o crt430x168.o crt430x169.o crt430x1610.o crt430x1611.o crt430x1612.o \
- crt430x2001.o crt430x2011.o \
- crt430x2002.o crt430x2012.o \
- crt430x2003.o crt430x2013.o \
- crt430x2101.o crt430x2111.o crt430x2121.o crt430x2131.o \
- crt430x2234.o crt430x2254.o crt430x2274.o \
- crt430x247.o crt430x248.o crt430x249.o crt430x2410.o \
- crt430x2471.o crt430x2481.o crt430x2491.o \
- crt430x2416.o crt430x2417.o crt430x2418.o crt430x2419.o \
- crt430x2616.o crt430x2617.o crt430x2618.o crt430x2619.o \
- crt430x311.o crt430x312.o crt430x313.o crt430x314.o crt430x315.o \
- crt430x323.o crt430x325.o crt430x336.o crt430x337.o \
- crt430x412.o crt430x413.o crt430x415.o crt430x417.o \
- crt430x423.o crt430x425.o crt430x427.o \
- crt430x4250.o crt430x4260.o crt430x4270.o \
- crt430xE423.o crt430xE425.o crt430xE427.o \
- crt430xW423.o crt430xW425.o crt430xW427.o \
- crt430xG437.o crt430xG438.o crt430xG439.o \
- crt430x435.o crt430x436.o crt430x437.o \
- crt430x447.o crt430x448.o crt430x449.o \
- crt430xG4616.o crt430xG4617.o crt430xG4618.o crt430xG4619.o
-
-build-crt: ${crt_all_objs}
+.PHONY: clean clean-crt clean-multilib
+
+#--------- crt ---------------------------------------
+BUILDDIR := $(BUILD_ROOT)
+MCU_MSP_LIST := $(strip $(shell $(CC) --target-help | sed -n '/Known MCU names/,/no/p' | sed -n '/msp430/p' 2>/dev/null))
+MCU_CC430_LIST := $(strip $(shell $(CC) --target-help | sed -n '/Known MCU names/,/no/p' | sed -n '/cc430/p' 2>/dev/null))
+CRT_MSP_OBJS := $(addprefix $(BUILDDIR)/, $(addsuffix .o,$(subst msp,crt,$(MCU_MSP_LIST))))
+CRT_CC430_OBJS := $(addprefix $(BUILDDIR)/, $(addsuffix .o,$(subst cc430,crtcc430,$(MCU_CC430_LIST))))
# match by name
+$(CRT_MSP_OBJS): $(BUILDDIR)/crt%.o: gcrt0.S stdlib/__low_level_init.S
+ ${AS} $(ASFLAGS) $(subst crt, -mmcu=msp, $(subst .o,,$(notdir $@))) -c $< -o $@
+
+$(CRT_CC430_OBJS): $(BUILDDIR)/crt%.o: gcrt0.S stdlib/__low_level_init.S
+ ${AS} $(ASFLAGS) $(subst crtcc, -mmcu=cc, $(subst .o,,$(notdir $@))) -c $< -o $@
+
+CRT_OBJS := $(CRT_MSP_OBJS) $(CRT_CC430_OBJS)
-${crt_all_objs}: crt%.o: gcrt0.S
- ${AS} ${CPPFLAGS} -mmcu=msp$* ${ALL_ASFLAGS} -c $(ABSPATH)$< -o $@
+crt: build-crt install-crt
+
+build-crt: makedir-crt $(CRT_OBJS)
clean-crt:
- ${RM} -f ${crt_all_objs}
+ ${RM} -f $(CRT_OBJS)
+
+install-crt: $(CRT_OBJS) ${libdir}
+ ${INSTALL}
-install-crt: ${crt_all_objs} ${libdir}
+makedir-crt:
+ mkdir -p $(BUILDDIR)
+
+#------- multilib --------
+multilib: build-multilib install-multilib
+build-multilib:
+ for i in `$(CC) --print-multi-lib 2>/dev/null`; do \
+ dir=`echo $$i | sed -e 's/;.*$$//'` ; \
+ options=`echo $$i | sed -e 's/[^@]*//' -e 's/@/ -/g'`; \
+ $(MAKE) "MULTILIB_DIR=$$dir" "LIB_OPTIONS=$$options" build-libc build-libm ; \
+ done;
+
+install-multilib:
+ for i in `$(CC) --print-multi-lib 2>/dev/null`; do \
+ dir=`echo $$i | sed -e 's/;.*$$//'` ; \
+ mkdir -p $(libdir)/$$dir; \
+ $(MAKE) MULTILIB_DIR="$$dir" install-libc install-libm ; \
+ done;
+
+.PHONY: clean-multilib clean-libc clean-libm
+clean-multilib:
+ for i in `$(CC) --print-multi-lib 2>/dev/null`; do \
+ dir=`echo $$i | sed -e 's/;.*$$//'` ; \
+ $(MAKE) "MULTILIB_DIR=$$dir" clean-libc clean-libm; \
+ done;
+
+#--------------- headers ---------------
+
+install-headers: ins-hr ins-hs ins-msp430
+
+ins-hr: $(wildcard $(SRC_ROOT)/../include/*.h) ${includedir}
${INSTALL}
-#--------------- a bit of libc
+ins-hs: $(wildcard $(SRC_ROOT)/../include/sys/*.h) ${includedir}/sys
+ ${INSTALL}
-libc_libs = msp1/libc.a msp2/libc.a
+ins-msp430: $(wildcard $(SRC_ROOT)/../include/msp430/*.h) ${includedir}/msp430
+ ${INSTALL}
+
+fix-limits: $(wildcard $(SRC_ROOT)/../include/limits.h) ${includedir}/../../lib/gcc-lib/msp430/3.0/include
+ ${INSTALL}
+
+#--------------- directories ---------------
+$(includedir) $(includedir)/sys $(includedir)/msp430:
+ $(MD)
+#------------------------------------------------------------------------
+#------------------------------------------------------------------------
+#------------------------------------------------------------------------
+#--------------- libc ------------------------
+BUILDDIR=$(BUILD_ROOT)/$(subst .,msp1,$(MULTILIB_DIR))
+LIBC = $(BUILDDIR)/libc.a
libc_c_sources = abs.c atol.c bsearch.c errno.c labs.c \
_init_section__.c malloc.c atoi.c strtol.c strtoul.c \
printf.c vprintf.c vuprintf.c uprintf.c puts.c \
rand.c itoa.c ltoa.c utoa.c ultoa.c
-libc_asm_sources = abort.S div.S exit.S ldiv.S setjmp.S
+libc_asm_sources = abort.S div.S exit.S ldiv.S setjmp.S \
+__do_clear_bss.S __do_copy_data.S __do_global_ctors.S \
+__do_global_dtors.S __init_stack.S __jump_to_main.S \
+__stop_progexec__.S _reset_vector__.S \
+_unexpected_.S
+
libc_str_sources = \
isascii.c memccpy.c strchr.c strncat.c swab.c \
isalpha.c isxdigit.c strcat.c strncasecmp.c strtok.c \
ispunct.c
+LIBC_OBJS = $(addprefix $(BUILDDIR)/,$(libc_str_sources:.c=.o) $(libc_c_sources:.c=.o) $(libc_asm_sources:.S=.o) )
+build-libc: create_libdir $(LIBC)
+create_libdir:
+ mkdir -p $(BUILDDIR)
-libc_msp430_ct_objs_1 = ${libc_c_sources:%.c=%.o}
-libc_msp430_ct_objs_2 = ${libc_c_sources:%.c=%.o}
-
-libc_msp430_asmt_objs_1 = ${libc_asm_sources:%.S=%.o}
-libc_msp430_asmt_objs_2 = ${libc_asm_sources:%.S=%.o}
-
-
-
-libc_msp430_c_objs_1 = $(addprefix msp1/, $(libc_msp430_ct_objs_1))
-libc_msp430_c_objs_2 = $(addprefix msp2/, $(libc_msp430_ct_objs_2))
-
-libc_msp430_S_objs_1 = $(addprefix msp1/, $(libc_msp430_asmt_objs_1))
-libc_msp430_S_objs_2 = $(addprefix msp2/, $(libc_msp430_asmt_objs_2))
-
-
-libc_msp430_objs_1 = ${libc_msp430_c_objs_1}
-libc_msp430_objs_2 = ${libc_msp430_c_objs_2}
-
-
-build-libc: mspdirs ${libc_libs}
-
-mspdirs:
- mkdir -p msp1 msp2
+$(BUILDDIR)/%.o: %.c
+ ${CC} -c $(CFLAGS) $< -o $@
-${libc_msp430_objs_1}: msp1/%.o: stdlib/%.c
- ${CC} -c ${CPPFLAGS} ${ALL_CFLAGS} -mmcu=msp1 -c $(ABSPATH)$< -o $@
-
-${libc_msp430_objs_2}: msp2/%.o: stdlib/%.c
- ${CC} -c ${CPPFLAGS} ${ALL_CFLAGS} -mmcu=msp2 -c $(ABSPATH)$< -o $@
-
-${libc_msp430_S_objs_1}: msp1/%.o: stdlib/%.S
- ${AS} -D_GNU_ASSEMBLER_ -mmcu=msp1 -c $(ABSPATH)$< -o $@
-
-${libc_msp430_S_objs_2}: msp2/%.o: stdlib/%.S
- ${AS} -D_GNU_ASSEMBLER_ -mmcu=msp2 -c $(ABSPATH)$< -o $@
-
-libc_msp430_cstr_objs_1 = ${libc_str_sources:%.c=%.o}
-libc_msp430_cstr_objs_2 = ${libc_str_sources:%.c=%.o}
-
-libc_msp430_str_objs_1 = $(addprefix msp1/, $(libc_msp430_cstr_objs_1))
-libc_msp430_str_objs_2 = $(addprefix msp2/, $(libc_msp430_cstr_objs_2))
-
-
-${libc_msp430_str_objs_1}: msp1/%.o: string/%.c
- ${CC} -c ${CPPFLAGS} ${ALL_CFLAGS} -mmcu=msp1 -c $(ABSPATH)$< -o $@
-
-${libc_msp430_str_objs_2}: msp2/%.o: string/%.c
- ${CC} -c ${CPPFLAGS} ${ALL_CFLAGS} -mmcu=msp2 -c $(ABSPATH)$< -o $@
-
-
-all_objs1 = ${libc_msp430_objs_1} ${libc_msp430_str_objs_1} ${libc_msp430_S_objs_1}
-all_objs2 = ${libc_msp430_objs_2} ${libc_msp430_str_objs_2} ${libc_msp430_S_objs_2}
-
-msp1/libc.a: ${all_objs1}
- ${AR} rc $@ $?
+$(BUILDDIR)/%.o: %.S
+ ${AS} -c $(ASFLAGS) $< -o $@
-msp2/libc.a: ${all_objs2}
+$(LIBC): $(LIBC_OBJS)
${AR} rc $@ $?
.PHONY: clean-libc
clean-libc:
- ${RM} -f msp1/libc.a msp2/libc.a msp1/*.o msp2/*.o
+ ${RM} -f $(LIBC) $(LIBC_OBJS)
-install-libc: ins-msp1 ins-msp2 ins-lib
-
-ins-msp1: msp1/libc.a ${libdir}/msp1
- ${INSTALL}
-
-ins-msp2: msp2/libc.a ${libdir}/msp2
- ${INSTALL}
-
-ins-lib: msp1/libc.a ${libdir}
- ${INSTALL}
-
-#--------------- headers ---------------
-
-install-headers: ins-hr ins-hs ins-msp430
-
-ins-hr: $(wildcard $(srcdir)/../include/*.h) ${includedir}
- ${INSTALL}
-
-ins-hs: $(wildcard $(srcdir)/../include/sys/*.h) ${includedir}/sys
+install-libc: $(LIBC) $(libdir)/$(MULTILIB_DIR)
${INSTALL}
-
-ins-msp430: $(wildcard $(srcdir)/../include/msp430/*.h) ${includedir}/msp430
- ${INSTALL}
-
-fix-limits: $(wildcard $(srcdir)/../include/limits.h) ${includedir}/../../lib/gcc-lib/msp430/3.0/include
- ${INSTALL}
-
-#--------------- directories ---------------
-libc_dirs = msp1 msp2
-install_lib_dirs = $(libdir) $(libdir)/msp1 $(libdir)/msp2
-
-$(libc_dirs) $(install_lib_dirs) $(includedir) $(includedir)/sys $(includedir)/msp430:
- $(MD)
-
-
-#------------------------------------------------------------------------
-#------------------------------------------------------------------------
-#------------------------------------------------------------------------
#------------------------------------------------------------------------
#-------------- Math & FP libs ---------------
math: build-libm
-
basic_fp = divsf.c fixsfsi.c floatdisf.c gtsf.c mulsf.c \
addsf.c eqsf.c fixunssfdi.c floatsisf.c lesf.c negsf.c \
cmpsf.c fixsfdi.c fixunssfsi.c gesf.c ltsf.c subsf.c nesf.c
ef_fmod.c ef_rem_pio2.c kf_rem_pio2.c sf_cos.c sf_infinity.c sf_nextafter.c
-libm_libs = msp1/libm.a msp2/libm.a msp1/libfp.a msp2/libfp.a
-
-libm_msp430_fp_objs_1 = ${basic_fp:%.c=%.o}
-libm_msp430_fp_objs_2 = ${basic_fp:%.c=%.o}
-
-libm_msp430_fc_objs_1 = ${fppfunc:%.c=%.o}
-libm_msp430_fc_objs_2 = ${fppfunc:%.c=%.o}
-
-
-libm_msp430_c_objs_1 = $(addprefix msp1/, $(libm_msp430_fp_objs_1))
-libm_msp430_c_objs_2 = $(addprefix msp2/, $(libm_msp430_fp_objs_2))
-
-libm_msp430_cf_objs_1 = $(addprefix msp1/, $(libm_msp430_fc_objs_1))
-libm_msp430_cf_objs_2 = $(addprefix msp2/, $(libm_msp430_fc_objs_2))
-
-
-build-libm: ${libm_libs}
-
-${libm_msp430_c_objs_1}: msp1/%.o: libm/%.c
- ${CC} -c ${CPPFLAGS} ${ALL_CFLAGS} -mmcu=msp1 -c $(ABSPATH)$< -o $@
-
-${libm_msp430_c_objs_2}: msp2/%.o: libm/%.c
- ${CC} -c ${CPPFLAGS} ${ALL_CFLAGS} -mmcu=msp2 -c $(ABSPATH)$< -o $@
-
-
-${libm_msp430_cf_objs_1}: msp1/%.o: libm/%.c
- ${CC} ${CPPFLAGS} -mmcu=msp1 ${ALL_CFLAGS} -c $(ABSPATH)$< -o $@
+LIBM = $(BUILDDIR)/libm.a
+LIBFP = $(BUILDDIR)/libfp.a
+LIBM_OBJS = $(addprefix $(BUILDDIR)/,$(notdir $(fppfunc:%.c=%.o)))
+LIBFP_OBJS = $(addprefix $(BUILDDIR)/,$(notdir $(basic_fp:%.c=%.o)))
-${libm_msp430_cf_objs_2}: msp2/%.o: libm/%.c
- ${CC} ${CPPFLAGS} -mmcu=msp2 ${ALL_CFLAGS} -c $(ABSPATH)$< -o $@
+build-libm: create_libdir $(LIBM) $(LIBFP)
-
-allm_objs1 = ${libm_msp430_cf_objs_1}
-allm_objs2 = ${libm_msp430_cf_objs_2}
-
-msp1/libm.a: ${allm_objs1}
- ${AR} rc $@ $?
-
-msp2/libm.a: ${allm_objs2}
- ${AR} rc $@ $?
-
-msp1/libfp.a:${libm_msp430_c_objs_1}
+$(LIBM): $(LIBM_OBJS)
${AR} rc $@ $?
-
-msp2/libfp.a:${libm_msp430_c_objs_2}
+$(LIBFP): $(LIBFP_OBJS)
${AR} rc $@ $?
-install-libm: insm-msp1 insm-msp2 insm-lib
-
-insm-msp1: msp1/libm.a msp1/libfp.a ${libdir}/msp1
- ${INSTALL}
-
-insm-msp2: msp2/libm.a msp2/libfp.a ${libdir}/msp2
- ${INSTALL}
-
-insm-lib: msp1/libm.a ${libdir}
+install-libm: $(LIBM) $(LIBFP) $(libdir)/$(MULTILIB_DIR)
${INSTALL}
-.PHONY: clean-libm
clean-libm:
- ${RM} -f msp1/libm.a msp2/libm.a msp1/libfp.a msp2/libfp.a msp1/*.o msp2/*.o
+ ${RM} -f $(LIBM) $(LIBFP) $(LIBM_OBJS) $(LIBFP_OBJS)