Document how to use submodules for a simple build

Change-Id: I14bd9d05999fcad7d68f78707c5f06d1093a3fe1
diff --git a/README.md b/README.md
index 0823996..4ff16fe 100644
--- a/README.md
+++ b/README.md
@@ -9,66 +9,19 @@
 Everything is in Gerrit.
 One should not need to clone anything from anywhere else.
 The build will download source tarballs of various open source components, though.
-The following branches are required:
-
-| Project | branch |
-|---------|:------:|
-| [github/buildroot/buildroot](https://gerrit.cesnet.cz/plugins/gitiles/github/buildroot/buildroot/) | `cesnet/cla-6` |
-| [CzechLight/br2-external](https://gerrit.cesnet.cz/plugins/gitiles/CzechLight/br2-external/) | `master` |
-
-Our SW uses several open-source projects which are special snowflakes and which are integrated by the CI due to their tight coupling:
-
-* [`libredblack`](https://gerrit.cesnet.cz/plugins/gitiles/github/sysrepo/libredblack/)
-* [`libyang`](https://gerrit.cesnet.cz/plugins/gitiles/github/CESNET/libyang/)
-* [`sysrepo`](https://gerrit.cesnet.cz/plugins/gitiles/github/sysrepo/sysrepo/)
-* [`cla-sysrepo`](https://gerrit.cesnet.cz/plugins/gitiles/CzechLight/cla-sysrepo/)
-* [`libnetconf2`](https://gerrit.cesnet.cz/plugins/gitiles/github/CESNET/libnetconf2/)
-* Netopeer2's [`keystored`](https://gerrit.cesnet.cz/plugins/gitiles/github/CESNET/Netopeer2/+/master/keystored/)
-* [`Netopeer2-server`](https://gerrit.cesnet.cz/plugins/gitiles/github/CESNET/Netopeer2/+/master/server/)
-
-TODO: Can we use git submodules instead of this madness?
-Will that work reasonably well for changes that need to be made in a lockstep?
 
 TODO: Automate this via the CI system.
 I want to get the `.img` files for testing of each change, eventually.
 
-The commit hashes (SHA1s) of the required versions are [stored in git](https://gerrit.cesnet.cz/plugins/gitiles/CzechLight/cla-sysrepo/+/master/ci/versions.sh).
-All of these projects have to be checked out and made available to Buildroot via a `local.mk` file in the build dir:
-
 ```sh
-DOCOPT_CPP_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/docopt/docopt.cpp
-SPDLOG_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/gabime/spdlog
-LIBYANG_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/CESNET/libyang
-SYSREPO_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/sysrepo/sysrepo
-LIBNETCONF2_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/CESNET/libnetconf2
-NETOPEER2_KEYSTORED_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/CESNET/Netopeer2
-NETOPEER2_SERVER_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/CESNET/Netopeer2
-NETOPEER2_CLI_OVERRIDE_SRCDIR = /home/cesnet/gerrit/github/CESNET/Netopeer2
-CLA_SYSREPO_OVERRIDE_SRCDIR = /home/cesnet/gerrit/CzechLight/cla-sysrepo
-```
-
-For each of these projects, clone them from Gerrit and then checkout a specific Git ref.
-The command might be something like:
-
-```sh
-git checkout -b wip || git checkout wip
-git fetch
-git reset --hard SHA_GOES_HERE
-```
-
-This `local.mk` instructs Buildroot to skip download of these critical packages from the Internet.
-Their sources will be used as-is from these source directories.
-No patches will be applied!
-
-
-```sh
-mkdir build-for-clearfog
-cd build-for-clearfog
-vim local.mk
-# ...edit as shown above...
-make O=$PWD -C /home/cesnet/gerrit/github/buildroot/buildroot \
-  BR2_EXTERNAL=/home/cesnet/gerrit/CzechLight/br2-external \
-  czechlight_clearfog_defconfig
+git clone ssh://$YOUR_LOGIN@cesnet.cz@gerrit.cesnet.cz:29418/CzechLight/br2-external czechlight
+pushd czechlight
+git submodule update --init --recursive
+popd
+mkdir build-clearfog
+cd build-clearfog
+../czechlight/dev-setup-git.sh
+make czechlight_clearfog_defconfig
 make
 ```
 
diff --git a/dev-setup-git.sh b/dev-setup-git.sh
new file mode 100755
index 0000000..c03ee69
--- /dev/null
+++ b/dev-setup-git.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+if git rev-parse &> /dev/null; then
+  echo "Error: run this from a new build directory, not from within a git repo"
+  exit 1
+fi
+
+# Configure the local.mk with path to the individual repositories
+CZECHLIGHT_BR2_EXT_LOC="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cat > local.mk <<EOF
+DOCOPT_CPP_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/docopt.cpp
+SPDLOG_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/spdlog
+LIBYANG_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/libyang
+SYSREPO_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/sysrepo
+LIBNETCONF2_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/libnetconf2
+NETOPEER2_KEYSTORED_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/Netopeer2
+NETOPEER2_SERVER_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/Netopeer2
+NETOPEER2_CLI_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo/submodules/Netopeer2
+CLA_SYSREPO_OVERRIDE_SRCDIR = ${CZECHLIGHT_BR2_EXT_LOC}/submodules/cla-sysrepo
+EOF
+
+# We have to run make first so that the proxy Makefile is created and the BR2_EXTERNAL is remembered
+make O=$PWD -C ${CZECHLIGHT_BR2_EXT_LOC}/submodules/buildroot BR2_EXTERNAL=${CZECHLIGHT_BR2_EXT_LOC} outputmakefile