Replace Makefiles with CMake build system

- CMake build process handles dependencies much more effectively

- Cleaner separation of test and binary builds

- permit co-existing test and multiple architecture builds

- add support for AVR from cmake-avr:
      https://github.com/mkleemann/cmake-avr

- new build process avoids creating files in the src directory
This commit is contained in:
Dave 2021-03-04 22:27:15 -06:00
parent 1bcf10ae29
commit e9c38e3c51
10 changed files with 751 additions and 392 deletions

View File

@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.19)
# Set up the toolchain and other architecture specific details
if(ARCH MATCHES atmega328p)
message(STATUS "setting up for atmega328p")
set(AVF_H_FUSE 0xd9)
set(AVR_L_FUSE 0xd2)
set(AVR_MCU ${ARCH})
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generic-gcc-avr.cmake)
set (ASDF_OUT_TARGET ${ASDF_TARGET}.elf)
elseif(ARCH MATCHES atmega2560)
message(STATUS "setting up for atmega2560")
set(AVF_H_FUSE 0x99)
set(AVR_L_FUSE 0xe7)
set(AVR_MCU ${ARCH})
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generic-gcc-avr.cmake)
set (ASDF_OUT_TARGET ${ASDF_TARGET}.elf)
endif()
project("asdf"
VERSION 2.0
DESCRIPTION "A customizable keyboard matrix controller for retrocomputers"
LANGUAGES C)
set_property(GLOBAL PROPERTY C_STANDARD 99)
set(ASDF_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
message("SRC Dir is ${ASDF_SRC_DIR}")
set (ASDF_TARGET_NAME asdf-${ARCH}-${PROJECT_VERSION})
set (ASDF_EXECUTABLE_TARGET_NAME ${ASDF_TARGET_NAME})
macro(temporary_config_file SOURCE_FILE GENERATED_FILE)
configure_file(${SOURCE_FILE} ${GENERATED_FILE}
COPYONLY)
list(APPEND TEMPFILE_LIST ${GENERATED_FILE})
endmacro(temporary_config_file)
if(ARCH MATCHES test)
add_subdirectory(test)
else()
if((ARCH MATCHES atmega328p) OR (ARCH MATCHES atmega2560))
set (ASDF_EXECUTABLE_TARGET_NAME ${ASDF_TARGET_NAME}.elf)
function(custom_add_executable EXECUTABLE_NAME)
add_avr_executable(${EXECUTABLE_NAME} ${ARGN})
endfunction(custom_add_executable)
endif()
add_subdirectory(src)
endif()

View File

@ -1 +0,0 @@
This directory contains the files resulting from the build process

View File

@ -0,0 +1,407 @@
##########################################################################
# "THE ANY BEVERAGE-WARE LICENSE" (Revision 42 - based on beer-ware
# license):
# <dev@layer128.net> wrote this file. As long as you retain this notice
# you can do whatever you want with this stuff. If we meet some day, and
# you think this stuff is worth it, you can buy me a be(ve)er(age) in
# return. (I don't like beer much.)
#
# Matthias Kleemann
##########################################################################
##########################################################################
# The toolchain requires some variables set.
#
# AVR_MCU (default: atmega8)
# the type of AVR the application is built for
# AVR_L_FUSE (NO DEFAULT)
# the LOW fuse value for the MCU used
# AVR_H_FUSE (NO DEFAULT)
# the HIGH fuse value for the MCU used
# AVR_UPLOADTOOL (default: avrdude)
# the application used to upload to the MCU
# NOTE: The toolchain is currently quite specific about
# the commands used, so it needs tweaking.
# AVR_UPLOADTOOL_PORT (default: usb)
# the port used for the upload tool, e.g. usb
# AVR_PROGRAMMER (default: avrispmkII)
# the programmer hardware used, e.g. avrispmkII
##########################################################################
##########################################################################
# options
##########################################################################
#option(WITH_MCU "Add the mCU type to the target file name." OFF)
##########################################################################
# executables in use
##########################################################################
find_program(AVR_CC avr-gcc)
find_program(AVR_CXX avr-g++)
find_program(AVR_OBJCOPY avr-objcopy)
find_program(AVR_SIZE_TOOL avr-size)
find_program(AVR_OBJDUMP avr-objdump)
##########################################################################
# toolchain starts with defining mandatory variables
##########################################################################
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR avr)
set(CMAKE_C_COMPILER ${AVR_CC})
set(CMAKE_CXX_COMPILER ${AVR_CXX})
##########################################################################
# Identification
##########################################################################
set(AVR 1)
##########################################################################
# some necessary tools and variables for AVR builds, which may not
# defined yet
# - AVR_UPLOADTOOL
# - AVR_UPLOADTOOL_PORT
# - AVR_PROGRAMMER
# - AVR_MCU
# - AVR_SIZE_ARGS
##########################################################################
# default upload tool
if(NOT AVR_UPLOADTOOL)
set(
AVR_UPLOADTOOL avrdude
CACHE STRING "Set default upload tool: avrdude"
)
find_program(AVR_UPLOADTOOL avrdude)
endif(NOT AVR_UPLOADTOOL)
# default upload tool port
if(NOT AVR_UPLOADTOOL_PORT)
set(
AVR_UPLOADTOOL_PORT usb
CACHE STRING "Set default upload tool port: usb"
)
endif(NOT AVR_UPLOADTOOL_PORT)
# default programmer (hardware)
if(NOT AVR_PROGRAMMER)
set(
AVR_PROGRAMMER avrispmkII
CACHE STRING "Set default programmer hardware model: avrispmkII"
)
endif(NOT AVR_PROGRAMMER)
# default MCU (chip)
if(NOT AVR_MCU)
set(
AVR_MCU atmega8
CACHE STRING "Set default MCU: atmega8 (see 'avr-gcc --target-help' for valid values)"
)
endif(NOT AVR_MCU)
#default avr-size args
if(NOT AVR_SIZE_ARGS)
if(APPLE)
set(AVR_SIZE_ARGS -B)
else(APPLE)
set(AVR_SIZE_ARGS -C;--mcu=${AVR_MCU})
endif(APPLE)
endif(NOT AVR_SIZE_ARGS)
# prepare base flags for upload tool
set(AVR_UPLOADTOOL_BASE_OPTIONS -p ${AVR_MCU} -c ${AVR_PROGRAMMER})
# use AVR_UPLOADTOOL_BAUDRATE as baudrate for upload tool (if defined)
if(AVR_UPLOADTOOL_BAUDRATE)
set(AVR_UPLOADTOOL_BASE_OPTIONS ${AVR_UPLOADTOOL_BASE_OPTIONS} -b ${AVR_UPLOADTOOL_BAUDRATE})
endif()
##########################################################################
# check build types:
# - Debug
# - Release
# - RelWithDebInfo
#
# Release is chosen, because of some optimized functions in the
# AVR toolchain, e.g. _delay_ms().
##########################################################################
if(NOT ((CMAKE_BUILD_TYPE MATCHES Release) OR
(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) OR
(CMAKE_BUILD_TYPE MATCHES Debug) OR
(CMAKE_BUILD_TYPE MATCHES MinSizeRel)))
set(
CMAKE_BUILD_TYPE Release
CACHE STRING "Choose cmake build type: Debug Release RelWithDebInfo MinSizeRel"
FORCE
)
endif(NOT ((CMAKE_BUILD_TYPE MATCHES Release) OR
(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) OR
(CMAKE_BUILD_TYPE MATCHES Debug) OR
(CMAKE_BUILD_TYPE MATCHES MinSizeRel)))
##########################################################################
##########################################################################
# target file name add-on
##########################################################################
if(WITH_MCU)
set(MCU_TYPE_FOR_FILENAME "-${AVR_MCU}")
else(WITH_MCU)
set(MCU_TYPE_FOR_FILENAME "")
endif(WITH_MCU)
##########################################################################
# add_avr_executable
# - IN_VAR: EXECUTABLE_NAME
#
# Creates targets and dependencies for AVR toolchain, building an
# executable. Calls add_executable with ELF file as target name, so
# any link dependencies need to be using that target, e.g. for
# target_link_libraries(<EXECUTABLE_NAME>-${AVR_MCU}.elf ...).
#
##########################################################################
function(add_avr_executable EXECUTABLE_NAME)
message(STATUS "target name: ${EXECUTABLE_NAME}")
if(NOT ARGN)
message(FATAL_ERROR "No source files given for ${EXECUTABLE_NAME}.")
endif(NOT ARGN)
# set file names
set(elf_file ${EXECUTABLE_NAME}${MCU_TYPE_FOR_FILENAME}.elf)
set(hex_file ${EXECUTABLE_NAME}${MCU_TYPE_FOR_FILENAME}.hex)
set(lst_file ${EXECUTABLE_NAME}${MCU_TYPE_FOR_FILENAME}.lst)
set(map_file ${EXECUTABLE_NAME}${MCU_TYPE_FOR_FILENAME}.map)
set(eeprom_image ${EXECUTABLE_NAME}${MCU_TYPE_FOR_FILENAME}-eeprom.hex)
message(STATUS "elf name: ${elf_file}")
# elf file
add_executable(${elf_file} EXCLUDE_FROM_ALL ${ARGN})
set_target_properties(
${elf_file}
PROPERTIES
COMPILE_FLAGS "-mmcu=${AVR_MCU}"
LINK_FLAGS "-mmcu=${AVR_MCU} -Wl,--gc-sections -mrelax -Wl,-Map,${map_file}"
)
add_custom_command(
OUTPUT ${hex_file}
COMMAND
${AVR_OBJCOPY} -j .text -j .data -O ihex ${elf_file} ${hex_file}
COMMAND
${AVR_SIZE_TOOL} ${AVR_SIZE_ARGS} ${elf_file}
DEPENDS ${elf_file}
)
add_custom_command(
OUTPUT ${lst_file}
COMMAND
${AVR_OBJDUMP} -d ${elf_file} > ${lst_file}
DEPENDS ${elf_file}
)
# eeprom
add_custom_command(
OUTPUT ${eeprom_image}
COMMAND
${AVR_OBJCOPY} -j .eeprom --set-section-flags=.eeprom=alloc,load
--change-section-lma .eeprom=0 --no-change-warnings
-O ihex ${elf_file} ${eeprom_image}
DEPENDS ${elf_file}
)
add_custom_target(
${EXECUTABLE_NAME}
ALL
DEPENDS ${hex_file} ${lst_file} ${eeprom_image}
)
set_target_properties(
${EXECUTABLE_NAME}
PROPERTIES
OUTPUT_NAME "${elf_file}"
)
# clean
get_directory_property(clean_files ADDITIONAL_MAKE_CLEAN_FILES)
set_directory_properties(
PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "${map_file}"
)
# upload - with avrdude
add_custom_target(
upload_${EXECUTABLE_NAME}
${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} ${AVR_UPLOADTOOL_OPTIONS}
-U flash:w:${hex_file}
-P ${AVR_UPLOADTOOL_PORT}
DEPENDS ${hex_file}
COMMENT "Uploading ${hex_file} to ${AVR_MCU} using ${AVR_PROGRAMMER}"
)
# upload eeprom only - with avrdude
# see also bug http://savannah.nongnu.org/bugs/?40142
add_custom_target(
upload_${EXECUTABLE_NAME}_eeprom
${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} ${AVR_UPLOADTOOL_OPTIONS}
-U eeprom:w:${eeprom_image}
-P ${AVR_UPLOADTOOL_PORT}
DEPENDS ${eeprom_image}
COMMENT "Uploading ${eeprom_image} to ${AVR_MCU} using ${AVR_PROGRAMMER}"
)
# disassemble
add_custom_target(
disassemble_${EXECUTABLE_NAME}
${AVR_OBJDUMP} -h -S ${elf_file} > ${EXECUTABLE_NAME}.lst
DEPENDS ${elf_file}
)
endfunction(add_avr_executable)
##########################################################################
# add_avr_library
# - IN_VAR: LIBRARY_NAME
#
# Calls add_library with an optionally concatenated name
# <LIBRARY_NAME>${MCU_TYPE_FOR_FILENAME}.
# This needs to be used for linking against the library, e.g. calling
# target_link_libraries(...).
##########################################################################
function(add_avr_library LIBRARY_NAME)
if(NOT ARGN)
message(FATAL_ERROR "No source files given for ${LIBRARY_NAME}.")
endif(NOT ARGN)
set(lib_file ${LIBRARY_NAME}${MCU_TYPE_FOR_FILENAME})
add_library(${lib_file} STATIC ${ARGN})
set_target_properties(
${lib_file}
PROPERTIES
COMPILE_FLAGS "-mmcu=${AVR_MCU}"
OUTPUT_NAME "${lib_file}"
)
if(NOT TARGET ${LIBRARY_NAME})
add_custom_target(
${LIBRARY_NAME}
ALL
DEPENDS ${lib_file}
)
set_target_properties(
${LIBRARY_NAME}
PROPERTIES
OUTPUT_NAME "${lib_file}"
)
endif(NOT TARGET ${LIBRARY_NAME})
endfunction(add_avr_library)
##########################################################################
# avr_target_link_libraries
# - IN_VAR: EXECUTABLE_TARGET
# - ARGN : targets and files to link to
#
# Calls target_link_libraries with AVR target names (concatenation,
# extensions and so on.
##########################################################################
function(avr_target_link_libraries EXECUTABLE_TARGET)
if(NOT ARGN)
message(FATAL_ERROR "Nothing to link to ${EXECUTABLE_TARGET}.")
endif(NOT ARGN)
get_target_property(TARGET_LIST ${EXECUTABLE_TARGET} OUTPUT_NAME)
foreach(TGT ${ARGN})
if(TARGET ${TGT})
get_target_property(ARG_NAME ${TGT} OUTPUT_NAME)
list(APPEND NON_TARGET_LIST ${ARG_NAME})
else(TARGET ${TGT})
list(APPEND NON_TARGET_LIST ${TGT})
endif(TARGET ${TGT})
endforeach(TGT ${ARGN})
target_link_libraries(${TARGET_LIST} ${NON_TARGET_LIST})
endfunction(avr_target_link_libraries EXECUTABLE_TARGET)
##########################################################################
# avr_target_include_directories
#
# Calls target_include_directories with AVR target names
##########################################################################
function(avr_target_include_directories EXECUTABLE_TARGET)
if(NOT ARGN)
message(FATAL_ERROR "No include directories to add to ${EXECUTABLE_TARGET}.")
endif()
get_target_property(TARGET_LIST ${EXECUTABLE_TARGET} OUTPUT_NAME)
set(extra_args ${ARGN})
target_include_directories(${TARGET_LIST} ${extra_args})
endfunction()
##########################################################################
# avr_target_compile_definitions
#
# Calls target_compile_definitions with AVR target names
##########################################################################
function(avr_target_compile_definitions EXECUTABLE_TARGET)
if(NOT ARGN)
message(FATAL_ERROR "No compile definitions to add to ${EXECUTABLE_TARGET}.")
endif()
get_target_property(TARGET_LIST ${EXECUTABLE_TARGET} OUTPUT_NAME)
set(extra_args ${ARGN})
target_compile_definitions(${TARGET_LIST} ${extra_args})
endfunction()
function(avr_generate_fixed_targets)
# get status
add_custom_target(
get_status
${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT} -n -v
COMMENT "Get status from ${AVR_MCU}"
)
# get fuses
add_custom_target(
get_fuses
${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT} -n
-U lfuse:r:-:b
-U hfuse:r:-:b
COMMENT "Get fuses from ${AVR_MCU}"
)
# set fuses
add_custom_target(
set_fuses
${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT}
-U lfuse:w:${AVR_L_FUSE}:m
-U hfuse:w:${AVR_H_FUSE}:m
COMMENT "Setup: High Fuse: ${AVR_H_FUSE} Low Fuse: ${AVR_L_FUSE}"
)
# get oscillator calibration
add_custom_target(
get_calibration
${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT}
-U calibration:r:${AVR_MCU}_calib.tmp:r
COMMENT "Write calibration status of internal oscillator to ${AVR_MCU}_calib.tmp."
)
# set oscillator calibration
add_custom_target(
set_calibration
${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT}
-U calibration:w:${AVR_MCU}_calib.hex
COMMENT "Program calibration status of internal oscillator from ${AVR_MCU}_calib.hex."
)
endfunction()

