From: Carl Worth Date: Mon, 22 Apr 2013 21:24:30 +0000 (-0700) Subject: Initial commit of fips repository X-Git-Url: https://git.cworth.org/git?p=fips;a=commitdiff_plain;h=5e4afc13a1514f253373e7054ef025baef9b0ed0 Initial commit of fips repository Just a build system and a stub of a main program for now, (which doesn't do anything yet). --- 5e4afc13a1514f253373e7054ef025baef9b0ed0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a5d08a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.deps +.first-build-message +Makefile.config +fips +*.o +*~ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6938f22 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +# Default target +all: + +# List all subdirectores here. Each contains its own Makefile.local +subdirs := + +# We make all targets depend on the Makefiles themselves. +global_deps = Makefile Makefile.config Makefile.local \ + $(subdirs:%=%/Makefile) $(subdirs:%=%/Makefile.local) + +# Get settings from the output of configure by running it to generate +# Makefile.config if it doesn't exist yet. + +# If Makefile.config doesn't exist, then srcdir won't be +# set. Conditionally set it (assuming a plain srcdir build) so that +# the rule to generate Makefile.config can actually work. +srcdir ?= . + +include Makefile.config +Makefile.config: $(srcdir)/configure +ifeq ($(configure_options),) + @echo "" + @echo "Note: Calling ./configure with no command-line arguments. This is often fine," + @echo " but if you want to specify any arguments (such as an alternate prefix" + @echo " into which to install), call ./configure explicitly and then make again." + @echo " See \"./configure --help\" for more details." + @echo "" +endif + $(srcdir)/configure $(configure_options) + +# Finally, include all of the Makefile.local fragments where all the +# real work is done. + +include $(subdirs:%=%/Makefile.local) Makefile.local diff --git a/Makefile.local b/Makefile.local new file mode 100644 index 0000000..8ca5136 --- /dev/null +++ b/Makefile.local @@ -0,0 +1,260 @@ +# -*- makefile -*- + +# Here's the (hopefully simple) versioning scheme. +# +# Releases of fips have a two-digit version (0.1, 0.2, etc.). We +# increment the second digit for each release and increment the first +# digit when we reach particularly major milestones of usability. +# +# Between releases, (such as when compiling fips from the git +# repository), we let git append identification of the actual commit. +PACKAGE=fips + +IS_GIT=$(shell if [ -d .git ] ; then echo yes ; else echo no; fi) + +ifeq ($(IS_GIT),yes) +DATE:=$(shell git log --date=short -1 --pretty=format:%cd) +else +DATE:=$(shell date +%F) +endif + +VERSION:=$(shell cat ${srcdir}/version) +ifeq ($(filter release release-message pre-release, $(MAKECMDGOALS)),) +ifeq ($(IS_GIT),yes) +VERSION:=$(shell git describe --match '[0-9.]*' 2>/dev/null | sed -e s/_/~/ -e s/-/+/ -e s/-/~/) +endif +endif + +UPSTREAM_TAG=$(subst ~,_,$(VERSION)) +DEB_TAG=debian/$(UPSTREAM_TAG)-1 + +RELEASE_HOST=cworth.org +RELEASE_DIR=/home/cworth/public_html/fips/releases +RELEASE_URL=http://cworth.org/fips/releases +TAR_FILE=$(PACKAGE)-$(VERSION).tar.gz +DEB_TAR_FILE=$(PACKAGE)_$(VERSION).orig.tar.gz +SHA1_FILE=$(TAR_FILE).sha1 +GPG_FILE=$(SHA1_FILE).asc + +# Smash together user's values with our extra values +FINAL_CFLAGS = -DFIPS_VERSION=$(VERSION) $(CFLAGS) $(WARN_CFLAGS) $(CONFIGURE_CFLAGS) $(extra_cflags) +FINAL_FIPS_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(TALLOC_LDFLAGS) +FINAL_FIPS_LINKER = CC +ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1) +FINAL_FIPS_LDFLAGS += $(CONFIGURE_LDFLAGS) +endif +ifeq ($(LIBDIR_IN_LDCONFIG),0) +FINAL_FIPS_LDFLAGS += $(RPATH_LDFLAGS) +endif + +.PHONY: all +all: fips +ifeq ($(MAKECMDGOALS),) +ifeq ($(shell cat .first-build-message 2>/dev/null),) + @FIPS_FIRST_BUILD=1 $(MAKE) --no-print-directory all + @echo "" + @echo "Compilation of fips is now complete. You can install fips with:" + @echo "" + @echo " make install" + @echo "" + @echo "Note that depending on the prefix to which you are installing" + @echo "you may need root permission (such as \"sudo make install\")." + @echo "See \"./configure --help\" for help on setting an alternate prefix." + @echo Printed > .first-build-message +endif +endif + +$(TAR_FILE): + if git tag -v $(VERSION) >/dev/null 2>&1; then \ + ref=$(VERSION); \ + else \ + ref="HEAD" ; \ + echo "Warning: No signed tag for $(VERSION)"; \ + fi ; \ + git archive --format=tar --prefix=$(PACKAGE)-$(VERSION)/ $$ref > $(TAR_FILE).tmp + echo $(VERSION) > version.tmp + tar --append -f $(TAR_FILE).tmp --transform s_^_$(PACKAGE)-$(VERSION)/_ --transform 's_.tmp$$__' version.tmp + rm version.tmp + gzip < $(TAR_FILE).tmp > $(TAR_FILE) + @echo "Source is ready for release in $(TAR_FILE)" + +$(SHA1_FILE): $(TAR_FILE) + sha1sum $^ > $@ + +$(GPG_FILE): $(SHA1_FILE) + @echo "Please enter your GPG password to sign the checksum." + gpg --armor --sign $^ + +.PHONY: dist +dist: $(TAR_FILE) + +.PHONY: test +test: + @echo "FIXME: Should consider adding a test suite here." + +# We invoke make recursively only to force ordering of our phony +# targets in the case of parallel invocation of make (-j). +# +# We carefully ensure that our VERSION variable is passed down to any +# sub-ordinate make invocations (which won't otherwise know that they +# are part of the release and need to take the version from the +# version file). +.PHONY: release +release: verify-source-tree-and-version + $(MAKE) VERSION=$(VERSION) verify-newer + $(MAKE) VERSION=$(VERSION) clean + $(MAKE) VERSION=$(VERSION) test + git tag -s -m "$(PACKAGE) $(VERSION) release" $(UPSTREAM_TAG) + $(MAKE) VERSION=$(VERSION) $(GPG_FILE) + ln -sf $(TAR_FILE) $(DEB_TAR_FILE) + pristine-tar commit $(DEB_TAR_FILE) $(UPSTREAM_TAG) + git tag -s -m "$(PACKAGE) Debian $(VERSION)-1 upload (same as $(VERSION))" $(DEB_TAG) + mkdir -p releases + mv $(TAR_FILE) $(SHA1_FILE) $(GPG_FILE) releases + $(MAKE) VERSION=$(VERSION) release-message > $(PACKAGE)-$(VERSION).announce +ifeq ($(REALLY_UPLOAD),yes) + git push origin $(VERSION) + cd releases && scp $(TAR_FILE) $(SHA1_FILE) $(GPG_FILE) $(RELEASE_HOST):$(RELEASE_DIR) + ssh $(RELEASE_HOST) "rm -f $(RELEASE_DIR)/LATEST-$(PACKAGE)-* ; ln -s $(TAR_FILE) $(RELEASE_DIR)/LATEST-$(TAR_FILE)" +endif + @echo "Please send a release announcement using $(PACKAGE)-$(VERSION).announce as a template." + +.PHONY: pre-release +pre-release: + $(MAKE) VERSION=$(VERSION) clean + $(MAKE) VERSION=$(VERSION) test + git tag -s -m "$(PACKAGE) $(VERSION) release" $(UPSTREAM_TAG) + git tag -s -m "$(PACKAGE) Debian $(VERSION)-1 upload (same as $(VERSION))" $(DEB_TAG) + $(MAKE) VERSION=$(VERSION) $(TAR_FILE) + ln -sf $(TAR_FILE) $(DEB_TAR_FILE) + pristine-tar commit $(DEB_TAR_FILE) $(UPSTREAM_TAG) + mkdir -p releases + mv $(TAR_FILE) $(DEB_TAR_FILE) releases + +.PHONY: debian-snapshot +debian-snapshot: + make VERSION=$(VERSION) clean + TMPFILE=$$(mktemp /tmp/fips.XXXXXX); \ + cp debian/changelog $${TMPFILE}; \ + EDITOR=/bin/true dch -b -v $(VERSION)+1 \ + -D UNRELEASED 'test build, not for upload'; \ + echo '3.0 (native)' > debian/source/format; \ + debuild -us -uc; \ + mv -f $${TMPFILE} debian/changelog; \ + echo '3.0 (quilt)' > debian/source/format + +.PHONY: release-message +release-message: + @echo "To: XXX" + @echo "Subject: $(PACKAGE) release $(VERSION) now available" + @echo "" + @echo "Where to obtain fips $(VERSION)" + @echo "===========================" + @echo " $(RELEASE_URL)/$(TAR_FILE)" + @echo "" + @echo "Which can be verified with:" + @echo "" + @echo " $(RELEASE_URL)/$(SHA1_FILE)" + @echo -n " " + @cat releases/$(SHA1_FILE) + @echo "" + @echo " $(RELEASE_URL)/$(GPG_FILE)" + @echo " (signed by `getent passwd "$$USER" | cut -d: -f 5 | cut -d, -f 1`)" + @echo "" + @echo "What's new in fips $(VERSION)" + @echo "=========================" + @sed -ne '/^[Ff]ips $(VERSION)/{n;n;b NEWS}; d; :NEWS /^===/q; {p;n;b NEWS}' < NEWS | head -n -2 + @echo "" + @echo "What is fips" + @echo "============" + @echo "Fips is a program for monitoring performance of OpenGL applications" + +# This is a chain of dependencies rather than a simple list simply to +# avoid the messages getting interleaved in the case of a parallel +# make invocation. +.PHONY: verify-source-tree-and-version +verify-source-tree-and-version: verify-no-dirty-code + +.PHONY: verify-no-dirty-code +verify-no-dirty-code: +ifeq ($(IS_GIT),yes) + @printf "Checking that source tree is clean..." +ifneq ($(shell git ls-files -m),) + @echo "No" + @echo "The following files have been modified since the most recent git commit:" + @echo "" + @git ls-files -m + @echo "" + @echo "The release will be made from the committed state, but perhaps you meant" + @echo "to commit this code first? Please clean this up to make it more clear." + @false +else + @echo "Good" +endif +endif + +.PHONY: verify-newer +verify-newer: + @echo -n "Checking that no $(VERSION) release already exists..." + @wget -q -O /dev/null $(RELEASE_URL)/$(TAR_FILE) ; \ + case $$? in \ + 8) echo "Good." ;; \ + 0) echo "Ouch."; \ + echo "Found: $(RELEASE_URL)/$(TAR_FILE)"; \ + echo "Refusing to replace an existing release."; \ + echo "Don't forget to update \"version\" as described in RELEASING before release." ; \ + false ;; \ + *) echo "An unexpected error occured"; \ + false;; esac + +# The user has not set any verbosity, default to quiet mode and inform the +# user how to enable verbose compiles. +ifeq ($(V),) +quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n" +quiet = @printf $(quiet_DOC)$(eval quiet_DOC:=)"$1 $@\n"; $($(shell echo $1 | sed -e s'/ .*//')) +endif +# The user has explicitly enabled quiet compilation. +ifeq ($(V),0) +quiet = @printf "$1 $@\n"; $($(shell echo $1 | sed -e s'/ .*//')) +endif +# Otherwise, print the full command line. +quiet ?= $($(shell echo $1 | sed -e s'/ .*//')) + +%.o: %.c $(global_deps) + @mkdir -p .deps/$(@D) + $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d + +.PHONY : clean +clean: + rm -rf $(CLEAN); rm -rf .deps + +.PHONY: distclean +distclean: clean + rm -rf $(DISTCLEAN) + +fips_srcs = \ + fips.c + +fips_modules = $(fips_srcs:.c=.o) + +fips: $(fips_modules) + $(call quiet,$(FINAL_FIPS_LINKER) $(CFLAGS)) $^ $(FINAL_FIPS_LDFLAGS) -o $@ + +.PHONY: install +install: all + mkdir -p $(DESTDIR)$(prefix)/bin/ + install fips $(DESTDIR)$(prefix)/bin/fips +ifeq ($(MAKECMDGOALS), install) + @echo "" + @echo "Fips is now installed to $(DESTDIR)$(prefix)" + @echo "" +endif + +SRCS := $(SRCS) $(fips_srcs) +CLEAN := $(CLEAN) fips $(fips_modules) + +DISTCLEAN := $(DISTCLEAN) .first-build-message Makefile.config + +DEPS := $(SRCS:%.c=.deps/%.d) +DEPS := $(DEPS:%.cc=.deps/%.d) +-include $(DEPS) diff --git a/configure b/configure new file mode 100755 index 0000000..f01633c --- /dev/null +++ b/configure @@ -0,0 +1,417 @@ +#! /bin/sh + +PROJECT=fips +PROJECT_BLURB="a program for monitoring performance of OpenGL applications" + +# Test whether this shell is capable of parameter substring processing. +( option='a/b'; : ${option#*/} ) 2>/dev/null || { + echo " +The shell interpreting '$0' is lacking some required features. + +To work around this problem you may try to execute: + + ksh $0 $* + or + bash $0 $* +" + exit 1 +} + +# Store original IFS value so it can be changed (and restored) in many places. +readonly DEFAULT_IFS="$IFS" + +srcdir=$(dirname "$0") + +# For a non-srcdir configure invocation (such as ../configure), create +# the directory structure and copy Makefiles. +if [ "$srcdir" != "." ]; then + + for dir in . $(grep "^subdirs *=" "$srcdir"/Makefile | sed -e "s/subdirs *= *//"); do + mkdir -p "$dir" + cp "$srcdir"/"$dir"/Makefile.local "$dir" + cp "$srcdir"/"$dir"/Makefile "$dir" + done +fi + +# Set several defaults (optionally specified by the user in +# environment variables) +CC=${CC:-gcc} +CFLAGS=${CFLAGS:--O2} +LDFLAGS=${LDFLAGS:-} + +# Set the defaults for values the user can specify with command-line +# options. +PREFIX=/usr/local +LIBDIR= + +usage () +{ + cat <-- Currently ignored + --host=-- Currently ignored + --infodir=DIR Currently ignored + --datadir=DIR Currently ignored + --localstatedir=DIR Currently ignored + --libexecdir=DIR Currently ignored + --disable-maintainer-mode Currently ignored + --disable-dependency-tracking Currently ignored + +EOF +} + +# Parse command-line options +for option; do + if [ "${option}" = '--help' ] ; then + usage + exit 0 + elif [ "${option%%=*}" = '--prefix' ] ; then + PREFIX="${option#*=}" + elif [ "${option%%=*}" = '--libdir' ] ; then + LIBDIR="${option#*=}" + elif [ "${option%%=*}" = '--includedir' ] ; then + INCLUDEDIR="${option#*=}" + elif [ "${option%%=*}" = '--mandir' ] ; then + MANDIR="${option#*=}" + elif [ "${option%%=*}" = '--sysconfdir' ] ; then + SYSCONFDIR="${option#*=}" + elif [ "${option%%=*}" = '--build' ] ; then + true + elif [ "${option%%=*}" = '--host' ] ; then + true + elif [ "${option%%=*}" = '--infodir' ] ; then + true + elif [ "${option%%=*}" = '--datadir' ] ; then + true + elif [ "${option%%=*}" = '--localstatedir' ] ; then + true + elif [ "${option%%=*}" = '--libexecdir' ] ; then + true + elif [ "${option}" = '--disable-maintainer-mode' ] ; then + true + elif [ "${option}" = '--disable-dependency-tracking' ] ; then + true + else + echo "Unrecognized option: ${option}" + echo "See:" + echo " $0 --help" + echo "" + exit 1 + fi +done + +# We set this value early, (rather than just while printing the +# Makefile.config file later like most values), because we need to +# actually investigate this value compared to the ldconfig_paths value +# below. +if [ -z "$LIBDIR" ] ; then + libdir_expanded="${PREFIX}/lib" +else + # very non-general variable expansion + libdir_expanded=`echo "$LIBDIR" | sed "s|\\${prefix}|${PREFIX}|g; s|\\$prefix/|${PREFIX}/|; s|//*|/|g"` +fi + +cat < /dev/null 2>&1; then + have_pkg_config=1 +else + have_pkg_config=0 +fi + +printf "Checking for talloc development files... " +if pkg-config --exists talloc; then + printf "Yes.\n" + have_talloc=1 + talloc_cflags=$(pkg-config --cflags talloc) + talloc_ldflags=$(pkg-config --libs talloc) +else + printf "No.\n" + have_talloc=0 + talloc_cflags= + errors=$((errors + 1)) +fi + +libdir_in_ldconfig=0 + +printf "Checking which platform we are on... " +uname=`uname` +if [ $uname = "Darwin" ] ; then + printf "Mac OS X.\n" + platform=MACOSX + linker_resolves_library_dependencies=0 +elif [ $uname = "SunOS" ] ; then + printf "Solaris.\n" + platform=SOLARIS + linker_resolves_library_dependencies=0 +elif [ $uname = "FreeBSD" ] ; then + printf "FreeBSD.\n" + platform=FREEBSD + linker_resolves_library_dependencies=0 +elif [ $uname = "OpenBSD" ] ; then + printf "OpenBSD.\n" + platform=OPENBSD + linker_resolves_library_dependencies=0 +elif [ $uname = "Linux" ] || [ $uname = "GNU" ] ; then + printf "$uname\n" + platform="$uname" + linker_resolves_library_dependencies=1 + + printf "Checking for $libdir_expanded in ldconfig... " + ldconfig_paths=$(/sbin/ldconfig -N -X -v 2>/dev/null | sed -n -e 's,^\(/.*\):\( (.*)\)\?$,\1,p') + # Separate ldconfig_paths only on newline (not on any potential + # embedded space characters in any filenames). Note, we use a + # literal newline in the source here rather than something like: + # + # IFS=$(printf '\n') + # + # because the shell's command substitution deletes any trailing newlines. + IFS=" +" + for path in $ldconfig_paths; do + if [ "$path" = "$libdir_expanded" ]; then + libdir_in_ldconfig=1 + fi + done + IFS=$DEFAULT_IFS + if [ "$libdir_in_ldconfig" = '0' ]; then + printf "No (will set RPATH)\n" + else + printf "Yes\n" + fi +else + printf "Unknown.\n" + cat < minimal.c + +WARN_CFLAGS="" +printf "Checking for available C compiler warning flags... " +for flag in -Wall -Wextra -Wmissing-declarations; do + if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1 + then + WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}" + fi +done +printf "\n\t${WARN_CFLAGS}\n" + +rm -f minimal minimal.c + +cat < Makefile.config < +#include +#include +#include + +static void +usage (void) +{ + printf("Usage: fips [OPTIONS...] [program args...]\n" + "\n" + "Execute and report GPU performance counters\n" + "\n" + "Options:\n" + " -h, --help show this help message\n" + "\n"); +} + +int +main (int argc, char *argv[]) +{ + int opt; + const char *short_options = "h"; + const struct option long_options[] = { + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + while (1) + { + opt = getopt_long(argc, argv, short_options, long_options, NULL); + if (opt == -1) + break; + + switch (opt) { + case 'h': + usage (); + return 0; + case '?': + break; + default: + fprintf(stderr, "Internal error: " + "unexpected getopt value: %d\n", opt); + exit (1); + } + } + + if (optind >= argc) { + fprintf (stderr, "Error: No program name provided, " + "see (fips --help)\n"); + exit (1); + } + + return 0; +} + + diff --git a/version b/version new file mode 100644 index 0000000..49d5957 --- /dev/null +++ b/version @@ -0,0 +1 @@ +0.1