view Makefile @ 123:2b3b254e24cc

8078598: [Master] Consolidate DIO build into a single 'make all' job Summary: osgi_all target is added Reviewed-by: alkonsta
author snazarki
date Fri, 24 Apr 2015 13:59:33 +0400
parents dada06425261
children 2f7da76bdc69
line wrap: on
line source
#########################################################################
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
#########################################################################
# Functions

# find-suffix-files
# finds all files with given suffix below given directories
# usage: $(call find-suffix-files <dir-list>,<suffix>)
# note: <suffix> should not contain the '.'
define find-suffix-files
$(patsubst ./%,%, \
  $(shell find $(1) -name "*.$(2)" -and -not -name ".*") \
)
endef

LIB_NAME := dio

###########################################################
# check for required env vars
ifeq ($(PI_TOOLS),)
  $(error "PI_TOOLS is not defined. Please set PI_TOOLS to point to the location of the raspberry pi GNU toolchain")
endif

ifeq ($(JAVA_HOME),)
  $(error "JAVA_HOME is not defined. Please set JAVA_HOME to point to the location of the JDK8 installation")
endif

BUILD_DEVICEACCESS := true

DIO_JAVA_API_DIRS := \
	src/share/classes/jdk

# specify java src directories
DIO_JAVA_IMPL_DIRS := \
	src/se/classes \
	src/share/classes/com

# specify native src directories
DIO_NATIVE_SRC_DIRS := \
	src/se/native \
	src/share/native \
	src/se/linux/native \
	src/share/linux/native

STRIP_PACKAGES ?=
# always strip out these apis (not yet implemented)
STRIP_PACKAGES_INTERNAL = $(STRIP_PACKAGES) pwm counter mmio

# specify sample java src directories
DIO_SAM_JAVA_SRC_DIR := \
                        samples/gpio/src

# define variables needed for dir setup
TARGET_CPU_LEGACY_LIB ?= arm
DIO_VERSION := 1.0.1
BUILD_NUMBER ?= dev

ifneq ($(BUILD_NUMBER),dev)
  # only include 'b' when you have an actual build number 
  B := b
endif
  

ifeq ($(TARGET_CPU_LEGACY_LIB),arm)
  OSGI_ARCH := armv6hf
  ARCH := armv6hf
else
  OSGI_ARCH := x86
  ARCH := i586
endif



# Output directorires
BUILD_DIR := $(CURDIR)/build
OSGI_BUILD_DIR := $(CURDIR)/build/osgi
OSGI_DIST_DIR := $(CURDIR)/build/dist/osgi
OSGI_JAR := $(OSGI_DIST_DIR)/dio-$(DIO_VERSION)-$(B)$(BUILD_NUMBER)-linux-$(ARCH).jar
SO_OUT_DIR := $(BUILD_DIR)/so
JAVA_OUT_DIR := $(BUILD_DIR)/classes
SAM_JAVA_OUT_DIR := $(BUILD_DIR)/samples/classes
NATIVE_OUT_DIR := $(BUILD_DIR)/obj
JAR_OUT_DIR := $(BUILD_DIR)/jar
DEVICE_IO_OUT_DIR := $(BUILD_DIR)/deviceio
BUNDLE_OUT_DIR := $(BUILD_DIR)/bundles

# find all src files
CPP_SRC_FILES := $(call find-suffix-files, $(DIO_NATIVE_SRC_DIRS),cpp)
C_SRC_FILES :=  $(call find-suffix-files, $(DIO_NATIVE_SRC_DIRS),c)
JAVA_IMPL_FILES := $(call find-suffix-files, $(DIO_JAVA_IMPL_DIRS),java)
JAVA_API_FILES := $(call find-suffix-files, $(DIO_JAVA_API_DIRS),java)
SAM_JAVA_SRC_FILES := $(call find-suffix-files, $(DIO_SAM_JAVA_SRC_DIR),java)

DIO_INCLUDE_DIRS := $(sort $(dir $(call find-suffix-files, $(DIO_NATIVE_SRC_DIRS),h)))

