Skip to content

Instantly share code, notes, and snippets.

@jynik
Created June 28, 2015 03:49
Show Gist options
  • Save jynik/573f4d48c791b5a3c45a to your computer and use it in GitHub Desktop.
Save jynik/573f4d48c791b5a3c45a to your computer and use it in GitHub Desktop.
Makefile for bladeRF-versions, with cross-compiling options (via a Yocto build)
#
# Simple cross-compilation example for Yocto-based toolchains and bladeRF
#
# Host build:
# make
#
# Wandboard Quad build:
# PLATFORM=wandboard-quad YOCTO_BUILD_DIR=path/to/build/dir make
#
# Raspberry Pi 2 build:
# PLATFORM=raspberrypi2 YOCTO_BUILD_DIR=path/to/build/dir make
#
################################################################################
CFLAGS := -Wall -Wextra -Wno-unused-parameter
LDFLAGS := -lbladeRF
ifdef (DEBUG)
CFLAGS += -O0 -ggdb3
else
CFLAGS += -O2
endif
# Default to wandboard-quad. Specify PLATFORM= on the command-line to override
PLATFORM ?= wandboard-quad
ifdef YOCTO_BUILD_DIR
CROSS_COMPILE := $(YOCTO_BUILD_DIR)/tmp/sysroots/x86_64-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)AR
ifeq ($(PLATFORM), raspberrypi2)
WORK_ARCH_DIR := cortexa7hf-vfp-vfpv4-neon-poky-linux-gnueabi
CFLAGS += -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon-vfpv4 -mtune=cortex-a7
endif
ifeq ($(PLATFORM), wandboard-quad)
WORK_ARCH_DIR := cortexa9hf-vfp-neon-poky-linux-gnueabi
CFLAGS += -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9
endif
CFLAGS += --sysroot=$(YOCTO_BUILD_DIR)/tmp/sysroots/$(PLATFORM)
CROSS_BLADERF_WORK_DIR := $(YOCTO_BUILD_DIR)/tmp/work/$(WORK_ARCH_DIR)/libbladerf/1.2.1-r0/git/
CROSS_BLADERF_BUILD_DIR := $(CROSS_BLADERF_WORK_DIR)/build/host/output/
CROSS_BLADERF_INC_DIR := $(CROSS_BLADERF_WORK_DIR)/host/libraries/libbladeRF/include
LDFLAGS += -L$(CROSS_BLADERF_BUILD_DIR)
INCLUDES += $(SYSROOT_INCLUDES) -I$(CROSS_BLADERF_INC_DIR)
endif
all: bladeRF-versions
bladeRF-versions: bladeRF-versions.c
$(CC) $(CFLAGS) $(INCLUDES) $^ $(LDFLAGS) -o $@
clean:
rm -f bladeRF-versions
.PHONY: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment