Skip to content

Commit

Permalink
Merge branch 'build-actions'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaromil committed Jan 26, 2022
2 parents 0c282b1 + 5ad2c32 commit 1ef58c9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 39 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build harvest using gcc
on: [push, pull_request]

jobs:
shared:
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
version: [11]
runs-on: '${{ matrix.os }}'
name: 'Version: ${{ matrix.os }} / ${{ matrix.version }}'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up GCC
uses: egor-tensin/setup-gcc@v1
with:
version: '${{ matrix.version }}'
platform: '${{ matrix.platform }}'
cc: 1
- name: Install dependencies
run: |
sudo apt-get update
# install deps
sudo apt-get install --force-yes pkg-config luarocks libluajit-5.1-dev curl mingw-w64 mingw-w64-x86-64-dev
sudo luarocks install luastatic
- name: Build
run: |
make && mv harvest harvest.elf
make clean
make win64
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
generate_release_notes: true
fail_on_unmatched_files: true
files: |
harvest.elf
harvest.exe
49 changes: 25 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,35 @@ LDADD ?= /usr/lib/x86_64-linux-gnu/libluajit-5.1.a -lm -ldl

MUSL_LDADD ?= /usr/lib/${ARCH}-linux-musl/libc.a

all: devuan-luajit-shared
all: shared

luajit:
make -C src/luajit CC=$(CC) CFLAGS="$(CFLAGS)"


luajit-win:
make -C src/luajit HOST_CC=gcc CC=$(CC) CFLAGS="$(CFLAGS)" TARGET_SYS=Windows

luastatic:
shared:
CC=$(CC) AR=$(AR) INCLUDE="$(INCLUDE)" LDADD="$(LDADD)" CFLAGS="$(CFLAGS)" make -C src

devuan-luajit-shared: luastatic
$(CC) -o harvest $(CFLAGS) $(INCLUDE) src/harvest.luastatic.c src/lfs.a $(LDADD)

devuan-luajit-static: LDADD = src/luajit/src/libluajit.a /usr/lib/${ARCH}-linux-musl/libc.a
devuan-luajit-static: INCLUDE = -I luajit/src
devuan-luajit-static: CC = musl-gcc
devuan-luajit-static: CFLAGS = -Os -static
devuan-luajit-static: luastatic luajit
$(CC) -static -o harvest $(CFLAGS) -I src/luajit/src src/harvest.luastatic.c src/lfs.a $(LDADD) -lm

mingw32-luajit-static: CC=x86_64-w64-mingw32-gcc
mingw32-luajit-static: AR=x86_64-w64-mingw32-ar
mingw32-luajit-static: INCLUDE = -I luajit/src
mingw32-luajit-static: LDADD = src/luajit/src/libluajit.a
mingw32-luajit-static: LDLIBS=-lm
mingw32-luajit-static: luastatic luajit-win
static: LDADD = /usr/lib/${ARCH}-linux-gnu/libluajit-5.1.a /usr/lib/${ARCH}-linux-musl/libc.a
static: CC = musl-gcc
static: CFLAGS = -O3 --fast-math -static
static:
CC=$(CC) AR=$(AR) INCLUDE="$(INCLUDE)" LDADD="$(LDADD)" CFLAGS="$(CFLAGS)" make -C src static
$(CC) -static -o harvest $(CFLAGS) $(INCLUDE) src/harvest.luastatic.c src/lfs.a $(LDADD) -lm

luajit-win64: CC=x86_64-w64-mingw32-gcc
luajit-win64: AR=x86_64-w64-mingw32-ar
luajit-win64:
if ! [ -r luajit.tar.gz ]; then curl -L https://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz > luajit.tar.gz; fi
if ! [ -d luajit ]; then mkdir -p luajit && tar -C luajit -xf luajit.tar.gz ; fi
mkdir -p luajit/include && cp -ra luajit/*/src/*.h luajit/include/
make -C luajit/Lua* HOST_CC=gcc CC=$(CC) CFLAGS="$(CFLAGS)" TARGET_SYS=Windows BUILDMODE=static
cp luajit/Lua*/src/libluajit.a luajit/

win64: CC=x86_64-w64-mingw32-gcc
win64: AR=x86_64-w64-mingw32-ar
win64: INCLUDE = -I luajit/include
win64: LDADD = luajit/libluajit.a
win64: LDLIBS=-lm
win64: luajit-win64
CC=$(CC) AR=$(AR) INCLUDE="$(INCLUDE)" LDADD="$(LDADD)" CFLAGS="$(CFLAGS)" make -C src static
$(CC) -static -o harvest.exe $(CFLAGS) $(INCLUDE) src/harvest.luastatic.c src/lfs.a $(LDADD)

win32: mingw32-luajit-static
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ all:
$(AR) rcs lfs.a lfs.o
CC="" luastatic $(SOURCES) lfs.a
$(CC) -c $(INCLUDE) $(CFLAGS) harvest.luastatic.c


static:
$(CC) -c $(INCLUDE) $(CFLAGS) lfs.c -o lfs.o
$(AR) rcs lfs.a lfs.o
-CC="" luastatic $(SOURCES) lfs.a -static $(INCLUDES)
$(CC) -c $(INCLUDE) $(CFLAGS) harvest.luastatic.c
17 changes: 2 additions & 15 deletions src/harvest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ local align = require'align'
local function stderr(_msg) io.stderr:write(_msg..'\n') end
local function stdout(_msg) io.stdout:write(_msg..'\n') end

-- debug
DEBUG=0
local inspect = require'inspect'
local function I(o)
if DEBUG > 0 then stderr( inspect.inspect(o) ) end end
local function D(s)
if DEBUG > 0 then stderr(s) end
end

-- # fuzzy thresholds
-- #
-- # this is the most important section to tune the selection: the higher
Expand Down Expand Up @@ -76,21 +67,18 @@ local function analyse_path(basedir, pathname, level)
local target = pathname or basedir
local curlev = level or 1
local scores = { other = { } }
-- D("analyse: "..target)
local path
for path in lfs.dir(target) do
if not (path == '.' or path == '..') then
local tarpath = target..'/'..path
if lfs.attributes(tarpath,"mode") == "directory" then
D("found dir:\t"..tarpath.." ("..curlev..")")
analyse_path(basedir, tarpath, curlev+1)

else -- file in subdir
local ftype = file_extension_list[ extparser(tarpath) ]
if ftype then
if not scores[ftype] then scores[ftype] = { } end
table.insert(scores[ftype], tarpath)
-- D("found "..ftype..":\t"..tarpath)
else
table.insert(scores['other'], tarpath)
end
Expand Down Expand Up @@ -161,7 +149,7 @@ cli:option("-o, --output=FORMAT", "csv", 'human')
cli:flag("--dir", "select only directories")
cli:flag("--file", "select only files")
cli:flag("-d", "run in DEBUG mode", function() DEBUG=1 end)
cli:flag("-v, --version", "print the version and exits", function()
cli:flag("-v, --version", "print the version and exit", function()
print("Harvest version 0.8") os.exit(0) end)

local args, err = cli:parse(arg)
Expand Down Expand Up @@ -196,11 +184,10 @@ elseif args then -- default command is scan
local fattr = lfs.attributes
for file in lfs.dir(args.path) do
local filepath = args.path.."/"..file
D("analyze "..filepath)
if not (file == '.' or file == '..') then
local attr = fattr(filepath)
attr.name = file
I(attr)
-- I(attr)
if type(attr) == 'table' then -- safety to os stat
if attr.mode == "directory" then
attr.type = 'dir'
Expand Down

0 comments on commit 1ef58c9

Please sign in to comment.