# filter out apis we don't want in this build
ifneq (,$(findstring i2c, $(STRIP_PACKAGES_INTERNAL)))
  CPP_SRC_FILES := $(foreach f,$(CPP_SRC_FILES),$(if $(findstring i2c,$(f)),,$(f)))
  C_SRC_FILES := $(foreach f,$(C_SRC_FILES),$(if $(findstring i2c,$(f)),,$(f)))
  JAVA_IMPL_FILES := $(foreach f,$(JAVA_IMPL_FILES),$(if $(findstring i2c,$(f)),,$(f)))
endif
ifneq (,$(findstring spibus, $(STRIP_PACKAGES_INTERNAL)))
  CPP_SRC_FILES := $(foreach f,$(CPP_SRC_FILES),$(if $(findstring spibus,$(f)),,$(f)))
  C_SRC_FILES := $(foreach f,$(C_SRC_FILES),$(if $(findstring spibus,$(f)),,$(f)))
  JAVA_IMPL_FILES := $(foreach f,$(JAVA_IMPL_FILES),$(if $(findstring spibus,$(f)),,$(f)))
endif
ifneq (,$(findstring uart, $(STRIP_PACKAGES_INTERNAL)))
  CPP_SRC_FILES := $(foreach f,$(CPP_SRC_FILES),$(if $(findstring uart,$(f)),,$(f)))
  C_SRC_FILES := $(foreach f,$(C_SRC_FILES),$(if $(findstring uart,$(f)),,$(f)))
  JAVA_IMPL_FILES := $(foreach f,$(JAVA_IMPL_FILES),$(if $(findstring uart,$(f)),,$(f)))
endif
ifneq (,$(findstring counter, $(STRIP_PACKAGES_INTERNAL)))
  CPP_SRC_FILES := $(foreach f,$(CPP_SRC_FILES),$(if $(findstring counter,$(f)),,$(f)))
  C_SRC_FILES := $(foreach f,$(C_SRC_FILES),$(if $(findstring counter,$(f)),,$(f)))
  JAVA_IMPL_FILES := $(foreach f,$(JAVA_IMPL_FILES),$(if $(findstring counter,$(f)),,$(f)))
endif
ifneq (,$(findstring pwm, $(STRIP_PACKAGES_INTERNAL)))
  CPP_SRC_FILES := $(foreach f,$(CPP_SRC_FILES),$(if $(findstring pwm,$(f)),,$(f)))
  C_SRC_FILES := $(foreach f,$(C_SRC_FILES),$(if $(findstring pwm,$(f)),,$(f)))
  JAVA_IMPL_FILES := $(foreach f,$(JAVA_IMPL_FILES),$(if $(findstring pwm,$(f)),,$(f)))
endif
ifneq (,$(findstring gpio, $(STRIP_PACKAGES_INTERNAL)))
  CPP_SRC_FILES := $(foreach f,$(CPP_SRC_FILES),$(if $(findstring gpio,$(f)),,$(f)))
  C_SRC_FILES := $(foreach f,$(C_SRC_FILES),$(if $(findstring gpio,$(f)),,$(f)))
  JAVA_IMPL_FILES := $(foreach f,$(JAVA_IMPL_FILES),$(if $(findstring gpio,$(f)),,$(f)))
endif
ifneq (,$(findstring mmio, $(STRIP_PACKAGES_INTERNAL)))
  CPP_SRC_FILES := $(foreach f,$(CPP_SRC_FILES),$(if $(findstring mmio,$(f)),,$(f)))
  C_SRC_FILES := $(foreach f,$(C_SRC_FILES),$(if $(findstring mmio,$(f)),,$(f)))
  JAVA_IMPL_FILES := $(foreach f,$(JAVA_IMPL_FILES),$(if $(findstring mmio,$(f)),,$(f)))
endif

# calculate obj files needed
CPP_OBJ_FILES := $(notdir $(subst .cpp,.o,$(CPP_SRC_FILES)))
C_OBJ_FILES := $(notdir $(subst .c,.o,$(C_SRC_FILES)))

# setup search paths
vpath %.cpp $(sort $(dir $(CPP_SRC_FILES)))
vpath %.c $(sort $(dir $(C_SRC_FILES)))
vpath %.o $(NATIVE_OUT_DIR)


