blob: 17558cb447701de5739eca4f2afe9a366b10662d [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
include $(top_builddir)/src/
override CFLAGS+= -w $(PTHREAD_CFLAGS)
override CPPFLAGS+= -I$(top_srcdir)/src/backend/libpq \
-I$(top_srcdir)/src/backend/gp_libpq_fe \
-I$(top_srcdir)/src/backend/postmaster \
-I. -I$(top_builddir)/src/port -I$(CMOCKERY_DIR) \
-I$(top_srcdir)/src/include/resourcemanager \
# TODO: add ldl for quick hack; we need to figure out why
# postgres in src/backend/Makefile doesn't need this and -pthread.
THRIFTLIB = -lthrift
#GLIBLIB = -lgobject-2.0 -lglib-2.0
MOCK_LIBS := -ldl -lpthread -lesmtp $(filter-out -lpgport -lesmtp -ledit, $(LIBS))
# We are unable to mock them up at the moment. Real objects should contain them.
EXCL_OBJS=src/backend/bootstrap/bootparse.o \
src/backend/catalog/caql/gram.o \
src/backend/parser/gram.o \
src/backend/regex/regcomp.o \
src/backend/regex/regexec.o \
src/backend/utils/adt/like.o \
src/backend/utils/misc/guc.o \
src/backend/access/parquet/metadatautil_c++/Metadatainterface.o \
src/backend/access/parquet/metadatautil_c++/MetadataUtil.o \
src/backend/access/parquet/metadatautil_c++/parquet_constants.o \
src/backend/access/parquet/metadatautil_c++/parquet_types.o \
src/backend/access/parquet/metadatautil_c++/thrift-util.o \
src/timezone/%.o \
src/backend/main/%.o \
src/backend/gpopt/%.o \
src/backend/gpopt/config/%.o \
src/backend/gpopt/relcache/%.o \
src/backend/gpopt/translate/%.o \
ALL_OBJS=$(addprefix $(top_srcdir)/, \
$(filter-out $(EXCL_OBJS), \
$(shell test -f $(OBJFILES) && cat $(OBJFILES))))
# A function that generates TARGET_OBJS = test case, mock objects, real objects,
# and cmockery.o. $(OBJFILES) contains %/objfiles.txt, because
# src/backend/Makefile will create it with rule=objfiles.txt, which is not
# expected in postgres rule. It actually uses expand_subsys to obtain the .o
# file list. But here we don't include so just clear out
# objfiles.txt from the list for $(TARGET_OBJS)
TARGET_OBJS=$(shell echo $(1)_test.o $(CMOCKERY_OBJS) $($(1)_REAL_OBJS) \
$(patsubst $(top_srcdir)/src/%.o,$(MOCK_DIR)/%_mock.o,\
$(filter-out $(SUT_OBJ) $($(1)_REAL_OBJS) %/objfiles.txt, \
# In order to avoid symlink issue, we should explicitly specify
# absolute path for both --out-dir and --src-dir.
$(MOCK_DIR)/%_mock.c: $(abs_top_srcdir)/src/%.c
@echo mocking $<
@(cd $(MOCK_DIR) && PYTHONPATH=$(python_libdir) $(PYTHON) \
--out-dir=$(abs_top_srcdir)/src/test/unit/mock \
--src-dir=$(abs_top_srcdir)/src $<)
# For some reason, mock.o files are intermediate files sometimes.
# Mark them as secondary in order not to be deleted automatically.
$(MOCK_DIR)/%_mock.o: $(MOCK_DIR)/%_mock.c
all: $(patsubst %,%.t,$(TARGETS))
# The test target depends on $(OBJFILES) which would update files including mocks.
%.t: $(OBJFILES) $(CMOCKERY_OBJS) %_test.o mockup-phony
$(CC) $(CFLAGS) $(LDFLAGS) $(call TARGET_OBJS,$*) $(MOCK_LIBS) -o $@
# We'd like to call only src/backend, but it seems we should build src/port and
# src/timezone before src/backend. This is not the case when main build has finished,
# but this makes sure a simple make works fine in this directory any time.
# With PARTIAL_LINKING it will generate objfiles.txt
$(MAKE) -C $(top_srcdir)/src
$(MAKE) PARTIAL_LINKING= -C $(top_srcdir)/src/backend objfiles.txt
# Need to separate make, as it's using the output of another make.
mockup-phony: $(OBJFILES)
$(MAKE) mockup
mockup: $(patsubst $(top_srcdir)/src/%.o,$(MOCK_DIR)/%_mock.o,$(ALL_OBJS))
check: $(patsubst %,%-check,$(TARGETS))
%-check: %.t
clean: $(patsubst %,%-clean,$(TARGETS))
rm -f $*.t $*_test.o
clean-mock: $(patsubst %,%-clean-mock,$(TARGETS))
rm -rf $(MOCK_DIR)/backend