aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Makefile
diff options
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile334
1 files changed, 171 insertions, 163 deletions
diff --git a/Makefile b/Makefile
index 0bd370b8..53e70937 100644
--- a/Makefile
+++ b/Makefile
@@ -1,96 +1,153 @@
VERSION=0.5.2
-# Generating file version.h if current version has changed
-SPARSE_VERSION:=$(shell git describe 2>/dev/null || echo '$(VERSION)')
-VERSION_H := $(shell cat version.h 2>/dev/null)
-ifneq ($(lastword $(VERSION_H)),"$(SPARSE_VERSION)")
-$(info $(shell echo ' GEN 'version.h))
-$(shell echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h)
-endif
-
+########################################################################
+# The following variables can be overwritten from the command line
OS = linux
CC = gcc
-COMMON_CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
-COMMON_CFLAGS += -Wall -Wwrite-strings
-LDFLAGS += -g
+CFLAGS = -O2 -finline-functions -g
+CFLAGS += -Wall -Wwrite-strings
LD = gcc
AR = ar
PKG_CONFIG = pkg-config
CHECKER = CHECK=./sparse ./cgcc -no-compile
-CHECKER_FLAGS =
+CHECKER_FLAGS = -Wno-vla
-ALL_CFLAGS = $(COMMON_CFLAGS) $(PKG_CFLAGS) $(CFLAGS)
-#
+DESTDIR=
+PREFIX ?= $(HOME)
+BINDIR=$(PREFIX)/bin
+MANDIR=$(PREFIX)/share/man
+MAN1DIR=$(MANDIR)/man1
+
+# Allow users to override build settings without dirtying their trees
# For debugging, put this in local.mk:
#
# CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
#
+SPARSE_LOCAL_CONFIG ?= local.mk
+-include ${SPARSE_LOCAL_CONFIG}
+########################################################################
+
+
+LIB_OBJS :=
+LIB_OBJS += allocate.o
+LIB_OBJS += builtin.o
+LIB_OBJS += char.o
+LIB_OBJS += compat-$(OS).o
+LIB_OBJS += cse.o
+LIB_OBJS += dissect.o
+LIB_OBJS += evaluate.o
+LIB_OBJS += expand.o
+LIB_OBJS += expression.o
+LIB_OBJS += flow.o
+LIB_OBJS += inline.o
+LIB_OBJS += lib.o
+LIB_OBJS += linearize.o
+LIB_OBJS += liveness.o
+LIB_OBJS += memops.o
+LIB_OBJS += opcode.o
+LIB_OBJS += optimize.o
+LIB_OBJS += parse.o
+LIB_OBJS += pre-process.o
+LIB_OBJS += ptrlist.o
+LIB_OBJS += scope.o
+LIB_OBJS += show-parse.o
+LIB_OBJS += simplify.o
+LIB_OBJS += sort.o
+LIB_OBJS += stats.o
+LIB_OBJS += storage.o
+LIB_OBJS += symbol.o
+LIB_OBJS += target.o
+LIB_OBJS += tokenize.o
+LIB_OBJS += unssa.o
+
+PROGRAMS :=
+PROGRAMS += compile
+PROGRAMS += ctags
+PROGRAMS += example
+PROGRAMS += graph
+PROGRAMS += obfuscate
+PROGRAMS += sparse
+PROGRAMS += test-dissect
+PROGRAMS += test-lexing
+PROGRAMS += test-linearize
+PROGRAMS += test-parsing
+PROGRAMS += test-unssa
-HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
-HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
- $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
- echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
+INST_PROGRAMS=sparse cgcc
+INST_MAN1=sparse.1 cgcc.1
-GTK_VERSION:=3.0
-HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
-ifneq ($(HAVE_GTK),yes)
- GTK_VERSION:=2.0
- HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
-endif
-LLVM_CONFIG:=llvm-config
-HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
+all:
+
+########################################################################
+# common flags/options/...
+
+cflags = -fno-strict-aliasing
GCC_BASE := $(shell $(CC) --print-file-name=)
-COMMON_CFLAGS += -DGCC_BASE=\"$(GCC_BASE)\"
+cflags += -DGCC_BASE=\"$(GCC_BASE)\"
MULTIARCH_TRIPLET := $(shell $(CC) -print-multiarch 2>/dev/null)
-COMMON_CFLAGS += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
+cflags += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
-ifeq ($(HAVE_GCC_DEP),yes)
-COMMON_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
-endif
+########################################################################
+# target specificities
-DESTDIR=
-PREFIX=$(HOME)
-BINDIR=$(PREFIX)/bin
-LIBDIR=$(PREFIX)/lib
-MANDIR=$(PREFIX)/share/man
-MAN1DIR=$(MANDIR)/man1
-INCLUDEDIR=$(PREFIX)/include
-PKGCONFIGDIR=$(LIBDIR)/pkgconfig
+compile: compile-i386.o
+EXTRA_OBJS += compile-i386.o
-PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
- test-linearize example test-unssa test-dissect ctags
-INST_PROGRAMS=sparse cgcc
-INST_MAN1=sparse.1 cgcc.1
+# Can we use GCC's generated dependencies?
+HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
+ $(CC) -c -Wp,-MP,-MMD,.gcc-test.d .gcc-test.c 2>/dev/null && \
+ echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
+ifeq ($(HAVE_GCC_DEP),yes)
+cflags += -Wp,-MP,-MMD,$(@D)/.$(@F).d
+endif
+# Can we use libxml (needed for c2xml)?
+HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
ifeq ($(HAVE_LIBXML),yes)
PROGRAMS+=c2xml
INST_PROGRAMS+=c2xml
-c2xml_EXTRA_OBJS = `$(PKG_CONFIG) --libs libxml-2.0`
-LIBXML_CFLAGS := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
+c2xml-ldlibs := $(shell $(PKG_CONFIG) --libs libxml-2.0)
+c2xml-cflags := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
else
$(warning Your system does not have libxml, disabling c2xml)
endif
+# Can we use gtk (needed for test-inspect)
+GTK_VERSION:=3.0
+HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
+ifneq ($(HAVE_GTK),yes)
+GTK_VERSION:=2.0
+HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
+endif
ifeq ($(HAVE_GTK),yes)
GTK_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-$(GTK_VERSION))
-GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION))
+ast-view-cflags := $(GTK_CFLAGS)
+ast-model-cflags := $(GTK_CFLAGS)
+ast-inspect-cflags := $(GTK_CFLAGS)
+test-inspect-cflags := $(GTK_CFLAGS)
+test-inspect-ldlibs := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION))
+test-inspect: ast-model.o ast-view.o ast-inspect.o
+EXTRA_OBJS += ast-model.o ast-view.o ast-inspect.o
PROGRAMS += test-inspect
INST_PROGRAMS += test-inspect
-test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
-test-inspect_OBJS := test-inspect.o $(test-inspect_EXTRA_DEPS)
-$(test-inspect_OBJS) $(test-inspect_OBJS:.o=.sc): PKG_CFLAGS += $(GTK_CFLAGS)
-test-inspect_EXTRA_OBJS := $(GTK_LIBS)
else
$(warning Your system does not have gtk3/gtk2, disabling test-inspect)
endif
+# Can we use LLVM (needed for ... sparse-llvm)?
+LLVM_CONFIG:=llvm-config
+HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
ifeq ($(HAVE_LLVM),yes)
-ifeq ($(shell uname -m | grep -q '\(i386\|x86\)' && echo ok),ok)
+arch := $(shell uname -m)
+ifeq (${MULTIARCH_TRIPLET},x86_64-linux-gnux32)
+arch := x32
+endif
+ifneq ($(filter ${arch},i386 i486 i586 i686 x86_64 amd64),)
LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
ifeq ($(shell expr "$(LLVM_VERSION)" : '[3-9]\.'),2)
LLVM_PROGS := sparse-llvm
@@ -101,145 +158,96 @@ LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
PROGRAMS += $(LLVM_PROGS)
INST_PROGRAMS += sparse-llvm sparsec
-sparse-llvm.o sparse-llvm.sc: PKG_CFLAGS += $(LLVM_CFLAGS)
-sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS) $(LLVM_LDFLAGS)
+sparse-llvm-cflags := $(LLVM_CFLAGS)
+sparse-llvm-ldflags := $(LLVM_LDFLAGS)
+sparse-llvm-ldlibs := $(LLVM_LIBS)
else
$(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
endif
else
-$(warning sparse-llvm disabled on $(shell uname -m))
+$(warning sparse-llvm disabled on ${arch})
endif
else
$(warning Your system does not have llvm, disabling sparse-llvm)
endif
-LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
- linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
- storage.h ptrlist.h dissect.h
+########################################################################
+LIBS := libsparse.a
+OBJS := $(LIB_OBJS) $(EXTRA_OBJS) $(PROGRAMS:%=%.o)
-LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
- expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
- char.o sort.o allocate.o compat-$(OS).o ptrlist.o \
- builtin.o \
- stats.o \
- flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o
+# Pretty print
+V := @
+Q := $(V:1=)
-LIB_FILE= libsparse.a
-SLIB_FILE= libsparse.so
+########################################################################
+all: $(PROGRAMS)
-# If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
-# Doing so incurs a noticeable performance hit, and Sparse does not have a
-# stable shared library interface, so this does not occur by default. If you
-# really want a shared library, you may want to build Sparse twice: once
-# without -fpic to get all the Sparse tools, and again with -fpic to get the
-# shared library.
-LIBS=$(LIB_FILE)
+ldflags += $($(@)-ldflags) $(LDFLAGS)
+ldlibs += $($(@)-ldlibs) $(LDLIBS)
+$(PROGRAMS): % : %.o $(LIBS)
+ @echo " LD $@"
+ $(Q)$(LD) $(ldflags) $^ $(ldlibs) -o $@
-#
-# Pretty print
-#
-V = @
-Q = $(V:1=)
-QUIET_CC = $(Q:@=@echo ' CC '$@;)
-QUIET_CHECK = $(Q:@=@echo ' CHECK '$<;)
-QUIET_AR = $(Q:@=@echo ' AR '$@;)
-QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
-QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
-# We rely on the -v switch of install to print 'file -> $install_dir/file'
-QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
-QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
+libsparse.a: $(LIB_OBJS)
+ @echo " AR $@"
+ $(Q)$(AR) rcs $@ $^
-define INSTALL_EXEC
- $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
-endef
+cflags += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS)
+%.o: %.c
+ @echo " CC $@"
+ $(Q)$(CC) $(cflags) -c -o $@ $<
-define INSTALL_FILE
- $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
+%.sc: %.c sparse
+ @echo " CHECK $<"
+ $(Q) $(CHECKER) $(CHECKER_FLAGS) $(cflags) -c $<
-endef
+selfcheck: $(OBJS:.o=.sc)
-SED_PC_CMD = 's|@version@|$(VERSION)|g; \
- s|@prefix@|$(PREFIX)|g; \
- s|@libdir@|$(LIBDIR)|g; \
- s|@includedir@|$(INCLUDEDIR)|g'
+SPARSE_VERSION:=$(shell git describe --dirty 2>/dev/null || echo '$(VERSION)')
+lib.o: version.h
+version.h: FORCE
+ @echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h.tmp
+ @if cmp -s version.h version.h.tmp; then \
+ rm version.h.tmp; \
+ else \
+ echo " GEN $@"; \
+ mv version.h.tmp version.h; \
+ fi
-# Allow users to override build settings without dirtying their trees
--include local.mk
+check: all
+ $(Q)cd validation && ./test-suite
+validation/%.t: $(PROGRAMS)
+ @validation/test-suite single $*.c
-all: $(PROGRAMS) sparse.pc
+clean: clean-check
+ @rm -f *.[oa] .*.d $(PROGRAMS) version.h
+clean-check:
+ @echo " CLEAN"
+ @find validation/ \( -name "*.c.output.*" \
+ -o -name "*.c.error.*" \
+ -o -name "*.o" \
+ \) -exec rm {} \;
-all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
-install: all-installable
+install: $(INST_PROGRAMS) $(INST_MAN1) install-dirs install-bin install-man
+install-dirs:
$(Q)install -d $(DESTDIR)$(BINDIR)
- $(Q)install -d $(DESTDIR)$(LIBDIR)
$(Q)install -d $(DESTDIR)$(MAN1DIR)
- $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
- $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
- $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
- $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
- $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
- $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
- $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
-
-sparse.pc: sparse.pc.in
- $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
-
-
-compile_EXTRA_DEPS = compile-i386.o
+install-bin: $(INST_PROGRAMS:%=$(DESTDIR)$(BINDIR)/%)
+install-man: $(INST_MAN1:%=$(DESTDIR)$(MAN1DIR)/%)
-$(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
-$(PROGRAMS): % : %.o
- $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
+$(DESTDIR)$(BINDIR)/%: %
+ @echo " INSTALL $@"
+ $(Q)install $< $@ || exit 1;
+$(DESTDIR)$(MAN1DIR)/%: %
+ @echo " INSTALL $@"
+ $(Q)install -m 644 $< $@ || exit 1;
-$(LIB_FILE): $(LIB_OBJS)
- $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
+.PHONY: FORCE
-$(SLIB_FILE): $(LIB_OBJS)
- $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
-
-DEP_FILES := $(wildcard .*.o.d)
-
-ifneq ($(DEP_FILES),)
-include $(DEP_FILES)
-endif
-
-c2xml.o c2xml.sc: PKG_CFLAGS += $(LIBXML_CFLAGS)
-
-pre-process.sc: CHECKER_FLAGS += -Wno-vla
-
-%.o: %.c $(LIB_H)
- $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
-
-%.sc: %.c sparse
- $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(ALL_CFLAGS) $<
-
-ALL_OBJS := $(LIB_OBJS) $(foreach p,$(PROGRAMS),$(p).o $($(p)_EXTRA_DEPS))
-selfcheck: $(ALL_OBJS:.o=.sc)
-
-
-clean: clean-check
- rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc version.h
-
-dist:
- @if test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
- echo 'Update VERSION in the Makefile before running "make dist".' ; \
- exit 1 ; \
- fi
- git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
-
-check: all
- $(Q)cd validation && ./test-suite
-
-clean-check:
- find validation/ \( -name "*.c.output.expected" \
- -o -name "*.c.output.got" \
- -o -name "*.c.output.diff" \
- -o -name "*.c.error.expected" \
- -o -name "*.c.error.got" \
- -o -name "*.c.error.diff" \
- \) -exec rm {} \;
+# GCC's dependencies
+-include $(OBJS:%.o=.%.o.d)