Index: config.lua ================================================================== --- config.lua +++ config.lua @@ -28,11 +28,11 @@ 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)); + -- 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'); ADDED dist/BSDmakefile Index: dist/BSDmakefile ================================================================== --- dist/BSDmakefile +++ dist/BSDmakefile @@ -0,0 +1,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 ADDED dist/GNUmakefile Index: dist/GNUmakefile ================================================================== --- dist/GNUmakefile +++ dist/GNUmakefile @@ -0,0 +1,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 Index: dist/default.nix ================================================================== --- dist/default.nix +++ dist/default.nix ADDED dist/makefile Index: dist/makefile ================================================================== --- dist/makefile +++ dist/makefile @@ -0,0 +1,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 Index: dist/readme.md ================================================================== --- dist/readme.md +++ dist/readme.md @@ -0,0 +1,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. Index: makefile ================================================================== --- makefile +++ makefile @@ -1,5 +1,6 @@ +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))) @@ -33,10 +34,25 @@ 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 @@ -49,39 +65,40 @@ -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 . + 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 -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 +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 - cd lib && tar zxf $*.tar.gz + $(ensurelib) && tar zxf $*.tar.gz mv lib/$$(tar tf $< | head -n1) $@ ifeq ($(dl), wget) - dlfile = wget "$(1)" -O "$(2)" + dlfile = mkdir -p $(dir $@) && wget "$1" -O "$@" endif ifeq ($(dl), curl) - dlfile = curl "$(1)" -o "$(2)" + dlfile = mkdir -p $(dir $@) && curl "$1" -o "$@" 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,$@) +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 Index: parsav.t ================================================================== --- parsav.t +++ parsav.t @@ -658,27 +658,30 @@ end local holler = print local suffix = config.exe and '' or ('.'..config.outform) local out = 'parsavd' .. suffix -local linkargs = {} +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 -for _,p in pairs(config.pkg) do util.append(linkargs, p.linkargs) 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(' → linking \27[1mparsav\27[m with "' .. table.concat(linkargs,' ') .. '"') +holler(' → writing \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,' ') .. '"') +holler(' → writing \27[1mparsavd\27[m with "' .. table.concat(linkargs_d,' ') .. '"') terralib.saveobj('parsavd'..suffix, { main = entry_daemon }, linkargs_d, target)