115
firmware/asdf/make-build-dirs.sh Executable file
View File

@ -0,0 +1,115 @@
#!/opt/local/bin/bash
CMAKE_TARGETS=""
VALID_TARGETS=""
add_valid_target() {
VALID_TARGETS+=" $1 "
}
add_valid_target test
add_valid_target atmega328p
add_valid_target atmega2560
build_arch() {
echo one: $1 two: $2 three: $3
echo star: "[$*]"
echo amp: "[$@]"
for target_arch in "$@"
do
if [[ ! -d "build-$target_arch" ]]
then
mkdir "build-$target_arch"
fi
if [[ -d "build-$target_arch" ]]
then
(cd "build-$target_arch" && cmake -DARCH=$target_arch ..)
fi
done
}
main() {
parse $@
echo "Valid: $VALID_TARGETS"
echo "Selected: $CMAKE_TARGETS"
run
}
run() {
echo "$CMAKE_TARGETS"
build_arch $CMAKE_TARGETS
}
syntax() {
echo "Usage:"
echo " $0 -t target [-t target] ..."
echo " $0 -a"
echo " $0 -h"
echo ""
echo "Options:"
echo " -t add an architecture directory"
echo " -h Display this help message"
echo " -a Add all valid architecture directories"
echo ""
echo "Valid targets: $VALID_TARGETS"
}
parse() {
local SYNTAX=""
local ALL=""
while getopts "t:ah" optname
do
case "$optname" in
h)
SYNTAX="yes"
;;
a)
ALL="yes"
;;
t)
# Test that target is valid and not already specified
if [[ " $VALID_TARGETS " == *" $OPTARG "* ]]
then
if [[ " $CMAKE_TARGETS " != *" $OPTARG "* ]]
then
CMAKE_TARGETS+=" $OPTARG "
fi
else
SYNTAX="yes"
fi
;;
esac
done
if [[ "$SYNTAX" == "yes" ]]; then
syntax && die
fi
if [[ "$ALL" == "yes" ]]
then
CMAKE_TARGETS="$VALID_TARGETS"
fi
if [[ -z "$CMAKE_TARGETS" ]]
then
die "No targets!"
fi
}
die() {
builtin echo $@
exit 1
}
main $@
exit 0

