<commit_before>.DEFAULT_GOAL := all

PROJECT_NAME := tx

###############################################################################
# Supress or show diagnostic compiler output
ifeq ("$(VERBOSE)", "1")
ECHO :=
else
ifeq ("$(V)", "1")
ECHO :=
else
ECHO := @
endif
endif


###############################################################################
# Toolchain commands
GNU_INSTALL_ROOT 	:= /opt/gcc-arm-none-eabi-5_2-2015q4
GNU_PREFIX       	:= arm-none-eabi
CC               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc'
AS               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as'
AR               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar' -r
LD               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld'
NM               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm'
OBJDUMP          	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump'
OBJCOPY          	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy'
SIZE             	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size'

OPENOCD          	:= /opt/openocd/bin/openocd
OPENOCD_INTERFACE   := stlink-v2
OPENOCD_TARGET      := stm32f1x

MK 				 	:= mkdir -p
RM 					:= rm -rf

OPENCM3_DIR 		:= ./libopencm3
OPENCM3_LIBNAME		:= opencm3_stm32f1


###############################################################################
# Source files, include paths, library paths and libraries
C_SOURCE_FILES += $(abspath main.c)
C_SOURCE_FILES += $(abspath ring_buffer.c)
C_SOURCE_FILES += $(abspath nrf24l01p.c)
C_SOURCE_FILES += $(abspath spi.c)

LIBS += -lc -lnosys
LIBS += -l$(OPENCM3_LIBNAME)

LINKER_SCRIPT = stm32f103c8t6.ld

INC_PATHS += -I$(abspath .)
INC_PATHS += -isystem$(abspath $(OPENCM3_DIR)/include)

LIB_PATHS += -L$(abspath $(OPENCM3_DIR)/lib)


###############################################################################
# Build directory, where all the intermediate files go
OBJECT_DIRECTORY = build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)

# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )


###############################################################################
# CPU architecture
ARCH_FLAGS = -DSTM32F1 -mcpu=cortex-m3 -mthumb -msoft-float -mfix-cortex-m3-ldrd


###############################################################################
# C compiler flags
CFLAGS := $(ARCH_FLAGS)
CFLAGS += --std=c99
CFLAGS += -MD
CFLAGS += -W -Wall -Wextra -Wpedantic
CFLAGS += -Wstrict-prototypes -Wshadow -Wwrite-strings
CFLAGS += -Wdeclaration-after-statement -Waddress -Wlogical-op
CFLAGS += -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations
CFLAGS += -Wmissing-field-initializers -Wdouble-promotion -Wfloat-equal
CFLAGS += -Wswitch-enum -Wswitch-default -Wuninitialized -Wunknown-pragmas
CFLAGS += -Wundef
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -fno-common -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin
CFLAGS += --short-enums -fsigned-char -fpack-struct=4
CFLAGS += -Os

###############################################################################
# Linker flags
LDFLAGS := $(ARCH_FLAGS)
LDFLAGS	+= --static
LDFLAGS	+= -nostartfiles
LDFLAGS += $(LIB_PATHS)
LDFLAGS += -T$(LINKER_SCRIPT)
LDFLAGS += -Wl,-Map=$(LISTING_DIRECTORY)/$(PROJECT_NAME).map
LDFLAGS += -Wl,--gc-sections
LDFLAGS += --specs=nano.specs


###############################################################################
# Create a list of object files and paths
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(sort $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )

vpath %.c $(C_PATHS)

OBJECTS = $(C_OBJECTS)


###############################################################################
# Build rules

# Building all targets
all: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex echosize

# Create build directories
$(BUILD_DIRECTORIES):
	@echo [MKDIR] $@
	$(ECHO)$(MK) $@

