3b2ae2b324497f9deb159efc8caa9f5f8b02af78
[fw/sdcc] / support / scripts / build.mak
1 # Makefile to get and build all the parts of GBDK
2
3 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
4         else if [ -x /bin/bash ]; then echo /bin/bash; \
5         else echo sh; fi ; fi)
6
7 TOPDIR  := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
8
9 BUILD = $(TOPDIR)/build/sdcc
10 SDCCLIB = $(BUILD)
11 CVSFLAGS = -z5
12 CVS = cvs
13 DIR = .
14 VER = 2.2.1
15 # Used as a branch name.
16 SHORTVER = 221
17
18 # Options:
19 # linux-linux    Building on Linux, targeting Linux
20 # linux-ming32   Building on Linux, targeting mingw32 based win32
21 # cygwin-mingw32 Building via cygwin on win32, targeting mingw32
22
23 COMPILE_MODE = linux-mingw32
24 SDCC_OR_GBDK = sdcc
25
26 ROOT_GBDK = :pserver:anonymous@cvs.gbdk.sourceforge.net:/cvsroot/gbdk
27 ROOT_SDCC = :pserver:anonymous@cvs.sdcc.sourceforge.net:/cvsroot/sdcc
28
29 ifeq ($(COMPILE_MODE),linux-linux)
30 # For Linux
31 SE = 
32 E =
33 SDCC_ROOT = /usr/lib/$(SDCC_OR_GBDK)
34 endif
35
36 ifeq ($(COMPILE_MODE),linux-mingw32)
37 # For mingw32 hosted on Linux
38 # Tools name prefix
39 TNP = i386-mingw32-
40 # Source extension - what the gcc generated files have appended
41 SE =
42 # Dest extenstion - what extension we want them to have.
43 E = .exe
44 SDCC_ROOT = /$(SDCC_OR_GBDK)
45 # Set to cross to bypass the detection
46 CROSS_LIBGC = 1
47 endif
48
49 ifeq ($(COMPILE_MODE),cygwin-mingw32)
50 # For mingw32 on win32
51 # Source extension - what the gcc generated files have appended
52 SE = .exe
53 # Dest extenstion - what extension we want them to have.
54 SDCC_ROOT = /$(SDCC_OR_GBDK)
55 endif
56
57 all: logged_in dist
58
59 clean:
60         for i in sdcc gbdk-lib gbdk-support/lcc; do make -C $$i clean; done
61         rm -f *~
62         rm -rf $(BUILD) gbdk-lib gbdk-support sdcc logged_in
63
64 update: logged_in
65         cd $(DIR); cvs $(CVSFLAGS) -d$(ROOT_SDCC) co -r sdcc-$(SHORTVER) sdcc
66         cd $(DIR); cvs $(CVSFLAGS) -d$(ROOT_GBDK) co -r sdcc-$(SHORTVER) gbdk-lib
67         cd $(DIR); cvs $(CVSFLAGS) -d$(ROOT_GBDK) co -r sdcc-$(SHORTVER) gbdk-support
68
69 _sdcc: sdcc-bin sdcc-misc sdcc-lib sdcc-doc
70
71 tidy:
72         rm -rf `find $(BUILD) -name "CVS"`
73         rm -rf `find $(BUILD)/lib -name "*.asm"`
74         -$(TNP)strip $(BUILD)/bin/*
75
76 sdcc-bin: sdcc/sdccconf.h
77         make -C sdcc sdcc-bin CROSS_LIBGC=$(CROSS_LIBGC)
78         mkdir -p $(BUILD)/bin
79         for i in \
80         sdcc sdcpp link-z80 as-z80 aslink asx8051; \
81         do cp sdcc/bin/$$i$(SE) $(BUILD)/bin/$$i$(E); done
82
83 sdcc-misc: sdcc/sdccconf.h
84         make -C sdcc sdcc-misc CROSS_LIBGC=$(CROSS_LIBGC)
85         mkdir -p $(BUILD)/bin
86         for i in \
87         sdcdb; \
88         do cp sdcc/bin/$$i$(SE) $(BUILD)/bin/$$i$(E); done
89         cp sdcc/sim/ucsim/s51.src/s51$(E) $(BUILD)/bin
90         cp sdcc/sim/ucsim/z80.src/sz80$(E) $(BUILD)/bin
91         cp sdcc/sim/ucsim/avr.src/savr$(E) $(BUILD)/bin
92         cp sdcc/debugger/mcs51/*.el $(BUILD)/bin
93
94 sdcc-doc:
95         (cd sdcc; tar cf - doc) | (cd $(BUILD); tar xf -)
96         cp sdcc/README sdcc/COPYING $(BUILD)
97         mkdir -p $(BUILD)/sim
98         for i in COPYING INSTALL README TODO; \
99         do cp sdcc/sim/ucsim/$$i $(BUILD)/sim; done
100         (cd sdcc/sim/ucsim; tar cf - doc) | (cd $(BUILD)/sim; tar xf -)
101
102 sdcc-lib: sdcc-lib-z80 sdcc-lib-gen
103         mkdir -p $(BUILD)/lib
104         (cd sdcc/device/lib; tar cf - small large) | (cd $(BUILD)/lib; tar xf -)
105         (cd sdcc/device; tar cf - examples include) | (cd $(BUILD); tar xf -)
106
107 sdcc-lib-z80:
108         make -C gbdk-lib/libc SDCCLIB=$(BUILD) PORTS=z80 PLATFORMS=consolez80
109         (cd gbdk-lib/build; tar cf - consolez80 z80) | (cd $(BUILD)/lib; tar xf -)
110         mkdir -p $(BUILD)/include/gbdk-lib
111         (cd gbdk-lib/include; tar cf - .) | (cd $(BUILD)/include/gbdk-lib; tar xf -)
112
113 sdcc-lib-gen:
114         make -C sdcc sdcc-device
115
116 lcc:
117         make -C gbdk-support/lcc SDCCLIB=$(SDCC_ROOT)/ TNP=$(TNP)
118         cp gbdk-support/lcc/lcc$(SE) $(BUILD)/bin/lcc$(E)
119
120 sdcc/sdccconf.h: sdcc/configure
121 ifdef TNP
122         cd sdcc; \
123         export CCC=$(TNP)c++; \
124         export RANLIB=$(TNP)ranlib; \
125         export CC=$(TNP)gcc; \
126         ./configure --datadir=$(SDCC_ROOT)
127         echo $$CCC
128 else
129         cd sdcc; ./configure --datadir=$(SDCC_ROOT)
130 endif
131
132 dist: _sdcc lcc tidy
133
134 zdist: dist
135         tar czf gbdk-$(VER).tar.gz gbdk
136
137 logged_in:
138         cvs -d$(ROOT_GBDK) login
139         cvs -d$(ROOT_SDCC) login
140         touch logged_in
141         make -f build.mak update