target			:= native

CFLAGS			:= $(filter-out -DCONFIG_X86_64,$(CFLAGS))
CFLAGS			+= -Wa,--noexecstack -fno-stack-protector -DCR_NOGLIBC

CFLAGS_native		+= -fpie

ifeq ($(ARCH),x86)
        target		+= compat
        CFLAGS_native	+= -DCONFIG_X86_64
        CFLAGS_compat	+= -fno-pic -m32 -DCONFIG_X86_32
endif

OBJS			+= log-simple.o util-fd.o util.o string.o

ifeq ($(VDSO),y)
        OBJS		+= util-vdso.o parasite-vdso.o ./$(ARCH_DIR)/vdso-pie.o

        ifeq ($(SRCARCH),aarch64)
                OBJS	+= ./$(ARCH_DIR)/intraprocedure.o
        endif

        ifeq ($(SRCARCH),ppc64)
                OBJS	+= ./$(ARCH_DIR)/vdso-trampoline.o
        endif
endif

ifeq ($(SRCARCH),ppc64)
        OBJS		+= ./$(ARCH_DIR)/memcpy_power7.o		\
			   ./$(ARCH_DIR)/memcmp_64.o ./$(ARCH_DIR)/misc.o
endif

ifeq ($(SRCARCH),x86)
        lib-y		+= ./$(ARCH_DIR)/memcpy.o
endif

define gen-native-objs
native-lib-y		+= $(1)
CFLAGS_$(1)		:= $(CFLAGS_native)
endef

compat-obj		= $(basename $(notdir $(1)))-compat.o
define gen-compat-objs
compat-lib-y		+= $(dir ./$(call objectify,$(1)))compat/$(compat-obj)
CFLAGS_$(compat-obj)	:= $(CFLAGS_compat)
endef

$(eval $(call map,gen-native-objs,$(OBJS)))
$(eval $(call map,gen-compat-objs,$(OBJS)))

#
# We can't provide proper mount implementation
# in parasite code -- it requires run-time rellocation
# applications, which is not the target of the
# project.
#
iquotes			:= -iquote $(SRC_DIR)/$(PIE_DIR)/piegen
iquotes			+= -iquote $(SRC_DIR)/$(ARCH_DIR)/include
iquotes			+= -iquote $(SRC_DIR) -iquote $(SRC_DIR)/criu/include -iquote $(SRC_DIR)/include
CFLAGS			:= $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS)) $(iquotes)
asflags-y		:= -D__ASSEMBLY__ $(iquotes)

ifeq ($(SRCARCH),arm)
	ccflags-y	+= -marm
endif

ifneq ($(filter-out ia32,$(ARCH)),)
        ccflags-y	+= -DCR_NOGLIBC -fpie -Wa,--noexecstack -fno-stack-protector
else
        ccflags-y	+= -DCR_NOGLIBC -fno-pic -Wa,--noexecstack -fno-stack-protector
endif

ccflags-y		+= -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
ccflags-y		+= -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0
