Making Go package source distributable and renaming to 'nginx/unit'.

All header files are copied to Go package sources.  As the result,
package can be (re-)build when required.

This closes #23 issue on GitHub.
This commit is contained in:
Max Romanov
2017-12-01 16:57:30 +03:00
parent ffb1c68609
commit 40eb1f8b9b
9 changed files with 53 additions and 108 deletions

View File

@@ -85,41 +85,37 @@ fi
cat << END >> $NXT_MAKEFILE cat << END >> $NXT_MAKEFILE
.PHONY: ${NXT_GO} ${NXT_GO}-install ${NXT_GO}-uninstall .PHONY: ${NXT_GO}
.PHONY: ${NXT_GO}-install
all: ${NXT_GO} .PHONY: ${NXT_GO}-install-src
.PHONY: ${NXT_GO}-install-build
NXT_ROOT = `pwd` .PHONY: ${NXT_GO}-uninstall
GOPATH = $NXT_GO_PATH GOPATH = $NXT_GO_PATH
GOOS = `${NXT_GO} env GOOS` GOOS = `${NXT_GO} env GOOS`
GOARCH = `${NXT_GO} env GOARCH` GOARCH = `${NXT_GO} env GOARCH`
${NXT_GO}: $NXT_BUILD_DIR/nxt_go_gen.h NXT_GO_DST = ${NXT_GO_PATH%%:*}
$NXT_BUILD_DIR/nxt_go_gen.h: src/go/unit/*.go
GOPATH=`pwd` \\
CGO_CPPFLAGS="-DNXT_CONFIGURE \\
-I`pwd`/src" \\
${NXT_GO} build -o $NXT_BUILD_DIR/nxt_go_gen.a \\
--buildmode=c-archive go/unit
install: ${NXT_GO}-install install: ${NXT_GO}-install
${NXT_GO}-install: ${NXT_GO} ${NXT_GO}:
install -d \$(DESTDIR)\$(GOPATH)/src/unit
install -p -m644 ./src/go/unit/* \$(DESTDIR)\$(GOPATH)/src/unit/ ${NXT_GO}-install: ${NXT_GO}-install-build
CGO_CFLAGS="-I\$(NXT_ROOT)/$NXT_BUILD_DIR -I\$(NXT_ROOT)/src" \\
CGO_LDFLAGS="-L\$(NXT_ROOT)/$NXT_BUILD_DIR ${NXT_LIBRT}" \\ ${NXT_GO}-install-src:
GOPATH=\$(DESTDIR)\$(GOPATH) \\ install -d \$(DESTDIR)\$(NXT_GO_DST)/src/nginx/unit
${NXT_GO} install -v unit install -p -m644 ./src/*.h ./build/*.h ./src/go/unit/* \
\$(DESTDIR)\$(NXT_GO_DST)/src/nginx/unit/
${NXT_GO}-install-build: ${NXT_GO}-install-src
GOPATH=\$(DESTDIR)\$(GOPATH) ${NXT_GO} build nginx/unit
uninstall: ${NXT_GO}-uninstall uninstall: ${NXT_GO}-uninstall
${NXT_GO}-uninstall: ${NXT_GO}-uninstall:
rm -rf \$(DESTDIR)\$(GOPATH)/src/unit rm -rf \$(DESTDIR)\$(NXT_GO_DST)/src/nginx/unit
rm -f \$(DESTDIR)\$(GOPATH)/pkg/\$(GOOS)_\$(GOARCH)/unit.a rm -rf \$(DESTDIR)\$(NXT_GO_DST)/pkg/\$(GOOS)_\$(GOARCH)/nginx/unit
END END

View File

@@ -0,0 +1,13 @@
// +build darwin
/*
* Copyright (C) Max Romanov
* Copyright (C) NGINX, Inc.
*/
package unit
/*
#cgo CFLAGS: -mmacosx-version-min=10.5
*/
import "C"

13
src/go/unit/linux-lrt.go Normal file
View File

@@ -0,0 +1,13 @@
// +build linux
/*
* Copyright (C) Max Romanov
* Copyright (C) NGINX, Inc.
*/
package unit
/*
#cgo LDFLAGS: -lrt
*/
import "C"

View File

@@ -4,8 +4,6 @@
* Copyright (C) NGINX, Inc. * Copyright (C) NGINX, Inc.
*/ */
#ifndef NXT_CONFIGURE
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
@@ -62,5 +60,3 @@ nxt_go_array_add(nxt_array_t *array)
return p; return p;
} }
#endif /* NXT_CONFIGURE */

View File

