<commit_before>#
# Copyright 2011 Google Inc. All Rights Reserved.
#

OSX_VERSION=$(shell sw_vers -productVersion 2>/dev/null | cut -d. -f1-2)
SWIG=$(shell type -p swig 2>/dev/null)
SIMIAN_VERSION=2.2.2
SIMIAN=simian-${SIMIAN_VERSION}
SDIST_TAR=dist/simian-${SIMIAN_VERSION}.tar
SDIST=${SDIST_TAR}.gz
MUNKI_VERSION=1.0.0.1867.0
MUNKI=munkitools-${MUNKI_VERSION}
MUNKIFILE=${MUNKI}.dmg
PYTHON_VERSION=2.6
PYTHON=$(shell type -p python${PYTHON_VERSION})
TS=$(shell date '+%s')
# This is the version that opensource.apple.com offers
SWIG_VERSION=1.3.40
SWIG_URL=http://downloads.sourceforge.net/project/swig/swig/swig-${SWIG_VERSION}/swig-${SWIG_VERSION}.tar.gz?r=&ts=${TS}
SVN_VERSION=$(shell svnversion | tr '[:upper:]' '[:lower:]')
SVN_REGEX=^[0-9]+[a-z]*$
BUILD_VERSION=$(shell if [[ '${SVN_VERSION}' =~ ${SVN_REGEX} ]]; then echo ${SVN_VERSION}; else echo ${SIMIAN_VERSION} | tr '.' '-'; fi)

os_check:
	@if [ -z "${OSX_VERSION}" ]; then echo Must run on OS X ; exit 1 ; fi

python_check:
	@if [ ! -x "${PYTHON}" ]; then echo Cannot find ${PYTHON} ; exit 1 ; fi

swig_check:
	@if [ -z "${SWIG}" -o ! -x "${SWIG}" ]; then \
	echo swig must be installed. type: ; \
	echo ; \
	echo "       make swig" ; \
	echo ; \
	echo and it will be done automatically for you. ; \
	exit 1 ; \
	fi

swig.tgz:
	curl -L -o swig.tgz "${SWIG_URL}"

swig: os_check swig.tgz
	rm -rf tmpswig
	mkdir -p tmpswig
	tar -zxf swig.tgz -C tmpswig
	cd tmpswig/swig-${SWIG_VERSION} ; \
	./configure --prefix=/usr/local ; \
	make ; \
	echo Type your password to exec sudo make install. ; \
	sudo make install
	rm -rf tmpswig
	@echo Success building and installing swig.

virtualenv: python_check
	${PYTHON} -c 'import virtualenv' || \
	sudo easy_install-${PYTHON_VERSION} -U virtualenv==1.10.1

VE: virtualenv python_check
	[ -d VE ] || \
	${PYTHON} $(shell type -p virtualenv) --no-site-packages VE

test: swig_check VE
	[ -f test ] || \
	env SIMIAN_CONFIG_PATH="${PWD}/etc/simian/" \
	VE/bin/python setup.py google_test && touch test && \
	echo ALL TESTS COMPLETED SUCCESSFULLY

settings_check: test
	VE/bin/python \
	src/simian/util/validate_settings.py etc/simian/ \
	src/ ./pyasn1*.egg ./tlslite*.egg

build: swig_check VE
	VE/bin/python setup.py build

