.gitignore

ifdef TARGET
TARGET = @(TARGET)
else
TARGET = @(TUP_PLATFORM)
endif

ifdef CC
CC = @(CC)
else
ifeq ($(TARGET),win32)
CC = x86_64-w64-mingw32-gcc
CC32 = i686-w64-mingw32-gcc
else
CC = gcc
endif
endif

ifeq (@(TUP_DEBUG),y)
CFLAGS += -Og
else
CFLAGS += -Os
endif
CFLAGS += -g

ifeq (@(TUP_SANITIZE),y)
CFLAGS += -fsanitize=address
LDFLAGS += -lasan

CFLAGS += -fsanitize=undefined
LDFLAGS += -lubsan
endif

ifdef AR
AR = @(AR)
else
ifeq ($(TARGET),win32)
AR = x86_64-w64-mingw32-ar
else
AR = ar
endif
endif

# Override AR settings if being built with busybox kconfig
ifeq ($(AR),y)
AR = ar
endif
ifeq ($(AR),n)
AR = ar
endif

CFLAGS += -W
CFLAGS += -Wall
ifeq (@(TUP_WERROR),y)
CFLAGS += -Werror
endif
CFLAGS += -Wbad-function-cast
CFLAGS += -Wcast-align
CFLAGS += -Wcast-qual
CFLAGS += -Wchar-subscripts
CFLAGS += -Wmissing-prototypes
CFLAGS += -Wnested-externs
CFLAGS += -Wpointer-arith
CFLAGS += -Wredundant-decls
CFLAGS += -Wshadow
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wwrite-strings
CFLAGS += -Wswitch-enum
CFLAGS += -D_FILE_OFFSET_BITS=64
CFLAGS += -fno-common
CFLAGS += -I$(TUP_VARIANTDIR)/src
CFLAGS += -I$(TUP_CWD)/src

ifeq (@(TUP_32_BIT),y)
CFLAGS += -m32
LDFLAGS += -m32
endif

ifeq (@(TUP_PROFILING),y)
CFLAGS += -pg
LDFLAGS += -pg
endif

!cc = |> ^ CC %f^ $(CC) -c %f -o %o $(CFLAGS) $(CFLAGS_%f) |> %B.o
!ld = |> ^ LINK %o^ $(CC) %f -o %o $(LDFLAGS) $(LDFLAGS_%o) |>
!ar = |> ^ AR %o^ $(AR) crs %o %f |>
!dot = |> ^ DOT %f^ dot -Efontname="Vernada, serif" -Nfontname="Vernada, serif" -Efontsize=10 -Nfontsize=10 -Tpng %f > %o |>
!cp = |> ^ CP %f -> %o^ cp %f %o |>

TUP_MONITOR = null
TUP_SUID_GROUP = root
TUP_USE_SYSTEM_PCRE = y
include $(TARGET).tup

ifdef TUP_USE_SYSTEM_PCRE
use_system_pcre = @(TUP_USE_SYSTEM_PCRE)
else
use_system_pcre = $(TUP_USE_SYSTEM_PCRE)
endif
ifeq ($(use_system_pcre),y)
CFLAGS += `pcre2-config --cflags`
else
CFLAGS += -I$(TUP_CWD)/src/pcre
CFLAGS += -DPCRE_STATIC
endif

ifneq (@(TUP_USE_SYSTEM_INIH),y)
CFLAGS += -I$(TUP_CWD)/src/inih
endif

ifeq ($(TUP_SERVER),ldpreload)
FPIC = -fpic
SHARED = -shared

LDFLAGS_tup-ldpreload.so += $(FPIC)
LDFLAGS_tup-ldpreload.so += $(SHARED)
LDFLAGS_tup-ldpreload.so += -ldl
LDFLAGS_tup-ldpreload.so += -pthread
endif
