From e003337b5c93493f241d71edb87b2df7747fe9ee Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 31 May 2023 15:30:42 +0000 Subject: [PATCH] Makefile FossilOrigin-Name: 9b32280cb809c26ca511f8dcda5fff3a8bc19a517ff60c095cde46ad3ad606e2 --- .fossil-settings/ignore-glob | 2 - Makefile | 103 +++++++++++++++++++++++++++ cmake/append_and_def.cmake | 37 ---------- cmake/os_hacks.cmake | 2 - premake5.lua | 130 ----------------------------------- 5 files changed, 103 insertions(+), 171 deletions(-) create mode 100644 Makefile delete mode 100644 cmake/append_and_def.cmake delete mode 100644 cmake/os_hacks.cmake delete mode 100644 premake5.lua diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob index 8bbcbd7..98f7ff8 100644 --- a/.fossil-settings/ignore-glob +++ b/.fossil-settings/ignore-glob @@ -1,4 +1,3 @@ -Makefile template ctemplate filec @@ -8,7 +7,6 @@ emojitoc static/*.ctmpl static/*.c mastodont-c -treebird.make config.h treebird test/tests diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4318830 --- /dev/null +++ b/Makefile @@ -0,0 +1,103 @@ +CC ?= cc +MASTODONT_DIR = mastodont-c + +ifneq ($(wildcard $(MASTODONT_DIR)/bin/Release),) +MASTODONT = $(MASTODONT_DIR)/bin/Release/ +else ifneq ($(wildcard $(MASTODONT_DIR)/bin/Debug),) +MASTODONT = $(MASTODONT_DIR)/bin/Debug/ +endif + + +CFLAGS += -Wall -I $(MASTODONT_DIR)/include/ -Wno-unused-variable -Wno-ignored-qualifiers \ + -I/usr/include/ -I $(MASTODONT_DIR)/libs $(shell pkg-config --cflags libcurl) \ + `perl -MExtUtils::Embed -e ccopts` -DDEBUGGING_MSTATS +LDFLAGS += -L$(MASTODONT) -lmastodont $(shell pkg-config --libs libcurl) -lfcgi \ + -lpthread `perl -MExtUtils::Embed -e ldopts` -DDEBUGGING_MSTATS +# libpcre2-8 (?) +SRC = $(wildcard src/*.c) +OBJ = $(patsubst %.c,%.o,$(SRC)) +HEADERS = $(wildcard src/*.h) config.h +TMPL_DIR = templates +TMPLS = $(wildcard $(TMPL_DIR)/*.tt) +TMPLS_C = $(patsubst %.tt,%.ctt,$(TMPLS)) +TEST_DIR = test/unit +TESTS = $(wildcard $(TEST_DIR)/t*.c) +UNIT_TESTS = $(patsubst %.c,%.bin,$(TESTS)) +DIST = dist/ +PREFIX ?= /usr/local +TARGET = treebird +# For tests +OBJ_NO_MAIN = $(filter-out src/main.o,$(OBJ)) + +MASTODONT_URL = https://fossil.nekobit.net/mastodont-c + +# Not parallel friendly +#all: $(MASTODONT_DIR) dep_build $(TARGET) + + +ifneq ($(strip $(DEBUG)),) +CFLAGS += -DDEBUG +endif + +all: +ifeq ($(wildcard $(MASTODONT_DIR)),) + @echo "[ERROR] Mastodont-c/ not found. Link it with ln -s in this directory." + @exit 1 +endif + $(MAKE) filec + $(MAKE) make_tmpls + $(MAKE) $(TARGET) + +install_deps: + cpan Template::Toolkit + +$(TARGET): $(HEADERS) $(OBJ) + $(CC) -o $(TARGET) $(OBJ) $(PAGES_C_OBJ) $(LDFLAGS) + +filec: src/file-to-c/main.o + $(CC) $(LDFLAGS) -o filec $< + +emojitoc: scripts/emoji-to.o + $(CC) -o emojitoc $< $(LDFLAGS) + ./emojitoc meta/emoji.json > src/emoji_codes.h + +$(TMPL_DIR)/%.ctt: $(TMPL_DIR)/%.tt + ./filec $< data_$(notdir $*)_tt > $@ + +make_tmpls: $(TMPLS_C) + +$(MASTODONT_DIR): + cd ..; fossil clone $(MASTODONT_URL) || true + cd treebird; ln -s ../mastodont-c . + +install: $(TARGET) + install -m 755 treebird $(PREFIX)/bin/ + install -d $(PREFIX)/share/treebird/ + cp -r dist/ $(PREFIX)/share/treebird/ + +test: all $(UNIT_TESTS) + @echo " ... Tests ready" + @./test/test.pl + +%.o: %.c %.h $(PAGES) + $(CC) $(CFLAGS) -c $< -o $@ + +# For tests +%.bin: %.c + @$(CC) $(CFLAGS) $< -o $@ $(OBJ_NO_MAIN) $(PAGES_C_OBJ) $(LDFLAGS) + @echo -n " $@" + +clean: + rm -f $(OBJ) src/file-to-c/main.o + rm -f $(TMPLS_C) + rm -f test/unit/*.bin + rm -f filec ctemplate + rm $(TARGET) || true + make -C $(MASTODONT_DIR) clean + +clean_deps: + rm -r $(MASTODONT_DIR) + +clean_all: clean clean_deps + +.PHONY: all filec clean update clean clean_deps clean_all test install_deps diff --git a/cmake/append_and_def.cmake b/cmake/append_and_def.cmake deleted file mode 100644 index 14e5086..0000000 --- a/cmake/append_and_def.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# For ease of development, you can enable and disable pages. This is useful if -# the code doesn't compile correctly, for which you can do an `#ifdef' with the -# C Preprocessor - -function(append_and_def TARGET SCOPE NAME) - math(EXPR LEN "${ARGC}-1") - foreach(I RANGE 3 ${LEN}) - list(GET ARGV ${I} filename) - # Convert name partto uppercase for the definition - get_filename_component(name ${filename} NAME_WE) - string(TOUPPER ${name} file_up) - - get_target_property( - targ_comp - ${TARGET} - COMPILE_DEFINITIONS - ) - - if ("${targ_comp}" STREQUAL "targ_comp-NOTFOUND") - set_target_properties( - ${TARGET} - PROPERTIES COMPILE_DEFINITIONS "${file_up}" - ) - else() - set_target_properties( - ${TARGET} - PROPERTIES COMPILE_DEFINITIONS "${targ_comp};${file_up}" - ) - endif() - - # Will return copy of files - list(APPEND out_list ${filename}) - endforeach() - - # Return - set(${NAME} ${out_list} PARENT_SCOPE) -endfunction() diff --git a/cmake/os_hacks.cmake b/cmake/os_hacks.cmake deleted file mode 100644 index 5686853..0000000 --- a/cmake/os_hacks.cmake +++ /dev/null @@ -1,2 +0,0 @@ -# TODO set some FreeBSD bullshit i gotta deal with - diff --git a/premake5.lua b/premake5.lua deleted file mode 100644 index dc8ccc3..0000000 --- a/premake5.lua +++ /dev/null @@ -1,130 +0,0 @@ -if not os.isfile('config.h') then - print("Note: `config.h' not found, until a new Treebird release comes out,"); - print(" please copy `config.def.h' and edit it."); - os.exit(1); -end - -workspace "Treebird"; - -project("file-to-c"); -kind("ConsoleApp"); -language("C"); -files { "src/file-to-c/main.c" }; - -configurations { "Debug", "Release" }; - -local c_files = { - 'main.c', - 'types.c', - 'cookie.c', - 'easprintf.c', - 'error.c', - 'memory.c', - 'helpers.c', - 'key.c', - 'local_config.c', - 'local_config_set.c', - 'query.c', - 'string.c', - 'string_helpers.c', - 'request.c', - 'session.c', - 'path.c', - 'mime.c', -}; - --- Not actually real 'pages', but the ones we compile in / create definitions --- This setup is pretty jank, but it helped me transition the Async refactor -local pages = { - 'about.c', - 'account.c', - 'applications.c', - 'attachments.c', - 'base_page.c', - 'conversations.c', - 'emoji.c', - 'emoji_reaction.c', - 'global_cache.c', - 'global_perl.c', - 'hashtag.c', - 'http.c', - 'index.c', - 'lists.c', --- 'login.c', --- 'memory_page.c', - 'notifications.c', --- 'page_config.c', - 'scrobble.c', --- 'search.c', - 'status.c', - 'timeline.c', -}; - -local definitions = {}; - --- Create definitions for page enabling -for i=1, #pages do - local def = 'CMP_ENABLE_' .. string.upper(string.sub(pages[i], 0, -3)); - table.insert(definitions, def); -end - --- Prepend with 'src/' -for i=1, #c_files do c_files[i] = 'src/'.. c_files[i] end -for i=1, #pages do pages[i] = 'src/'.. pages[i] end - --- BEGIN Mastodont project -project("treebird"); -dependson("file-to-c"); -kind("ConsoleApp"); -language("C"); --- Merge pages into c_files -for _, v in ipairs(pages) do - table.insert(c_files, v); -end -files(c_files); -includedirs { "include/" }; -defines(definitions); - --- For some reason this one doesn't have a pkg-config file -local libfcgi = os.findlib("libfcgi"); -if not libfcgi then - print("Couldn't find libfcgi (aka fcgi-devkit). Probably gonna need that.\n"); - os.exit(1); -end - -rule "filec" - display "filec" - fileextension ".ctt" - buildmessage "Building %(filename)" - buildcommands 'filec -c "%(FullPath)" -o "%(IntDir)/%(Filename).obj"' - buildoutputs '%(IntDir)/%(Filename).obj' - -filter { "action:gmake*" }; - linkoptions{ "`pkg-config --libs mastodont` `perl -MExtUtils::Embed -e ldopts`" }; - buildoptions{ "`pkg-config --cflags mastodont` `perl -MExtUtils::Embed -e ccopts`" }; - links{"fcgi"}; - -filter { "toolset:clang" }; - buildoptions{"-Wno-compound-token-split-by-macro"}; - -filter { "configurations:Debug" }; - defines { "DEBUG" }; - symbols("On"); - -filter { "configurations:Release" }; - defines { "NDEBUG" }; - optimize("On"); --- END Mastodont-c - -local prefix = os.getenv("PREFIX") or "/usr/local"; - -newaction { - trigger = "install", - description = "install binary", - execute = function() - os.copyfile("treebird", prefix .. "/bin"); - os.mkdir(prefix .. "/share/treebird"); - os.execute("cp -r dist/ " .. prefix .. "/share/treebird/dist/"); - os.execute("cp -r perl/ " .. prefix .. "/share/treebird/perl/"); - end -}