# SPDX-License-Identifier: LGPL-2.1-only
#
# Makefile - Makefile for the PLIN driver utilities.
#
# Copyright (C) 2001-2025 PEAK System-Technik GmbH <www.peak-system.com>
#
# Contact:  <linux.peak@hms-networks.com>
# Author:   Stephane Grosjean <stephane.grosjean@hms-networks.com>
#
ALL = lin linwrite linread

# override default CC = cc
CC = $(CROSS_COMPILE)gcc

# PLINDRV_DIR should normally NOT be defined. 
# But as utilities are built BEFORE the installation of the package, they
# must use the local version of plin.h. Since plin.h is then installed under
# /usr/include, then a 'normal' user application doesn't need to define a new
# include directory in CFLAGS to get access to plin.h.
PLINDRV_DIR := ../driver

ifneq ($(PLINDRV_DIR),)
CFLAGS += -I$(PLINDRV_DIR)
endif

ifeq ($(BITS),32)
CFLAGS += -m32
LDFLAGS += -m32
endif

all: banner $(ALL)

linwrite: linwrite.o
	$(CC) $^ $(LDFLAGS) -o $@

linread: linread.o
	$(CC) $^ $(LDFLAGS) -o $@

lin: lin.o
	$(CC) $^ $(LDFLAGS) -o $@

%.o: %.c
	$(CC) $< -c $(CFLAGS) -o $@

banner:
	@echo
	@echo Building plin utilities:
	@echo

clean: clean_tmp
	-rm -f $(ALL)

clean_tmp:
	-rm -f *.o

install:
	@echo
	@echo Installing plin utilities under $(DESTDIR)/usr/bin...
	@echo
	cp -f $(ALL) $(DESTDIR)/usr/bin

uninstall:
	@echo
	@echo Removing plin utilities from $(DESTDIR)/usr/bin
	@echo
	-cd $(DESTDIR)/usr/bin; rm -f $(ALL)

all32:
	$(MAKE) BITS=32
