diff 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
line wrap: on
line diff
--- a/Makefile	Sat Jun 29 21:54:43 2019 -0600
+++ b/Makefile	Mon Aug 05 21:27:09 2019 -0600
@@ -7,12 +7,29 @@
 #PROGSUFFIX := .exe
 #BUILDTPREFIX=i586-mingw32msvc-
 
+LWTOOLS_VERSION = 4.8
+LWTOOLS_VERSION_SUFFIX = -devcc
+
+PACKAGE_VERSION = $(LWTOOLS_VERSION)$(LWTOOLS_VERSION_SUFFIX)
+
+ifeq ($(PREFIX),)
 ifneq ($(DESTDIR),)
-INSTALLDIR = $(DESTDIR)/usr/bin
+PREFIX = /usr
 else
-INSTALLDIR ?= /usr/local/bin
+PREFIX = /usr/local
+endif
 endif
 
+LIBDIR = $(PREFIX)/lib
+BINDIR = $(PREFIX)/bin
+
+INSTALLDIR = $(DESTDIR)$(PREFIX)
+INSTALLBIN = $(DESTDIR)$(BINDIR)
+INSTALLLIB = $(DESTDIR)$(LIBDIR)
+
+LWCC_LIBDIR = $(LIBDIR)/lwcc/$(PACKAGE_VERSION)
+LWCC_INSTALLLIBDIR = $(DESTDIR)$(LWCC_LIBDIR)
+
 # this are probably pointless but they will make sure
 # the variables are set without overriding the environment
 # or automatic values from make itself.
@@ -28,6 +45,8 @@
 endif
 
 CPPFLAGS += -I lwlib -Icommon
+CPPFLAGS += -DPREFIX=$(PREFIX) -DLWCC_LIBDIR=$(LWCC_LIBDIR)
+CPPFLAGS += -DPROGSUFFIX=$(PROGSUFFIX)
 LDFLAGS += -Llwlib -llw
 
 CFLAGS ?= -O3 -Wall -Wno-char-subscripts
@@ -35,7 +54,14 @@
 MAIN_TARGETS := lwasm/lwasm$(PROGSUFFIX) \
 	lwlink/lwlink$(PROGSUFFIX) \
 	lwar/lwar$(PROGSUFFIX) \
-	lwlink/lwobjdump$(PROGSUFFIX)
+	lwlink/lwobjdump$(PROGSUFFIX) \
+	lwcc/lwcc$(PROGSUFFIX) \
+	lwcc/lwcc-cpp$(PROGSUFFIX) \
+	lwcc/lwcc-cc$(PROGSUFFIX)
+
+LWCC_LIBBIN_FILES = lwcc/lwcc-cpp$(PROGSUFFIX) lwcc/lwcc-cc$(PROGSUFFIX)
+LWCC_LIBLIB_FILES =
+LWCC_LIBINC_FILES =
 
 .PHONY: all
 all: $(MAIN_TARGETS)
@@ -44,7 +70,8 @@
 lwar_srcs := $(addprefix lwar/,$(lwar_srcs))
 
 lwlib_srcs := lw_alloc.c lw_realloc.c lw_free.c lw_error.c lw_expr.c \
-	lw_stack.c lw_string.c lw_stringlist.c lw_cmdline.c
+	lw_stack.c lw_string.c lw_stringlist.c lw_cmdline.c lw_strbuf.c \
+	lw_strpool.c
 lwlib_srcs := $(addprefix lwlib/,$(lwlib_srcs))
 
 lwlink_srcs := main.c lwlink.c readfiles.c expr.c script.c link.c output.c map.c
@@ -71,11 +98,37 @@
 lwlib_deps := $(lwlib_srcs:.c=.d)
 lwobjdump_deps := $(lwobjdump_srcs:.c=.d)
 
-.PHONY: lwlink lwasm lwar lwobjdump
+lwcc_driver_srcs := driver-main.c
+lwcc_driver_srcs := $(addprefix lwcc/,$(lwcc_driver_srcs))
+lwcc_driver_objs := $(lwcc_driver_srcs:.c=.o)
+lwcc_driver_deps := $(lwcc_driver_srcs:.c=.d)
+
+lwcc_cpp_srcs := cpp-main.c
+lwcc_cpp_srcs := $(addprefix lwcc/,$(lwcc_cpp_srcs))
+lwcc_cpp_objs := $(lwcc_cpp_srcs:.c=.o)
+lwcc_cpp_deps := $(lwcc_cpp_srcs:.c=.d)
+
+# parse_c.c needs to be first here
+lwcc_cc_srcs := parse_c.c cc-main.c tree.c parse.c token_names.c
+lwcc_cc_srcs := $(addprefix lwcc/,$(lwcc_cc_srcs))
+lwcc_cc_objs := $(lwcc_cc_srcs:.c=.o)
+lwcc_cc_deps := $(lwcc_cc_srcs:.c=.d)
+
+lwcc_cpplib_srcs := cpp.c lex.c token.c preproc.c symbol.c
+lwcc_cpplib_srcs := $(addprefix lwcc/,$(lwcc_cpplib_srcs))
+lwcc_cpplib_objs := $(lwcc_cpplib_srcs:.c=.o)
+lwcc_cpplib_deps := $(lwcc_cpplib_srcs:.c=.d)
+
+lwcc_deps := $(lwcc_cpp_deps) $(lwcc_driver_deps) $(lwcc_cpplib_deps) $(lwcc_cc_deps)
+
+.PHONY: lwlink lwasm lwar lwobjdump lwcc
 lwlink: lwlink/lwlink$(PROGSUFFIX)
 lwasm: lwasm/lwasm$(PROGSUFFIX)
 lwar: lwar/lwar$(PROGSUFFIX)
 lwobjdump: lwlink/lwobjdump$(PROGSUFFIX)
