Skip to content

Commit

Permalink
use common init.mk to match indigo/bigcode/infra
Browse files Browse the repository at this point in the history
  • Loading branch information
rlane committed Oct 25, 2013
1 parent 71bee3f commit ad1777a
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 245 deletions.
89 changes: 89 additions & 0 deletions init.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
################################################################
#
# Copyright 2013, Big Switch Networks, Inc.
#
# Licensed under the Eclipse Public License, Version 1.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the
# License.
#
################################################################

#
# The root of of our repository is here:
#
ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))

#
# Resolve submodule dependencies.
#
ifndef SUBMODULE_INFRA
ifdef SUBMODULES
SUBMODULE_INFRA := $(SUBMODULES)/infra
else
SUBMODULE_INFRA := $(ROOT)/submodules/infra
SUBMODULES_LOCAL += infra
endif
endif

ifndef SUBMODULE_BIGCODE
ifdef SUBMODULES
SUBMODULE_BIGCODE := $(SUBMODULES)/bigcode
else
SUBMODULE_BIGCODE := $(ROOT)/submodules/bigcode
SUBMODULES_LOCAL += bigcode
endif
endif

ifndef SUBMODULE_INDIGO
ifdef SUBMODULES
SUBMODULE_INDIGO := $(SUBMODULES)/indigo
else
SUBMODULE_INDIGO := $(ROOT)/submodules/indigo
SUBMODULES_LOCAL += indigo
endif
endif

ifndef SUBMODULE_LUAJIT2
ifdef SUBMODULES
SUBMODULE_LUAJIT2 := $(SUBMODULES)/luajit-2.0
else
SUBMODULE_LUAJIT2 := $(ROOT)/submodules/luajit-2.0
SUBMODULES_LOCAL += luajit2
endif
endif

ifdef SUBMODULES_LOCAL
SUBMODULES_LOCAL_UPDATE := $(shell python $(ROOT)/submodules/init.py --update $(SUBMODULES_LOCAL))
ifneq ($(lastword $(SUBMODULES_LOCAL_UPDATE)),submodules:ok.)
$(info Local submodule update failed.)
$(info Result:)
$(info $(SUBMODULES_LOCAL_UPDATE))
$(error Abort)
endif
endif

export SUBMODULE_INFRA
export SUBMODULE_BIGCODE
export SUBMODULE_INDIGO
export SUBMODULE_LUAJIT2
export BUILDER := $(SUBMODULE_INFRA)/builder/unix

MODULE_DIRS := $(ROOT)/Modules \
$(SUBMODULE_INFRA)/modules \
$(SUBMODULE_BIGCODE)/modules \
$(SUBMODULE_INDIGO)/modules

.show-submodules:
@echo infra @ $(SUBMODULE_INFRA)
@echo bigcode @ $(SUBMODULE_BIGCODE)
@echo indigo @ $(SUBMODULE_INDIGO)
@echo luajit2 @ $(SUBMODULE_LUAJIT2)
85 changes: 85 additions & 0 deletions submodules/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/python
################################################################
#
# Copyright 2013, Big Switch Networks, Inc.
#
# Licensed under the Eclipse Public License, Version 1.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the
# License.
#
################################################################

################################################################
#
# This script updates all local submodules if they haven't
# been initialized.
#
################################################################
import os
import sys
import subprocess
import argparse

ap = argparse.ArgumentParser(description="Submodule Management.")

#
# The root of the repository.
# We assume by default that this script resides in
# the $(ROOT)/submodules directory.
#
root_default = os.path.abspath("%s/../" % os.path.dirname(__file__))

ap.add_argument("--root", help="The root of the respository.",
default=root_default)

ap.add_argument("--update", help="Update the named submodules.",
nargs='+', default=None, metavar='SUBMODULE')

ap.add_argument("--list", help="List all submodules.",
action='store_true')

ops = ap.parse_args();

# Move to the root of the repository
os.chdir(ops.root)

# Get the status of all submodules
submodule_status = {}
try:
for entry in subprocess.check_output(['git', 'submodule', 'status']).split("\n"):
data = entry.split()
if len(data) >= 2:
submodule_status[data[1].replace("submodules/", "")] = data[0]
except Exception as e:
print repr(e)
raise

if ops.list:
for (module, status) in submodule_status.iteritems():
print module

if ops.update:
for (module, status) in submodule_status.iteritems():
if module in ops.update or "all" in ops.update:
if status[0] == '-':
# This submodule has not yet been updated
print "Updating submodule %s" % module
if subprocess.check_call(['git', 'submodule', 'update', '--init', 'submodules/%s' % module]) != 0:
print "git error updating module '%s'." % (module, switchlight_root, module)
sys.exit(1)
else:
print "Submodule %s is already checked out." % module
print "submodules:ok."




27 changes: 1 addition & 26 deletions targets/flowtable-benchmark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,13 @@
# License.
#
################################################################

ifndef ROOT
ROOT := $(dir $(lastword $(MAKEFILE_LIST)))/../..
endif

