1#-------------------------------------------------------------------------
2#
3# Makefile for the fuzzer module
4#
5# src/backend/fuzzer/Makefile
6#
7#-------------------------------------------------------------------------
8subdir = src/backend/fuzzer
9top_builddir = ../../..
10include $(top_builddir)/src/Makefile.global
11
12subsysfilename = objfiles.txt
13
14SUBDIROBJS = $(SUBDIRS:%=%/$(subsysfilename))
15
16# make function to expand objfiles.txt contents
17expand_subsys = $(foreach file,$(1),$(if $(filter %/objfiles.txt,$(file)),$(patsubst ../../src/backend/%,%,$(addprefix $(top_builddir)/,$(shell cat $(file)))),$(file)))
18
19objfiles.txt: Makefile $(SUBDIROBJS) $(OBJS_FUZZERS)
20# Don't rebuild the list if only the OBJS have changed.
21	 $(if $(filter-out $(OBJS_FUZZERS),$?),( $(if $(SUBDIROBJS),cat $(SUBDIROBJS); )echo $(addprefix $(subdir)/,$(OBJS_FUZZERS)) ) >$@,touch $@)
22
23SUBDIRS = ../access ../bootstrap ../catalog ../parser ../commands ../executor ../foreign ../lib ../libpq \
24	../main ../nodes ../optimizer ../partitioning ../port ../postmaster \
25	../regex ../replication ../rewrite \
26	../statistics ../storage ../tcop ../tsearch ../utils $(top_builddir)/src/timezone \
27	../jit
28
29OBJS = \
30	$(LOCALOBJS) \
31	$(SUBDIROBJS) \
32	$(top_builddir)/src/common/libpgcommon_srv.a \
33	$(top_builddir)/src/port/libpgport_srv.a \
34
35OBJS_FUZZERS = $(filter-out ../main/objfiles.txt, $(OBJS))
36
37createdb: dbfuzz
38
39fuzzer: simple_query_fuzzer \
40	json_parser_fuzzer \
41	protocol_fuzzer
42
43simple_query_fuzzer json_parser_fuzzer: %: %.o fuzzer_initialize.o $(OBJS_FUZZERS)
44	$(CXX) $(CFLAGS) $(call expand_subsys,$^) -o $@ $(LIB_FUZZING_ENGINE)
45
46simple_query_fuzzer.o json_parser_fuzzer.o protocol_fuzzer.o fuzzer_initialize.o: %.o: %.c
47	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $^
48
49protocol_fuzzer: %: %.o $(OBJS_FUZZERS)
50	$(CXX) $(CFLAGS) $(call expand_subsys,$^) -o $@ $(LIB_FUZZING_ENGINE) -Wl,--wrap=exit -Wl,--wrap=pq_getbyte
51
52dbfuzz: dbfuzz.o | submake-libpgport temp-install
53	$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@ \
54	&& PATH="$(abs_top_builddir)/tmp_install$(bindir):$$PATH" LD_LIBRARY_PATH="$(abs_top_builddir)/tmp_install/usr/local/pgsql/lib" ./dbfuzz
55
56dbfuzz.o: dbfuzz.c $(top_builddir)/src/port/pg_config_paths.h
57dbfuzz.o: override CPPFLAGS := $(CPPFLAGS) -I$(top_builddir)/src/port -I$(top_builddir)/../src/test/regress '-DSHELLPROG="$(SHELL)"'
58
59$(top_builddir)/src/port/pg_config_paths.h: | submake-libpgport
60	$(MAKE) -C $(top_builddir)/src/port pg_config_paths.h
61