comparison Makefile @ 495:5b8871fd7503

Merged previous lwcc development branch into mainline.
author William Astle <lost@l-w.ca>
date Mon, 05 Aug 2019 21:27:09 -0600
parents 7fbf3171ca15 a3e277c58df9
children 1bd2d590d734
comparison
equal deleted inserted replaced
493:6073f4a33475 495:5b8871fd7503
5 # BUILDTPREFIX: prefix added to build utilities (cc, etc.) for xcompile 5 # BUILDTPREFIX: prefix added to build utilities (cc, etc.) for xcompile
6 # can also set them when invoking "make" 6 # can also set them when invoking "make"
7 #PROGSUFFIX := .exe 7 #PROGSUFFIX := .exe
8 #BUILDTPREFIX=i586-mingw32msvc- 8 #BUILDTPREFIX=i586-mingw32msvc-
9 9
10 LWTOOLS_VERSION = 4.8
11 LWTOOLS_VERSION_SUFFIX = -devcc
12
13 PACKAGE_VERSION = $(LWTOOLS_VERSION)$(LWTOOLS_VERSION_SUFFIX)
14
15 ifeq ($(PREFIX),)
10 ifneq ($(DESTDIR),) 16 ifneq ($(DESTDIR),)
11 INSTALLDIR = $(DESTDIR)/usr/bin 17 PREFIX = /usr
12 else 18 else
13 INSTALLDIR ?= /usr/local/bin 19 PREFIX = /usr/local
14 endif 20 endif
21 endif
22
23 LIBDIR = $(PREFIX)/lib
24 BINDIR = $(PREFIX)/bin
25
26 INSTALLDIR = $(DESTDIR)$(PREFIX)
27 INSTALLBIN = $(DESTDIR)$(BINDIR)
28 INSTALLLIB = $(DESTDIR)$(LIBDIR)
29
30 LWCC_LIBDIR = $(LIBDIR)/lwcc/$(PACKAGE_VERSION)
31 LWCC_INSTALLLIBDIR = $(DESTDIR)$(LWCC_LIBDIR)
15 32
16 # this are probably pointless but they will make sure 33 # this are probably pointless but they will make sure
17 # the variables are set without overriding the environment 34 # the variables are set without overriding the environment
18 # or automatic values from make itself. 35 # or automatic values from make itself.
19 CC ?= cc 36 CC ?= cc
26 AR := $(BUILDTPREFIX)$(AR) 43 AR := $(BUILDTPREFIX)$(AR)
27 RANLIB := $(BUILDTPREFIX)$(RANLIB) 44 RANLIB := $(BUILDTPREFIX)$(RANLIB)
28 endif 45 endif
29 46
30 CPPFLAGS += -I lwlib -Icommon 47 CPPFLAGS += -I lwlib -Icommon
48 CPPFLAGS += -DPREFIX=$(PREFIX) -DLWCC_LIBDIR=$(LWCC_LIBDIR)
49 CPPFLAGS += -DPROGSUFFIX=$(PROGSUFFIX)
31 LDFLAGS += -Llwlib -llw 50 LDFLAGS += -Llwlib -llw
32 51
33 CFLAGS ?= -O3 -Wall -Wno-char-subscripts 52 CFLAGS ?= -O3 -Wall -Wno-char-subscripts
34 53
35 MAIN_TARGETS := lwasm/lwasm$(PROGSUFFIX) \ 54 MAIN_TARGETS := lwasm/lwasm$(PROGSUFFIX) \
36 lwlink/lwlink$(PROGSUFFIX) \ 55 lwlink/lwlink$(PROGSUFFIX) \
37 lwar/lwar$(PROGSUFFIX) \ 56 lwar/lwar$(PROGSUFFIX) \
38 lwlink/lwobjdump$(PROGSUFFIX) 57 lwlink/lwobjdump$(PROGSUFFIX) \
58 lwcc/lwcc$(PROGSUFFIX) \
59 lwcc/lwcc-cpp$(PROGSUFFIX) \
60 lwcc/lwcc-cc$(PROGSUFFIX)
61
62 LWCC_LIBBIN_FILES = lwcc/lwcc-cpp$(PROGSUFFIX) lwcc/lwcc-cc$(PROGSUFFIX)
63 LWCC_LIBLIB_FILES =
64 LWCC_LIBINC_FILES =
39 65
40 .PHONY: all 66 .PHONY: all
41 all: $(MAIN_TARGETS) 67 all: $(MAIN_TARGETS)
42 68
43 lwar_srcs := add.c extract.c list.c lwar.c main.c remove.c replace.c 69 lwar_srcs := add.c extract.c list.c lwar.c main.c remove.c replace.c
44 lwar_srcs := $(addprefix lwar/,$(lwar_srcs)) 70 lwar_srcs := $(addprefix lwar/,$(lwar_srcs))
45 71
46 lwlib_srcs := lw_alloc.c lw_realloc.c lw_free.c lw_error.c lw_expr.c \ 72 lwlib_srcs := lw_alloc.c lw_realloc.c lw_free.c lw_error.c lw_expr.c \
47 lw_stack.c lw_string.c lw_stringlist.c lw_cmdline.c 73 lw_stack.c lw_string.c lw_stringlist.c lw_cmdline.c lw_strbuf.c \
74 lw_strpool.c
48 lwlib_srcs := $(addprefix lwlib/,$(lwlib_srcs)) 75 lwlib_srcs := $(addprefix lwlib/,$(lwlib_srcs))
49 76
50 lwlink_srcs := main.c lwlink.c readfiles.c expr.c script.c link.c output.c map.c 77 lwlink_srcs := main.c lwlink.c readfiles.c expr.c script.c link.c output.c map.c
51 lwobjdump_srcs := objdump.c 78 lwobjdump_srcs := objdump.c
52 lwlink_srcs := $(addprefix lwlink/,$(lwlink_srcs)) 79 lwlink_srcs := $(addprefix lwlink/,$(lwlink_srcs))
69 lwlink_deps := $(lwlink_srcs:.c=.d) 96 lwlink_deps := $(lwlink_srcs:.c=.d)
70 lwar_deps := $(lwar_srcs:.c=.d) 97 lwar_deps := $(lwar_srcs:.c=.d)
71 lwlib_deps := $(lwlib_srcs:.c=.d) 98 lwlib_deps := $(lwlib_srcs:.c=.d)
72 lwobjdump_deps := $(lwobjdump_srcs:.c=.d) 99 lwobjdump_deps := $(lwobjdump_srcs:.c=.d)
73 100
74 .PHONY: lwlink lwasm lwar lwobjdump 101 lwcc_driver_srcs := driver-main.c
102 lwcc_driver_srcs := $(addprefix lwcc/,$(lwcc_driver_srcs))
103 lwcc_driver_objs := $(lwcc_driver_srcs:.c=.o)
104 lwcc_driver_deps := $(lwcc_driver_srcs:.c=.d)
105
106 lwcc_cpp_srcs := cpp-main.c
107 lwcc_cpp_srcs := $(addprefix lwcc/,$(lwcc_cpp_srcs))
108 lwcc_cpp_objs := $(lwcc_cpp_srcs:.c=.o)
109 lwcc_cpp_deps := $(lwcc_cpp_srcs:.c=.d)
110
111 # parse_c.c needs to be first here
112 lwcc_cc_srcs := parse_c.c cc-main.c tree.c parse.c token_names.c
113 lwcc_cc_srcs := $(addprefix lwcc/,$(lwcc_cc_srcs))
114 lwcc_cc_objs := $(lwcc_cc_srcs:.c=.o)
115 lwcc_cc_deps := $(lwcc_cc_srcs:.c=.d)
116
117 lwcc_cpplib_srcs := cpp.c lex.c token.c preproc.c symbol.c
118 lwcc_cpplib_srcs := $(addprefix lwcc/,$(lwcc_cpplib_srcs))
119 lwcc_cpplib_objs := $(lwcc_cpplib_srcs:.c=.o)
120 lwcc_cpplib_deps := $(lwcc_cpplib_srcs:.c=.d)
121
122 lwcc_deps := $(lwcc_cpp_deps) $(lwcc_driver_deps) $(lwcc_cpplib_deps) $(lwcc_cc_deps)
123
124 .PHONY: lwlink lwasm lwar lwobjdump lwcc
75 lwlink: lwlink/lwlink$(PROGSUFFIX) 125 lwlink: lwlink/lwlink$(PROGSUFFIX)
76 lwasm: lwasm/lwasm$(PROGSUFFIX) 126 lwasm: lwasm/lwasm$(PROGSUFFIX)
77 lwar: lwar/lwar$(PROGSUFFIX) 127 lwar: lwar/lwar$(PROGSUFFIX)
78 lwobjdump: lwlink/lwobjdump$(PROGSUFFIX) 128 lwobjdump: lwlink/lwobjdump$(PROGSUFFIX)
129 lwcc: lwcc/lwcc$(PROGSUFFIX)
130 lwcc-cpp: lwcc/lwcc-cpp$(PROGSUFFIX)
131 lwcc-cpplib: lwcc/libcpp.a
79 132
80 lwasm/lwasm$(PROGSUFFIX): $(lwasm_objs) lwlib 133 lwasm/lwasm$(PROGSUFFIX): $(lwasm_objs) lwlib
81 @echo Linking $@ 134 @echo Linking $@
82 @$(CC) -o $@ $(lwasm_objs) $(LDFLAGS) 135 @$(CC) -o $@ $(lwasm_objs) $(LDFLAGS)
83 136
90 @$(CC) -o $@ $(lwobjdump_objs) $(LDFLAGS) 143 @$(CC) -o $@ $(lwobjdump_objs) $(LDFLAGS)
91 144
92 lwar/lwar$(PROGSUFFIX): $(lwar_objs) lwlib 145 lwar/lwar$(PROGSUFFIX): $(lwar_objs) lwlib
93 @echo Linking $@ 146 @echo Linking $@
94 @$(CC) -o $@ $(lwar_objs) $(LDFLAGS) 147 @$(CC) -o $@ $(lwar_objs) $(LDFLAGS)
148
149 lwcc/lwcc$(PROGSUFFIX): $(lwcc_driver_objs) lwlib
150 @echo Linking $@
151 @$(CC) -o $@ $(lwcc_driver_objs) $(LDFLAGS)
152
153 lwcc/lwcc-cpp$(PROGSUFFIX): $(lwcc_cpp_objs) lwlib lwcc-cpplib
154 @echo Linking $@
155 @$(CC) -o $@ $(lwcc_cpp_objs) lwcc/libcpp.a $(LDFLAGS)
156
157 lwcc/lwcc-cc$(PROGSUFFIX): $(lwcc_cc_objs) lwlib lwcc-cpplib
158 @echo Linking $@
159 @$(CC) -o $@ $(lwcc_cc_objs) lwcc/libcpp.a $(LDFLAGS)
160
161 .INTERMEDIATE: lwcc-cpplib
162 lwcc-cpplib: lwcc/libcpp.a
163 lwcc/libcpp.a: $(lwcc_cpplib_objs)
164 @echo Linking $@
165 @$(AR) rc $@ $(lwcc_cpplib_objs)
166 @$(RANLIB) $@
95 167
96 #.PHONY: lwlib 168 #.PHONY: lwlib
97 .INTERMEDIATE: lwlib 169 .INTERMEDIATE: lwlib
98 lwlib: lwlib/liblw.a 170 lwlib: lwlib/liblw.a
99 171
100 lwlib/liblw.a: $(lwlib_objs) 172 lwlib/liblw.a: $(lwlib_objs)
101 @echo Linking $@ 173 @echo Linking $@
102 @$(AR) rc $@ $(lwlib_objs) 174 @$(AR) rc $@ $(lwlib_objs)
103 @$(RANLIB) $@ 175 @$(RANLIB) $@
104 176
105 alldeps := $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) ($lwobjdump_deps) 177 alldeps := $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) ($lwobjdump_deps) $(lwcc_deps)
106 178
107 -include $(alldeps) 179 -include $(alldeps)
108 180
109 extra_clean := $(extra_clean) *~ */*~ 181 extra_clean := $(extra_clean) *~ */*~
182
183 lwcc/parse_c.c lwcc/parse_c.h: lwcc/parse_c.y
184 rm -f lwcc/parse_c.h lwcc/parse_c.c
185 lemon -q lwcc/parse_c.y
186
187 lwcc/token_names.c: lwcc/parse_c.h
188 echo "char *ptoken_names[] = {" > $@
189 echo '"TOKEN_NONE",' >> $@
190 cat lwcc/parse_c.h | sed -e 's/#define \(.*\) .*$$/"\1",/g' -e 's/ //g' >> $@
191 echo '"" };' >> $@
192
110 193
111 %.o: %.c 194 %.o: %.c
112 @echo "Building dependencies for $@" 195 @echo "Building dependencies for $@"
113 @$(CC) -MM $(CPPFLAGS) -o $*.d $< 196 @$(CC) -MM -MG $(CPPFLAGS) -o $*.d $<
114 @mv -f $*.d $*.d.tmp 197 @mv -f $*.d $*.d.tmp
115 @sed -e 's|.*:|$*.o $*.d:|' < $*.d.tmp > $*.d 198 @sed -e 's|.*:|$*.o $*.d:|' < $*.d.tmp > $*.d
116 @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $*.d 199 @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
117 @rm -f $*.d.tmp 200 @rm -f $*.d.tmp
118 @echo Building $@ 201 @echo Building $@
121 204
122 .PHONY: clean 205 .PHONY: clean
123 clean: $(cleantargs) 206 clean: $(cleantargs)
124 @echo "Cleaning up" 207 @echo "Cleaning up"
125 @rm -f lwlib/liblw.a lwasm/lwasm$(PROGSUFFIX) lwlink/lwlink$(PROGSUFFIX) lwlink/lwobjdump$(PROGSUFFIX) lwar/lwar$(PROGSUFFIX) 208 @rm -f lwlib/liblw.a lwasm/lwasm$(PROGSUFFIX) lwlink/lwlink$(PROGSUFFIX) lwlink/lwobjdump$(PROGSUFFIX) lwar/lwar$(PROGSUFFIX)
209 @rm -f lwcc/lwcc$(PROGSUFFIX) lwcc/lwcc-cpp$(PROGSUFFIX) lwcc/libcpp.a
210 @rm -f $(lwcc_driver_objs) $(lwcc_cpp_objs) $(lwcc_cpplib_objs) $(lwcc_cc_objs)
126 @rm -f $(lwasm_objs) $(lwlink_objs) $(lwar_objs) $(lwlib_objs) $(lwobjdump_objs) 211 @rm -f $(lwasm_objs) $(lwlink_objs) $(lwar_objs) $(lwlib_objs) $(lwobjdump_objs)
127 @rm -f $(extra_clean) 212 @rm -f $(extra_clean)
128 @rm -f */*.exe 213 @rm -f */*.exe
129 214
130 .PHONY: realclean 215 .PHONY: realclean
131 realclean: clean $(realcleantargs) 216 realclean: clean $(realcleantargs)
132 @echo "Cleaning up even more" 217 @echo "Cleaning up even more"
133 @rm -f $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) $(lwobjdump_deps) 218 @rm -f $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) $(lwobjdump_deps)
219 @rm -f $(lwcc_driver_deps) $(lwcc_cpp_deps) $(lwcc_cpplib_deps) $(lwcc_cc_deps)
134 220
135 print-%: 221 print-%:
136 @echo $* = $($*) 222 @echo $* = $($*)
137 223
138 .PHONY: install 224 .PHONY: install
139 install: $(MAIN_TARGETS) 225 install: $(MAIN_TARGETS)
140 install -d $(INSTALLDIR) 226 install -d $(INSTALLDIR)
141 install $(MAIN_TARGETS) $(INSTALLDIR) 227 install $(MAIN_TARGETS) $(INSTALLDIR)
228 install -d $(LWCC_INSTALLLIBDIR)
229 install -d $(LWCC_INSTALLLIBDIR)/bin
230 install -d $(LWCC_INSTALLLIBDIR)/lib
231 install -d $(LWCC_INSTALLLIBDIR)/include
232 ifneq ($(LWCC_LIBBIN_FILES),)
233 install $(LWCC_LIBBIN_FILES) $(LWCC_INSTALLLIBDIR)/bin
234 endif
235 ifneq ($(LWCC_LIBLIB_FILES),)
236 install $(LWCC_LIBLIB_FILES) $(LWCC_INSTALLLIBDIR)/lib
237 endif
238 ifneq ($(LWCC_LIBINC_FILES),)
239 install $(LWCC_LIBINC_FILES) $(LWCC_INSTALLLIBDIR)/include
240 endif
142 241
143 .PHONY: test 242 .PHONY: test
144 test: all test/runtests 243 test: all test/runtests
145 @test/runtests 244 @test/runtests
146 245