install: swig_check client_config build
	VE/bin/python setup.py install
	mkdir -p /etc/simian/ && cp -Rf etc/simian /etc && chmod 644 /etc/simian/*.cfg

clean_contents:
	rm -rf contents.tar contents.tar.gz tmpcontents

clean_pkgs:
	rm -rf tmppkgs

clean_sdist:
	rm -rf ${SDIST} ${SDIST_TAR}

clean_test:
	rm -f test

clean_ve:
	rm -rf VE

clean: clean_contents clean_pkgs clean_sdist clean_test clean_ve
	rm -rf ${SIMIAN}.dmg ${SIMIAN}-${MUNKI}.dmg dist/* build/* *.egg install_name_tool

${SDIST}: VE clean_sdist client_config
	VE/bin/python setup.py sdist --formats=tar
	gzip ${SDIST_TAR}

server_config:
	src/simian/util/create_gae_bundle.sh $(PWD)
	sed -i "" "s/^application:.*/application: `PYTHONPATH=. python src/simian/util/appid_generator.py`/" gae_bundle/app.yaml
	src/simian/util/link_module.sh PyYAML
	src/simian/util/link_module.sh pytz
	src/simian/util/link_module.sh tlslite
	src/simian/util/link_module.sh pyasn1
	src/simian/util/link_module.sh icalendar
	VE/bin/python src/simian/util/compile_js.py gae_bundle/simian/mac/admin/js/simian.js

client_config: settings_check

${MUNKIFILE}:
	curl -o $@ http://munkibuilds.org/${MUNKI_VERSION}/$@
	hdiutil verify "$@" || (rm -f "$@" ; exit 1)

add_munkicontents: os_check ${MUNKIFILE}
	mkdir -p tmpcontents/
	# Munki moved to a mpkg, scrape out all the contents of each
	# mpkg in this shell multiliner.
	mnt=`hdiutil attach ${MUNKIFILE} | tail -1 | awk '{print $$3};'` ; \
	cd tmpcontents && \
	for pkg in $$mnt/${MUNKI}.mpkg/Contents/Packages/*.pkg; do \
	gzip -dc "$$pkg/Contents/Archive.pax.gz" | pax -r ; done ; \
	hdiutil detach "$$mnt"

contents.tar.gz: client_config
	mkdir -p tmpcontents/etc/simian/ssl/certs
	mkdir -p tmpcontents/etc/simian/ssl/private_keys
	chmod 750 tmpcontents/etc/simian/ssl/private_keys<commit_msg>download Munki DMG over SSL<commit_after>#
# Copyright 2011 Google Inc. All Rights Reserved.
#

OSX_VERSION=$(shell sw_vers -productVersion 2>/dev/null | cut -d. -f1-2)
SWIG=$(shell type -p swig 2>/dev/null)
SIMIAN_VERSION=2.2.2
SIMIAN=simian-${SIMIAN_VERSION}
SDIST_TAR=dist/simian-${SIMIAN_VERSION}.tar
SDIST=${SDIST_TAR}.gz
MUNKI_VERSION=1.0.0.1867.0
MUNKI=munkitools-${MUNKI_VERSION}
MUNKIFILE=${MUNKI}.dmg
PYTHON_VERSION=2.6
PYTHON=$(shell type -p python${PYTHON_VERSION})
TS=$(shell date '+%s')
# This is the version that opensource.apple.com offers
SWIG_VERSION=1.3.40
SWIG_URL=http://downloads.sourceforge.net/project/swig/swig/swig-${SWIG_VERSION}/swig-${SWIG_VERSION}.tar.gz?r=&ts=${TS}
SVN_VERSION=$(shell svnversion | tr '[:upper:]' '[:lower:]')
SVN_REGEX=^[0-9]+[a-z]*$
BUILD_VERSION=$(shell if [[ '${SVN_VERSION}' =~ ${SVN_REGEX} ]]; then echo ${SVN_VERSION}; else echo ${SIMIAN_VERSION} | tr '.' '-'; fi)

os_check:
	@if [ -z "${OSX_VERSION}" ]; then echo Must run on OS X ; exit 1 ; fi

python_check:
	@if [ ! -x "${PYTHON}" ]; then echo Cannot find ${PYTHON} ; exit 1 ; fi

swig_check:
	@if [ -z "${SWIG}" -o ! -x "${SWIG}" ]; then \
	echo swig must be installed. type: ; \
	echo ; \
	echo "       make swig" ; \
	echo ; \
	echo and it will be done automatically for you. ; \
	exit 1 ; \
	fi

swig.tgz:
	curl -L -o swig.tgz "${SWIG_URL}"

swig: os_check swig.tgz
	rm -rf tmpswig
	mkdir -p tmpswig
	tar -zxf swig.tgz -C tmpswig
	cd tmpswig/swig-${SWIG_VERSION} ; \
	./configure --prefix=/usr/local ; \
	make ; \
	echo Type your password to exec sudo make install. ; \
	sudo make install
	rm -rf tmpswig
	@echo Success building and installing swig.

virtualenv: python_check
	${PYTHON} -c 'import virtualenv' || \
	sudo easy_install-${PYTHON_VERSION} -U virtualenv==1.10.1

VE: virtualenv python_check
	[ -d VE ] || \
	${PYTHON} $(shell type -p virtualenv) --no-site-packages VE

test: swig_check VE
	[ -f test ] || \
	env SIMIAN_CONFIG_PATH="${PWD}/etc/simian/" \
	VE/bin/python setup.py google_test && touch test && \
	echo ALL TESTS COMPLETED SUCCESSFULLY

settings_check: test
	VE/bin/python \
	src/simian/util/validate_settings.py etc/simian/ \
	src/ ./pyasn1*.egg ./tlslite*.egg

build: swig_check VE
	VE/bin/python setup.py build

install: swig_check client_config build
	VE/bin/python setup.py install
	mkdir -p /etc/simian/ && cp -Rf etc/simian /etc && chmod 644 /etc/simian/*.cfg

clean_contents:
	rm -rf contents.tar contents.tar.gz tmpcontents

clean_pkgs:
	rm -rf tmppkgs

clean_sdist:
	rm -rf ${SDIST} ${SDIST_TAR}

clean_test:
	rm -f test

clean_ve:
	rm -rf VE

clean: clean_contents clean_pkgs clean_sdist clean_test clean_ve
	rm -rf ${SIMIAN}.dmg ${SIMIAN}-${MUNKI}.dmg dist/* build/* *.egg install_name_tool

${SDIST}: VE clean_sdist client_config
	VE/bin/python setup.py sdist --formats=tar
	gzip ${SDIST_TAR}

server_config:
	src/simian/util/create_gae_bundle.sh $(PWD)
	sed -i "" "s/^application:.*/application: `PYTHONPATH=. python src/simian/util/appid_generator.py`/" gae_bundle/app.yaml
	src/simian/util/link_module.sh PyYAML
	src/simian/util/link_module.sh pytz
	src/simian/util/link_module.sh tlslite
	src/simian/util/link_module.sh pyasn1
	src/simian/util/link_module.sh icalendar
	VE/bin/python src/simian/util/compile_js.py gae_bundle/simian/mac/admin/js/simian.js

