Skip to content

Commit

Permalink
Makefile simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dargueta committed Nov 20, 2024
1 parent 3355387 commit be70ab3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
30 changes: 7 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ UNICORN_INCDIR = /usr/include
LUA := $(shell $(LUAROCKS) config variables.LUA)
LUA_DIR := $(shell $(LUAROCKS) config variables.LUA_DIR)
LUA_INCDIR = $(LUA_DIR)/include
LUA_LIBDIR = $(LUA_DIR)/lib
LUA_VERSION = $(shell $(LUA) -e 'print(_VERSION:sub(5))')

################################################################################

IS_LUAJIT = $(shell $(LUA) -e 'if _G.jit ~= nil then print(1) else print(0) end')
ifeq ($(IS_LUAJIT),1)
# LuaJIT
DEFAULT_LUA_LIB_NAME = luajit-$(LUA_VERSION)
LUAJIT_VERSION = $(shell \
$(LUA) -e 'print(string.format("%d.%d", jit.version_num / 10000, (jit.version_num / 100) % 100))' \
)
FALLBACK_LUA_INCDIR = $(LUA_DIR)/include/luajit-$(LUAJIT_VERSION)
else
# Regular Lua
DEFAULT_LUA_LIB_NAME = lua
FALLBACK_LUA_INCDIR = $(LUA_DIR)/include
endif

Expand Down Expand Up @@ -68,9 +65,7 @@ LIB_OBJECT_FILES = $(LIB_C_SOURCES:.c=.$(OBJ_EXTENSION))

TEMPLATE_DATA_FILES = $(addprefix $(SOURCE_DIR)/template_data/,basic_control_functions.lua register_types.lua)

# Unicorn 1.x gets put into places not on the typical linker search path, so we need to
# hardcode these additional directories it could appear in.
LIBRARY_DIRECTORIES = $(strip $(LUA_LIBDIR) $(UNICORN_LIBDIR) $(PTHREAD_LIBDIR) /usr/lib64 /usr/local/lib)
LIBRARY_DIRECTORIES = $(strip $(UNICORN_LIBDIR) $(PTHREAD_LIBDIR))

# The hardcoded version-specific paths here are fallbacks because my IDE can't find the
# Lua headers without them. Is it necessary? No. Will it cause problems? Unlikely. But
Expand All @@ -89,28 +84,17 @@ LIB_PATH_FLAGS = $(addprefix -L,$(LIBRARY_DIRECTORIES))
REQUIRED_LIBS = unicorn pthread
REQUIRED_LIBS_FLAGS = $(addprefix -l,$(REQUIRED_LIBS))

# LuaRocks doesn't always set the LUALIB variable. This breaks building our tests on
# LuaJIT, which uses a filename other than `liblua.a` for its library. Thus, -llua won't
# work on LuaJIT (any platform) or Windows (any Lua version).
LINK_TO_LUA_FLAG = $(if $(LUALIB),-l:$(LUALIB),-l$(DEFAULT_LUA_LIB_NAME))

# https://github.com/PowerDNS/pdns/issues/4295
ifeq ($(shell uname -s),Darwin)
ifeq ($(IS_LUAJIT),1)
# This workaround isn't needed for LuaJIT 2.1+
ifeq ($(LUAJIT_VERSION),2.0)
LINK_TO_LUA_FLAG += -pagezero_size 10000 -image_base 100000000
endif
endif
endif


C_CMD = $(CC) $(INCLUDE_PATH_FLAGS) $(CFLAGS) $(USER_C_FLAGS)
LINK_CMD = $(LD) $(LIB_PATH_FLAGS) $(LDFLAGS)


# Uncomment for debugging autogenerated files
# .PRECIOUS: $(ALL_AUTOGENERATED_SOURCES) $(LUA_SOURCE_DIR)/%_extracted_consts.lua %_const_gen.c
#.PRECIOUS: $(ALL_AUTOGENERATED_SOURCES) \
# $(LUA_SOURCE_DIR)/%_const_gen.c \
# $(LUA_SOURCE_DIR)/%_extracted_consts.txt \
# $(LUA_SOURCE_DIR)/%_extracted_consts.lua \
# %registers_const_gen.c \
# %_const_gen.c


# This must be the first rule, don't move it.
Expand Down
3 changes: 1 addition & 2 deletions unicorn-2.3.0-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ build = {
LD = "$(LD)",
LIBFLAG = "$(LIBFLAG)",
LUA_DIR = "$(LUA_DIR)",
LUA_INCDIR="$(LUA_INCDIR)",
LUA_INCDIR = "$(LUA_INCDIR)",
UNICORN_INCDIR = "$(UNICORN_INCDIR)",
UNICORN_LIBDIR = "$(UNICORN_LIBDIR)",
PTHREAD_LIBDIR = "$(PTHREAD_LIBDIR)",
LUALIB = "$(LUALIB)",
},
install_target = "__install",
install_variables = {
Expand Down

0 comments on commit be70ab3

Please sign in to comment.