diff --git a/Makefile b/Makefile index ac454c8..9214aa6 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,54 @@ -SRC = example.c -SRC+= source/scpi_parser.c -SRC+= source/scpi_regs.c -SRC+= source/scpi_builtins.c -SRC+= source/scpi_errors.c - -HDRS= source/scpi_parser.h -HDRS+= source/scpi_regs.h -HDRS+= source/scpi_builtins.h -HDRS+= source/scpi_errors.h - -CFLAGS += -std=gnu99 +############################################################################### + +# Makefile to build a library for ARM CortexM3 + +FP_FLAGS = -mfloat-abi=hard -mfpu=fpv4-sp-d16 +ARCH_FLAGS = -mthumb -mcpu=cortex-m4 $(FP_FLAGS) + +INCL_DIR = include +SRC_DIR = source + +LIBNAME = arm_cortexM4_scpi + +OBJS = $(SRC_DIR)/scpi_parser.o +OBJS += $(SRC_DIR)/scpi_regs.o +OBJS += $(SRC_DIR)/scpi_errors.o +OBJS += $(SRC_DIR)/scpi_builtins.o + +JUNK = *.o *.d *.elf *.bin *.hex *.srec *.list *.map *.dis *.disasm *.a + +############################################################################### + +PREFIX ?= arm-none-eabi + +CC := $(PREFIX)-gcc +AR := $(PREFIX)-ar + +############################################################################### + +CFLAGS += -Os -ggdb -std=gnu99 -Wfatal-errors CFLAGS += -Wall -Wextra -Wshadow -CFLAGS += -Wwrite-strings -Wold-style-definition -Winline -CFLAGS += -Wredundant-decls -Wfloat-equal -Wsign-compare -Wunused-function +CFLAGS += -Wwrite-strings -Wold-style-definition -Winline -Wmissing-noreturn -Wstrict-prototypes +CFLAGS += -Wredundant-decls -Wfloat-equal -Wsign-compare +CFLAGS += -fno-common -ffunction-sections -fdata-sections -Wunused-function +CFLAGS += -I$(INCL_DIR) +############################################################################### -all: $(SRC) $(HDRS) - gcc $(CFLAGS) $(SRC) -o example.elf +all: lib -run: all - ./example.elf +%.o: %.c + $(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -o $(*).o -c $(*).c + +lib: lib/lib$(LIBNAME).a + +lib/lib$(LIBNAME).a: $(OBJS) + $(Q)$(AR) rcs $@ $(OBJS) clean: - rm -f *.o *.d *.so *.elf *.bin *.hex - cd source - rm -f *.o *.d *.so *.elf *.bin *.hex + $(Q)$(RM) $(JUNK) + $(Q)cd source && $(RM) $(JUNK) + $(Q)cd lib && $(RM) $(JUNK) + $(Q)cd example && $(RM) $(JUNK) + +.PHONY: clean all lib diff --git a/README.md b/README.md index 4b707e3..c921289 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,11 @@ Built-in commands can be overriden in user command array. ## How to use -See main.c for example of how to use the library. +To test it with regular gcc, run the Makefile in the `example` directory. + +The main Makefile builds a library for ARM Cortex M4 (can be easily adjusted for others). + +### Stubs to implement Here's an overview of stubs you have to implement (at the time of writing this readme): diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..9eb068d --- /dev/null +++ b/example/Makefile @@ -0,0 +1,30 @@ +SRC = example.c +SRC += ../source/scpi_parser.c +SRC += ../source/scpi_regs.c +SRC += ../source/scpi_builtins.c +SRC += ../source/scpi_errors.c + +INCL_DIR = ../include + +CFLAGS = -std=gnu99 +CFLAGS += -Wall -Wextra -Wshadow +CFLAGS += -Wwrite-strings -Wold-style-definition -Winline +CFLAGS += -Wredundant-decls -Wfloat-equal -Wsign-compare -Wunused-function + +CC = gcc + +%.o: %.c + + +all: example.elf + +example.elf: $(SRC) + $(Q)$(CC) $(CFLAGS) -I$(INCL_DIR) -o example.elf $(SRC) + +run: example.elf + ./example.elf + +clean: + rm -f *.o *.d *.so *.elf *.bin *.hex + cd ../source + rm -f *.o *.d *.so *.elf *.bin *.hex diff --git a/example.c b/example/example.c similarity index 98% rename from example.c rename to example/example.c index 6d8409a..d34cd0d 100644 --- a/example.c +++ b/example/example.c @@ -2,7 +2,7 @@ #include #include -#include "source/scpi_parser.h" +#include "scpi_parser.h" // ------- TESTING ---------- diff --git a/source/scpi_builtins.h b/include/scpi_builtins.h similarity index 100% rename from source/scpi_builtins.h rename to include/scpi_builtins.h diff --git a/source/scpi_errors.h b/include/scpi_errors.h similarity index 100% rename from source/scpi_errors.h rename to include/scpi_errors.h diff --git a/source/scpi_parser.h b/include/scpi_parser.h similarity index 100% rename from source/scpi_parser.h rename to include/scpi_parser.h diff --git a/source/scpi_regs.h b/include/scpi_regs.h similarity index 100% rename from source/scpi_regs.h rename to include/scpi_regs.h diff --git a/lib/.gitkeep b/lib/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/scpi b/scpi deleted file mode 100755 index 939e605..0000000 Binary files a/scpi and /dev/null differ