Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
3a1c9f14
Commit
3a1c9f14
authored
11 years ago
by
px4dev
Browse files
Options
Downloads
Patches
Plain Diff
Teach the PX4 build system how to handle pre-built libraries.
parent
504b6d12
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
makefiles/firmware.mk
+62
-14
62 additions, 14 deletions
makefiles/firmware.mk
makefiles/library.mk
+169
-0
169 additions, 0 deletions
makefiles/library.mk
makefiles/module.mk
+2
-22
2 additions, 22 deletions
makefiles/module.mk
with
233 additions
and
36 deletions
makefiles/firmware.mk
+
62
−
14
View file @
3a1c9f14
...
...
@@ -180,18 +180,6 @@ EXTRA_CLEANS =
# Modules
################################################################################
#
# We don't actually know what a module is called; all we have is a path fragment
# that we can search for, and where we expect to find a module.mk file.
#
# As such, we replicate the successfully-found path inside WORK_DIR for the
# module's build products in order to keep modules separated from each other.
#
# XXX If this becomes unwieldy or breaks for other reasons, we will need to
# move to allocating directory names and keeping tabs on makefiles via
# the directory name. That will involve arithmetic (it'd probably be time
# for GMSL).
# where to look for modules
MODULE_SEARCH_DIRS
+=
$(
WORK_DIR
)
$(
MODULE_SRC
)
$(
PX4_MODULE_SRC
)
...
...
@@ -248,6 +236,66 @@ $(MODULE_CLEANS):
MODULE_MK
=
$(
mkfile
)
\
clean
################################################################################
# Libraries
################################################################################
# where to look for libraries
LIBRARY_SEARCH_DIRS
+=
$(
WORK_DIR
)
$(
MODULE_SRC
)
$(
PX4_MODULE_SRC
)
# sort and unique the library list
LIBRARIES
:=
$(
sort
$(
LIBRARIES
))
# locate the first instance of a library by full path or by looking on the
# library search path
define
LIBRARY_SEARCH
$(
firstword
$(
abspath
$(
wildcard
$(
1
)
/library.mk
))
\
$(
abspath
$(
foreach search_dir,
$(
LIBRARY_SEARCH_DIRS
)
,
$(
wildcard
$(
search_dir
)
/
$(
1
)
/library.mk
)))
\
MISSING_
$1
)
endef
# make a list of library makefiles and check that we found them all
LIBRARY_MKFILES
:=
$(
foreach library,
$(
LIBRARIES
)
,
$(
call LIBRARY_SEARCH,
$(
library
)))
MISSING_LIBRARIES
:=
$(
subst MISSING_,,
$(
filter MISSING_%,
$(
LIBRARY_MKFILES
)))
ifneq
($(MISSING_LIBRARIES),)
$(error Can't find library(s)
:
$(MISSING_LIBRARIES))
endif
# Make a list of the archive files we expect to build from libraries
# Note that this path will typically contain a double-slash at the WORK_DIR boundary; this must be
# preserved as it is used below to get the absolute path for the library.mk file correct.
#
LIBRARY_LIBS
:=
$(
foreach path,
$(
dir
$(
LIBRARY_MKFILES
))
,
$(
WORK_DIR
)$(
path
)
library.a
)
# rules to build module objects
.PHONY
:
$(LIBRARY_LIBS)
$(LIBRARY_LIBS)
:
relpath = $(patsubst $(WORK_DIR)%
,
%
,
$@)
$(LIBRARY_LIBS)
:
mkfile = $(patsubst %library.a
,
%library.mk
,
$(relpath))
$(LIBRARY_LIBS)
:
workdir = $(@D)
$(LIBRARY_LIBS)
:
$(GLOBAL_DEPS) $(NUTTX_CONFIG_HEADER)
$(
Q
)
$(
MKDIR
)
-p
$(
workdir
)
$(
Q
)
$(
MAKE
)
-r
-f
$(
PX4_MK_DIR
)
library.mk
\
-C
$(
workdir
)
\
LIBRARY_WORK_DIR
=
$(
workdir
)
\
LIBRARY_LIB
=
$@
\
LIBRARY_MK
=
$(
mkfile
)
\
LIBRARY_NAME
=
$(
lastword
$(
subst /, ,
$(
workdir
)))
\
library
# make a list of phony clean targets for modules
LIBRARY_CLEANS
:=
$(
foreach path,
$(
dir
$(
LIBRARY_MKFILES
))
,
$(
WORK_DIR
)$(
path
)
/clean
)
# rules to clean modules
.PHONY
:
$(LIBRARY_CLEANS)
$(LIBRARY_CLEANS)
:
relpath = $(patsubst $(WORK_DIR)%
,
%
,
$@)
$(LIBRARY_CLEANS)
:
mkfile = $(patsubst %clean
,
%library.mk
,
$(relpath))
$(LIBRARY_CLEANS)
:
@$(
ECHO
)
%% cleaning using
$(
mkfile
)
$(
Q
)
$(
MAKE
)
-r
-f
$(
PX4_MK_DIR
)
library.mk
\
LIBRARY_WORK_DIR
=
$(
dir
$@
)
\
LIBRARY_MK
=
$(
mkfile
)
\
clean
################################################################################
# NuttX libraries and paths
################################################################################
...
...
@@ -420,8 +468,8 @@ $(PRODUCT_BUNDLE): $(PRODUCT_BIN)
$(PRODUCT_BIN)
:
$(PRODUCT_ELF)
$(
call SYM_TO_BIN,
$<
,
$@
)
$(PRODUCT_ELF)
:
$(OBJS) $(MODULE_OBJS) $(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES)
$(
call LINK,
$@
,
$(
OBJS
)
$(
MODULE_OBJS
))
$(PRODUCT_ELF)
:
$(OBJS) $(MODULE_OBJS)
$(LIBRARY_LIBS)
$(GLOBAL_DEPS) $(LINK_DEPS) $(MODULE_MKFILES)
$(
call LINK,
$@
,
$(
OBJS
)
$(
MODULE_OBJS
)
$(
LIBRARY_LIBS
)
)
#
# Utility rules
...
...
This diff is collapsed.
Click to expand it.
makefiles/library.mk
0 → 100644
+
169
−
0
View file @
3a1c9f14
#
# Copyright (c) 2013 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# Framework makefile for PX4 libraries
#
# This makefile is invoked by firmware.mk to build each of the linraries
# that will subsequently be linked into the firmware image.
#
# Applications are built as standard ar archives. Unlike modules,
# all public symbols in library objects are visible across the entire
# firmware stack.
#
# In general, modules should be preferred to libraries when possible.
# Libraries may also be pre-built.
#
# IMPORTANT NOTE:
#
# This makefile assumes it is being invoked in the library's output directory.
#
#
# Variables that can be set by the library's library.mk:
#
#
# SRCS (optional)
#
# Lists the .c, cpp and .S files that should be compiled/assembled to
# produce the library.
#
# PREBUILT_LIB (optional)
#
# Names the prebuilt library in the source directory that should be
# linked into the firmware.
#
# INCLUDE_DIRS (optional, must be appended, ignored if SRCS not set)
#
# The list of directories searched for include files. If non-standard
# includes (e.g. those from another module) are required, paths to search
# can be added here.
#
#
#
# Variables visible to the library's library.mk:
#
# CONFIG
# BOARD
# LIBRARY_WORK_DIR
# LIBRARY_LIB
# LIBRARY_MK
# Anything set in setup.mk, board_$(BOARD).mk and the toolchain file.
# Anything exported from config_$(CONFIG).mk
#
################################################################################
# No user-serviceable parts below.
################################################################################
ifeq
($(LIBRARY_MK),)
$(
error
No library makefile specified
)
endif
$(info
%%
LIBRARY_MK
=
$(
LIBRARY_MK
)
)
#
# Get the board/toolchain config
#
include
$(PX4_MK_DIR)/board_$(BOARD).mk
#
# Get the library's config
#
include
$(LIBRARY_MK)
LIBRARY_SRC
:=
$(
dir
$(
LIBRARY_MK
))
$(info
%
LIBRARY_NAME
=
$(
LIBRARY_NAME
)
)
$(info
%
LIBRARY_SRC
=
$(
LIBRARY_SRC
)
)
$(info
%
LIBRARY_LIB
=
$(
LIBRARY_LIB
)
)
$(info
%
LIBRARY_WORK_DIR
=
$(
LIBRARY_WORK_DIR
)
)
#
# Things that, if they change, might affect everything
#
GLOBAL_DEPS
+=
$(
MAKEFILE_LIST
)
################################################################################
# Build rules
################################################################################
#
# What we're going to build
#
library
:
$(LIBRARY_LIB)
ifneq
($(PREBUILT_LIB),)
VPATH
=
$(
LIBRARY_SRC
)
$(LIBRARY_LIB)
:
$(PREBUILT_LIB) $(GLOBAL_DEPS)
@$(
ECHO
)
"PREBUILT:
$(
PREBUILT_LIB
)
"
$(
Q
)
$(
COPY
)
$<
$@
else
##
## Object files we will generate from sources
##
OBJS
=
$(
addsuffix .o,
$(
SRCS
))
#
# SRCS -> OBJS rules
#
$(OBJS)
:
$(GLOBAL_DEPS)
vpath
%.c
$(LIBRARY_SRC)
$(filter %.c.o,$(OBJS))
:
%.c.o: %.c $(GLOBAL_DEPS)
$(
call COMPILE,
$<
,
$@
)
vpath
%.cpp
$(LIBRARY_SRC)
$(filter %.cpp.o,$(OBJS))
:
%.cpp.o: %.cpp $(GLOBAL_DEPS)
$(
call COMPILEXX,
$<
,
$@
)
vpath
%.S
$(LIBRARY_SRC)
$(filter %.S.o,$(OBJS))
:
%.S.o: %.S $(GLOBAL_DEPS)
$(
call ASSEMBLE,
$<
,
$@
)
#
# Built product rules
#
$(LIBRARY_LIB)
:
$(OBJS) $(GLOBAL_DEPS)
$(
call ARCHIVE,
$@
,
$(
OBJS
))
endif
#
# Utility rules
#
clean
:
$(
Q
)
$(
REMOVE
)
$(
LIBRARY_LIB
)
$(
OBJS
)
This diff is collapsed.
Click to expand it.
makefiles/module.mk
+
2
−
22
View file @
3a1c9f14
...
...
@@ -35,7 +35,7 @@
# This makefile is invoked by firmware.mk to build each of the modules
# that will subsequently be linked into the firmware image.
#
#
Application
s are built as prelinked objects with a limited set of exported
#
Module
s are built as prelinked objects with a limited set of exported
# symbols, as the global namespace is shared between all modules. Normally an
# module will just export one or more <command>_main functions.
#
...
...
@@ -183,30 +183,10 @@ CXXFLAGS += -fvisibility=$(DEFAULT_VISIBILITY) -include $(PX4_INCLUDE_DIR)visibi
#
module
:
$(MODULE_OBJ) $(MODULE_COMMAND_FILES)
##
## Locate sources (allows relative source paths in module.mk)
##
#define SRC_SEARCH
# $(abspath $(firstword $(wildcard $1) $(wildcard $(MODULE_SRC)/$1) MISSING_$1))
#endef
#
#ABS_SRCS ?= $(foreach src,$(SRCS),$(call SRC_SEARCH,$(src)))
#MISSING_SRCS := $(subst MISSING_,,$(filter MISSING_%,$(ABS_SRCS)))
#ifneq ($(MISSING_SRCS),)
#$(error $(MODULE_MK): missing in SRCS: $(MISSING_SRCS))
#endif
#ifeq ($(ABS_SRCS),)
#$(error $(MODULE_MK): nothing to compile in SRCS)
#endif
#
##
## Object files we will generate from sources
##
#OBJS := $(foreach src,$(ABS_SRCS),$(MODULE_WORK_DIR)$(src).o)
OBJS
=
$(
addsuffix .o,
$(
SRCS
))
$(info
SRCS
$(SRCS))
$(info
OBJS
$(OBJS))
OBJS
=
$(
addsuffix .o,
$(
SRCS
))
#
# SRCS -> OBJS rules
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment