parsav  Check-in [d248dc5965]

Overview
Comment:add dist mechanism
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d248dc59659e83f0d814a8d6fe85b2236286e1383e2b1a1dee76359f3c4fec21
User & Date: lexi on 2021-01-19 22:02:23
Other Links: manifest | tags
Context
2021-01-22
16:48
somewhat defuckulate build system check-in: 251b382f5c user: lexi tags: trunk
2021-01-19
22:02
add dist mechanism check-in: d248dc5965 user: lexi tags: trunk
2021-01-14
17:38
check in missing file check-in: 576487f566 user: lexi tags: trunk
Changes

Modified config.lua from [af9c45003f] to [cba33505b3].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	pkg = {};
	dist      = default('parsav_dist', coalesce(
		os.getenv('NIX_PATH')  and 'nixos',
		os.getenv('NIX_STORE') and 'nixos',
	''));
	tgttrip   = default('parsav_arch_triple'); -- target triple, used in xcomp
	tgtcpu    = default('parsav_arch_cpu'); -- target cpu, used in xcomp
	tgthf     = u.tobool(default('parsav_arch_armhf',true)); 
	doc       = {
		online  = u.tobool(default('parsav_online_documentation',true)); 
		offline = u.tobool(default('parsav_offline_documentation',true)); 
	};
	outform   = default('parsav_emit_type', 'o');
	endian    = default('parsav_arch_endian', 'little');
	prefix    = default('parsav_install_prefix', '.');







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	pkg = {};
	dist      = default('parsav_dist', coalesce(
		os.getenv('NIX_PATH')  and 'nixos',
		os.getenv('NIX_STORE') and 'nixos',
	''));
	tgttrip   = default('parsav_arch_triple'); -- target triple, used in xcomp
	tgtcpu    = default('parsav_arch_cpu'); -- target cpu, used in xcomp
	-- tgthf     = u.tobool(default('parsav_arch_armhf',true)); 
	doc       = {
		online  = u.tobool(default('parsav_online_documentation',true)); 
		offline = u.tobool(default('parsav_offline_documentation',true)); 
	};
	outform   = default('parsav_emit_type', 'o');
	endian    = default('parsav_arch_endian', 'little');
	prefix    = default('parsav_install_prefix', '.');

Added dist/BSDmakefile version [7f20717fa4].































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# being extremely paranoid here, but there's some vague plans to get nix
# shit working under BSD kernels, so we may as well future-proof the thing
.if defined(NIX_STORE) || defined(NIX_PATH)
    l-glibc-path != nix path-info nixos.glibc
	rt-path = $(l-glibc-path)/lib
.endif

rt-path ?= /usr/lib
runtime = $(rt-path)/crt1.o \
		  $(rt-path)/crti.o \
		  $(rt-path)/crtbegin.o \
		  $(rt-path)/crtend.o \
		  $(rt-path)/crtn.o

.include <makefile>

Added dist/GNUmakefile version [1a1f87c1d5].







































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# we need to detect the environment and set the runtime path appropriately
ifndef      NIX_STORE
else ifndef NIX_PATH
else
    distro = nix
endif

ifndef runtime
    ifeq ($(distro),nix)
        rt-pfx = $(shell nix path-info nixos.glibc)/lib
    else ifeq ($(shell test -e /usr/local/lib/crt1.o; echo $$?),0)
        rt-pfx = /usr/local/lib
    else ifeq ($(shell test -e /lib/crt1.o; echo $$?),0)
        rt-pfx = /lib
    endif
	runtime = $(rt-pfx)/crt1.o $(rt-pfx)/crti.o $(rt-pfx)/crtn.o
endif

include makefile

Added dist/default.nix version [a7ffc6f8bf].

Added dist/makefile version [de98ce3076].





















>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
# vim: ft=make
runtime ?= /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o
all: parsav parsavd

%: %.o
	ld -o $@ $< $(runtime) ${NIX_LDFLAGS} -L. -ljson-c -lpq -lmbedtls -lmbedcrypto -lmongoose -lc
	strip @$

%.o: %.ll
	llc --filetype=obj --relocation-model=pic $<

Added dist/readme.md version [d87e8d1b5f].



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# parsav distribution
to prepare a binary (or LLVM IR) distribution of parsav, simply `cd` into its directory and issue the command `make`. any version of `make` should work; you may need to manually set the location of the C runtime with the `runtime` variable if you're not using GNU or BSD make (e.g. `make runtime='crt1.o crti.o crtn.o' all`). certain distributions may need extra parameters to be passed to the makefile, or the makefile may need to be run in a particular environment, such as on `nix`.

# dependencies
the standard releases are built with most dependencies statically linked at compile time. several dependencies will need to be installed before linking parsav, however:

 * libc: used for OS calls
 * binutils: used to link and strip the binary
 * libjsonc: used for fediverse integration
 * libpq: used for the postgres backend (usually part of the postgres distribution)

## makefile variables

## special cases

### nixos
on nixos, `make` will not work unless you use `nix-shell` to enter an environment with all the dependencies available. however, if you just want to install parsav, you can use `default.nix` to build a package.

Modified makefile from [d43e9d6c44] to [51cc28542c].


1
2
3
4
5
6
7
..
31
32
33
34
35
36
37















38
39
40
41
42
43
44
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

dl = git
dbg-flags = $(if $(dbg),-g)

images = static/default-avatar.webp static/query.webp static/heart.webp static/retweet.webp static/reply.webp static/file.webp static/follow.webp
#$(addsuffix .webp, $(basename $(wildcard static/*.svg)))
styles = $(addsuffix .css, $(basename $(wildcard static/*.scss)))

................................................................................
dep: dep.mbedtls dep.mongoose dep.json-c
dep.mbedtls: lib/mbedtls/library/libmbedtls.a \
	lib/mbedtls/library/libmbedcrypto.a \
	lib/mbedtls/library/libmbedx509.a
dep.mongoose: lib/mongoose/libmongoose.a
dep.json-c: lib/json-c/libjson-c.a
















lib:
	mkdir $@
# generate a shim static library so mongoose cooperates
# with the build apparatus. note that parsav is designed
# to be fronted by a real web server like nginx if SSL
# is to be used, so we don't turn on SSL in mongoose
lib/mongoose/libmongoose.a: lib/mongoose lib/mongoose/mongoose.c lib/mongoose/mongoose.h
................................................................................
		-DMG_ENABLE_IPV6=1 \
		-DMG_ENABLE_HTTP_WEBDAV=1 \
		-DMG_ENABLE_HTTP_WEBSOCKET=0
	ar rcs $@ lib/mongoose/*.o
	ranlib $@

lib/json-c/Makefile: lib/json-c lib/json-c/CMakeLists.txt
	cd lib/json-c && cmake .
lib/json-c/libjson-c.a: lib/json-c/Makefile
	$(MAKE) -C lib/json-c
lib/mbedtls/library/%.a: lib/mbedtls 
	$(MAKE) -C lib/mbedtls/library $*.a

ifeq ($(dl), git)
clone = git clone --depth 1 # save time

lib/mongoose: lib
	cd lib && $(clone) https://github.com/cesanta/mongoose.git
lib/mbedtls: lib
	cd lib && $(clone) https://github.com/ARMmbed/mbedtls.git
lib/json-c: lib
	cd lib && $(clone) https://github.com/json-c/json-c.git
else
lib/%: lib/%.tar.gz
	cd lib && tar zxf $*.tar.gz
	mv lib/$$(tar tf $< | head -n1) $@

ifeq ($(dl), wget)
    dlfile = wget "$(1)" -O "$(2)"
endif

ifeq ($(dl), curl)
    dlfile = curl "$(1)" -o "$(2)"
endif

lib/mongoose.tar.gz: lib
	$(call dlfile,https://api.github.com/repos/cesanta/mongoose/tarball/master,$@)
lib/mbedtls.tar.gz: lib
	$(call dlfile,https://api.github.com/repos/ARMmbed/mbedtls/tarball/master,$@)
lib/json-c.tar.gz: lib
	$(call dlfile,https://api.github.com/repos/json-c/json-c/tarball/master,$@)
endif
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







>
|
|
|
|
|
|


|



|



|


|
|
|
|
|
|

1
2
3
4
5
6
7
8
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
version = dev
dl = git
dbg-flags = $(if $(dbg),-g)

images = static/default-avatar.webp static/query.webp static/heart.webp static/retweet.webp static/reply.webp static/file.webp static/follow.webp
#$(addsuffix .webp, $(basename $(wildcard static/*.svg)))
styles = $(addsuffix .css, $(basename $(wildcard static/*.scss)))

................................................................................
dep: dep.mbedtls dep.mongoose dep.json-c
dep.mbedtls: lib/mbedtls/library/libmbedtls.a \
	lib/mbedtls/library/libmbedcrypto.a \
	lib/mbedtls/library/libmbedx509.a
dep.mongoose: lib/mongoose/libmongoose.a
dep.json-c: lib/json-c/libjson-c.a

static-libs = lib/json-c/libjson-c.a \
		      lib/mongoose/libmongoose.a \
		      lib/mbedtls/library/libmbedx509.a \
		      lib/mbedtls/library/libmbedcrypto.a \
		      lib/mbedtls/library/libmbedtls.a

dist-kind ?= o
parsav-dist = parsav-$(dist-kind)dist-$(version)
$(parsav-dist).txz: parsav.$(dist-kind) parsavd.$(dist-kind) dist/readme.md dist/GNUmakefile dist/BSDmakefile dist/makefile dist/default.nix $(static-libs)
	mkdir -p $(parsav-dist)
	cp -u $^ $(parsav-dist)/
	tar cf   $(parsav-dist){.tar,}
	xz -c9e  $(parsav-dist).tar > $@
	rm -r    $(parsav-dist){.tar,}

lib:
	mkdir $@
# generate a shim static library so mongoose cooperates
# with the build apparatus. note that parsav is designed
# to be fronted by a real web server like nginx if SSL
# is to be used, so we don't turn on SSL in mongoose
lib/mongoose/libmongoose.a: lib/mongoose lib/mongoose/mongoose.c lib/mongoose/mongoose.h
................................................................................
		-DMG_ENABLE_IPV6=1 \
		-DMG_ENABLE_HTTP_WEBDAV=1 \
		-DMG_ENABLE_HTTP_WEBSOCKET=0
	ar rcs $@ lib/mongoose/*.o
	ranlib $@

lib/json-c/Makefile: lib/json-c lib/json-c/CMakeLists.txt
	cd $< && cmake .
lib/json-c/libjson-c.a: lib/json-c/Makefile
	$(MAKE) -C lib/json-c
lib/mbedtls/library/%.a: lib/mbedtls 
	$(MAKE) -C lib/mbedtls/library $*.a

ifeq ($(dl), git)
clone = git clone --depth 1 # save time
ensurelib = mkdir -p lib && cd lib
lib/mongoose: 
	$(ensurelib) && $(clone) https://github.com/cesanta/mongoose.git
lib/mbedtls: 
	$(ensurelib) && $(clone) https://github.com/ARMmbed/mbedtls.git
lib/json-c: 
	$(ensurelib) && $(clone) https://github.com/json-c/json-c.git
else
lib/%: lib/%.tar.gz
	$(ensurelib) && tar zxf $*.tar.gz
	mv lib/$$(tar tf $< | head -n1) $@

ifeq ($(dl), wget)
    dlfile = mkdir -p $(dir $@) && wget "$1" -O "$@"
endif

ifeq ($(dl), curl)
    dlfile = mkdir -p $(dir $@) && curl "$1" -o "$@"
endif

lib/mongoose.tar.gz:
	$(call dlfile,https://api.github.com/repos/cesanta/mongoose/tarball/master)
lib/mbedtls.tar.gz:
	$(call dlfile,https://api.github.com/repos/ARMmbed/mbedtls/tarball/master)
lib/json-c.tar.gz:
	$(call dlfile,https://api.github.com/repos/json-c/json-c/tarball/master)
endif

Modified parsav.t from [8d6924c4e0] to [b6e7e54998].

656
657
658
659
660
661
662
663
664
665
666
667
668
669
670


671
672
673

674

675
676
677
678
679
680
681
682
683
684
	print(util.dump(config))
	os.exit(0)
end

local holler = print
local suffix = config.exe and '' or ('.'..config.outform)
local out = 'parsavd' .. suffix
local linkargs = {}
local target = config.tgttrip and terralib.newtarget {
	Triple = config.tgttrip;
	CPU = config.tgtcpu;
	FloatABIHard = config.tgthf;
} or nil

if bflag('quiet','q') then holler = function() end end


if bflag('asan','s') then linkargs[#linkargs+1] = '-fsanitize=address' end
if bflag('lsan','S') then linkargs[#linkargs+1] = '-fsanitize=leak' end


for _,p in pairs(config.pkg) do util.append(linkargs, p.linkargs) end

local linkargs_d = linkargs -- controller is not multithreaded
if config.posix then
	linkargs_d[#linkargs_d+1] = '-pthread'
end

holler(' → linking \27[1mparsav\27[m with "' .. table.concat(linkargs,' ') .. '"')
terralib.saveobj('parsav' ..suffix, { main = lib.mgtool }, linkargs, target)

holler(' → linking \27[1mparsavd\27[m with "' .. table.concat(linkargs_d,' ') .. '"')
terralib.saveobj('parsavd'..suffix, { main = entry_daemon }, linkargs_d, target)







|





<

>
>



>
|
>





|


|

656
657
658
659
660
661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
	print(util.dump(config))
	os.exit(0)
end

local holler = print
local suffix = config.exe and '' or ('.'..config.outform)
local out = 'parsavd' .. suffix
local linkargs = {'-g'}
local target = config.tgttrip and terralib.newtarget {
	Triple = config.tgttrip;
	CPU = config.tgtcpu;
	FloatABIHard = config.tgthf;
} or nil

if bflag('quiet','q') then holler = function() end end

if target then holler(' * building for triple ' .. tostring(target)) end
if bflag('asan','s') then linkargs[#linkargs+1] = '-fsanitize=address' end
if bflag('lsan','S') then linkargs[#linkargs+1] = '-fsanitize=leak' end

if config.exe then
	for _,p in pairs(config.pkg) do util.append(linkargs, p.linkargs) end
end
local linkargs_d = linkargs -- controller is not multithreaded
if config.posix then
	linkargs_d[#linkargs_d+1] = '-pthread'
end

holler(' → writing \27[1mparsav\27[m with "' .. table.concat(linkargs,' ') .. '"')
terralib.saveobj('parsav' ..suffix, { main = lib.mgtool }, linkargs, target)

holler(' → writing \27[1mparsavd\27[m with "' .. table.concat(linkargs_d,' ') .. '"')
terralib.saveobj('parsavd'..suffix, { main = entry_daemon }, linkargs_d, target)