Skip to content

Commit

Permalink
examples: add example for "make bindist"
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Mar 30, 2016
1 parent c04877d commit 1a003eb
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/bindist/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# name of your application
APPLICATION = bindist

# If no BOARD is found in the environment, use this default:
BOARD ?= native

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
CFLAGS += -DDEVELHELP

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

# bindist specific stuff:
#
# build and use module "abc".
# use BINARY_DIRS instead of DIRS
BINARY_DIRS += abc
USEMODULE += abc

# list of files to include in binary distribution
# "bin/$(BOARD)/$(APPLICATION).elf" will automatically be added
DIST_FILES += Makefile
DIST_FILES += bin/$(BOARD)/abc.a

include $(RIOTBASE)/Makefile.include
41 changes: 41 additions & 0 deletions examples/bindist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Introduction

RIOT allows for creating a "binary distribution", which can be used to ship
proprietary, compiled objects in a way that makes it possible to re-link them
against a freshly compiled RIOT.
This "binary distribution" also contains version information and md5 hashes of
a linked binary, making verification of correctness of a link possible.

This application serves as simple example for "make bindist".
It consists of an application module (bindist.a) and another example module
(abc.a).

## Instructions

Calling "make bindist" creates a folder "bindist", which only contains the
compiled and linked binary, bindist.a, abc.a and Makefiles.

In order to recompile RIOT, adjust "RIOTBASE" in Makefile to point to a RIOT
source checkout, then call "make check_bindist".

RIOT will be build as usual, but just take the pre-compiled bindist.a and
abc.a. Their source is not necessary. The resulting binary will then be
compared with te precompiled "bindist.elf" (using md5sum) and the result gets
printed. If the same RIOT source tree and build environment (compiler version,
etc.) was used, the binaries should match.

Step-by-step:

1. # cd <riot-checkout>/examples/bindist
2. # make all
3. # make bindist
4. # cd bindist
5. <adjust RIOTBASE variable (../.. -> ../../..)
6. # make check_bindist

## Needed Makefile changes

In order to enable "make bindist" for your application, several things have to
be changed in the main application's Makefile.

See this application's Makefile as example.
1 change: 1 addition & 0 deletions examples/bindist/abc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
29 changes: 29 additions & 0 deletions examples/bindist/abc/abc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2016 Kaspar Schleiser <[email protected]>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup examples
* @{
*
* @file
* @brief Binary distribution example code
*
* This file contains just example code that will end up in a example binary
* distribution folder.
*
* @author Kaspar Schleiser <[email protected]>
*
* @}
*/

#include <stdio.h>

void abc(void)
{
printf("abc!\n");
}
36 changes: 36 additions & 0 deletions examples/bindist/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2016 Kaspar Schleiser <[email protected]>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup examples
* @{
*
* @file
* @brief Binary distribution example
*
* This application serves as simple example for "make bindist", a makefile
* target that can be used to ship proprietary, compiled objects together
* with a compiled binary in a way that allows re-linking and makes
* verification possible.
*
* @author Kaspar Schleiser <[email protected]>
*
* @}
*/

#include <stdio.h>

extern void abc(void);

int main(void)
{
puts("Hello closed-source!");
abc();

return 0;
}

0 comments on commit 1a003eb

Please sign in to comment.