🔧 build: 修改 makefile

develop
xiaojin 5 years ago
parent 3818bdcad8
commit 841999c589

@ -1,19 +0,0 @@
Copyright (C) 2010-2013 nsf <no.smile.face@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@ -21,6 +21,9 @@ SHIFTTIMER_SO = $(LUA_CLIB_PATH)/shiftimer.so
CLUA_SO = $(LUA_CLIB_PATH)/clua.so CLUA_SO = $(LUA_CLIB_PATH)/clua.so
AOI_SO = $(LUA_CLIB_PATH)/aoi.so AOI_SO = $(LUA_CLIB_PATH)/aoi.so
ECS_SO = $(LUA_CLIB_PATH)/ecs.so ECS_SO = $(LUA_CLIB_PATH)/ecs.so
LUASOCKET_SO = $(LUA_CLIB_PATH)/socket.so
TERMFX_SO = $(LUA_CLIB_PATH)/termfx.so
RC4_SO = $(LUA_CLIB_PATH)/rc4.so
##################################################### #####################################################
all: $(LFS_SO) \ all: $(LFS_SO) \
@ -31,6 +34,9 @@ all: $(LFS_SO) \
$(SHIFTTIMER_SO) \ $(SHIFTTIMER_SO) \
$(AOI_SO) \ $(AOI_SO) \
$(ECS_SO) \ $(ECS_SO) \
$(LUASOCKET_SO) \
$(TERMFX_SO) \
$(RC4_SO) \
$(CLUA_SO) $(CLUA_SO)
##################################################### #####################################################
@ -61,11 +67,25 @@ $(CLUA_SO):
$(ECS_SO): $(ECS_SO):
cd lua-ecs && $(MAKE) PLAT=$(PLAT) cd lua-ecs && $(MAKE) PLAT=$(PLAT)
##################################################### $(RC4_SO):
cd lua-rc4 && $(MAKE) PLAT=$(PLAT)
$(TERMFX_SO):
cd lua-termfx && $(MAKE)
cp -f lua-termfx/termfx.so $@
$(LUASOCKET_SO):
cd luasocket && $(MAKE) DEBUG=DEBUG PLAT=$(PLAT) LUAINC_$(PLAT)=$(SKYNET_ROOT)/3rd/lua/ CDIR_$(PLAT)=$(SKYNET_ROOT)/3rd/lua/ LDIR_$(PLAT)=$(SKYNET_ROOT)/3rd/lua/
cp -f luasocket/src/socket-3.0-rc1.so $@
#####################################################
cleanall: cleanall:
rm -f $(LUA_CLIB_PATH)/*.so && \ rm -f $(LUA_CLIB_PATH)/*.so && \
rm -rf $(LUA_CLIB_PATH)/*.dSYM && \ rm -rf $(LUA_CLIB_PATH)/*.dSYM && \
rm -f $(LUA_CLIB_PATH)/*.o rm -f $(LUA_CLIB_PATH)/*.o && \
cd lua-termfx && $(MAKE) clean && \
cd .. && \
cd luasocket && $(MAKE) clean && \
cd ../../
.PHONY: all cleanall .PHONY: all cleanall

@ -1,26 +1,30 @@
PROJECT = rc4 SKYNET_ROOT ?= ../../skynet
SRC = . include $(SKYNET_ROOT)/platform.mk
INC = -I. -I/usr/local/include
CC = gcc
CC_FLAGS = -O2 -fPIC $(INC) -Wall -Wextra -c
SRC_C = $(foreach dir, $(SRC), $(wildcard $(dir)/*.c)) PLAT ?= none
OBJ_C = $(patsubst %.c, %.o, $(SRC_C))
OBJ = $(OBJ_C)
.PHONY : all TARGET = ../../luaclib/rc4.so
all: $(PROJECT).so
$(PROJECT).so: $(OBJ) ifeq ($(PLAT), macosx)
ld -shared $(OBJ) -o $(PROJECT).so CFLAGS = -g -O2 -dynamiclib -Wl,-undefined,dynamic_lookup
ifdef OUTPUT else
cp -f $(PROJECT).so $(OUTPUT) ifeq ($(PLAT), linux)
CFLAGS = -g -O2 -shared -fPIC
endif endif
endif
LUA_LIB ?= $(SKYNET_ROOT)/3rd/lua/
LUA_INC ?= $(SKYNET_ROOT)/3rd/lua/
SKYNET_SRC ?= $(SKYNET_ROOT)/skynet-src
SRC = .
.PHONY: all clean
all: $(TARGET)
$(OBJ_C) : %.o : %.c $(TARGET): $(foreach dir, $(SRC), $(wildcard $(dir)/*.c))
$(CC) $(CC_FLAGS) -o $@ $< $(CC) $(CFLAGS) $(SHARED) -I$(LUA_INC) -I$(SKYNET_SRC) $^ -o $@
.PHONY : clean
clean: clean:
rm -f $(PROJECT).so $(OBJ) rm -f *.o $(TARGET)

@ -3,14 +3,15 @@
# Gunnar Zötl <gz@tset.de>, 2014-2015. # Gunnar Zötl <gz@tset.de>, 2014-2015.
# Released under the terms of the MIT license. See file LICENSE for details. # Released under the terms of the MIT license. See file LICENSE for details.
TERMBOX = ../../3rd//termbox_next TERMBOX = ../../3rd/termbox_next
SKYNET_ROOT ?= ../../skynet
# try some automatic discovery. If that does not work for you, just set # try some automatic discovery. If that does not work for you, just set
# the following values manually. # the following values manually.
OS = $(shell uname -s) OS = $(shell uname -s)
LUAVERSION = $(shell lua -e "print(string.match(_VERSION, '%d+%.%d+'))") LUAVERSION = $(shell lua -e "print(string.match(_VERSION, '%d+%.%d+'))")
LUA_BINDIR = $(shell dirname `which lua`) # LUA_BINDIR = $(shell dirname `which lua`)
LUAROOT = $(shell dirname $(LUA_BINDIR)) # LUAROOT = $(shell dirname $(LUA_BINDIR))
OBJS = termfx.o termfx_color.o tbutils.o OBJS = termfx.o termfx_color.o tbutils.o
@ -18,8 +19,9 @@ TARGET = termfx.so
CC = gcc CC = gcc
CFLAGS = -fPIC -Wall CFLAGS = -fPIC -Wall
LUA_INCDIR = $(LUAROOT)/include
LUA_LIBDIR = $(LUAROOT)/lib LUA_INCDIR ?= $(SKYNET_ROOT)/3rd/lua/
LUA_LIBDIR ?= $(SKYNET_ROOT)/3rd/lua/
# OS specialities # OS specialities
ifeq ($(OS),Darwin) ifeq ($(OS),Darwin)

@ -20,4 +20,14 @@ local profile = require "profile.c"
print("profile", profile) print("profile", profile)
local clua = require "clua" local clua = require "clua"
print("clua", clua) print("clua", clua)
local rc4 = require "rc4.c"
print("rc4", rc4)
local termfx = require "termfx"
print("termfx", termfx)
local socket = require "socket"
print("socket", socket)

@ -1,81 +1,93 @@
-- sample for termfx -- sample for termfx
-- Gunnar Zötl <gz@tset.de>, 2014-2015 -- Gunnar Zötl <gz@tset.de>, 2014-2015
-- Released under the terms of the MIT license. See file LICENSE for details. -- Released under the terms of the MIT license. See file LICENSE for details.
tfx = require "termfx" tfx = require "termfx"
tfx.init() tfx.init()
function makespr(s, fg, bg) function makespr(s, fg, bg)
local c = "-:+=%ZXH#" local c = "-:+=%ZXH#"
local spr = tfx.newbuffer(s, s/2) local spr = tfx.newbuffer(s, s / 2)
spr:attributes(fg, bg) spr:attributes(fg, bg)
for y=1, s/2 do for y = 1, s / 2 do
for x=1, s do for x = 1, s do
local lx, ly = (x-0.5)/s, (2*y-1)/s local lx, ly = (x - 0.5) / s, (2 * y - 1) / s
local v = math.floor((math.sin(lx*math.pi) + math.sin(ly*math.pi)) / 2 * #c) local v = math.floor((math.sin(lx * math.pi) + math.sin(ly * math.pi)) / 2 * #c)
local ch = string.sub(c, v, v) local ch = string.sub(c, v, v)
spr:setcell(x, y, ch) spr:setcell(x, y, ch)
end end
end end
return spr return spr
end end
tfx.outputmode(tfx.output.NORMAL) tfx.outputmode(tfx.output.NORMAL)
ok, err = pcall(function() ok, err = pcall(function()
local sprites = {} local sprites = {}
local blit2screen = true local blit2screen = true
for i=1, 5 do for i = 1, 5 do
sprites[i] = makespr(2^(i+2), i+1, tfx.color.BLACK) sprites[i] = makespr(2 ^ (i + 2), i + 1, tfx.color.BLACK)
end end
local snum = 1 local snum = 1
local spr = sprites[snum] local spr = sprites[snum]
local sw, sh = spr:width(), spr:height() local sw, sh = spr:width(), spr:height()
local x, y = 1-sw, 1-sh local x, y = 1 - sw, 1 - sh
local xo, yo = 1, 1 local xo, yo = 1, 1
local fw, fh = tfx.width(), tfx.height() local fw, fh = tfx.width(), tfx.height()
local target = tfx.newbuffer(fw - 2, fh - 2) local target = tfx.newbuffer(fw - 2, fh - 2)
local w, h = target:width(), target:height() local w, h = target:width(), target:height()
repeat
repeat if blit2screen then
tfx.clear(tfx.color.WHITE, tfx.color.BLACK)
if blit2screen then tfx.blit(x, y, spr)
tfx.clear(tfx.color.WHITE, tfx.color.BLACK) else
tfx.blit(x, y, spr) tfx.clear(tfx.color.WHITE, tfx.color.RED)
else target:clear(tfx.color.WHITE, tfx.color.BLACK)
tfx.clear(tfx.color.WHITE, tfx.color.RED) target:blit(x, y, spr)
target:clear(tfx.color.WHITE, tfx.color.BLACK) tfx.blit(2, 2, target)
target:blit(x, y, spr) end
tfx.blit(2, 2, target)
end
x = x + xo x = x + xo
if x > w or x < 1-sw then xo = -xo end if x > w or x < 1 - sw then
y = y + yo xo = -xo
if y > h or y < 1-sh then yo = -yo end end
y = y + yo
if y > h or y < 1 - sh then
yo = -yo
end
tfx.printat(1, tfx.height(), "print 1.."..#sprites.." for sprite size, t to toggle blit to screen or buffer, q to quit") tfx.printat(1, tfx.height(),
tfx.printat(1, 1, "Current size: "..snum.." ("..spr:width().."x"..spr:height()..")") "print 1.." .. #sprites .. " for sprite size, t to toggle blit to screen or buffer, q to quit")
tfx.printat(1, 1, "Current size: " .. snum .. " (" .. spr:width() .. "x" .. spr:height() .. ")")
tfx.present() tfx.present()
evt = tfx.pollevent(333) evt = tfx.pollevent(333)
snum = evt and tonumber(evt.char) or snum snum = evt and tonumber(evt.char) or snum
if snum >= 1 and snum <= #sprites then if snum >= 1 and snum <= #sprites then
spr = sprites[snum] spr = sprites[snum]
sw, sh = spr:width(), spr:height() sw, sh = spr:width(), spr:height()
if x < 1-sw then x = 1-sw xo = 1 end if x < 1 - sw then
if y < 1-sh then y = 1-sh yo = 1 end x = 1 - sw
end xo = 1
end
if evt and evt.char == 't' then if y < 1 - sh then
blit2screen = not blit2screen y = 1 - sh
end yo = 1
end
until evt and evt.type == "key" and evt.char == "q" end
if evt and evt.char == 't' then
blit2screen = not blit2screen
end
until evt and evt.type == "key" and evt.char == "q"
end) end)
tfx.shutdown() tfx.shutdown()
if not ok then print("Error: "..err) end if not ok then
print("Error: " .. err)
end

@ -1,7 +1,6 @@
-- sample for termfx -- sample for termfx
-- Gunnar Zötl <gz@tset.de>, 2014-2015 -- Gunnar Zötl <gz@tset.de>, 2014-2015
-- Released under the terms of the MIT license. See file LICENSE for details. -- Released under the terms of the MIT license. See file LICENSE for details.
--[[ screenshot.lua --[[ screenshot.lua
a simple screenshot facility for termfx programs, outputs html in a simple screenshot facility for termfx programs, outputs html in
a string. Cell colors and attributes are preserved. Note, this only a string. Cell colors and attributes are preserved. Note, this only
@ -21,68 +20,71 @@
html = screenshot(buf) html = screenshot(buf)
-- then write it to a file, surrounded by a html template as necessary. -- then write it to a file, surrounded by a html template as necessary.
--]] --]] local tfx = require "termfx"
local tfx = require "termfx"
local function to_html(scr) local function to_html(scr)
local fg, bg local fg, bg
local res = { "<pre>" } local res = {"<pre>"}
for y=1, scr.h do for y = 1, scr.h do
for x=1, scr.w do for x = 1, scr.w do
local cel = scr[y][x] local cel = scr[y][x]
if fg ~= cel.fg or bg ~= cel.bg then if fg ~= cel.fg or bg ~= cel.bg then
if fg then if fg then
res[#res+1] = "</span>" res[#res + 1] = "</span>"
end end
local fgcol, fgattr = tfx.colorinfo(cel.fg % 256), math.floor(cel.fg / 256) local fgcol, fgattr = tfx.colorinfo(cel.fg % 256), math.floor(cel.fg / 256)
local bgcol = tfx.colorinfo(cel.bg % 256) local bgcol = tfx.colorinfo(cel.bg % 256)
local style, weight = "", "" local style, weight = "", ""
if fgattr % 2 == 1 then if fgattr % 2 == 1 then
weight = "; font-weight: bold" weight = "; font-weight: bold"
end end
fgattr = fgattr / 2 fgattr = fgattr / 2
if fgattr % 2 == 1 then if fgattr % 2 == 1 then
style = "; text-decoration: underline" style = "; text-decoration: underline"
end end
fgattr = fgattr / 2 fgattr = fgattr / 2
if fgattr % 2 == 1 then if fgattr % 2 == 1 then
fgcol, bgcol = bgcol, fgcol fgcol, bgcol = bgcol, fgcol
end end
res[#res+1] = string.format('<span style="color: %s; background-color: %s', fgcol, bgcol) res[#res + 1] = string.format('<span style="color: %s; background-color: %s', fgcol, bgcol)
res[#res+1] = weight .. style res[#res + 1] = weight .. style
res[#res+1] = '">' res[#res + 1] = '">'
fg = cel.fg fg = cel.fg
bg = cel.bg bg = cel.bg
end end
res[#res+1] = string.format('%c', cel.ch) res[#res + 1] = string.format('%c', cel.ch)
end end
res[#res+1] = "<br>" res[#res + 1] = "<br>"
end end
res[#res+1] = "</span></pre>" res[#res + 1] = "</span></pre>"
return table.concat(res) return table.concat(res)
end end
local function screenshot(buf) local function screenshot(buf)
local w, h, getcell local w, h, getcell
if buf then if buf then
w, h = buf:size() w, h = buf:size()
getcell = function(x, y) return buf:getcell(x, y) end getcell = function(x, y)
else return buf:getcell(x, y)
w, h = tfx.size() end
getcell = tfx.getcell else
end w, h = tfx.size()
getcell = tfx.getcell
end
local res = {w = w, h = h} local res = {
for y=1, h do w = w,
res[y] = {} h = h,
for x=1, w do }
res[y][x] = getcell(x, y) for y = 1, h do
end res[y] = {}
end for x = 1, w do
res[y][x] = getcell(x, y)
end
end
return to_html(res) return to_html(res)
end end
return screenshot return screenshot

@ -1,7 +1,6 @@
-- sample for termfx -- sample for termfx
-- Gunnar Zötl <gz@tset.de>, 2014-2015 -- Gunnar Zötl <gz@tset.de>, 2014-2015
-- Released under the terms of the MIT license. See file LICENSE for details. -- Released under the terms of the MIT license. See file LICENSE for details.
--[[ --[[
simpleui.lua simpleui.lua
@ -30,104 +29,114 @@ local _M = {}
local tfx = require "termfx" local tfx = require "termfx"
local function draw_box(x, y, w, h) local function draw_box(x, y, w, h)
local ccell = tfx.newcell('+') local ccell = tfx.newcell('+')
local hcell = tfx.newcell('-') local hcell = tfx.newcell('-')
local vcell = tfx.newcell('|') local vcell = tfx.newcell('|')
for i = x, x+w do for i = x, x + w do
tfx.setcell(i, y-1, hcell) tfx.setcell(i, y - 1, hcell)
tfx.setcell(i, y+h, hcell) tfx.setcell(i, y + h, hcell)
end end
for i = y, y+h do for i = y, y + h do
tfx.setcell(x-1, i, vcell) tfx.setcell(x - 1, i, vcell)
tfx.setcell(x+w, i, vcell) tfx.setcell(x + w, i, vcell)
end end
tfx.setcell(x-1, y-1, ccell) tfx.setcell(x - 1, y - 1, ccell)
tfx.setcell(x-1, y+h, ccell) tfx.setcell(x - 1, y + h, ccell)
tfx.setcell(x+w, y-1, ccell) tfx.setcell(x + w, y - 1, ccell)
tfx.setcell(x+w, y+h, ccell) tfx.setcell(x + w, y + h, ccell)
tfx.rect(x, y, w, h, ' ', fg, bg) tfx.rect(x, y, w, h, ' ', fg, bg)
end end
_M.box = draw_box _M.box = draw_box
local function frame(w, h) local function frame(w, h)
local tw, th = tfx.size() local tw, th = tfx.size()
if w + 2 > tw then w = tw - 2 end if w + 2 > tw then
if h + 2 > th then h = th - 2 end w = tw - 2
local x = math.floor((tw - w) / 2) end
local y = math.floor((th - h) / 2) if h + 2 > th then
h = th - 2
draw_box(x, y, w, h) end
local x = math.floor((tw - w) / 2)
return x, y, w, h local y = math.floor((th - h) / 2)
draw_box(x, y, w, h)
return x, y, w, h
end end
function _M.ask(msg) function _M.ask(msg)
local mw = #msg local mw = #msg
if mw < 6 then mw = 6 end if mw < 6 then
local x, y, w, h = frame(mw, 3) mw = 6
tfx.printat(x, y, msg, w) end
local p = x + math.floor((w - 6) / 2) local x, y, w, h = frame(mw, 3)
tfx.attributes(tfx.color.BLACK, tfx.color.GREEN) tfx.printat(x, y, msg, w)
tfx.printat(p, y+2, "Yes") local p = x + math.floor((w - 6) / 2)
tfx.attributes(tfx.color.BLACK, tfx.color.RED) tfx.attributes(tfx.color.BLACK, tfx.color.GREEN)
tfx.printat(p+4, y+2, "No") tfx.printat(p, y + 2, "Yes")
tfx.present() tfx.attributes(tfx.color.BLACK, tfx.color.RED)
tfx.printat(p + 4, y + 2, "No")
local answer = nil tfx.present()
while answer == nil do
local evt = tfx.pollevent() local answer = nil
if evt.char == 'y' or evt.char == 'Y' then while answer == nil do
answer = true local evt = tfx.pollevent()
elseif evt.char == 'n' or evt.char == 'N' then if evt.char == 'y' or evt.char == 'Y' then
answer = false answer = true
end elseif evt.char == 'n' or evt.char == 'N' then
end answer = false
return answer end
end
return answer
end end
function _M.message(msg) function _M.message(msg)
local mw = #msg local mw = #msg
local x, y, w, h = frame(mw, 3) local x, y, w, h = frame(mw, 3)
tfx.printat(x, y, msg, w) tfx.printat(x, y, msg, w)
local p = x + math.floor((w - 2) / 2) local p = x + math.floor((w - 2) / 2)
tfx.attributes(tfx.color.BLACK, tfx.color.GREEN) tfx.attributes(tfx.color.BLACK, tfx.color.GREEN)
tfx.printat(p, y+2, "Ok") tfx.printat(p, y + 2, "Ok")
tfx.present() tfx.present()
local evt local evt
repeat repeat
evt = tfx.pollevent() evt = tfx.pollevent()
until evt.key == tfx.key.ENTER or evt.key == tfx.key.SPACE or evt.key == tfx.key.ESC until evt.key == tfx.key.ENTER or evt.key == tfx.key.SPACE or evt.key == tfx.key.ESC
end end
function _M.select(msg, tbl) function _M.select(msg, tbl)
local mw = #msg local mw = #msg
local mh = #tbl local mh = #tbl
if mh > 9 then mh = 9 end if mh > 9 then
for i=1, mh do mh = 9
if mw < #tbl[i] + 2 then mw = #tbl[i] + 2 end end
end for i = 1, mh do
if mw < #tbl[i] + 2 then
local x, y, w, h = frame(mw, mh+2) mw = #tbl[i] + 2
tfx.printat(x, y, msg, w) end
for i=1, mh do end
tfx.printat(x, y+1+i, i.." "..tbl[i], w)
end local x, y, w, h = frame(mw, mh + 2)
tfx.present() tfx.printat(x, y, msg, w)
for i = 1, mh do
local answer = nil tfx.printat(x, y + 1 + i, i .. " " .. tbl[i], w)
while answer == nil do end
local evt = tfx.pollevent() tfx.present()
if evt.char >= '1' and evt.char <= tostring(mh) then
answer = tbl[tonumber(evt.char)] local answer = nil
elseif evt.key == tfx.key.ENTER or evt.key == tfx.key.SPACE or evt.key == tfx.key.ESC then while answer == nil do
answer = false local evt = tfx.pollevent()
end if evt.char >= '1' and evt.char <= tostring(mh) then
end answer = tbl[tonumber(evt.char)]
return answer elseif evt.key == tfx.key.ENTER or evt.key == tfx.key.SPACE or evt.key == tfx.key.ESC then
answer = false
end
end
return answer
end end
return _M return _M

Loading…
Cancel
Save