extra files for Unix
authorvb
Wed, 25 Jun 2014 18:46:19 +0200
changeset 106e02338bdd8
parent 0 16f27efbef98
child 2 f1fc3afacfd6
extra files for Unix
Makefile
Makefile.conf
src/Makefile
src/platform_unix.c
src/platform_unix.h
src/update.sql
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Wed Jun 25 18:46:19 2014 +0200
     1.3 @@ -0,0 +1,33 @@
     1.4 +include Makefile.conf
     1.5 +
     1.6 +all:
     1.7 +	$(MAKE) -C src all
     1.8 +
     1.9 +.PHONY: clean build_test test package install uninstall
    1.10 +
    1.11 +install:
    1.12 +	$(MAKE) -C src install
    1.13 +
    1.14 +uninstall:
    1.15 +	$(MAKE) -C src uninstall
    1.16 +
    1.17 +clean:
    1.18 +	$(MAKE) -C src clean
    1.19 +	$(MAKE) -C test clean
    1.20 +
    1.21 +test: all
    1.22 +	$(MAKE) -C test test
    1.23 +
    1.24 +package: clean
    1.25 +	cd .. ; COPYFILE_DISABLE=true tar  cjf pEpEngine.tar.bz2 pEpEngine
    1.26 +
    1.27 +windist:
    1.28 +ifneq ($(BUILD_FOR),Windoze)
    1.29 +	@echo use BUILD_FOR=Windoze \(did you forget -e ?\)
    1.30 +else
    1.31 +	make clean
    1.32 +	$(MAKE) all
    1.33 +	$(MAKE) -C test all
    1.34 +	zip -j pEpEngine-dist.zip src/pEpEngine.h src/keymanagement.h src/pEpEngine.dll src/pEpEngine.def test/pEpEngineTest.exe test/*.asc test/*.key db/*.db test/*.txt test/*.asc src/*.sql
    1.35 +endif
    1.36 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile.conf	Wed Jun 25 18:46:19 2014 +0200
     2.3 @@ -0,0 +1,7 @@
     2.4 +BUILD_ON=$(shell uname)
     2.5 +BUILD_FOR=$(BUILD_ON)
     2.6 +#OPTIMIZE=-g -O0
     2.7 +OPTIMIZE=-O3 -DNDEBUG
     2.8 +# the next two lines are not for Windoze
     2.9 +SYSTEM_DB=/usr/local/share/pEp/system.db
    2.10 +PREFIX=$(HOME)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/Makefile	Wed Jun 25 18:46:19 2014 +0200
     3.3 @@ -0,0 +1,123 @@
     3.4 +include ../Makefile.conf
     3.5 +
     3.6 +ifeq ($(BUILD_ON),Darwin)
     3.7 +ifeq ($(BUILD_FOR),Darwin)
     3.8 +
     3.9 +TARGET=libpEpEngine.dylib
    3.10 +MACOSX_VERSION_MIN=10.6
    3.11 +GPGME_IN=$(HOME)
    3.12 +LIBGPGME=libgpgme-pthread.dylib
    3.13 +CC=gcc -std=c99
    3.14 +CFLAGS=-I$(GPGME_IN)/include -I/opt/local/include $(OPTIMIZE) -pedantic \
    3.15 +	-DSYSTEM_DB=\"$(SYSTEM_DB)\" -DLIBGPGME=\"$(LIBGPGME)\"  -DSQLITE_THREADSAFE=1
    3.16 +LDFLAGS=-lc -macosx_version_min $(MACOSX_VERSION_MIN) -dylib -arch x86_64
    3.17 +
    3.18 +else ifeq ($(BUILD_FOR),Windoze)
    3.19 +
    3.20 +TARGET=pEpEngine.dll
    3.21 +GPGME_IN=$(HOME)
    3.22 +LIBGPGME=libgpgme-11.dll
    3.23 +CC=i686-w64-mingw32-gcc -std=c99
    3.24 +CXX=i686-w64-mingw32-g++
    3.25 +LD=i686-w64-mingw32-gcc
    3.26 +CFLAGS=-I$(HOME)/i686-w64-mingw32/include -I$(GPGME_IN)/include $(OPTIMIZE) -pedantic \
    3.27 +	-DLIBGPGME=\"$(LIBGPGME)\" -DWIN32 -DSQLITE_THREADSAFE=1
    3.28 +LDFLAGS=-shared -L$(HOME)/i686-w64-mingw32/lib -llibstdc++ \
    3.29 +	-Wl,--output-def,pEpEngine.def,--out-implib,libpEpEngine.a
    3.30 +
    3.31 +else
    3.32 +$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    3.33 +endif
    3.34 +
    3.35 +else ifeq ($(BUILD_ON),Linux)
    3.36 +ifeq ($(BUILD_FOR),Linux)
    3.37 +
    3.38 +TARGET=libpEpEngine.so
    3.39 +GPGME_IN=$(HOME)
    3.40 +LIBGPGME=libgpgme.so.11
    3.41 +CC=gcc -std=c99
    3.42 +CFLAGS=-I$(GPGME_IN)/include $(OPTIMIZE) -fPIC -pedantic \
    3.43 +	-DSYSTEM_DB=\"$(SYSTEM_DB)\" -DLIBGPGME=\"$(LIBGPGME)\" -DSQLITE_THREADSAFE=1
    3.44 +LDFLAGS=-L$(GPGME_IN) -shared -lc -ldl
    3.45 +
    3.46 +else ifeq ($(BUILD_FOR),Windoze)
    3.47 +
    3.48 +TARGET=pEpEngine.dll
    3.49 +GPGME_IN=$(HOME)
    3.50 +LIBGPGME=libgpgme-11.dll
    3.51 +CC=i686-w64-mingw32-gcc -std=c99
    3.52 +CXX=i686-w64-mingw32-g++
    3.53 +LD=i686-w64-mingw32-gcc
    3.54 +CFLAGS=-I/usr/i686-w64-mingw32/include -I$(GPGME_IN)/include $(OPTIMIZE) -pedantic \
    3.55 +	-DLIBGPGME=\"$(LIBGPGME)\" -DWIN32 -DSQLITE_THREADSAFE=1
    3.56 +LDFLAGS=-shared -L/usr/i686-w64-mingw32/lib -llibstdc++ \
    3.57 +	-Wl,--output-def,pEpEngine.def,--out-implib,libpEpEngine.a
    3.58 +
    3.59 +else
    3.60 +$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    3.61 +endif
    3.62 +
    3.63 +else ifeq ($(BUILD_ON),MINGW32_NT-6.1)
    3.64 +
    3.65 +TARGET=pEpEngine.dll
    3.66 +GPGME_IN=/c/Program\ Files/GNU/GnuPG
    3.67 +LIBGPGME=libgpgme-11.dll
    3.68 +CC=gcc -std=gnu99
    3.69 +CFLAGS=-I$(GPGME_IN)/include $(OPTIMIZE) -pedantic -DWIN32 -DSQLITE_THREADSAFE=1
    3.70 +LD=gcc
    3.71 +LDFLAGS=-shared -llibstdc++ -Wl,--output-def,pEpEngine.def,--out-implib,libpEpEngine.a
    3.72 +
    3.73 +else
    3.74 +$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    3.75 +endif
    3.76 +
    3.77 +ifeq ($(BUILD_FOR),Windoze)
    3.78 +ALL_SOURCE=$(filter-out platform_unix.c,$(wildcard *.c))
    3.79 +else ifeq ($(BUILD_FOR),MINGW32_NT-6.1)
    3.80 +ALL_SOURCE=$(filter-out platform_unix.c,$(wildcard *.c))
    3.81 +else
    3.82 +ALL_SOURCE=$(wildcard *.c)
    3.83 +endif
    3.84 +
    3.85 +DEPENDS=$(subst .c,.d,$(ALL_SOURCE))
    3.86 +
    3.87 +ifeq ($(BUILD_FOR),Windoze)
    3.88 +ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE)) platform_windows.o
    3.89 +else ifeq ($(BUILD_FOR),MINGW32_NT-6.1)
    3.90 +ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE)) platform_windows.o
    3.91 +else
    3.92 +ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
    3.93 +endif
    3.94 +
    3.95 +all: $(TARGET)
    3.96 +
    3.97 +%.d: %.c
    3.98 +	@set -e; rm -f $@; \
    3.99 +	$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
   3.100 +	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
   3.101 +	rm -f $@.$$$$
   3.102 +
   3.103 +-include $(DEPENDS)
   3.104 +
   3.105 +platform_windows.o: platform_windows.cpp
   3.106 +	$(CXX) $(CXX_FLAGS) -o $@ -c $<
   3.107 +
   3.108 +$(TARGET): libpEpEngine.a
   3.109 +	$(LD) $(ALL_OBJECTS) $(LDFLAGS) -o $@
   3.110 +
   3.111 +objects: $(ALL_OBJECTS)
   3.112 +
   3.113 +libpEpEngine.a: $(ALL_OBJECTS)
   3.114 +	ar -r $@ $(ALL_OBJECTS)
   3.115 +
   3.116 +.PHONY: clean
   3.117 +
   3.118 +clean:
   3.119 +	rm -f *.d *.o *.a $(TARGET) *.dll *.so *.zip *.d.* *.def *~
   3.120 +
   3.121 +install: $(TARGET)
   3.122 +	cp $< $(PREFIX)/lib/
   3.123 +
   3.124 +uninstall:
   3.125 +	rm -f $(PREFIX)/lib/$(TARGET)
   3.126 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/platform_unix.c	Wed Jun 25 18:46:19 2014 +0200
     4.3 @@ -0,0 +1,66 @@
     4.4 +#define _POSIX_C_SOURCE 200809L
     4.5 +
     4.6 +#include <string.h>
     4.7 +#include <stdlib.h>
     4.8 +#include <assert.h>
     4.9 +#include "platform_unix.h"
    4.10 +
    4.11 +#define MAX_PATH 1024
    4.12 +#define LOCAL_DB_FILENAME ".pEp_management.db"
    4.13 +
    4.14 +#ifndef bool
    4.15 +#define bool int
    4.16 +#define true 1
    4.17 +#define false 0
    4.18 +#endif
    4.19 +
    4.20 +const char *unix_local_db(void)
    4.21 +{
    4.22 +    static char buffer[MAX_PATH];
    4.23 +    static bool done = false;
    4.24 +
    4.25 +    if (!done) {
    4.26 +        char *p = stpncpy(buffer, getenv("HOME"), MAX_PATH);
    4.27 +        size_t len = MAX_PATH - (p - buffer) - 2;
    4.28 +
    4.29 +        if (len < strlen(LOCAL_DB_FILENAME)) {
    4.30 +            assert(0);
    4.31 +            return NULL;
    4.32 +        }
    4.33 +
    4.34 +        *p++ = '/';
    4.35 +        strncpy(p, LOCAL_DB_FILENAME, len);
    4.36 +        done = true;
    4.37 +    }
    4.38 +    return buffer;
    4.39 +}
    4.40 +
    4.41 +static const char *gpg_conf_path = ".gnupg";
    4.42 +static const char *gpg_conf_name = "gpg.conf";
    4.43 +
    4.44 +const char *gpg_conf(void)
    4.45 +{
    4.46 +    static char buffer[MAX_PATH];
    4.47 +    static bool done = false;
    4.48 +
    4.49 +    if (!done) {
    4.50 +        char *p = stpncpy(buffer, getenv("HOME"), MAX_PATH);
    4.51 +        size_t len = MAX_PATH - (p - buffer) - 3;
    4.52 +
    4.53 +        if (len < strlen(gpg_conf_path) + strlen(gpg_conf_name))
    4.54 +        {
    4.55 +            assert(0);
    4.56 +            return NULL;
    4.57 +        }
    4.58 +
    4.59 +        *p++ = '/';
    4.60 +        strncpy(p, gpg_conf_path, len);
    4.61 +        p += strlen(gpg_conf_path);
    4.62 +        len -= strlen(gpg_conf_path) - 1;
    4.63 +        *p++ = '/';
    4.64 +        strncpy(p, gpg_conf_name, len);
    4.65 +
    4.66 +        done = true;
    4.67 +    }
    4.68 +    return buffer;
    4.69 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/platform_unix.h	Wed Jun 25 18:46:19 2014 +0200
     5.3 @@ -0,0 +1,2 @@
     5.4 +const char *unix_local_db(void);
     5.5 +const char *gpg_conf(void);
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/update.sql	Wed Jun 25 18:46:19 2014 +0200
     6.3 @@ -0,0 +1,33 @@
     6.4 +create table trust (
     6.5 +   user_id text references person (id) on delete cascade,
     6.6 +   pgp_keypair_fpr text references pgp_keypair (fpr) on delete cascade,
     6.7 +   comm_type integer not null,
     6.8 +   comment text
     6.9 +);
    6.10 +
    6.11 +create unique index trust_index on trust (
    6.12 +   user_id,
    6.13 +   pgp_keypair_fpr
    6.14 +);
    6.15 +
    6.16 +insert into trust (user_id, pgp_keypair_fpr, comm_type)
    6.17 +    select user_id, main_key_id, comm_type from identity;
    6.18 +
    6.19 +alter table identity rename to identity_old;
    6.20 +
    6.21 +create table identity (
    6.22 +	address text primary key,
    6.23 +	user_id text
    6.24 +		references person (id)
    6.25 +		on delete cascade,
    6.26 +	main_key_id text
    6.27 +		references pgp_keypair (fpr)
    6.28 +		on delete set null,
    6.29 +	comment text
    6.30 +);
    6.31 +
    6.32 +insert into identity (address, user_id, main_key_id)
    6.33 +    select address, user_id, main_key_id from identity_old;
    6.34 +
    6.35 +drop table identity_old;
    6.36 +