aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 5b63d46dd1c29cfac0d16abb951b4699a48a9d44 (plain) (blame)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
.POSIX:

CONFIGFILE = config.mk
include $(CONFIGFILE)

OS = linux
# Linux:   linux
# Mac OS:  macos
# Windows: windows
include mk/$(OS).mk


LIB_MAJOR = 1
LIB_MINOR = 0
LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
LIB_NAME = exec


OBJ =\
	libexec_add_pluming.o\
	libexec_add_output_document.o\
	libexec_add_output_fd.o\
	libexec_clear_environ.o\
	libexec_close.o\
	libexec_construct_command.o\
	libexec_copy_environ.o\
	libexec_destroy_command.o\
	libexec_destroy_document.o\
	libexec_destroy_pluming.o\
	libexec_destroy_result.o\
	libexec_dup.o\
	libexec_exec.o\
	libexec_get_documents.o\
	libexec_getenv.o\
	libexec_getenv_last.o\
	libexec_input_data_copy.o\
	libexec_input_data_gift.o\
	libexec_input_text_copy.o\
	libexec_input_text_gift.o\
	libexec_open.o\
	libexec_openat.o\
	libexec_openat2.o\
	libexec_pipe_commands.o\
	libexec_pipe_commandsv.o\
	libexec_pipe_commandsvn.o\
	libexec_put_arguments.o\
	libexec_put_argumentsn.o\
	libexec_putenv.o\
	libexec_putenv_append.o\
	libexec_putenv_noclobber.o\
	libexec_putenv_noreplace.o\
	libexec_putenv_prepend.o\
	libexec_putenv_replace.o\
	libexec_putenvf.o\
	libexec_putenvf_append.o\
	libexec_putenvf_noclobber.o\
	libexec_putenvf_noreplace.o\
	libexec_putenvf_prepend.o\
	libexec_putenvf_replace.o\
	libexec_recv_document.o\
	libexec_renumber_fd.o\
	libexec_run.o\
	libexec_run_pipeline.o\
	libexec_send_document.o\
	libexec_set_environ.o\
	libexec_set_exec_fd.o\
	libexec_set_exec_path.o\
	libexec_set_executable.o\
	libexec_set_require_path.o\
	libexec_setenv.o\
	libexec_setenv_append.o\
	libexec_setenv_noclobber.o\
	libexec_setenv_noreplace.o\
	libexec_setenv_prepend.o\
	libexec_setenv_replace.o\
	libexec_setenvf.o\
	libexec_setenvf_append.o\
	libexec_setenvf_noclobber.o\
	libexec_setenvf_noreplace.o\
	libexec_setenvf_prepend.o\
	libexec_setenvf_replace.o\
	libexec_spawn.o\
	libexec_unsetenv.o\
	libexec_unsetenv_first.o\
	libexec_unsetenv_last.o\
	libexec_vconstruct_command.o\
	libexec_vpipe_commands.o\
	libexec_vputenvf.o\
	libexec_vputenvf_append.o\
	libexec_vputenvf_noclobber.o\
	libexec_vputenvf_noreplace.o\
	libexec_vputenvf_prepend.o\
	libexec_vputenvf_replace.o\
	libexec_vrun.o\
	libexec_vsetenvf.o\
	libexec_vsetenvf_append.o\
	libexec_vsetenvf_noclobber.o\
	libexec_vsetenvf_noreplace.o\
	libexec_vsetenvf_prepend.o\
	libexec_vsetenvf_replace.o

HDR =\
	libexec.h\
	common.h

LOBJ = $(OBJ:.o=.lo)
TOBJ = $(OBJ:.o=.to) LIBEXEC_COMMAND_INIT.to
TEST = $(TOBJ:.to=.test)


all: libexec.a libexec.$(LIBEXT) $(TEST)
$(OBJ): $(HDR)
$(LOBJ): $(HDR)
$(TOBJ): $(HDR)
$(TEST): testhelp.o libexec.a

.c.o:
	$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)

.c.lo:
	$(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS)

.c.to:
	$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -DTEST

.to.test:
	$(CC) -o $@ $< testhelp.o libexec.a $(LDFLAGS)

libexec.a: $(OBJ)
	@rm -f -- $@
	$(AR) rc $@ $(OBJ)
	$(AR) ts $@ > /dev/null

libexec.$(LIBEXT): $(LOBJ)
	$(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS)

check: $(TEST)
	@status=0;\
	for t in $(TEST); do\
		if test -z "$(CHECK_PREFIX)"; then\
			printf './%s\n' "$$t";\
		else\
			printf '%s ./%s\n' "$(CHECK_PREFIX)" "$$t";\
		fi;\
		if ! $(CHECK_PREFIX) "./$$t"; then\
			printf '\033[1;31m%s failed!\033[m\n' "$$t";\
			status=1;\
		fi;\
	done;\
	exit $$status

install: libexec.a libexec.$(LIBEXT)
	mkdir -p -- "$(DESTDIR)$(PREFIX)/lib"
	mkdir -p -- "$(DESTDIR)$(PREFIX)/include"
	cp -- libexec.a "$(DESTDIR)$(PREFIX)/lib/"
	cp -- libexec.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libexec.$(LIBMINOREXT)"
	$(FIX_INSTALL_NAME) "$(DESTDIR)$(PREFIX)/lib/libexec.$(LIBMINOREXT)"
	ln -sf -- libexec.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libexec.$(LIBMAJOREXT)"
	ln -sf -- libexec.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libexec.$(LIBEXT)"
	cp -- libexec.h "$(DESTDIR)$(PREFIX)/include/"

uninstall:
	-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libexec.a"
	-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libexec.$(LIBMAJOREXT)"
	-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libexec.$(LIBMINOREXT)"
	-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libexec.$(LIBEXT)"
	-rm -f -- "$(DESTDIR)$(PREFIX)/include/libexec.h"

clean:
	-rm -f -- *.o *.a *.lo *.to *.su *.so *.so.* *.dll *.dylib
	-rm -f -- *.gch *.gcov *.gcno *.gcda *.test *.$(LIBEXT)

.SUFFIXES:
.SUFFIXES: .lo .o .c .to .test

.PHONY: all check install uninstall clean