forked from zain1337/vely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmakefile
executable file
·128 lines (90 loc) · 5.25 KB
/
vmakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#SPDX-License-Identifier: EPL-2.0
#Copyright 2019 DaSoftver LLC. Written by Sergio Mijatovic.
#Licensed under Eclipse Public License - v 2.0. See LICENSE file.
#On the web https://vely.dev/ - this file is part of Vely framework.
#variable names for Vely start with VV_ (VV_C_ being compiling-related) and _ (internal)
#
# Vely make file
#
#
# Setting of build variables
#
SHELL:=/bin/bash
export VV_EXPLAIN
_SYSTEMID=$(shell $$VV_LIBRARY_PATH/sys showid)
# c/linker flags
_CC=gcc
#ASAN (internal)
ifeq ($(strip $(VV_C_ASAN)),1)
_ASAN=-fsanitize=address -fsanitize-recover=address
else
_ASAN=
endif
ifeq ($(strip $(VV_C_DEBUG)),1)
_OPTIM_COMP=-g3 -DDEBUG -rdynamic
_OPTIM_LINK=-rdynamic
else
_OPTIM_COMP=-O3
_OPTIM_LINK=
endif
_APPMAKE=-DVV_APPMAKE=1
VV_FCGI_TARGET=$(VV_BLD)/$(VV_C_NAME).fcgi
VV_TARGET=$(VV_BLD)/$(VV_C_NAME)
ifeq ($(strip $(_SYSTEMID)),opensuse)
VV_FCGI_INCLUDE=-I /usr/include/fastcgi
else
VV_FCGI_INCLUDE=
endif
#If c-lines is used, then show all diagnostics
VV_DIAG_OUT=
ifeq ($(strip $(VV_C_SKIPLINES)),1)
VV_X_FLAG=-x
else
VV_X_FLAG=
endif
ifeq ($(strip $(VV_C_POSIXREGEX)),1)
VV_POSIXREGEX_FLAG=-DVV_C_POSIXREGEX
else
VV_POSIXREGEX_FLAG=
endif
#even though VV_DIAG_OUT is set to "", at run time it will have value from make_source macro. This is because of how makefile assignments work with = (and not :=)
_CFLAGS=-fpic -fmax-errors=$(VV_C_MAXERRORS) $(VV_DIAG_OUT) -Werror -Wall -Wuninitialized -Wmissing-declarations -Wformat -Wno-format-zero-length -fsigned-char $(VV_MARIADB_USED) $(VV_CURL_USED) $(VV_TREE_USED) $(VV_PCRE2_USED) $(VV_FCGI_USED) $(VV_CRYPTO_USED) $(VV_MODULES_INCLUDE) $(VV_FCGI_INCLUDE) -DVV_OSNAME_ID=$(VV_OSNAME_ID) $(VV_POSIXREGEX_FLAG) -I $(shell pwd) -I $(VV_INCLUDE_PATH) $(VV_C_CFLAGS) -I $(VV_BLD) $(_APPMAKE) $(_OPTIM_COMP) $(_ASAN)
#
# Rules for building
#
all: $(VV_FCGI_TARGET) $(VV_TARGET)
#clean files. *.velyo is produced by VELY, the result is generated/object files
clean:
if [ -d "$(VV_BLD)" ]; then find $(VV_BLD)/ -name "*" -type f \( -name "*.o" -or -name "*.c" -or -name "*.h" \) -exec rm -f {} \; ; fi
#include $(VV_BLD)/source.vely
#obtain VV_SOURCE_FILES and VV_HEADER_FILES from generated source.vely
ifneq (clean,$(filter clean,$(MAKECMDGOALS)))
include $(VV_BLD)/source.vely
endif
VV_HEADER_FILES:=$(VV_HEADER_FILES)
#string subst: short for $(patsubst %.vely,%.o,$(VV_SOURCE_FILES)) which finds whitespace-separated word in $(VV_SOURCE_FILES) that match %.vely and replaces them with %.o
_OBJ_FILES=$(VV_SOURCE_FILES:%.vely=$(VV_BLD)/%.o)
#when making source, start with compiling; then if error, check if plain diagnostic; if not, recompile with error processed by vdiag script to produce highlights (in which
#case we don't use caret, we produce one ourselves instead of gcc)
define make_source
$(VV_LIBRARY_PATH)/v1 $(VV_X_FLAG) -plain-diag "1" -name "$(VV_C_NAME)" $< -out $(VV_BLD)/__$(shell basename $@).c
VV_DIAG_OUT="" ; $(_CC) -c $(VV_BLD)/__$(shell basename $@).c $(_CFLAGS) -o $@ -I`pwd` 2>$(VV_BLD)/.comperr ; if [ "$$?" != "0" ]; then if [ "$$VV_C_PLAINDIAG" == "1" ]; then cat $(VV_BLD)/.comperr; exit -1; else VV_DIAG_OUT="-fno-diagnostics-show-caret"; $(VV_LIBRARY_PATH)/v1 $(VV_X_FLAG) -plain-diag "$(VV_C_PLAINDIAG)" -name "$(VV_C_NAME)" $< -out $(VV_BLD)/__$(shell basename $@).c; $(_CC) -c $(VV_BLD)/__$(shell basename $@).c $(_CFLAGS) -o $@ -I`pwd` 2>$(VV_BLD)/.comperr; cat $(VV_BLD)/.comperr | $(VV_LIBRARY_PATH)/vdiag "$(VV_C_NAME)" $(VV_C_PLAINDIAG) ; fi ; fi
endef
#the rest if compilation of source files and producing object files and libraries needed for apache,
#do not change these
$(VV_BLD)/vely_dispatch_request.o: $(VV_BLD)/vely_dispatch_request.vely $(VV_INCLUDE_PATH)/vely.h $(VV_HEADER_FILES) $(VV_BLD)/velyapp.h $(VV_BLD)/blds
$(call make_source)
$(VV_BLD)/%.o: %.vely $(VV_INCLUDE_PATH)/vely.h $(VV_HEADER_FILES) $(VV_BLD)/velyapp.h $(VV_BLD)/blds
$(call make_source)
#does not need to depend on velyfcgiapp.c because it makes it. There's a dependency on params (blds) and list of files to be made (.reqlist)
#because now we have hash list there that accounts for all request name. If we didn't have this, adding new .vely file would not be picked up until
#the next next time something changes on the vv command line!
$(VV_BLD)/velyfcgiapp.o: $(VV_BLD)/blds $(VV_BLD)/.reqlist
$(VV_LIBRARY_PATH)/v1 $(VV_X_FLAG) -plain-diag "$(VV_C_PLAINDIAG)" -main -name "$(VV_C_NAME)" -max-upload "$(VV_C_MAXUPLOAD)" -app-path "$(VV_C_RESTPATH)" -trace "$(VV_C_TRACE)" -out $(VV_BLD)/velyfcgiapp.c
$(_CC) -c $(VV_BLD)/velyfcgiapp.c $(_CFLAGS) -DCMOD -o $@ -I`pwd`
_LDFLAGS=-Wl,--no-undefined -Wl,--rpath=$(VV_LIBRARY_PATH) $(VV_C_LFLAGS) -L$(VV_LIBRARY_PATH) $(_OPTIM_LINK) $(_ASAN)
#libs are always specified *after* the object where they're needed. Link flags (including -L) go first.
$(VV_BLD)/$(VV_C_NAME).fcgi: $(VV_BLD)/velyfcgiapp.o $(VV_BLD)/vely_dispatch_request.o $(_OBJ_FILES) $(VV_BLD)/vely_dispatch_request.o
$(_CC) -o $@ $^ $(_LDFLAGS) $(VV_EVENT_STUBS) -lfcgively -lfcgi $(VV_MOD_LIBS) $(VV_MODULES) $(VV_STUBS)
$(VV_BLD)/$(VV_C_NAME): $(VV_BLD)/velyfcgiapp.o $(VV_BLD)/vely_dispatch_request.o $(_OBJ_FILES) $(VV_BLD)/vely_dispatch_request.o
$(_CC) -o $@ $^ $(_LDFLAGS) $(VV_EVENT_STUBS) -lvely $(VV_MOD_LIBS) $(VV_MODULES) $(VV_STUBS)