# Create objects from C source files
$(OBJECT_DIRECTORY)/%.o: %.c
	@echo [CC] $(notdir $<)
	$(ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<

# Create list files
$(LISTING_DIRECTORY)/%.lst: %.c
	@echo [LIST] $<
	$(ECHO)$(CC) -c -g -Wa,-adlhn $(CFLAGS) $(INC_PATHS) $< -o /dev/null > $@

# Link
$(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
	@echo [LD] $(PROJECT_NAME).out
	$(ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out

# Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out
	@echo [OBJCOPY] $(PROJECT_NAME).bin
	$(ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).bin

# Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out
	@echo [OBJCOPY] $(PROJECT_NAME).hex
	$(ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex

# Create list files that include C code as well as Assembler
list: $(BUILD_DIRECTORIES) $(OBJECTS:.o=.lst)

echosize:
	-@echo ''
	$(ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out
	-@echo ''

clean:
	$(ECHO)$(RM) $(BUILD_DIRECTORIES)

program: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex
	$(OPENOCD) -f interface/$(OPENOCD_INTERFACE).cfg -f target/$(OPENOCD_TARGET).cfg -c "init; reset halt ; nrf51 mass_erase ; sleep 500 ; flash write_image $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex ; reset ; shutdown"

flash: program

reset:
	$(OPENOCD) -f interface/$(OPENOCD_INTERFACE).cfg -f target/$(OPENOCD_TARGET).cfg -c "init; reset ; shutdown"

terminal:
	miniterm.py -p /dev/ttyUSB0 -b 460800


.PHONY: clean program flash reset terminal echosize list all


###############################################################################
# Include (optional) dependency files. Needs -MD in CFLAGS
-include $(OBJECTS:.o=.d)
<commit_msg>Remove CFLAGS that may become an issue<commit_after>.DEFAULT_GOAL := all

PROJECT_NAME := tx

###############################################################################
# Supress or show diagnostic compiler output
ifeq ("$(VERBOSE)", "1")
ECHO :=
else
ifeq ("$(V)", "1")
ECHO :=
else
ECHO := @
endif
endif


###############################################################################
# Toolchain commands
GNU_INSTALL_ROOT 	:= /opt/gcc-arm-none-eabi-5_2-2015q4
GNU_PREFIX       	:= arm-none-eabi
CC               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc'
AS               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as'
AR               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar' -r
LD               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld'
NM               	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm'
OBJDUMP          	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump'
OBJCOPY          	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy'
SIZE             	:= '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size'

OPENOCD          	:= /opt/openocd/bin/openocd
OPENOCD_INTERFACE   := stlink-v2
OPENOCD_TARGET      := stm32f1x

MK 				 	:= mkdir -p
RM 					:= rm -rf

OPENCM3_DIR 		:= ./libopencm3
OPENCM3_LIBNAME		:= opencm3_stm32f1


###############################################################################
# Source files, include paths, library paths and libraries
C_SOURCE_FILES += $(abspath main.c)
C_SOURCE_FILES += $(abspath ring_buffer.c)
C_SOURCE_FILES += $(abspath nrf24l01p.c)
C_SOURCE_FILES += $(abspath spi.c)

LIBS += -lc -lnosys
LIBS += -l$(OPENCM3_LIBNAME)

LINKER_SCRIPT = stm32f103c8t6.ld

INC_PATHS += -I$(abspath .)
INC_PATHS += -isystem$(abspath $(OPENCM3_DIR)/include)

LIB_PATHS += -L$(abspath $(OPENCM3_DIR)/lib)


###############################################################################
# Build directory, where all the intermediate files go
OBJECT_DIRECTORY = build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)

# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )


###############################################################################
# CPU architecture
ARCH_FLAGS = -DSTM32F1 -mcpu=cortex-m3 -mthumb -msoft-float -mfix-cortex-m3-ldrd


###############################################################################
# C compiler flags
CFLAGS := $(ARCH_FLAGS)
CFLAGS += --std=c99
CFLAGS += -MD
CFLAGS += -W -Wall -Wextra -Wpedantic
CFLAGS += -Wstrict-prototypes -Wshadow -Wwrite-strings
CFLAGS += -Wdeclaration-after-statement -Waddress -Wlogical-op
CFLAGS += -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations
CFLAGS += -Wmissing-field-initializers -Wdouble-promotion -Wfloat-equal
CFLAGS += -Wswitch-enum -Wswitch-default -Wuninitialized -Wunknown-pragmas
CFLAGS += -Wundef
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -fno-builtin
CFLAGS += -fsigned-char
CFLAGS += -Os

###############################################################################
# Linker flags
LDFLAGS := $(ARCH_FLAGS)
LDFLAGS	+= --static
LDFLAGS	+= -nostartfiles
LDFLAGS += $(LIB_PATHS)
LDFLAGS += -T$(LINKER_SCRIPT)
LDFLAGS += -Wl,-Map=$(LISTING_DIRECTORY)/$(PROJECT_NAME).map
LDFLAGS += -Wl,--gc-sections
LDFLAGS += --specs=nano.specs


###############################################################################
# Create a list of object files and paths
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(sort $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )

vpath %.c $(C_PATHS)

OBJECTS = $(C_OBJECTS)


###############################################################################
# Build rules

# Building all targets
all: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex echosize

# Create build directories
$(BUILD_DIRECTORIES):
	@echo [MKDIR] $@
	$(ECHO)$(MK) $@

# Create objects from C source files
$(OBJECT_DIRECTORY)/%.o: %.c
	@echo [CC] $(notdir $<)
	$(ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<

# Create list files
$(LISTING_DIRECTORY)/%.lst: %.c
	@echo [LIST] $<
	$(ECHO)$(CC) -c -g -Wa,-adlhn $(CFLAGS) $(INC_PATHS) $< -o /dev/null > $@

# Link
$(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
	@echo [LD] $(PROJECT_NAME).out
	$(ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out

# Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out
	@echo [OBJCOPY] $(PROJECT_NAME).bin
	$(ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).bin

# Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out
	@echo [OBJCOPY] $(PROJECT_NAME).hex
	$(ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex

# Create list files that include C code as well as Assembler
list: $(BUILD_DIRECTORIES) $(OBJECTS:.o=.lst)

echosize:
	-@echo ''
	$(ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).out
	-@echo ''

clean:
	$(ECHO)$(RM) $(BUILD_DIRECTORIES)

program: $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex
	$(OPENOCD) -f interface/$(OPENOCD_INTERFACE).cfg -f target/$(OPENOCD_TARGET).cfg -c "init; reset halt ; nrf51 mass_erase ; sleep 500 ; flash write_image $(OUTPUT_BINARY_DIRECTORY)/$(PROJECT_NAME).hex ; reset ; shutdown"

flash: program

reset:
	$(OPENOCD) -f interface/$(OPENOCD_INTERFACE).cfg -f target/$(OPENOCD_TARGET).cfg -c "init; reset ; shutdown"

terminal:
	miniterm.py -p /dev/ttyUSB0 -b 460800


.PHONY: clean program flash reset terminal echosize list all


###############################################################################
# Include (optional) dependency files. Needs -MD in CFLAGS
-include $(OBJECTS:.o=.d)

{'fraction_non_alphanumeric': 0.26932565789473684, 'fraction_numerical': 0.008799342105263157, 'mean_word_length': 5.33715476810839, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2550831', 'n_tokens_mistral': 4395, 'n_tokens_neox': 4056, 'n_words': 816}