client_config: settings_check

${MUNKIFILE}:
	curl -o $@ https://munkibuilds.org/${MUNKI_VERSION}/$@
	hdiutil verify "$@" || (rm -f "$@" ; exit 1)

add_munkicontents: os_check ${MUNKIFILE}
	mkdir -p tmpcontents/
	# Munki moved to a mpkg, scrape out all the contents of each
	# mpkg in this shell multiliner.
	mnt=`hdiutil attach ${MUNKIFILE} | tail -1 | awk '{print $$3};'` ; \
	cd tmpcontents && \
	for pkg in $$mnt/${MUNKI}.mpkg/Contents/Packages/*.pkg; do \
	gzip -dc "$$pkg/Contents/Archive.pax.gz" | pax -r ; done ; \
	hdiutil detach "$$mnt"

contents.tar.gz: client_config
	mkdir -p tmpcontents/etc/simian/ssl/certs
	mkdir -p tmpcontents/etc/simian/ssl/private_keys
	chmod 750 tmpcontents/etc/simian/ssl/private_keys
{'fraction_non_alphanumeric': 0.15401813439324308, 'fraction_numerical': 0.0111787355607999, 'mean_word_length': 3.9857585139318887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2900872', 'n_tokens_mistral': 3386, 'n_tokens_neox': 3249, 'n_words': 755}