From 3e91c553c18d236de8ea85b01b1b03e7ba482e62 Mon Sep 17 00:00:00 2001 From: Hanspeter Portner Date: Sun, 8 Jan 2017 17:29:33 +0100 Subject: [PATCH] prototype gilab ci recipe. --- .gitlab-ci.yml | 72 ++++++++++++++++++++++++++++++ CMakeLists.txt | 4 ++ README.md | 2 +- VERSION | 1 + cmake/arm-linux-gnueabihf.cmake | 18 ++++++++ cmake/i686-linux-gnu.cmake | 7 +++ cmake/i686-w64-mingw32.cmake | 23 ++++++++++ cmake/universal-apple-darwin.cmake | 20 +++++++++ cmake/x86_64-linux-gnu.cmake | 4 ++ cmake/x86_64-w64-mingw32.cmake | 23 ++++++++++ dfuse_pack.c | 32 ++++++------- 11 files changed, 189 insertions(+), 17 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 VERSION create mode 100644 cmake/arm-linux-gnueabihf.cmake create mode 100644 cmake/i686-linux-gnu.cmake create mode 100644 cmake/i686-w64-mingw32.cmake create mode 100644 cmake/universal-apple-darwin.cmake create mode 100644 cmake/x86_64-linux-gnu.cmake create mode 100644 cmake/x86_64-w64-mingw32.cmake diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..bf7dae6 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,72 @@ +stages: + - build + - deploy + +.variables_template: &variables_definition + variables: + BASE_NAME: "dfuse_pack" + PKG_CONFIG_PATH: "/opt/lv2/lib/pkgconfig:/opt/${CI_BUILD_NAME}/lib/pkgconfig" + TOOLCHAIN_FILE: "${CI_PROJECT_DIR}/cmake/${CI_BUILD_NAME}.cmake" + +.common_template: &common_definition + <<: *variables_definition + stage: build + artifacts: + name: "${BASE_NAME}-$(cat VERSION)-${CI_BUILD_NAME}" + paths: + - "${BASE_NAME}-$(cat VERSION)/" + +.build_template: &build_definition + <<: *common_definition + script: + - mkdir build + - pushd build + - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${CI_PROJECT_DIR}/${BASE_NAME}-$(cat ../VERSION)/${CI_BUILD_NAME}" -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE} .. + - cmake .. # needed for darwin + - make + - make install + +.universal_linux_template: &universal_linux_definition + image: ventosus/universal-linux-gnu + <<: *build_definition + +.arm_linux_template: &arm_linux_definition + image: ventosus/arm-linux-gnueabihf + <<: *build_definition + +.universal_w64_template: &universal_w64_definition + image: ventosus/universal-w64-mingw32 + <<: *build_definition + +.universal_apple_template: &universal_apple_definition + image: ventosus/universal-apple-darwin + <<: *build_definition + +# building in docker +x86_64-linux-gnu: + <<: *universal_linux_definition + +i686-linux-gnu: + <<: *universal_linux_definition + +arm-linux-gnueabihf: + <<: *arm_linux_definition + +x86_64-w64-mingw32: + <<: *universal_w64_definition + +i686-w64-mingw32: + <<: *universal_w64_definition + +universal-apple-darwin: + <<: *universal_apple_definition + +pack: + <<: *variables_definition + stage: deploy + script: + - echo 'packing up...' + artifacts: + name: "${BASE_NAME}-$(cat VERSION)" + paths: + - "${BASE_NAME}-$(cat VERSION)/" diff --git a/CMakeLists.txt b/CMakeLists.txt index ec852be..a7f6cf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 2.8) project(dfuse_pack) +set(CMAKE_C_FLAGS "-fdata-sections -ffunction-sections ${CMAKE_C_FLAGS}") +set(CMAKE_C_FLAGS "-std=gnu11 -Wextra -Wno-unused-parameter -ffast-math -fvisibility=hidden ${CMAKE_C_FLAGS}") +set(CMAKE_C_FLAGS "-Wshadow -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes ${CMAKE_C_FLAGS}") + include_directories("${PROJECT_SOURCE_DIR}") # dfuse_pack diff --git a/README.md b/README.md index 608d012..56e4556 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This command line utility lets you pack raw binary firmware images into a DfuSe ### Build status -[![Build Status](https://travis-ci.org/OpenMusicKontrollers/dfuse_pack.svg?branch=master)](https://travis-ci.org/OpenMusicKontrollers/dfuse_pack) +[![build status](https://gitlab.com/OpenMusicKontrollers/dfuse_pack/badges/master/build.svg)](https://gitlab.com/OpenMusicKontrollers/dfuse_pack/commits/master) ### Dependencies diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..78bc1ab --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.10.0 diff --git a/cmake/arm-linux-gnueabihf.cmake b/cmake/arm-linux-gnueabihf.cmake new file mode 100644 index 0000000..102583c --- /dev/null +++ b/cmake/arm-linux-gnueabihf.cmake @@ -0,0 +1,18 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR "armv7h") +set(TOOLCHAIN "arm-linux-gnueabihf") + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER "${TOOLCHAIN}-gcc") +set(CMAKE_CXX_COMPILER "${TOOLCHAIN}-g++") + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH "usr/${TOOLCHAIN}") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/i686-linux-gnu.cmake b/cmake/i686-linux-gnu.cmake new file mode 100644 index 0000000..7768048 --- /dev/null +++ b/cmake/i686-linux-gnu.cmake @@ -0,0 +1,7 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR "i686") +set(TOOLCHAIN "i686-linux-gnu") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags") diff --git a/cmake/i686-w64-mingw32.cmake b/cmake/i686-w64-mingw32.cmake new file mode 100644 index 0000000..dfd9783 --- /dev/null +++ b/cmake/i686-w64-mingw32.cmake @@ -0,0 +1,23 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR "i686") +set(TOOLCHAIN "i686-w64-mingw32") + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER "${TOOLCHAIN}-gcc") +set(CMAKE_CXX_COMPILER "${TOOLCHAIN}-g++") +set(CMAKE_RC_COMPILER "${TOOLCHAIN}-windres") + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH "/usr/${TOOLCHAIN}") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(LIBS ${LIBS} "-static-libgcc") + +set(WINE wine32) diff --git a/cmake/universal-apple-darwin.cmake b/cmake/universal-apple-darwin.cmake new file mode 100644 index 0000000..3be88f1 --- /dev/null +++ b/cmake/universal-apple-darwin.cmake @@ -0,0 +1,20 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_PROCESSOR "x86_64") +set(TOOLCHAIN "universal-apple-darwin") + +set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER "/usr/${TOOLCHAIN}/bin/x86_64-apple-darwin15-clang") +set(CMAKE_CXX_COMPILER "/usr/${TOOLCHAIN}/bin/x86_64-apple-darwin15-clang++") + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH "/usr/${TOOLCHAIN}") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/x86_64-linux-gnu.cmake b/cmake/x86_64-linux-gnu.cmake new file mode 100644 index 0000000..7ab5477 --- /dev/null +++ b/cmake/x86_64-linux-gnu.cmake @@ -0,0 +1,4 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR "x86_64") +set(TOOLCHAIN "x86_64-linux-gnu") diff --git a/cmake/x86_64-w64-mingw32.cmake b/cmake/x86_64-w64-mingw32.cmake new file mode 100644 index 0000000..87c5eae --- /dev/null +++ b/cmake/x86_64-w64-mingw32.cmake @@ -0,0 +1,23 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR "x86_64") +set(TOOLCHAIN "x86_64-w64-mingw32") + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER "${TOOLCHAIN}-gcc") +set(CMAKE_CXX_COMPILER "${TOOLCHAIN}-g++") +set(CMAKE_RC_COMPILER "${TOOLCHAIN}-windres") + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH "/usr/${TOOLCHAIN}") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(LIBS ${LIBS} "-static-libgcc") + +set(WINE wine64) diff --git a/dfuse_pack.c b/dfuse_pack.c index 1d33356..7bc6b63 100644 --- a/dfuse_pack.c +++ b/dfuse_pack.c @@ -84,8 +84,8 @@ crc32_update_no_xor (uint32_t crc, uint8_t *buf, size_t len) return crc; } -DfuSe_Entry * -new_entry() +static DfuSe_Entry * +new_entry(void) { DfuSe_Entry *entry = calloc(1, sizeof(DfuSe_Entry)); @@ -99,8 +99,8 @@ new_entry() return entry; } -DfuSe_Entry_Image * -new_image() +static DfuSe_Entry_Image * +new_image(void) { DfuSe_Entry_Image *image = calloc(1, sizeof(DfuSe_Entry_Image)); @@ -117,7 +117,7 @@ new_image() (LIST); \ (LIST) = (LIST)->next, (DATA) = (LIST) ? (LIST)->data : NULL, free(HEAD)) -DfuSe_List * +static DfuSe_List * list_append(DfuSe_List *list, void *data) { DfuSe_List *next = malloc(sizeof(DfuSe_List)); @@ -143,7 +143,7 @@ list_append(DfuSe_List *list, void *data) return list; } -size_t +static size_t list_count(DfuSe_List *list) { size_t count = 0; @@ -186,7 +186,7 @@ main (int argc, char **argv) entry = entry ? entry : new_entry(); entry->tPrefix.bAlternateSetting = asetting; if(!entry->images) - FAIL("at least one image [-i] needed for altsetting %i\n", entry->tPrefix.bAlternateSetting); + FAIL("at least one image [-i] needed for altsetting %"PRIu8"\n", entry->tPrefix.bAlternateSetting); targets = list_append(targets, entry); entry = NULL; break; @@ -314,11 +314,11 @@ main (int argc, char **argv) // write container to file printf("Output container: %s\n", out); - printf("Firmware version: 0x%04x\n", version); - printf("Product ID: 0x%04x\n", product); - printf("Vendor ID: 0x%04x\n", vendor); - printf("Targets: %zu\n", list_count(targets)); - printf("CRC: 0x%04x\n\n", crc); + printf("Firmware version: 0x%04"PRIx16"\n", version); + printf("Product ID: 0x%04"PRIx16"\n", product); + printf("Vendor ID: 0x%04"PRIx16"\n", vendor); + printf("Targets: %"PRIuPTR"\n", list_count(targets)); + printf("CRC: 0x%04"PRIx32"\n\n", crc); if(!(dfuse = fopen(out, "wb"))) FAIL("could not open output file '%s'\n", out); @@ -326,8 +326,8 @@ main (int argc, char **argv) LIST_FOREACH(targets, l, entry) { printf("Target\n"); - printf("\tAltsetting: %i\n", entry->tPrefix.bAlternateSetting); - printf("\tImages: %zu\n", list_count(entry->images)); + printf("\tAltsetting: %"PRIu8"\n", entry->tPrefix.bAlternateSetting); + printf("\tImages: %"PRIuPTR"\n", list_count(entry->images)); printf("\tName: %s\n\n", entry->tPrefix.szTargetName); fwrite (&entry->tPrefix, DFUSE_TARGET_PREFIX_SIZE, 1, dfuse); @@ -335,8 +335,8 @@ main (int argc, char **argv) { printf("\tImage\n"); printf("\t\tPath: %s\n", image->path); - printf("\t\tAddress: 0x%08x\n", image->element.dwElementAddress); - printf("\t\tSize: %i bytes\n\n", image->len); + printf("\t\tAddress: 0x%08"PRIx32"\n", image->element.dwElementAddress); + printf("\t\tSize: %"PRIu32" bytes\n\n", image->len); fwrite (&image->element, DFUSE_IMAGE_ELEMENT_SIZE, 1, dfuse); fwrite (image->buf, sizeof(uint8_t), image->len, dfuse); -- 2.38.5