ifndef INFRA
INFRA := $(ROOT)/submodules/infra
endif

ifndef BIGCODE
BIGCODE := $(ROOT)/submodules/bigcode
endif

ifndef INDIGO
INDIGO := $(ROOT)/submodules/indigo
endif

ifndef BUILDER
BUILDER := $(INFRA)/builder/unix
endif

ifndef BUILD_DIR
export BUILD_DIR := ./build
endif
include ../../init.mk

ALLOW_DECLARATION_AFTER_STATEMENT = 1

MODULE := flowtable_benchmark
include $(BUILDER)/standardinit.mk

MODULE_DIRS := $(INDIGO)/modules $(INFRA)/modules $(BIGCODE)/modules $(ROOT)/Modules

LIBRARY := flowtable_benchmark_main
$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(BUILDER)/lib.mk
Expand Down
21 changes: 1 addition & 20 deletions targets/ivs-ctl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,17 @@
# License.
#
################################################################

ifndef ROOT
ROOT := $(dir $(lastword $(MAKEFILE_LIST)))/../..
endif

ifndef INFRA
INFRA := $(ROOT)/submodules/infra
endif

ifndef BUILDER
BUILDER := $(INFRA)/builder/unix
endif

ifndef BUILD_DIR
export BUILD_DIR := ./build
endif
include ../../init.mk

ALLOW_DECLARATION_AFTER_STATEMENT = 1

MODULE := IVSCtl
include $(BUILDER)/standardinit.mk

MODULE_DIRS := $(INDIGO)/Modules $(ROOT)/Modules

LIBRARY := IVSCtlMain
$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(BUILDER)/lib.mk

MODULEMANIFEST := $(INDIGO)/Modules/Manifest.mk

DEPENDMODULES :=
include $(BUILDER)/dependmodules.mk

Expand Down
54 changes: 1 addition & 53 deletions targets/ivs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,7 @@
# License.
#
################################################################

###############################################################################
#
# Makefile
#
# ivs
#
###############################################################################

# Not needed by the build system directly, but necessary for some
# of the variables we are going to set
ifndef ROOT
ROOT := $(dir $(lastword $(MAKEFILE_LIST)))/../..
endif

ifndef INFRA
INFRA := $(ROOT)/submodules/infra
endif

ifndef INDIGO
INDIGO := $(ROOT)/submodules/indigo
endif

ifndef BIGCODE
BIGCODE := $(ROOT)/submodules/bigcode
endif

ifndef BUILDER
BUILDER := $(INFRA)/builder/unix
endif

#
# Default to a local build directory for everything
#
ifndef BUILD_DIR
export BUILD_DIR := ./build
endif
include ../../init.mk

ALLOW_DECLARATION_AFTER_STATEMENT = 1

Expand All @@ -64,8 +28,6 @@ ALLOW_DECLARATION_AFTER_STATEMENT = 1
MODULE := IVS
include $(BUILDER)/standardinit.mk

MODULE_DIRS := $(INDIGO)/modules $(INFRA)/modules $(BIGCODE)/modules $(ROOT)/Modules

#
# We're now ready to specify the "stuff" we want built.
#
Expand All @@ -75,20 +37,6 @@ LIBRARY := IVSMain
$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(BUILDER)/lib.mk

#
# Our binary is going to depend upon BigCode modules.
#
# The Manifest.mk for BigCode, which describes the locations
# of all of the available modules, is in $INDIGO/Modules/Manifest.mk
#
# The settings in the Manifest.mk file will provide the information
# necessary to build the modules on which this binary will depend.
#
# All you have to do is point to the Manifest.mk,
# specify which Modules you want built, and include dependmodules.mk:
#
MODULEMANIFEST := $(INDIGO)/modules/Manifest.mk $(INFRA)/modules/Manifest.mk

#
# Set the modules we want to automatically build for this binary
#
Expand Down
27 changes: 1 addition & 26 deletions targets/l2table-benchmark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,13 @@
# License.
#
################################################################

ifndef ROOT
ROOT := $(dir $(lastword $(MAKEFILE_LIST)))/../..
endif

ifndef INFRA
INFRA := $(ROOT)/submodules/infra
endif

ifndef BIGCODE
BIGCODE := $(ROOT)/submodules/bigcode
endif

ifndef INDIGO
INDIGO := $(ROOT)/submodules/indigo
endif

ifndef BUILDER
BUILDER := $(INFRA)/builder/unix
endif

ifndef BUILD_DIR
export BUILD_DIR := ./build
endif
include ../../init.mk

ALLOW_DECLARATION_AFTER_STATEMENT = 1

MODULE := l2table_benchmark
include $(BUILDER)/standardinit.mk

MODULE_DIRS := $(INDIGO)/modules $(INFRA)/modules $(BIGCODE)/modules $(ROOT)/Modules

LIBRARY := l2table_benchmark_main
$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(BUILDER)/lib.mk
Expand Down
Loading

0 comments on commit ad1777a

Please sign in to comment.