Skip to content

Commit

Permalink
Store object files for both the builds in separate directory
Browse files Browse the repository at this point in the history
Artifacts for the build can be found at
    build/native for native builds
    build/pi for raspberry pi builds
  • Loading branch information
anshulrouthu committed Dec 1, 2017
1 parent 7d0b5ab commit 97d3dd8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 68 deletions.
76 changes: 35 additions & 41 deletions Makefile
Expand Up @@ -35,13 +35,13 @@ PKG_CONFIG_PATH=$(PROJECT_ROOT)/staging/lib/pkgconfig
#CFLAGS:= $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
FFMPEGLIBS:=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs $(FFMPEG_LIBS))

BUILD_PATH:=build
BUILD_PATH:=build/native
CC:=g++
RPATH:=$(PROJECT_ROOT)/staging/lib/
CFLAGS:=-Wall -Werror -fpic -g -O2 -Wl,-rpath=$(RPATH)
EXT_LDLIBS:=-lUnitTest++ $(FFMPEGLIBS)
EXT_LDPATH:=-L$(PROJECT_ROOT)/staging/lib
LDFLAGS:=-Lbuild/ -lrpicast
LDFLAGS:=-L$(BUILD_PATH) -lrpicast

############ ----- Project include paths ----- ##############
INC:=-I$(PROJECT_ROOT)/staging/include/ \
Expand All @@ -55,7 +55,9 @@ MAINFILES:=$(PROJECT_ROOT)/source/main/rpicast.cpp \
$(PROJECT_ROOT)/source/main/rpicast-server.cpp \
$(PROJECT_ROOT)/source/porting_layers/components/video_tunnel.cpp

