1# Copyright (c) 2019 Georg Brein. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are met:
5#
6# 1. Redistributions of source code must retain the above copyright notice,
7#    this list of conditions and the following disclaimer.
8#
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice ,this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# 3. Neither the name of the copyright holder nor the names of its
14#    contributors may be used to endorse or promote products derived from
15#    this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28
29
30SYSTEM=$(shell uname -s)
31CFLAGS=-std=c99 -pedantic -O3 -Wall
32ifeq ($(SYSTEM),Linux)
33CFLAGS+=-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE_EXTENDED
34CFLAGS+=-I /usr/include/ncursesw
35LIBS=-lncursesw
36else ifeq ($(SYSTEM),Darwin)
37CFLAGS+=-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE_EXTENDED
38LIBS=-lcurses
39else ifeq ($(SYSTEM),DragonFly)
40CFLAGS+=-D_XOPEN_SOURCE_EXTENDED
41LIBS=-lncursesw
42else ifeq ($(SYSTEM),NetBSD)
43LIBS=-lcurses
44else ifeq ($(SYSTEM),OpenBSD)
45CFLAGS+=-D_XOPEN_SOURCE_EXTENDED
46LIBS=-lcurses
47else ifeq ($(SYSTEM),SunOS)
48OLDSOLARIS=$(shell uname -r | awk -F. '{if ($$2<10) print "-DOLD_SOLARIS";}')
49NCURSESROOT=/opt/csw
50CFLAGS+=-D_XOPEN_SOURCE_EXTENDED -D__EXTENSIONS__ $(OLDSOLARIS)
51CFLAGS+=-I $(NCURSESROOT)/include/ncursesw -I $(NCURSESROOT)/include
52LP64ISA=$(shell isalist | tr " " "\n" | egrep '^(v9|amd64)$')
53ifeq ($(LP64ISA),)
54LIBS=-L $(NCURSESROOT)/lib -R $(NCURSESROOT)/lib
55else
56CFLAGS+=-m64
57LIBS=-L $(NCURSESROOT)/lib/64 -R $(NCURSESROOT)/lib/64
58endif
59LIBS+=-lncursesw -lrt
60endif
61OBJS=main.o readconf.o util.o screen.o cpu.o os.o chario.o
62CONVERT_OBJS=tnylpo-convert.o readconf.o util.o
63
64all: tnylpo tnylpo-convert
65
66tnylpo: $(OBJS)
67	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
68
69tnylpo-convert: $(CONVERT_OBJS)
70	$(CC) $(CFLAGS) $(LDFLAGS) $(CONVERT_OBJS) -o $@
71
72$(OBJS): tnylpo.h
73$(CONVERT_OBJS): tnylpo.h
74
75clean:
76	rm -f $(OBJS) $(CONVERT_OBJS)
77
78veryclean: clean
79	rm -f tnylpo tnylpo-convert
80