From 2a97c5d18df8fc20b1d9adf8224c25f4b285b466 Mon Sep 17 00:00:00 2001 From: PHO Date: Fri, 5 Jun 2009 14:33:40 +0900 Subject: [PATCH 1/1] Initial revision of bindings-uname --- .gitignore | 4 ++ Bindings/Uname.hsc | 42 +++++++++++++++++++++ GNUmakefile | 1 + Setup.lhs | 3 ++ bindings-uname.cabal | 26 +++++++++++++ cabal-package.mk | 89 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 165 insertions(+) create mode 100644 .gitignore create mode 100644 Bindings/Uname.hsc create mode 100644 GNUmakefile create mode 100644 Setup.lhs create mode 100644 bindings-uname.cabal create mode 100644 cabal-package.mk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cf4112 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +Setup +*.hi +*.o +dist diff --git a/Bindings/Uname.hsc b/Bindings/Uname.hsc new file mode 100644 index 0000000..ec03f1d --- /dev/null +++ b/Bindings/Uname.hsc @@ -0,0 +1,42 @@ +module Bindings.Uname + ( Utsname + , uname + + , sysname + , nodename + , release + , version + , machine + ) + where + +#include + +import Foreign +import Foreign.C + +foreign import ccall unsafe "sys/utsname.h uname" + uname :: Ptr Utsname -> IO CInt + +data Utsname + +instance Storable Utsname where + sizeOf = const #size struct utsname + alignment = sizeOf + poke = error "Storable Utsname: peek: unsupported operation" + peek = error "Storable Utsname: poke: unsupported operation" + +sysname :: Ptr Utsname -> IO CString +sysname = (#peek struct utsname, sysname) + +nodename :: Ptr Utsname -> IO CString +nodename = (#peek struct utsname, nodename) + +release :: Ptr Utsname -> IO CString +release = (#peek struct utsname, release) + +version :: Ptr Utsname -> IO CString +version = (#peek struct utsname, version) + +machine :: Ptr Utsname -> IO CString +machine = (#peek struct utsname, machine) diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..d37032e --- /dev/null +++ b/GNUmakefile @@ -0,0 +1 @@ +include cabal-package.mk diff --git a/Setup.lhs b/Setup.lhs new file mode 100644 index 0000000..4c441d1 --- /dev/null +++ b/Setup.lhs @@ -0,0 +1,3 @@ +#!/usr/bin/env runhaskell +> import Distribution.Simple +> main = defaultMainWithHooks simpleUserHooks diff --git a/bindings-uname.cabal b/bindings-uname.cabal new file mode 100644 index 0000000..854d1b4 --- /dev/null +++ b/bindings-uname.cabal @@ -0,0 +1,26 @@ +Name: bindings-uname +Version: 0.1 +Synopsis: Low-level binding to POSIX uname(3) +Description: + This is a low-level binding to POSIX uname(3) + function. Perhaps it shoule be part of unix package. +Category: FFI, System +License: PublicDomain +Author: PHO +Maintainer: PHO +Stability: Experimental +Cabal-Version: >= 1.2 +Build-Type: Simple + +Library + Build-Depends: + base + + Exposed-Modules: + Bindings.Uname + + Extensions: + EmptyDataDecls, ForeignFunctionInterface + + GHC-Options: + -Wall \ No newline at end of file diff --git a/cabal-package.mk b/cabal-package.mk new file mode 100644 index 0000000..ca291ff --- /dev/null +++ b/cabal-package.mk @@ -0,0 +1,89 @@ +# -*- makefile-gmake -*- +# +# Variables: +# +# CONFIGURE_ARGS :: arguments to be passed to ./Setup configure +# default: --disable-optimization +# +# RUN_COMMAND :: command to be run for "make run" +# + +GHC ?= ghc +FIND ?= find +RM_RF ?= rm -rf +SUDO ?= sudo +AUTOCONF ?= autoconf + +CONFIGURE_ARGS ?= --disable-optimization + +SETUP_FILE := $(wildcard Setup.*hs) +CABAL_FILE := $(wildcard *.cabal) + +ifeq ($(shell ls configure.ac 2>/dev/null),configure.ac) + AUTOCONF_AC_FILE := configure.ac + AUTOCONF_FILE := configure +else + ifeq ($(shell ls configure.in 2>/dev/null),configure.in) + AUTOCONF_AC_FILE := configure.in + AUTOCONF_FILE := configure + else + AUTOCONF_AC_FILE := + AUTOCONF_FILE := + endif +endif + +BUILDINFO_IN_FILE := $(wildcard *.buildinfo.in) +BUILDINFO_FILE := $(BUILDINFO_IN_FILE:.in=) + +all: build + +build: setup-config build-hook + ./Setup build + +build-hook: + +ifeq ($(RUN_COMMAND),) +run: + @echo "cabal-package.mk: No command to run." + @echo "cabal-package.mk: If you want to run something, define RUN_COMMAND variable." +else +run: build + @echo ".:.:. Let's go .:.:." + $(RUN_COMMAND) +endif + +setup-config: dist/setup-config setup-config-hook $(BUILDINFO_FILE) + +setup-config-hook: + +dist/setup-config: $(CABAL_FILE) Setup $(AUTOCONF_FILE) + ./Setup configure $(CONFIGURE_ARGS) + +$(AUTOCONF_FILE): $(AUTOCONF_AC_FILE) + $(AUTOCONF) + +$(BUILDINFO_FILE): $(BUILDINFO_IN_FILE) configure + ./Setup configure $(CONFIGURE_ARGS) + +Setup: $(SETUP_FILE) + $(GHC) --make Setup + +clean: clean-hook + $(RM_RF) dist Setup *.o *.hi .setup-config *.buildinfo + $(FIND) . -name '*~' -exec rm -f {} \; + +clean-hook: + +doc: setup-config + ./Setup haddock + +install: build + $(SUDO) ./Setup install + +sdist: setup-config + ./Setup sdist + +test: build + ./Setup test + +.PHONY: build build-hook setup-config setup-config-hook run clean clean-hook install doc sdist test -- 2.40.0