+lwcc: lwcc/lwcc$(PROGSUFFIX)
+lwcc-cpp: lwcc/lwcc-cpp$(PROGSUFFIX)
+lwcc-cpplib: lwcc/libcpp.a
 
 lwasm/lwasm$(PROGSUFFIX): $(lwasm_objs) lwlib
 	@echo Linking $@
@@ -93,6 +146,25 @@
 	@echo Linking $@
 	@$(CC) -o $@ $(lwar_objs) $(LDFLAGS)
 
+lwcc/lwcc$(PROGSUFFIX): $(lwcc_driver_objs) lwlib
+	@echo Linking $@
+	@$(CC) -o $@ $(lwcc_driver_objs) $(LDFLAGS)
+
+lwcc/lwcc-cpp$(PROGSUFFIX): $(lwcc_cpp_objs) lwlib lwcc-cpplib
+	@echo Linking $@
+	@$(CC) -o $@ $(lwcc_cpp_objs) lwcc/libcpp.a $(LDFLAGS)
+
+lwcc/lwcc-cc$(PROGSUFFIX): $(lwcc_cc_objs) lwlib lwcc-cpplib
+	@echo Linking $@
+	@$(CC) -o $@ $(lwcc_cc_objs) lwcc/libcpp.a $(LDFLAGS)
+
+.INTERMEDIATE: lwcc-cpplib
+lwcc-cpplib: lwcc/libcpp.a
+lwcc/libcpp.a: $(lwcc_cpplib_objs)
+	@echo Linking $@
+	@$(AR) rc $@ $(lwcc_cpplib_objs)
+	@$(RANLIB) $@
+
 #.PHONY: lwlib
 .INTERMEDIATE: lwlib
 lwlib: lwlib/liblw.a
@@ -102,15 +174,26 @@
 	@$(AR) rc $@ $(lwlib_objs)
 	@$(RANLIB) $@
 
-alldeps := $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) ($lwobjdump_deps)
+alldeps := $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) ($lwobjdump_deps) $(lwcc_deps)
 
 -include $(alldeps)
 
 extra_clean := $(extra_clean) *~ */*~
 
+lwcc/parse_c.c lwcc/parse_c.h: lwcc/parse_c.y
+	rm -f lwcc/parse_c.h lwcc/parse_c.c
+	lemon -q lwcc/parse_c.y
+
+lwcc/token_names.c: lwcc/parse_c.h
+	echo "char *ptoken_names[] = {" > $@
+	echo '"TOKEN_NONE",' >> $@
+	cat lwcc/parse_c.h | sed -e 's/#define \(.*\) .*$$/"\1",/g' -e 's/ //g' >> $@
+	echo '"" };' >> $@
+
+
 %.o: %.c
 	@echo "Building dependencies for $@"
-	@$(CC) -MM $(CPPFLAGS) -o $*.d $<
+	@$(CC) -MM -MG $(CPPFLAGS) -o $*.d $<
 	@mv -f $*.d $*.d.tmp
 	@sed -e 's|.*:|$*.o $*.d:|' < $*.d.tmp > $*.d
 	@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@@ -123,6 +206,8 @@
 clean: $(cleantargs)
 	@echo "Cleaning up"
 	@rm -f lwlib/liblw.a lwasm/lwasm$(PROGSUFFIX) lwlink/lwlink$(PROGSUFFIX) lwlink/lwobjdump$(PROGSUFFIX) lwar/lwar$(PROGSUFFIX)
+	@rm -f lwcc/lwcc$(PROGSUFFIX) lwcc/lwcc-cpp$(PROGSUFFIX) lwcc/libcpp.a
+	@rm -f $(lwcc_driver_objs) $(lwcc_cpp_objs) $(lwcc_cpplib_objs) $(lwcc_cc_objs)
 	@rm -f $(lwasm_objs) $(lwlink_objs) $(lwar_objs) $(lwlib_objs) $(lwobjdump_objs)
 	@rm -f $(extra_clean)
 	@rm -f */*.exe
@@ -131,6 +216,7 @@
 realclean: clean $(realcleantargs)
 	@echo "Cleaning up even more"
 	@rm -f $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) $(lwobjdump_deps)
+	@rm -f $(lwcc_driver_deps) $(lwcc_cpp_deps) $(lwcc_cpplib_deps) $(lwcc_cc_deps)
 
 print-%:
 	@echo $* = $($*)
@@ -139,6 +225,19 @@
 install: $(MAIN_TARGETS)
 	install -d $(INSTALLDIR)
 	install $(MAIN_TARGETS) $(INSTALLDIR)
+	install -d $(LWCC_INSTALLLIBDIR)
+	install -d $(LWCC_INSTALLLIBDIR)/bin
+	install -d $(LWCC_INSTALLLIBDIR)/lib
+	install -d $(LWCC_INSTALLLIBDIR)/include
+ifneq ($(LWCC_LIBBIN_FILES),)
+	install $(LWCC_LIBBIN_FILES) $(LWCC_INSTALLLIBDIR)/bin
+endif
+ifneq ($(LWCC_LIBLIB_FILES),)
+	install $(LWCC_LIBLIB_FILES) $(LWCC_INSTALLLIBDIR)/lib
+endif
+ifneq ($(LWCC_LIBINC_FILES),)
+	install $(LWCC_LIBINC_FILES) $(LWCC_INSTALLLIBDIR)/include
+endif
 
 .PHONY: test
 test: all test/runtests