Load perl

FossilOrigin-Name: 0107dd3706329714f684f913c2ae67d072851eca96b981c11f5315e1ef780c22
This commit is contained in:
nekobit 2022-07-22 03:56:41 +00:00
parent 09a667a6cd
commit 10875ff940
6 changed files with 71 additions and 5 deletions

View File

@ -9,4 +9,5 @@ mastodont-c
config.h
treebird
test/tests
scripts/*.o
scripts/*.o
perl/*.cpl

View File

@ -2,26 +2,31 @@ CC ?= cc
GIT ?= git
MASTODONT_DIR = mastodont-c/
MASTODONT = $(MASTODONT_DIR)libmastodont.a
CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-ignored-qualifiers -I/usr/include/ -I $(MASTODONT_DIR)/libs $(shell pkg-config --cflags libcurl libpcre2-8)
LDFLAGS = -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcurl libpcre2-8) -lfcgi -lpthread
CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-ignored-qualifiers -I/usr/include/ -I $(MASTODONT_DIR)/libs $(shell pkg-config --cflags libcurl libpcre2-8) `perl -MExtUtils::Embed -e ccopts`
LDFLAGS = -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcurl libpcre2-8) -lfcgi -lpthread `perl -MExtUtils::Embed -e ldopts`
SRC = $(wildcard src/*.c)
OBJ = $(patsubst %.c,%.o,$(SRC))
HEADERS = $(wildcard src/*.h) config.h
PAGES_DIR = static
PERL_DIR = perl
PAGES = $(wildcard $(PAGES_DIR)/*.tmpl)
PERLS = $(wildcard $(PERL_DIR)/*.pl)
PAGES_CMP = $(patsubst %.tmpl,%.ctmpl,$(PAGES))
PAGES_C = $(patsubst %.tmpl, %.c,$(PAGES))
PAGES_C_OBJ = $(patsubst %.c,%.o,$(PAGES_C))
PERLS_C = $(patsubst %.pl,%.cpl,$(PERLS))
DIST = dist/
PREFIX ?= /usr/local
TARGET = treebird
$(info $(PERLS) and $(PERLS_C))
MASTODONT_URL = https://fossil.nekobit.net/mastodont-c
all: $(MASTODONT_DIR) dep_build $(TARGET)
apache: all apache_start
$(TARGET): filec template $(PAGES_CMP) $(PAGES_C) $(PAGES_C_OBJ) $(OBJ) $(HEADERS)
$(TARGET): filec template $(PERLS_C) $(PAGES_CMP) $(PAGES_C) $(PAGES_C_OBJ) $(OBJ) $(HEADERS)
$(CC) -o $(TARGET) $(OBJ) $(PAGES_C_OBJ) $(LDFLAGS)
template: src/template/main.o
@ -39,6 +44,9 @@ emojitoc: scripts/emoji-to.o
$(PAGES_DIR)/%.ctmpl: $(PAGES_DIR)/%.tmpl
./template $< $(notdir $*) 2> $(PAGES_DIR)/$(notdir $*).c 1> $@
$(PERL_DIR)/%.cpl: $(PERL_DIR)/%.pl
./filec $< data_$(notdir $*)_pl > $@
$(MASTODONT_DIR):
cd ..; fossil clone $(MASTODONT_URL) || true
cd treebird; ln -s ../mastodont-c .

View File

@ -9,8 +9,10 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <mastodont.h>
#if !(defined(FALSE) && defined(TRUE))
#define FALSE 0
#define TRUE 1
#endif
#define UNSET NULL
/*

9
perl/main.pl Normal file
View File

@ -0,0 +1,9 @@
use strict;
use warnings;
sub square
{
2 * 2;
}
print "Hello treebird" . square;

26
src/global_perl.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GLOBAL_PERL_H
#define GLOBAL_PERL_H
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter* perl;
#endif /* GLOBAL_PERL_H */

View File

@ -16,8 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <EXTERN.h>
#include <perl.h>
#include <pthread.h>
#include <fcgi_stdio.h>
#include "global_perl.h"
#include <fcgiapp.h>
#include <string.h>
#include <mastodont.h>
@ -44,6 +47,7 @@
#include "local_config_set.h"
#include "global_cache.h"
#include "conversations.h"
#include "../perl/main.cpl"
#define THREAD_COUNT 20
@ -190,12 +194,23 @@ static void* cgi_start(void* arg)
return NULL;
}
int main(void)
int main(int argc, char **argv, char **env)
{
// Global init
mastodont_global_curl_init();
FCGX_Init();
// Initialize Perl
PERL_SYS_INIT3(&argc, &argv, &env);
perl = perl_alloc();
perl_construct(perl);
//char* perl_argv[] = { "", "-e", data_main_pl, NULL };
char* perl_argv[] = { "", "perl/main.pl", NULL };
perl_parse(perl, NULL, (sizeof(perl_argv) / sizeof(perl_argv[0])) - 1, perl_argv, (char**)NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_run(perl);
// Initiate mastodont library
mastodont_t api;
mastodont_init(&api);
@ -215,4 +230,9 @@ int main(void)
free_instance_info_cache();
mastodont_cleanup(&api);
mastodont_global_curl_cleanup();
perl_destruct(perl);
perl_free(perl);
PERL_SYS_TERM();
return EXIT_SUCCESS;
}