Skip to content

mv make makeover

Matthew Von-Maszewski edited this page Jan 5, 2016 · 9 revisions

Status

  • merged to master -
  • code complete - January 5, 2016
  • development started - January 4, 2016

History / Context

Basho initially intended to use leveldb purely as a third-party storage library. There was no desire to invest for long term maintenance or development. Therefore there was no need to invest time in adapting Google's "build once" Makefile into something more appropriate to an active development usage model. Yet ongoing development kept creeping into various Riak release plans. This branch is an acknowledgement that Basho is going to continue to invest development time into Google's leveldb. This branch makes the following enhancements to the existing make process:

  • Create full dependency files to simplify rebuilds during development
  • Add explicit "debug" and "prof" targets to eliminate need to edit the Makefile (and accidentally check the modifications into git)
  • Produce the shared and static libraries from same object files to reduce make execution time
  • Build the test and tool executables build from libraries to reduce make execution time
  • Use static linking of snappy on Linux platforms for tools executables to simplify distribution of the tools with Riak

Branch Description

.gitignore

Have git ignore .d dependency files that this branch now generates on all platforms. Also have git ignore the .dSYM directories now generated on Mac IOS platforms.

Makefile

The Makefile automatically generates new .d dependency file for any source file or any of a source file's include files. The build_detect_platform script contains a recent change that creates an ldb_config.h file. The ldb_config.h is a dependency of almost every source file. The Makefile previously executed the build_detect_platform script upon every execution. build_detect_platform would therefore create a new db_config.h upon every execution. The new db_config.h would cause every file in the system to rebuild upon every execution. The "ifeq ($(wildcard build_config.mk),)" line makes the execution of build_detect_platform conditional. The script only executes if its prime output, build_config.mk, does not exists. This ends the continual rebuild loop.

The "if ($PLATFORM),OS_LINUX)" line adjusts the linker flags to use static libraries when building on Linux. The syntax used is not supported on OS X, and no other non-Linux platforms received testing. The static library usage is therefore limited to Linux builds which comprise the majority of Riak distributions. This change is only to facilitate easier use of Basho provided leveldb tools. It is not essential to the use of leveldb itself.

The "$(SHARED3)" recipe (construction rule) is reorganized as presented by Richard Hull's pull request:

https://github.com/basho/leveldb/pull/148

This fix reorganized the presentation of "new" objects versus "referenced libraries" on the command line in a manner that corrects how the linker records third-party libraries needed by this library.

The lines "ifneq ($(filter debug,$(MAKECMDGOALS)),)" and "ifneq ($(filter prof,$(MAKECMDGOALS)),)" create command line equivalents to hard coded options listed in lines 13, 14, and 15. The developer can now type "make debug" or "make debug check" to generate debug libraries or unit tests respectively. The goal is to reduce the number of times a Makefile that is set for debug build is accidentally checked into git.

The original Makefile from Google had an independent rule for every executable test program and tool program. New static dependency rules now cover most of the executables. Comments added to the Makefile discuss the various details of how the executables now build. The executables db_bench, db_bench_sqlite3, and db_bench_tree_db still have custom rules. They too might work with static dependency rules given more effort.

The last 3 line of the Makefile load dependency .d files. The $(DEPEND) variable holds a list of dependency file names. Dependency files have the name of the related .cc file as their stem, then followed by .d instead of .cc. Example: db/db_impl.cc source file becomes db/db_impl.d dependency file. The big magic is that the "-include" statement first looks to see if the .d file exists. If not, it will attempt to build the .d file via the earlier rule "%.d: %.cc" and then load the result.

build_detect_platform

A different pull request removed "so" as the default for the PLATFORM_SHARED_EXT variable. The change helped the make process execute faster by disabling the shared library file's creation. This Makefile now creates the shared library via the same object files that produce the static library. The creation overhead is negligible.

For Linux platforms only, use the static snappy library to build tool and test executables. This makes the tool executables easier to deploy as part of Riak.

db/c_test.c

Correcting a warning generated on OSX platform.

tools/perf_dump.cc and tools/sst_scan.cc

The eleveldb compile environment adds the "-Wall" compiler flag to leveldb's build environment. This flag caused warnings with the builds of perf_dump.cc and sst_scan.cc. The unused variable removal and transition of "%ull" to "PRIu64" eliminates the warnings.

tools/sst_rewrite.cc

The build of sst_rewrite.cc on Mac OSX had printf warnings. Transitioned us of "%dl" to "PRIu64" in six places eliminated the warnings.

Clone this wiki locally