#######################################################################################################
# tool and flag setup for arm (rasp pi) build
TARGET_TOOLCHAIN := $(PI_TOOLS)
TARGET_CC := $(TARGET_TOOLCHAIN)/bin/gcc
TARGET_CXX := $(TARGET_TOOLCHAIN)/bin/g++
TARGET_LD := $(TARGET_TOOLCHAIN)/bin/gcc
JAVAC := $(JAVA_HOME)/bin/javac
JAR := $(JAVA_HOME)/bin/jar
MKDIR := mkdir -p
TARGET_C_FLAGS = $(USER_C_FLAGS) -fPIC -Wno-psabi -DJAVACALL_REPORT_LEVEL=0 -DENABLE_DEVICEACCESS -c -MMD -MF $(NATIVE_OUT_DIR)/$(@).d
TARGET_INCLUDES = $(foreach d,$(DIO_INCLUDE_DIRS),-I$(d)) -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
TARGET_CXX_FLAGS = $(USER_CXX_FLAGS) -fPIC -Wno-psabi -DJAVACALL_REPORT_LEVEL=4 -DENABLE_DEVICEACCESS -c
TARGET_LD_FLAGS= $(USER_LD_FLAGS) -Xlinker -z -Xlinker defs -Xlinker -O1 \
          -shared \
          -Xlinker -rpath -Xlinker \$$ORIGIN -lpthread -lrt \
          -Xlinker -z -Xlinker muldefs -lstdc++

ALL_TARGETS := dirs $(LIB_NAME).jar lib$(LIB_NAME).so device-io

# Don't build samples if we're stripping extra packages. Build might fail.
ifeq (,$(STRIP_PACKAGES))
  ALL_TARGETS := $(ALL_TARGETS) $(LIB_NAME)-samples.jar
endif

#######################################################################################################
#
BUNDLE_NAME := device-io

#######################################################################################################
# targets

.PHONY: clean all dirs device-io bundle osgi

# target osgi_build_i586, osgi_build_arm, and osgi_all maybe only available on Jenkins, you may not be able to run it on your local machione

