1#!/usr/bin/make -f
2#
3#Copyright 2021, dettus@dettus.net
4#
5#Redistribution and use in source and binary forms, with or without modification,
6#are permitted provided that the following conditions are met:
7#
8#1. Redistributions of source code must retain the above copyright notice, this
9#   list of conditions and the following disclaimer.
10#
11#2. Redistributions in binary form must reproduce the above copyright notice,
12#   this list of conditions and the following disclaimer in the documentation
13#   and/or other materials provided with the distribution.
14#
15#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26PREFIX?=/usr/local
27INSTALLBIN=$(PREFIX)/bin
28INSTALLSHARE=$(PREFIX)/share/games
29INSTALLMAN=$(PREFIX)/share/man
30
31CC?=gcc
32AR?=ar
33#CFLAGS=-g -O0
34CFLAGS?=-O3
35CFLAGS+=-Wall
36#CFLAGS+=-Werror
37PROJ_HOME=./
38INCFLAGS=-I$(PROJ_HOME)src/gui -I$(PROJ_HOME)src/toplevel -I$(PROJ_HOME)src/loader -I$(PROJ_HOME)src/engine/vm68k -I$(PROJ_HOME)src/engine/linea -I$(PROJ_HOME)src/engine/include
39OBJDIR=$(PROJ_HOME)obj/
40LINK=$(CC)
41LDFLAGS+="-L"$(OBJDIR)
42
43SOURCES_LOADER=	\
44	src/loader/loader_common.c	\
45	src/loader/loader_msdos.c	\
46	src/loader/loader_mw.c		\
47	src/loader/loader_d64.c		\
48	src/loader/loader_dsk.c		\
49	src/loader/loader_archimedes.c	\
50	src/loader/loader_atarixl.c	\
51	src/loader/loader_appleii.c	\
52	src/loader/maggfxloader.c
53
54SOURCES_LINEA=	\
55	src/engine/linea/gfx1loader.c	\
56	src/engine/linea/gfx2loader.c	\
57	src/engine/linea/linea.c
58
59SOURCES_VM68K=	\
60	src/engine/vm68k/vm68k.c	\
61	src/engine/vm68k/vm68k_decode.c	\
62	src/engine/vm68k/vm68k_loadstore.c
63
64SOURCES_GUI=	\
65	src/gui/default_callbacks.c	\
66	src/gui/default_palette.c	\
67	src/gui/default_render.c
68
69SOURCES_TOPLEVEL=	\
70	src/toplevel/configuration.c	\
71	src/toplevel/dMagnetic_helpscreens.c	\
72	src/toplevel/dMagnetic.c
73
74OBJ_LOADER=${SOURCES_LOADER:.c=.o}
75OBJ_LINEA=${SOURCES_LINEA:.c=.o}
76OBJ_VM68K=${SOURCES_VM68K:.c=.o}
77OBJ_GUI=${SOURCES_GUI:.c=.o}
78OBJ_TOPLEVEL=${SOURCES_TOPLEVEL:.c=.o}
79
80all:	dMagnetic dMagnetic.ini
81#	strip dMagnetic
82
83clean:
84	rm -rf dMagnetic dMagnetic.ini
85	rm -rf $(OBJ_LOADER)
86	rm -rf $(OBJ_LINEA)
87	rm -rf $(OBJ_VM68K)
88	rm -rf $(OBJ_GUI)
89	rm -rf $(OBJ_TOPLEVEL)
90
91install: all dMagnetic.6 dMagneticini.5
92	mkdir -p $(INSTALLBIN)
93	mkdir -p $(INSTALLMAN)/man6/
94	mkdir -p $(INSTALLMAN)/man5/
95	mkdir -p $(INSTALLSHARE)/dMagnetic/
96
97	cp dMagnetic $(INSTALLBIN)
98	cp dMagnetic.6 $(INSTALLMAN)/man6/
99	cp dMagneticini.5 $(INSTALLMAN)/man5/
100	cp README.txt $(INSTALLSHARE)/dMagnetic/
101	cp LICENSE.txt $(INSTALLSHARE)/dMagnetic/
102	cp dMagnetic.ini $(INSTALLSHARE)/dMagnetic/
103
104
105dMagnetic:	$(OBJ_LOADER) $(OBJ_LINEA) $(OBJ_VM68K) $(OBJ_GUI) $(OBJ_TOPLEVEL)
106	$(LINK) $(LDFLAGS) -o $@ $(OBJ_LOADER) $(OBJ_LINEA) $(OBJ_VM68K) $(OBJ_GUI) $(OBJ_TOPLEVEL)
107
108dMagnetic.ini:	dMagnetic
109	./dMagnetic -helpini >dMagnetic.ini
110
111.c.o:
112	$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_EXTRA) $(INCFLAGS) -c -o $@ $<
113
114
115## in case some post-compilation checks are needed
116## if not, please comment out this line
117include ./checks.mk
118