-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
110 lines (94 loc) · 3 KB
/
Makefile
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
################################################################################
# MAKEFILE for MSEM library and PHP extension
#
# NOTE
# This software can be built into two different targets.
#
# 0. A user-space executable 'msem' which can be used to
# manage and monitor the use of the synchronization
# files on the system.
#
# 1. A shared library 'msem.so' containing PHP bindings
# to enable it to be manipulated from a PHP execution
# environment.
#
################################################################################
CC=gcc
LD_JDL=./deps
#
# position-independent include
# code libJDL
# \ optimize warnings |
# \ lvl 3 \ | |
C_FLAGS=-fPIC -O3 -Wall -I$(LD_JDL)
C_LDFLAGS=-lm -lncurses -lpanel
# \
# math.h
#
#
# position-independent
# code |
# |
PHP_FLAGS=-fPIC -I$(LD_JDL)
PHP_LDFLAGS=$(shell php-config --includes) -lncurses -lpanel
# ````````````/``````````````
# Get PHP system includes
#
#
################################################################################
# MAIN CONFIGURATION
################################################################################
NAME=msem
SOFILE=$(NAME).so
INIFILE=$(NAME).ini
EXECUTABLE=$(NAME)
SWIGFILE=$(NAME).i
BIN_INSTALL=/usr/local/bin
MAN_PAGE=msem.1
MAN_PATH=/usr/share/man
#PREFIX obtained from environment
#
# Used to build the C file
#
C_STATIC_LIBS=$(LD_JDL)/jlib.a
C_SOURCES=main.c msem.c
C_OBJECTS=$(C_SOURCES:.c=.o)
#
# Generated by SWIG (wraps the C file)
#
SWIG_PHP_SOURCES=$(NAME)_wrap.c
SWIG_PHP_HEADERS=php_$(NAME).h
SWIG_PHP_INCLUDE=$(NAME).php
SWIG_PHP_OBJECTS=$(SWIG_PHP_SOURCES:.c=.o)
SWIG_PHP_GENERATED=$(SWIG_PHP_SOURCES) $(SWIG_PHP_HEADERS) $(SWIG_PHP_INCLUDE) $(SWIG_PHP_OBJECTS)
#
# Used to create the final shared library.
#
ALL_OBJECTS=$(C_OBJECTS) $(C_STATIC_LIBS) $(SWIG_PHP_OBJECTS)
# Build the C file as usual.
all: $(C_SOURCES)
$(CC) $(C_FLAGS) $(C_SOURCES) $(C_STATIC_LIBS) -o $(EXECUTABLE) $(C_LDFLAGS)
install:
install -D $(MAN_PAGE) $(PREFIX)$(MAN_PATH)/man1/$(MAN_PAGE)
install -D $(EXECUTABLE) $(PREFIX)$(BIN_INSTALL)/$(EXECUTABLE)
#
# Build the PHP module (.so)
#
# This requires the static libraries but NOT the
# C sources, which have to be compiled into object
# code and then linked into a shared object.
#
php: $(C_STATIC_LIBS)
swig -php $(SWIGFILE)
$(CC) $(C_FLAGS) -c $(C_SOURCES) $(C_STATIC_LIBS) $(C_LDFLAGS)
$(CC) $(PHP_FLAGS) -c $(SWIG_PHP_SOURCES) $(C_STATIC_LIBS) $(PHP_LDFLAGS)
$(CC) -shared $(ALL_OBJECTS) -o $(SOFILE) $(PHP_LDFLAGS)
# Install the module (.so) with the other extensions.
php-install:
install -D $(SOFILE) $(PREFIX)$(shell php-config --extension-dir)/$(SOFILE)
install -D $(INIFILE) $(PREFIX)$(shell php-config --configure-options | tr '[ ]' '[\n]' | grep -e '--with-config-file-scan-dir' | cut -d'=' -f2)/$(INIFILE)
# Generate the SWIG wrappers alone
swig:
swig -php $(SWIGFILE)
clean:
rm -f $(SWIG_PHP_GENERATED) $(C_OBJECTS) $(SOFILE) $(EXECUTABLE) gmon.out