osgi_build_i586:
	rm -rf $(OSGI_BUILD_DIR)/*
	@echo "Build osgi bundle for i586..."
	make bundle TARGET_CPU_LEGACY_LIB=i586 PI_TOOLS=/usr USER_C_FLAGS="-march=i586 -m32" USER_CXX_FLAGS="-march=i586 -m32" USER_LD_FLAGS="-march=i586 -m32" osgi

osgi_build_arm:
	rm -rf $(OSGI_BUILD_DIR)/*
	@echo "Build osgi bundle for arm..."
	make bundle PI_TOOLS=/opt/pi-tools osgi

osgi_all: osgi_all_clean osgi_build_i586 osgi_build_arm
	@echo "osgi bundles built for all architectures..."

osgi_all_clean:
	@echo "clean: removing $(OSGI_BUILD_DIR) and $(OSGI_DIST_DIR)"
	rm -rf $(OSGI_BUILD_DIR)/*
	rm -rf $(OSGI_DIST_DIR)/*
    
dirs:
	@echo "Creating output directories"
	@$(MKDIR) $(SO_OUT_DIR)
	@$(MKDIR) $(JAVA_OUT_DIR)
	@$(MKDIR) $(SAM_JAVA_OUT_DIR)
	@$(MKDIR) $(NATIVE_OUT_DIR)
	@$(MKDIR) $(JAR_OUT_DIR)
	@$(MKDIR) $(DEVICE_IO_OUT_DIR)
	@$(MKDIR) $(BUNDLE_OUT_DIR)

$(CPP_OBJ_FILES): %.o: %.cpp dirs
	@echo Compiling $<
	@$(TARGET_CC) $(TARGET_C_FLAGS) $(TARGET_INCLUDES) $< -o $(NATIVE_OUT_DIR)/$@

$(C_OBJ_FILES): %.o: %.c dirs
	@echo compiling $<
	@$(TARGET_CC) $(TARGET_C_FLAGS) $(TARGET_INCLUDES) $< -o $(NATIVE_OUT_DIR)/$@

lib$(LIB_NAME).so: $(CPP_OBJ_FILES) $(C_OBJ_FILES) dirs
	@echo linking $@
	@$(TARGET_LD) -o $(SO_OUT_DIR)/$@ $(foreach o,$(CPP_OBJ_FILES) $(C_OBJ_FILES),$(NATIVE_OUT_DIR)/$(o)) $(TARGET_LD_FLAGS)

$(LIB_NAME).jar: $(JAVA_IMPL_FILES) $(JAVA_API_FILES) dirs
	@echo Compiling Java source files to $(JAR_OUT_DIR)/$@
	@$(JAVAC) -d $(JAVA_OUT_DIR) $(JAVA_IMPL_FILES) $(JAVA_API_FILES)
	@sed -e  "s/BUILD_NUMBER/$(B)$(BUILD_NUMBER)/g" src/se/manifest.mf > $(BUILD_DIR)/manifest.mf
	@$(JAR) cfm $(JAR_OUT_DIR)/$@ $(BUILD_DIR)/manifest.mf -C $(JAVA_OUT_DIR) .

$(LIB_NAME)-samples.jar: $(SAM_JAVA_SRC_FILES) dirs $(LIB_NAME).jar
	@echo Compiling Java source files to $(JAR_OUT_DIR)/$@
	@$(JAVAC) -cp $(JAR_OUT_DIR)/$(LIB_NAME).jar -d $(SAM_JAVA_OUT_DIR) $(SAM_JAVA_SRC_FILES)
	@$(JAR) cf $(JAR_OUT_DIR)/$@ -C $(SAM_JAVA_OUT_DIR) .

device-io: dirs $(LIB_NAME).jar lib$(LIB_NAME).so
	@$(MKDIR) $(DEVICE_IO_OUT_DIR)/lib/ext
	@$(MKDIR) $(DEVICE_IO_OUT_DIR)/lib/$(TARGET_CPU_LEGACY_LIB)
	@cp $(JAR_OUT_DIR)/$(LIB_NAME).jar $(DEVICE_IO_OUT_DIR)/lib/ext
	@cp $(SO_OUT_DIR)/lib$(LIB_NAME).so $(DEVICE_IO_OUT_DIR)/lib/$(TARGET_CPU_LEGACY_LIB)

bundle: device-io dirs
	@echo creating $(BUNDLE_NAME).zip
	@cp jrecreate/* $(BUILD_DIR)/deviceio
	@(cd $(BUILD_DIR) ; zip -r $(BUNDLE_OUT_DIR)/$(BUNDLE_NAME).zip deviceio )

osgi: $(LIB_NAME).jar lib$(LIB_NAME).so
	rm -rf $(OSGI_BUILD_DIR)/*
	mkdir -p $(OSGI_DIST_DIR)
	mkdir -p $(OSGI_BUILD_DIR)/lib
	mkdir -p $(OSGI_BUILD_DIR)/OSGI-INF
	sed -e  "s/BUILD_NUMBER/$(B)$(BUILD_NUMBER)/g;s/OSGI_ARCH/$(OSGI_ARCH)/g;s/DIO_VERSION/$(DIO_VERSION)/g" src/se/manifest.mf-osgi > $(OSGI_BUILD_DIR)/manifest.mf
	cp src/se/permissions.perm-osgi $(OSGI_BUILD_DIR)/OSGI-INF/permissions.perm
	cp $(JAR_OUT_DIR)/$(LIB_NAME).jar $(OSGI_JAR)
	cp $(SO_OUT_DIR)/lib$(LIB_NAME).so $(OSGI_BUILD_DIR)/lib
	$(JAR) ufm $(OSGI_JAR) $(OSGI_BUILD_DIR)/manifest.mf -C $(OSGI_BUILD_DIR) lib/lib$(LIB_NAME).so -C $(OSGI_BUILD_DIR) OSGI-INF/permissions.perm

clean:
	@echo "clean: removing $(BUILD_DIR)"
	@rm -rf $(BUILD_DIR)