@@ -4,62 +4,13 @@
* Copyright (C) NGINX, Inc. * Copyright (C) NGINX, Inc.
*/ */
#ifdef NXT_CONFIGURE
#include <stdio.h>
#include "nxt_go_lib.h"
// Stubs to compile during configure process.
int
nxt_go_response_write(nxt_go_request_t r, void *buf, size_t len)
{
return -1;
}
int
nxt_go_request_read(nxt_go_request_t r, void *dst, size_t dst_len)
{
return -1;
}
int
nxt_go_request_read_from(nxt_go_request_t r, void *dst, size_t dst_len,
void *src, size_t src_len)
{
return -1;
}
int
nxt_go_request_close(nxt_go_request_t r)
{
return -1;
}
int
nxt_go_request_done(nxt_go_request_t r)
{
return -1;
}
void
nxt_go_ready()
{
}
nxt_go_request_t
nxt_go_process_port_msg(void *buf, size_t buf_len, void *oob, size_t oob_len)
{
return 0;
}
#else
#include "nxt_go_run_ctx.h" #include "nxt_go_run_ctx.h"
#include "nxt_go_log.h" #include "nxt_go_log.h"
#include "nxt_go_port.h" #include "nxt_go_port.h"
#include "_cgo_export.h"
#include <nxt_main.h> #include <nxt_main.h>
#include <nxt_go_gen.h>
int int
nxt_go_response_write(nxt_go_request_t r, void *buf, size_t len) nxt_go_response_write(nxt_go_request_t r, void *buf, size_t len)
@@ -190,6 +141,3 @@ nxt_go_process_port_msg(void *buf, size_t buf_len, void *oob, size_t oob_len)
{ {
return nxt_go_port_on_read(buf, buf_len, oob, oob_len); return nxt_go_port_on_read(buf, buf_len, oob, oob_len);
} }
#endif /* NXT_CONFIGURE */

View File

@@ -4,16 +4,14 @@
* Copyright (C) NGINX, Inc. * Copyright (C) NGINX, Inc.
*/ */
#ifndef NXT_CONFIGURE
#include "nxt_go_port.h" #include "nxt_go_port.h"
#include "nxt_go_log.h" #include "nxt_go_log.h"
#include "nxt_go_process.h" #include "nxt_go_process.h"
#include "nxt_go_run_ctx.h" #include "nxt_go_run_ctx.h"
#include "_cgo_export.h"
#include <nxt_main.h> #include <nxt_main.h>
#include <nxt_go_gen.h>
#define nxt_go_str(p) ((nxt_go_str_t *)(p)) #define nxt_go_str(p) ((nxt_go_str_t *)(p))
@@ -205,6 +203,3 @@ fail:
return 0; return 0;
} }
#endif /* NXT_CONFIGURE */

View File

@@ -4,15 +4,13 @@
* Copyright (C) NGINX, Inc. * Copyright (C) NGINX, Inc.
*/ */
#ifndef NXT_CONFIGURE
#include "nxt_go_port_memory.h" #include "nxt_go_port_memory.h"
#include "nxt_go_process.h" #include "nxt_go_process.h"
#include "nxt_go_array.h" #include "nxt_go_array.h"
#include "nxt_go_log.h" #include "nxt_go_log.h"
#include <nxt_go_gen.h> #include "_cgo_export.h"
#include <nxt_main.h> #include <nxt_main.h>
#if (NXT_HAVE_MEMFD_CREATE) #if (NXT_HAVE_MEMFD_CREATE)
@@ -197,6 +195,3 @@ unlock_return:
return hdr; return hdr;
} }
#endif /* NXT_CONFIGURE */

View File

@@ -4,9 +4,6 @@
* Copyright (C) NGINX, Inc. * Copyright (C) NGINX, Inc.
*/ */
#ifndef NXT_CONFIGURE
#include "nxt_go_process.h" #include "nxt_go_process.h"
#include "nxt_go_array.h" #include "nxt_go_array.h"
#include "nxt_go_mutex.h" #include "nxt_go_mutex.h"
@@ -149,6 +146,3 @@ fail:
nxt_go_mutex_unlock(&process->incoming_mutex); nxt_go_mutex_unlock(&process->incoming_mutex);
} }
#endif /* NXT_CONFIGURE */

View File

@@ -4,9 +4,6 @@
* Copyright (C) NGINX, Inc. * Copyright (C) NGINX, Inc.
*/ */
#ifndef NXT_CONFIGURE
#include "nxt_go_run_ctx.h" #include "nxt_go_run_ctx.h"
#include "nxt_go_log.h" #include "nxt_go_log.h"
#include "nxt_go_process.h" #include "nxt_go_process.h"
@@ -14,9 +11,10 @@
#include "nxt_go_mutex.h" #include "nxt_go_mutex.h"
#include "nxt_go_port_memory.h" #include "nxt_go_port_memory.h"
#include "_cgo_export.h"
#include <nxt_port_memory_int.h> #include <nxt_port_memory_int.h>
#include <nxt_main.h> #include <nxt_main.h>
#include <nxt_go_gen.h>
static nxt_int_t static nxt_int_t
@@ -530,6 +528,3 @@ nxt_go_ctx_read_raw(nxt_go_run_ctx_t *ctx, void *dst, size_t size)
return res; return res;
} }
#endif /* NXT_CONFIGURE */