#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
#export DH_OPTIONS=-v

# Avoid unneeded library dependencies
LDFLAGS = $(shell dpkg-buildflags --get LDFLAGS)
LDFLAGS += -Wl,--as-needed

# Target for stripping / not stripping
BUILD_TARGET = astyle
ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
    BUILD_TARGET = astyled
endif

# For hardening options
CFLAGS += $(CPPFLAGS)

%:
	dh $@

override_dh_auto_build:
	$(MAKE) -C build/gcc $(BUILD_TARGET)
	[ "$(BUILD_TARGET)" = "astyle" ] || mv bin/$(BUILD_TARGET) bin/astyle

override_dh_auto_clean:
	$(MAKE) -C build/gcc clean
	[ ! -d build/gcc/obj ] || rmdir build/gcc/obj
	[ ! -d bin ] || rmdir bin