OBJS:=$(patsubst %.cpp, %.o, $(filter-out $(MAINFILES),$(wildcard $(PROJECT_ROOT)/source/porting_layers/components/*.cpp) \
OBJS_OUT_DIR:=$(PROJECT_ROOT)/$(BUILD_PATH)
OBJS:=$(patsubst $(PROJECT_ROOT)/%.cpp, $(OBJS_OUT_DIR)/%.o, $(filter-out $(MAINFILES), \
$(wildcard $(PROJECT_ROOT)/source/porting_layers/components/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/framework/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/osapi/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/porting_layers/av_pipe/*.cpp)))
Expand All @@ -71,6 +73,10 @@ all: $(BUILD_PATH) libs $(TARGET) tests

$(BUILD_PATH):
@mkdir -p $@
@mkdir -p $(dir $(OBJS))
@mkdir -p $(PROJECT_ROOT)/$(BUILD_PATH)/source/main
@mkdir -p $(PROJECT_ROOT)/$(BUILD_PATH)/source/tests
@mkdir -p $(PROJECT_ROOT)/$(BUILD_PATH)/samples

.PHONY:libs
libs: $(TARGET_LIB)
Expand All @@ -79,19 +85,20 @@ $(TARGET_LIB): $(OBJS)
@echo "Linking... $@"
@$(CC) $(CFLAGS) -fpic -shared $(EXT_LDPATH) $^ -o $@ $(EXT_LDLIBS)

$(TARGET): $(PROJECT_ROOT)/source/main/rpicast.o $(TARGET_LIB)
$(TARGET): $(PROJECT_ROOT)/$(BUILD_PATH)/source/main/rpicast.o $(TARGET_LIB)
@echo "Linking... $@"
@$(CXX) $(CFLAGS) $(LDPATH) $^ -o $@ $(LDFLAGS)

$(TARGET_SERVER): $(PROJECT_ROOT)/source/main/rpicast-server.o $(TARGET_LIB)
$(TARGET_SERVER): $(PROJECT_ROOT)/$(BUILD_PATH)/source/main/rpicast-server.o $(TARGET_LIB)
@echo "Linking... $@"
@$(CC) $(CFLAGS) $(LDPATH) $^ -o $@ $(LDFLAGS)
%.o: %.cpp
@$(CC) $(CFLAGS) $(LDPATH) $^ -o $@ $(LDFLAGS)

$(OBJS_OUT_DIR)/%.o: $(PROJECT_ROOT)/%.cpp
@echo "[CXX] $@"
@$(CXX) $(CFLAGS) $(INC) -c $< -o $@

%.o: %.c
@echo "[CXX] $@"
$(OBJS_OUT_DIR)/%.o: $(PROJECT_ROOT)/%.c
@echo "[CC] $@"
@$(CC) $(CFLAGS) $(INC) -c $< -o $@

############ ----- build samples ----- ##############
Expand All @@ -102,14 +109,14 @@ SAMPLES:= $(BUILD_PATH)/screencapture \
$(BUILD_PATH)/hello_world \
$(BUILD_PATH)/muxing

SAMPLE_SRC_DIR:=$(PROJECT_ROOT)/samples
SAMPLE_OBJ_DIR:=$(PROJECT_ROOT)/$(BUILD_PATH)/samples

.PHONY: sample
sample: $(TARGET_LIB) $(SAMPLES)

$(BUILD_PATH)/%: $(SAMPLE_SRC_DIR)/%.o
$(BUILD_PATH)/%: $(SAMPLE_OBJ_DIR)/%.o
@echo "Linking... $@"
@$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(EXT_LDPATH) $(FFMPEGLIBS)
@$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(EXT_LDPATH) $(FFMPEGLIBS)

############ ----- build tests ----- ##############

Expand All @@ -120,48 +127,35 @@ TESTS:= $(BUILD_PATH)/unittests \
$(BUILD_PATH)/test_demux \
$(BUILD_PATH)/test_ssdp

TEST_SRC_DIR:= $(PROJECT_ROOT)/source/tests
TEST_OBJ_DIR:= $(PROJECT_ROOT)/$(BUILD_PATH)/source/tests

.PHONY: tests
tests: $(TARGET_LIB) $(TESTS)

$(BUILD_PATH)/%: $(TEST_SRC_DIR)/%.o
$(BUILD_PATH)/%: $(TEST_OBJ_DIR)/%.o
@echo "Linking... $@"
@$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(EXT_LDPATH) -lUnitTest++
@$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(EXT_LDPATH) -lUnitTest++

############ ----- cleaning ----- ##############

.PHONY: clean
clean:
@rm -f $(PROJECT_ROOT)/source/framework/*.o \
$(PROJECT_ROOT)/source/osapi/*.o \
$(PROJECT_ROOT)/source/main/*.o \
$(PROJECT_ROOT)/source/porting_layers/av_pipe/*.o \
$(PROJECT_ROOT)/source/porting_layers/components/*.o \
$(PROJECT_ROOT)/source/tests/*.o \
$(PROJECT_ROOT)/samples/*.o

.PHONY:distclean
distclean:
@echo "Cleaning files..."
@rm -f $(TARGET) \
$(TARGET_LIB) \
$(BUILD_PATH)/*
@$(MAKE) -f Makefile.cross distclean
@rm -rf $(PROJECT_ROOT)/$(BUILD_PATH)

############ ----- cross compilation ----- ##############

cross-tests: clean
@$(MAKE) -f Makefile.cross tests clean
cross-tests:
@$(MAKE) -f Makefile.cross tests

cross-samples: clean
@$(MAKE) -f Makefile.cross samples clean
cross-samples:
@$(MAKE) -f Makefile.cross samples

cross-libs: clean
@$(MAKE) -f Makefile.cross libs clean
cross-distclean: clean
@$(MAKE) -f Makefile.cross distclean clean

cross-all: clean
@$(MAKE) -f Makefile.cross all clean
cross-libs:
@$(MAKE) -f Makefile.cross libs

cross-all:
@$(MAKE) -f Makefile.cross

cross-clean:
@$(MAKE) -f Makefile.cross clean
46 changes: 21 additions & 25 deletions Makefile.cross
Expand Up @@ -24,7 +24,7 @@ PROJECT_ROOT:=$(PWD)

TOOLCHAINPATH:=$(PROJECT_ROOT)/rpi-toolchain/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
CROSSPREFIX:=$(TOOLCHAINPATH)/arm-linux-gnueabihf-
BUILD_PATH:=rpi-build
BUILD_PATH:=build/pi
CC:=$(CROSSPREFIX)gcc
CXX:=$(CROSSPREFIX)g++
SYSROOT=$(PROJECT_ROOT)/rpi-staging
Expand All @@ -40,7 +40,7 @@ EXT_LDLIBS:=-lcurl -lUnitTest++ -pthread -lavdevice \
-lswresample -lswscale -lavutil -lm

EXT_LDPATH:=-L$(PROJECT_ROOT)/rpi-staging/usr/lib
LDFLAGS:=-Lrpi-build/ -lrpicast-server
LDFLAGS:=-L$(BUILD_PATH) -lrpicast-server

############ ----- rpi-OpenMax variables ----- ##############

Expand Down Expand Up @@ -69,9 +69,11 @@ INC:= $(OMXINC) -I$(PROJECT_ROOT)/rpi-staging/usr/include/ \
#list of files containing main() function, to prevent conflicts while linking
MAINFILES:=$(PROJECT_ROOT)/source/main/rpicast-server.cpp

OBJS:=$(patsubst %.cpp, %.o, $(filter-out $(MAINFILES),$(wildcard $(PROJECT_ROOT)/source/porting_layers/components/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/framework/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/osapi/*.cpp) \
OBJS_OUT_DIR:=$(PROJECT_ROOT)/$(BUILD_PATH)
OBJS:=$(patsubst $(PROJECT_ROOT)/%.cpp, $(OBJS_OUT_DIR)/%.o, $(filter-out $(MAINFILES), \
$(wildcard $(PROJECT_ROOT)/source/porting_layers/components/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/framework/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/osapi/*.cpp) \
$(wildcard $(PROJECT_ROOT)/source/porting_layers/av_pipe/*.cpp)))

############ ----- build main application ----- ##############
Expand All @@ -82,6 +84,10 @@ all: $(BUILD_PATH) libs $(TARGET) tests

$(BUILD_PATH):
@mkdir -p $@
@mkdir -p $(dir $(OBJS))
@mkdir -p $(PROJECT_ROOT)/$(BUILD_PATH)/source/main
@mkdir -p $(PROJECT_ROOT)/$(BUILD_PATH)/source/tests
@mkdir -p $(PROJECT_ROOT)/$(BUILD_PATH)/samples

.PHONY:libs
libs: $(TARGET_LIB)
Expand All @@ -90,15 +96,15 @@ $(TARGET_LIB): $(OBJS)
@echo "Linking... $@"
@$(CXX) $(CFLAGS) -fpic -shared $^ -o $@ $(EXT_LDPATH) $(EXT_LDLIBS)

$(TARGET): $(PROJECT_ROOT)/source/main/rpicast-server.o
$(TARGET): $(PROJECT_ROOT)/$(BUILD_PATH)/source/main/rpicast-server.o
@echo "Linking... $@"
@$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(EXT_LDPATH) $(EXT_LDLIBS) $(OMXLDFLAGS)

%.o: %.cpp
$(OBJS_OUT_DIR)/%.o: $(PROJECT_ROOT)/%.cpp
@echo "[CXX] $@"
@$(CXX) $(CFLAGS) $(OMXCFLAGS) $(INC) -c $< -o $@

%.o: %.c
$(OBJS_OUT_DIR)/%.o: $(PROJECT_ROOT)/%.c
@echo "[CC] $@"
@$(CC) $(CFLAGS) $(OMXCFLAGS) $(INC) -c $< -o $@

Expand All @@ -110,12 +116,12 @@ SAMPLES:= $(BUILD_PATH)/screencapture \
$(BUILD_PATH)/hello_world \
$(BUILD_PATH)/hello_video

SAMPLE_SRC_DIR:=$(PROJECT_ROOT)/samples
SAMPLE_OBJ_DIR:=$(PROJECT_ROOT)/$(BUILD_PATH)/samples

.PHONY: sample
sample: $(TARGET_LIB) $(SAMPLES)

$(BUILD_PATH)/%: $(SAMPLE_SRC_DIR)/%.o
$(BUILD_PATH)/%: $(SAMPLE_OBJ_DIR)/%.o
@echo "Linking... $@"
@$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(EXT_LDPATH) $(EXT_LDLIBS) $(OMXLDFLAGS)

Expand All @@ -128,29 +134,19 @@ TESTS:= $(BUILD_PATH)/unittests \
$(BUILD_PATH)/test_demux \
$(BUILD_PATH)/test_ssdp

TEST_SRC_DIR:= $(PROJECT_ROOT)/source/tests
TEST_OBJ_DIR:= $(PROJECT_ROOT)/$(BUILD_PATH)/source/tests

.PHONY: tests
tests: $(TARGET_LIB) $(TESTS)

$(BUILD_PATH)/%: $(TEST_SRC_DIR)/%.o
$(BUILD_PATH)/%: $(TEST_OBJ_DIR)/%.o
@echo "Linking... $@"
@$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(EXT_LDPATH) $(EXT_LDLIBS) $(OMXLDFLAGS)

############ ----- cleaning ----- ##############


.PHONY: clean
clean:
@rm -f $(PROJECT_ROOT)/source/framework/*.o \
$(PROJECT_ROOT)/source/osapi/*.o \
$(PROJECT_ROOT)/source/main/*.o \
$(PROJECT_ROOT)/source/porting_layers/av_pipe/*.o \
$(PROJECT_ROOT)/source/porting_layers/components/*.o \
$(PROJECT_ROOT)/source/tests/*.o \
$(PROJECT_ROOT)/samples/*.o

.PHONY:distclean
distclean:
@rm -f $(TARGET) \
$(TARGET_LIB) \
$(BUILD_PATH)/*
@echo "Cleaning files..."
@rm -rf $(PROJECT_ROOT)/$(BUILD_PATH)
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -12,11 +12,13 @@ Build Instructions
------------------
Run setup.sh first, This script will build ffmpeg (with x11grab & libx264 enabled), UnitTest++ and install all the built libraries in the staging dir where the makefile will look for these libs. It will also pull the cross compiler toolchain for building rpi apps and cross staging tarball from my dropbox and extract in rpi-staging for cross compiling rpi apps.

NOTE: setup.sh will setup cross compilation environment, hence should be run in development machine.

$ ./setup.sh (you should run this only first time after new checkout, this should take appx 8-10 mins)<br>
$ make cross-all all

You can find the native binaries in ./build dir and the rpi's binaries in ./rpi-build dir
Transfer the ./rpi-build/* to RaspberryPi
You can find the native binaries in ./build/native and the rpi's binaries in ./build/pi
Transfer the binaries in ./build/pi directory to RaspberryPi

Usage
-----
Expand Down

0 comments on commit 97d3dd8

Please sign in to comment.