Use arm-specific version of 'ar' instead of system one
[fw/pdclib] / Makefile
index b88acff9e9b7f56998b0efbb299f175d2302bc67..cca5a4f1fc49bdb4ce1f16ebd8c9862379cafd92 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,18 +1,33 @@
 # $Id$
 
-DESTDIR=
+ifndef prefix
 prefix=/opt/cortex
+endif
+
 libdir=$(prefix)/lib
 bindir=$(prefix)/bin
 includedir=$(prefix)/include
 
 #CPU=cortex-m3
-CPUS=cortex-m0 cortex-m3
+CPUS=cortex-m0 cortex-m3 cortex-m4
 FIRSTCPU=cortex-m0
 CPU=none
 BUILD=build-$(CPU)
 
-CC=$(bindir)/arm-none-eabi-gcc
+# CPU specific compiler flags
+ifeq ($(CPU),cortex-m0)
+CPU_FLAGS=
+endif
+ifeq ($(CPU),cortex-m3)
+CPU_FLAGS=
+endif
+ifeq ($(CPU),cortex-m4)
+CPU_FLAGS=-mfloat-abi=hard
+endif
+
+#CC=$(bindir)/arm-none-eabi-gcc
+CC=/usr/bin/arm-none-eabi-gcc
+AR=/usr/bin/arm-none-eabi-ar
 
 # This is where you chose which platform to compile for (see 'make links' / './platform')
 PLATFORM := altos
@@ -46,24 +61,27 @@ REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
 
 WARNINGS := -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wuninitialized -Wstrict-prototypes 
-PLATFORM_FLAGS=-nostdinc -mlittle-endian -mthumb -mcpu=$(CPU) -ffreestanding -nostdlib
-CFLAGS := -fno-builtin -Os -g -std=c99 -I./$(BUILD)/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
+PLATFORM_FLAGS=-mlittle-endian -mthumb -mcpu=$(CPU) -ffreestanding $(CPU_FLAGS)
+CFLAGS := -Os -g -std=c99 -I./$(BUILD)/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
 
 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
 
-PDCLIB=pdclib-$(CPU).a
+PDCLIBNAME=libpdclib
+PDCLIB=$(PDCLIBNAME)-$(CPU).a
 
 all:
-       +for i in $(CPUS); do make CPU=$$i links pdclib-$$i.a; done
+       +for i in $(CPUS); do make CPU=$$i links; make CPU=$$i $(PDCLIBNAME)-$$i.a; done
 
 install: install-hdr
-       +for i in $(CPUS); do make CPU=$$i install-lib-$$i; done
+       @echo '######' install
+       +for i in $(CPUS); do make CPU=$$i prefix=$(prefix) install-lib-$$i; done
 
 install-hdr:
-       +make CPU=$(FIRSTCPU) install-hdr-$(FIRSTCPU)
+       @echo '######' install-hdr
+       +make CPU=$(FIRSTCPU) prefix=$(prefix) install-hdr-$(FIRSTCPU)
 
 clean:
-       +for i in $(CPUS); do make CPU=$$i clean-$$i; done
+       +for i in $(CPUS); do make CPU=$$i clean-$$i; rm -rf build-$$i; done
 
 check: all testdrivers regtestdrivers
        @echo
@@ -81,17 +99,20 @@ check: all testdrivers regtestdrivers
 
 $(PDCLIB): $(BUILD) $(OBJFILES)
        @echo " AR      $@"
-       @ar rc $@ $(OBJFILES)
+       @$(AR) rc $@ $(OBJFILES)
        @echo
 
 install-$(CPU): install-$(CPU)-lib install-hdr
+       @echo '######' install-$(CPU)
 
-install-lib-$(CPU): $(BUILD) $(PDCLIB)
+install-lib-$(CPU): $(PDCLIB)
+       @echo '######' install-lib-$(CPU)
        install -D -c $(PDCLIB) $(DESTDIR)$(libdir)/$(PDCLIB)
 
 install-hdr-$(CPU): $(BUILD) $(BUILDHDRFILES)
+       @echo '######' install-hdr-$(CPU)
        for file in $(BUILDHDRFILES); do \
-               install -D -c $$file $(DESTDIR)$(includedir)/.; \
+               install -m 0444 -D -c $$file $(DESTDIR)$(includedir)/.; \
        done
 
 test: functions/$(FILE)
@@ -131,6 +152,7 @@ links: $(BUILD)
        @for dir in $$(find functions includes internals -type d); do mkdir -p $(BUILD)/$$dir; done
        @for file in $$(find platform/$(PLATFORM) -mindepth 2 -type f ! -path *.svn* -printf "%P\n"); do if [ ! -f $(BUILD)/$$file ]; then ln -s $$(dirname $$file | sed "s@[^/]*@..@g")/../platform/$(PLATFORM)/$$file $(BUILD)/$$file; fi; done
        @for super in $(PROJDIRS); do for file in $$(find $$super -type f ! -path *.svn* -printf "%P\n"); do if [ ! -f $(BUILD)/$$super/$$file ]; then ln -s $$(echo $$file | sed "s@[^/]*@..@g")/../$$super/$$file $(BUILD)/$$super/$$file; fi; done; done
+       if [ -f platform/$(PLATFORM)/include-exclude ]; then for ex in `cat platform/$(PLATFORM)/include-exclude`; do echo exclude $$ex; rm -f $(BUILD)/includes/$$ex; done; fi; true
 
 unlink: $(BUILD)
        @echo "Unlinking platform files..."
@@ -161,8 +183,8 @@ help:
        @echo "(Usage: USERFLAGS=\"flags\" make [...])."
 
 %.o: %.c Makefile
-       echo " CC       $(patsubst functions/%,%,$@)"
-       $(CC) $(CFLAGS) -MMD -MP -I./$(BUILD)/includes -c $< -o $@
+       @echo " CC      $(patsubst functions/%,%,$@)"
+       @$(CC) $(CFLAGS) -MMD -MP -I./$(BUILD)/includes -c $< -o $@
 
 %_t: %.c Makefile $(PDCLIB)
        @echo " CC      $(patsubst functions/%,%,$@)"
@@ -173,4 +195,4 @@ help:
        @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@
 
 $(BUILD):
-       mkdir -p $(BUILD)
\ No newline at end of file
+       mkdir -p $(BUILD)