]> git.sur5r.net Git - cc65/blob - make/gcc.mak
New version by Greg King.
[cc65] / make / gcc.mak
1 #! /usr/bin/make -f
2 # -*- make -*-
3 #
4 # Main gcc Makefile.
5 # This makefile is maintained by Greg King <greg.king4@verizon.net>.
6
7 # Goals that are supported by the cc65 package
8 .PHONY: all bins libs docs samples tests clean zap
9 .PHONY: uninstall install install-bins install-libs install-docs install-samps
10
11 # If SYS is defined on this makefile's command-line, then we want it to go
12 # to "samples" and "tests", but not to the other rules.  So, we disable a
13 # feature of GNU make that would have given ${SYS} to every sub-make.
14 #MAKEOVERRIDES=
15 # (That trick has been disabled.)
16
17 # The install prefix and directories
18 prefix          = /usr/local
19 exec_prefix     = $(prefix)
20
21 bindir          = $(exec_prefix)/bin
22 datadir         = $(prefix)/share
23 docdir          = $(datadir)/doc
24 libdir          = $(exec_prefix)/lib
25
26 CC65_DOC        = $(docdir)/cc65
27 CC65_HOME       = $(libdir)/cc65
28
29 CA65_INC        = $(CC65_HOME)/asminc
30 CC65_INC        = $(CC65_HOME)/include
31 LD65_CFG        = $(CC65_HOME)/cfg
32 LD65_LIB        = $(CC65_HOME)/lib
33 LD65_OBJ        = $(CC65_HOME)/obj
34
35 # Programs
36
37 MKDIR           = mkdir -m 755
38
39 # BSD-like install-script/-program
40 INSTALL         = make/install-sh
41
42 INSTALL_DATA    = $(INSTALL) -c -m 644
43 INSTALL_PROG    = $(INSTALL) -c -m 755
44 INSTALL_STRIP   = $(INSTALL_PROG) -s
45
46 # This file-name extension is needed on DOS/Windows systems.
47 ifdef COMSPEC
48 EXT     = .exe
49 endif
50
51 # Rules
52
53 # The sample and library-test programs must be compiled for only one platform
54 # at a time.  So, those rules are done automatically only when a user names
55 # a system on the command-line.  (A user can do those rules with their
56 # defaults by putting "all samples tests" on the command-line.)
57 #
58 all:    bins libs docs $(SYS:%=samples tests)
59
60 bins:
61         @$(MAKE) -C src -f make/gcc.mak CA65_INC=\\\"${CA65_INC}/\\\" \
62           CC65_INC=\\\"${CC65_INC}/\\\" LD65_CFG=\\\"${LD65_CFG}/\\\" \
63           LD65_LIB=\\\"${LD65_LIB}/\\\" LD65_OBJ=\\\"${LD65_OBJ}/\\\"
64
65 libs:
66         @$(MAKE) -C libsrc
67
68 # This rule won't try to generate HTML files
69 # if a host system doesn't have LinuxDoc Tools.
70 docs:
71         @if linuxdoc -B check doc/index >/dev/null 2>&1; \
72           then $(MAKE) -C doc html; \
73           else echo '"LinuxDoc Tools" is not installed; skipping HTML documentation.'; \
74           fi
75
76 # Some platforms cannot compile all of the sample and library-test programs.
77 # So, these rules ignore errors.
78
79 samples:
80         -@$(MAKE) -k -C samples prefix=$(prefix) $(SYS:%=SYS=%)
81
82 tests:
83         -@$(MAKE) -k -C testcode/lib prefix=$(prefix) $(SYS:%=SYS=%)
84
85 clean zap:
86         @$(MAKE) -C src -f make/gcc.mak $@
87         @$(MAKE) -C libsrc $@
88         @$(MAKE) -C doc $@
89         @$(MAKE) -C samples $@
90 #       @$(MAKE) -C testcode/lib $@ $(SYS:%=SYS=%)
91
92 uninstall:      install-test
93         cd $(bindir) && $(RM) ar65${EXT} ca65${EXT} cc65${EXT} cl65${EXT} \
94           co65${EXT} da65${EXT} ld65${EXT} od65${EXT} grc${EXT} ca65html
95         $(RM) -R $(CC65_HOME) $(CC65_DOC)
96
97 install:        install-test install-dirs install-bins install-libs install-docs
98         @echo
99         @echo 'If you put the files into non-standard directories, then'
100         @echo 'you might need to export some shell environment variables:'
101         @echo
102         @echo 'CC65_HOME=$(CC65_HOME)'
103         @echo ' or'
104         @echo 'CA65_INC=$(CA65_INC)'
105         @echo 'CC65_INC=$(CC65_INC)'
106         @echo 'LD65_CFG=$(LD65_CFG)'
107         @echo 'LD65_LIB=$(LD65_LIB)'
108         @echo 'LD65_OBJ=$(LD65_OBJ)'
109         @echo
110
111 .PHONY: install-test
112 install-test:
113         @if [ `id -u` != 0 ]; then \
114           echo; \
115           echo 'If you are denied permission to install or uninstall this package,'; \
116           echo 'then you will need to do "make/gcc.mak install" or "make/gcc.mak uninstall"'; \
117           echo 'as either the root user or an administrator.'; \
118           echo; \
119           fi 2>/dev/null
120
121 .PHONY: install-dirs
122 install-dirs:   $(bindir) $(datadir) $(docdir) $(libdir) \
123                 $(CC65_DOC) $(CC65_HOME) \
124                 $(CA65_INC) $(CC65_INC) \
125                 $(CC65_INC)/em $(CC65_INC)/geos $(CC65_INC)/joystick \
126                 $(CC65_INC)/mouse $(CC65_INC)/sys $(CC65_INC)/tgi \
127                 $(LD65_CFG) $(LD65_LIB) $(LD65_OBJ) \
128                 $(CC65_HOME)/emd $(CC65_HOME)/joy $(CC65_HOME)/mou \
129                 $(CC65_HOME)/ser $(CC65_HOME)/tgi
130
131 $(bindir) $(datadir) $(docdir) $(libdir) \
132 $(CC65_DOC) $(CC65_HOME) \
133 $(CA65_INC) $(CC65_INC) \
134 $(LD65_CFG) $(LD65_LIB) $(LD65_OBJ):
135         $(MKDIR) $@
136
137 $(CC65_HOME)/% $(CC65_INC)/% $(CC65_DOC)/%:
138         $(MKDIR) $@
139
140 install-bins:
141         for f in ar65 ca65 cc65 cl65 co65 da65 ld65 od65 grc; \
142           do $(INSTALL_STRIP) src/$$f/$$f${EXT} $(bindir) || exit $$?; \
143           done
144         $(INSTALL_PROG) src/ca65html/ca65html $(bindir)
145
146 install-libs:
147         for f in asminc/*.inc; \
148           do $(INSTALL_DATA) $$f $(CA65_INC) || exit $$?; \
149           done
150         for f in include/*.h; \
151           do $(INSTALL_DATA) $$f $(CC65_INC) || exit $$?; \
152           done
153         for d in em geos joystick mouse sys tgi; \
154           do for f in include/$$d/*.h; \
155             do $(INSTALL_DATA) $$f $(CC65_INC)/$$d || exit $$?; \
156             done || exit $$?; \
157           done
158         for f in libsrc/*.lib; \
159           do $(INSTALL_DATA) $$f $(LD65_LIB) || exit $$?; \
160           done
161         for f in libsrc/*-*.o; \
162           do $(INSTALL_DATA) $$f $(LD65_OBJ) || exit $$?; \
163           done
164         for d in emd joy mou ser tgi; \
165           do for f in libsrc/*.$$d; \
166             do $(INSTALL_DATA) $$f $(CC65_HOME)/$$d || exit $$?; \
167             done || exit $$?; \
168           done
169         for f in src/ld65/cfg/*-*.cfg; \
170           do $(INSTALL_DATA) $$f $(LD65_CFG) || exit $$?; \
171           done
172
173 install-docs:
174         for f in src/ca65/macpack/*.mac; \
175           do $(INSTALL_DATA) $$f $(CC65_DOC) || exit $$?; \
176           done
177         for f in readme.1st compile.txt CREDITS BUGS internal.txt newvers.txt; \
178           do $(INSTALL_DATA) doc/$$f $(CC65_DOC) || exit $$?; \
179           done
180         if [ -f doc/index.htm* ]; \
181           then for f in doc/*.htm*; \
182             do $(INSTALL_DATA) $$f $(CC65_DOC) || exit $$?; \
183             done; \
184           fi
185
186 install-samps:  ${addprefix $(CC65_DOC)/, $(shell find samples -type d)}
187         @$(MAKE) -C samples zap
188         for d in `find samples -type d`; \
189           do for f in $$d/*; \
190             do if [ -f $$f ]; \
191               then $(INSTALL_DATA) $$f $(CC65_DOC)/$$d || exit $$?; \
192               fi; \
193             done || exit $$?; \
194           done