View File

@ -0,0 +1,71 @@
set (KEYMAP "production")
message("C compiler: ${CMAKE_C_COMPILER}")
temporary_config_file(${ASDF_SRC_DIR}/Arch/asdf_arch_${ARCH}.h ${CMAKE_CURRENT_BINARY_DIR}/asdf_arch.h)
temporary_config_file(${ASDF_SRC_DIR}/Arch/asdf_arch_${ARCH}.c ${CMAKE_CURRENT_BINARY_DIR}/asdf_arch.c)
temporary_config_file(${ASDF_SRC_DIR}/Keymaps/asdf_all_keymap_defs_${KEYMAP}.h ${CMAKE_CURRENT_BINARY_DIR}/asdf_keymap_defs.h)
list(APPEND C_FLAGS
-std=c99
-Wall
-funsigned-char
-funsigned-bitfields
-ffunction-sections
-fdata-sections
-fpack-struct
-fshort-enums
-O2
-Wall
-Wextra
-Wpointer-arith
-Wcast-align
-Wwrite-strings
-Wswitch-default
-Wunreachable-code
-Winit-self
-Wmissing-field-initializers
-Wno-unknown-pragmas
-Wstrict-prototypes
-Wundef
-Wold-style-definition
)
list (APPEND SOURCES
asdf.c
${CMAKE_CURRENT_BINARY_DIR}/asdf_arch.c
asdf_buffer.c
asdf_hook.c
asdf_keymaps.c
asdf_modifiers.c
asdf_physical.c
asdf_repeat.c
asdf_virtual.c
main.c
)
# add the executable
if (COMMAND custom_add_executable)
custom_add_executable(${ASDF_TARGET_NAME}
${SOURCES}
)
else()
add_executable(${ASDF_TARGET_NAME})
endif()
target_include_directories(${ASDF_EXECUTABLE_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_options(${ASDF_EXECUTABLE_TARGET_NAME}
PRIVATE
${CFLAGS}
)

View File

@ -1,24 +0,0 @@
# -*- makefile -*-
ARCH ?= atmega2560
KEYMAP ?= production
TARGET_MAKEFILE ?= Makefile.app
BUILD_DIR = ../build
all: app
app:
make -f $(TARGET_MAKEFILE) ARCH=$(ARCH) KEYMAP=$(KEYMAP)
test:
make -f Makefile.test
clean:
make -f $(TARGET_MAKEFILE) clean
make -f Makefile.test clean
cleanall:
make -f $(TARGET_MAKEFILE) cleanall
make -f Makefile.test cleanall

View File

@ -1,162 +0,0 @@
# -*- makefile -*-
ARCH ?= atmega2560
KEYMAP ?= production
ARCH_TOKEN = _Arch_$(ARCH)
TARGET = asdf-$(ARCH)
TEST_DIR = ../test
UNITY_DIR = $(TEST_DIR)/unity
BUILD_DIR = ../build
DEP_DIR := ./.deps
TARGET_BIN := $(BUILD_DIR)/$(TARGET).elf
TARGET_HEX := $(BUILD_DIR)/$(TARGET).hex
TARGET_MAP := $(BUILD_DIR)/$(TARGET).map
UNITY_SCRIPTS = $(UNITY_DIR)/auto
ARCH_DIR = Arch
KEYMAPS_DIR = Keymaps
VERSION =
RELEASE=
SIZE_COMMAND = avr-size
CLEAN_FILES =
CLEANALL_FILES =
CC = avr-gcc
CFLAGS = -std=c99
CFLAGS += -Wall
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -O2
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Wpointer-arith
CFLAGS += -Wcast-align
CFLAGS += -Wwrite-strings
CFLAGS += -Wswitch-default
CFLAGS += -Wunreachable-code
CFLAGS += -Winit-self
CFLAGS += -Wmissing-field-initializers
CFLAGS += -Wno-unknown-pragmas
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
CFLAGS += -Wold-style-definition
CFLAGS += -mmcu=$(ARCH)
LDFLAGS = -Wl,-Map=$(TARGET_MAP)
LDFLAGS += -Wl,--start-group
LDFLAGS += -Wl,-lm
LDFLAGS += -Wl,--end-group
LDFLAGS += -Wl,--gc-sections
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
MAKEDEPEND = $(CPP) $(DEPFLAGS) $(CPPFLAGS) $< \
| sed -n 's,^\# *[0-9][0-9]* *"\([^"<]*\)".*,$@: \1\n\1:,p' \
| sort -u > $*.d
SRC_FILES = main.c asdf.c asdf_modifiers.c asdf_repeat.c asdf_keymaps.c
SRC_FILES += asdf_buffer.c asdf_arch.c asdf_virtual.c asdf_physical.c
SRC_FILES += asdf_hook.c
OBJ_FILES := $(SRC_FILES:.c=.o)
DEP_FILES := $(SRC_FILES:%.c=$(DEP_DIR)/%.d)
MAP_FILE = $(TARGET).map
CLEAN_FILES += $(MAP_FILE)
CLEAN_FILES += $(TARGET_BIN)
CLEAN_FILES += $(TARGET_MAP)
CLEANALL_FILES += $(TARGET_HEX)
MAKEFILES = Makefile
GENERATED_FILES = conventions.h machine.h
ALL_FILES = $(MAKEFILES) $(SRC_FILES) $(TXTFILES) $(GENERATED_FILES)
.SUFFIXES:
.SUFFIXES: .c .o .bin .hex
all: $(TARGET_HEX)
%.d : %.c $(DEP_DIR)/%.d | $(DEP_DIR)
@$(MAKEDEPEND)
$(DEP_DIR): ; @mkdir -p $@
$(DEPFILES):
include $(wildcard $(DEPFILES))
%.o: %.c $(DEP_DIR)/%.d | $(DEP_DIR)
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) $<
asdf_keymap_defs.h: $(KEYMAPS_DIR)/asdf_all_keymap_defs_$(KEYMAP).h $(KEYMAPDEFS_H_TOKEN)
cp $< $@
GENERATED_FILES += asdf_keymap_defs.h
asdf_arch.c: $(ARCH_DIR)/asdf_arch_$(ARCH).c $(ARCH_C_TOKEN)
cp $< $@
GENERATED_FILES += asdf_arch.c
asdf_arch.h: $(ARCH_DIR)/asdf_arch_$(ARCH).h $(ARCH_H_TOKEN)
cp $< $@
GENERATED_FILES += asdf_arch.h
$(ARCH_H_TOKEN):
touch $@
$(ARCH_C_TOKEN):
touch $@
$(KEYMAP_H_TOKEN):
touch $@
size:
$(SIZE_COMMAND) $(TARGET_BIN)
$(TARGET_HEX): $(TARGET_BIN)
avr-objcopy -j .text -j .data -j .fuses -O ihex $< $@
$(TARGET_BIN): $(OBJ_FILES)
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $^
$(SIZE_COMMAND) $(TARGET_BIN)
asdf_keymaps.o: asdf_keymaps.c asdf.h asdf_ascii.h asdf_modifiers.h asdf_arch.h asdf_keymaps.h asdf_keymap_defs.h
main.o: main.c asdf.h asdf_arch.h
asdf.o: asdf.c asdf.h asdf_arch.h asdf_keymaps.h asdf_config.h asdf_keymap_defs.h
asdf_repeat.o: asdf_repeat.c asdf_repeat.h asdf_config.h
asdf_buffer.o: asdf_buffer.c asdf.h asdf_config.h
asdf_modifiers.o: asdf_modifiers.c asdf_modifiers.h
asdf_virtual.o: asdf_virtual.c asdf_virtual.h asdf_arch.h asdf_physical.h asdf_keymap_defs.h
asdf_physical.o: asdf_physical.c asdf_virtual.h asdf_arch.h
asdf_hook.o: asdf_hook.c asdf_hook.h asdf_arch.h asdf_keymap_defs.h
tags: $(SRC_FILES)
etags $(SRC_FILES)
CLEAN_FILES += $(TEST_BUILD_FILES) _Arch_* *.o
CLEAN_FILES += ~* *\#
CLEANALL_FILES += $(GENERATED_FILES) $(TARGET_BUILD_FILES) $(TEST_BUILD_FILES)
.PHONY: clean
clean:
rm -f $(CLEAN_FILES)
.PHONY: cleanall
cleanall:
rm -f $(CLEAN_FILES) $(CLEANALL_FILES)

View File

@ -1,21 +0,0 @@
# -*- makefile -*-
DEP_DIR := .deps
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
MAKEDEPEND = $(CPP) $(DEPFLAGS) $(CPPFLAGS) $< \
| sed -n 's,^\# *[0-9][0-9]* *"\([^"<]*\)".*,$@: \1\n\1:,p' \
| sort -u > $*.d
%.d : %.c $(DEP_DIR)/%.d | $(DEPDIR)
@$(MAKEDEPEND)
$(DEP_DIR): ; @mkdir -p $@
DEPFILES := $(SRC_FILES:%.c=$(DEP_DIR)/%.d)
$(DEPFILES):
include $(wildcard $(DEPFILES))

View File

@ -1,184 +0,0 @@
# -*- makefile -*-
ARCH = test
KEYMAP = test
ARCH_TOKEN = _Arch_$(ARCH)
TEST_DIR = ../test
UNITY_DIR = $(TEST_DIR)/unity
BUILD_DIR = ../build
UNITY_SCRIPTS = $(UNITY_DIR)/auto
ARCH_DIR = ./Arch
KEYMAPS_DIR = ./Keymaps
CC = gcc
VERSION =
RELEASE=
CLEAN_FILES =
CLEANALL_FILES =
CFLAGS=-std=c99
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Wpointer-arith
CFLAGS += -Wcast-align
CFLAGS += -Wwrite-strings
CFLAGS += -Wswitch-default
CFLAGS += -Wunreachable-code
CFLAGS += -Winit-self
CFLAGS += -Wmissing-field-initializers
CFLAGS += -Wno-unknown-pragmas
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
CFLAGS += -Wold-style-definition
SRC_FILES = main.c asdf.c asdf_actions.c asdf_modifiers.c asdf_repeat.c asdf_keymaps.c asdf_buffer.c asdf_arch.c
OBJ_FILES = $(SRC_FILES:.c=.o)
ARCH_FILES = asdf_arch.c asdf_arch.h
CLEAN_FILES += ARCH_FILES
TESTS = repeat modifiers keymaps interface keyscan virtual
TEST1 = asdf_repeat
TEST1_SRC = $(TEST_DIR)/test_$(TEST1).c
TEST1_DEPS = ./$(TEST1).c $(UNITY_DIR)/unity.c
TEST1_BUILD = $(BUILD_DIR)/test_$(TEST1)
TEST2 = asdf_modifiers
TEST2_SRC = $(TEST_DIR)/test_$(TEST2).c ./asdf_arch.c ./asdf_virtual.c ./asdf_physical.c
TEST2_DEPS = ./$(TEST2).c $(UNITY_DIR)/unity.c
TEST2_BUILD = $(BUILD_DIR)/test_$(TEST2)
TEST3 = asdf_keymaps
TEST3_SRC = $(TEST_DIR)/test_$(TEST3).c
TEST3_DEPS = ./$(TEST3).c $(UNITY_DIR)/unity.c ./asdf_physical.c \
$(TEST_DIR)/test_asdf_lib.c ./asdf_virtual.c \
./asdf_hook.c ./asdf_modifiers.c ./asdf_arch.c
TEST3_BUILD = $(BUILD_DIR)/test_$(TEST3)
TEST4 = asdf_buffer
TEST4_SRC = $(TEST_DIR)/test_$(TEST4).c
TEST4_DEPS = ./$(TEST4).c $(UNITY_DIR)/unity.c
TEST4_BUILD = $(BUILD_DIR)/test_$(TEST4)
TEST5 = asdf_virtual
TEST5_SRC = $(TEST_DIR)/test_$(TEST5).c
TEST5_DEPS = ./$(TEST5).c $(UNITY_DIR)/unity.c ./asdf_physical.c ./asdf_modifiers.c \
./asdf_hook.c ./asdf_arch.c ./asdf_keymaps.c $(TEST_DIR)/test_asdf_lib.c
TEST5_BUILD = $(BUILD_DIR)/test_$(TEST5)
TEST7 = asdf_hook
TEST7_SRC = $(TEST_DIR)/test_$(TEST7).c ./asdf_arch.c $(TEST_DIR)/test_asdf_lib.c
TEST7_DEPS = ./$(TEST7).c $(UNITY_DIR)/unity.c ./asdf_keymaps.c ./asdf.c \
./asdf_modifiers.c ./asdf_buffer.c \
./asdf_virtual.c ./asdf_physical.c ./asdf_repeat.c
TEST7_BUILD = $(BUILD_DIR)/test_$(TEST7)
.SUFFIXES:
.SUFFIXES: .c .o .bin .hex
%.o: %.c
$(TARGET_CC) -c $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $<
all: test
asdf_keymap_defs.h: $(KEYMAPS_DIR)/asdf_all_keymap_defs_$(KEYMAP).h $(KEYMAPDEFS_H_TOKEN)
cp $< $@
GENERATED_FILES += asdf_keymap_defs.h
asdf_arch.c: $(ARCH_DIR)/asdf_arch_$(ARCH).c _Arch_$(ARCH)
cp $< $@
GENERATED_FILES += asdf_arch.c
asdf_arch.h: $(ARCH_DIR)/asdf_arch_$(ARCH).h _Arch_$(ARCH)
cp $< $@
GENERATED_FILES += asdf_arch.h
$(ARCH_TOKEN):
touch $(ARCH_TOKEN)
asdf_keymaps.c: asdf.h asdf_ascii.h asdf_modifiers.h asdf_arch.h asdf_keymaps.h asdf_keymap_defs.h
asdf_modifiers.c: asdf_modifiers.h asdf_arch.h asdf_keymap_defs.h
asdf_arch.h: asdf_arch.h
asdf_virtual.c: asdf_virtual.h asdf_arch.h asdf_keymap_defs.h
asdf_hook.c: asdf_hook.h asdf_keymap_defs.h asdf_arch.h
tags: $(SRC_FILES)
etags $(SRC_FILES)
.PHONY: test
test: test1 test2 test3 test4 test6 test5 test7
.PHONY: test1
test1: $(TEST1_BUILD)
$(TEST1_BUILD)
.PHONY: test2
test2: $(TEST2_BUILD)
$(TEST2_BUILD)
.PHONY: test3
test3: $(TEST3_BUILD)
$(TEST3_BUILD)
.PHONY: test4
test4: $(TEST4_BUILD)
$(TEST4_BUILD)
.PHONY: test5
test5: $(TEST5_BUILD)
$(TEST5_BUILD)
.PHONY: test6
test6: $(TEST6_BUILD)
$(TEST6_BUILD)
.PHONY: test7
test7: $(TEST7_BUILD)
$(TEST7_BUILD)
$(TEST1_BUILD): $(TEST1_SRC) $(TEST1_DEPS)
$(CC) -o $@ -I. -I$(TEST_DIR) -I$(UNITY_DIR) $(CFLAGS) $(TEST1_SRC) $(TEST1_DEPS)
$(TEST2_BUILD): $(TEST2_SRC) $(TEST2_DEPS)
$(CC) -o $@ -I. -I$(TEST_DIR) -I$(UNITY_DIR) $(CFLAGS) $(TEST2_SRC) $(TEST2_DEPS)
$(TEST3_BUILD): $(TEST3_SRC) $(TEST3_DEPS)
$(CC) -o $@ -I. -I$(TEST_DIR) -I$(UNITY_DIR) $(CFLAGS) $(TEST3_SRC) $(TEST3_DEPS)
$(TEST4_BUILD): $(TEST4_SRC) $(TEST4_DEPS)
$(CC) -o $@ -I. -I$(TEST_DIR) -I$(UNITY_DIR) $(CFLAGS) $(TEST4_SRC) $(TEST4_DEPS)
$(TEST5_BUILD): $(TEST5_SRC) $(TEST5_DEPS)
$(CC) -o $@ -I. -I$(TEST_DIR) -I$(UNITY_DIR) $(CFLAGS) $(TEST5_SRC) $(TEST5_DEPS)
$(TEST6_BUILD): $(TEST6_SRC) $(TEST6_DEPS)
$(CC) -o $@ -I. -I$(TEST_DIR) -I$(UNITY_DIR) $(CFLAGS) $(TEST6_SRC) $(TEST6_DEPS)
$(TEST7_BUILD): $(TEST7_SRC) $(TEST7_DEPS)
$(CC) -o $@ -I. -I$(TEST_DIR) -I$(UNITY_DIR) $(CFLAGS) $(TEST7_SRC) $(TEST7_DEPS)
TEST_BUILD_FILES += $(TEST1_BUILD) $(TEST2_BUILD) $(TEST3_BUILD) $(TEST4_BUILD) $(TEST5_BUILD) $(TEST6_BUILD) $(TEST7_BUILD)
CLEAN_FILES += $(TEST_BUILD_FILES) _Arch_* *.o
CLEAN_FILES += ~* *\#
CLEANALL_FILES += $(GENERATED_FILES) $(TARGET_BUILD_FILES) $(TEST_BUILD_FILES)
.PHONY: clean
clean:
rm -f $(CLEAN_FILES)
.PHONY: cleanall
cleanall:
rm -f $(CLEAN_FILES) $(CLEANALL_FILES)
include Makefile.deps

View File

@ -0,0 +1,100 @@
temporary_config_file(${ASDF_SRC_DIR}/Keymaps/asdf_all_keymap_defs_test.h ${CMAKE_CURRENT_BINARY_DIR}/asdf_keymap_defs.h)
list(APPEND C_FLAGS
"-std=c99"
"-Wall"
"-Wextra"
"-Wpointer-arith"
"-Wcast-align"
"-Wwrite-strings"
"-Wswitch-default"
"-Wunreachable-code"
"-Winit-self"
"-Wmissing-field-initializers"
"-Wno-unknown-pragmas"
"-Wstrict-prototypes"
"-Wundef"
"-Wold-style-definition"
)
list(APPEND TEST_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/unity
${ASDF_SRC_DIR}
${ASDF_SRC_DIR}/Arch
)
add_library(asdf_core
STATIC
${ASDF_SRC_DIR}/asdf.c
${ASDF_SRC_DIR}/asdf_buffer.c
${ASDF_SRC_DIR}/asdf_hook.c
${ASDF_SRC_DIR}/asdf_keymaps.c
${ASDF_SRC_DIR}/asdf_modifiers.c
${ASDF_SRC_DIR}/asdf_physical.c
${ASDF_SRC_DIR}/asdf_repeat.c
${ASDF_SRC_DIR}/asdf_virtual.c
${ASDF_SRC_DIR}/Arch/asdf_arch_test.c
)
target_include_directories(asdf_core
PRIVATE
${ASDF_SRC_DIR}
${ASDF_SRC_DIR}/Arch
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
add_library(test_helpers
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/test_asdf_lib.c
)
target_include_directories(test_helpers
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${ASDF_SRC_DIR}
${CMAKE_BINARY_DIR}
)
target_compile_options(test_helpers
PRIVATE
${CFLAGS}
)
function(setup_test testname)
add_executable(${testname}
${testname}.c
unity/unity.c
)
target_compile_options(${testname}
PRIVATE
${CFLAGS}
)
target_include_directories(${testname}
PRIVATE
${TEST_INCLUDES}
)
target_link_libraries(${testname} asdf_core test_helpers)
add_test(
NAME ${testname}
COMMAND ${CMAKE_BINARY_DIR}/test/${testname}
)
endfunction()
enable_testing()
setup_test(test_asdf_repeat)
setup_test(test_asdf_modifiers)
setup_test(test_asdf_keymaps)
setup_test(test_asdf_buffer)
setup_test(test_asdf_virtual)
setup_test(test_asdf_hook)