Permalink
Browse files

Adjusted examples make system to work for 64-bit binaries on 32-bit m…

…achines

- This is needed for OS X on most machines
- Most examples are 64-bit specific, so we can't compile them to 32-bit just by adding "is64bit: false"
- Included a 32.mk makefile include for future reference
- Added system requirements to HOW_TO_BUILD
  • Loading branch information...
1 parent 01eba8e commit f7eaa8beaae7cebe548173a891498e097ced5bb2 Jay Conrod committed Jun 16, 2011
Showing with 78 additions and 27 deletions.
  1. +19 −0 examples/32.mk
  2. +12 −0 examples/64.mk
  3. +10 −0 examples/HOW_TO_BUILD
  4. +12 −27 examples/Makefile
  5. +25 −0 examples/common.mk
View
@@ -0,0 +1,19 @@
+# NOTE: This file is currently not used. It is provided for reference when we
+# add some 32-bit examples.
+
+LLVM_RUNTIME_SOURCE = ../llvm/runtime/runtime32.ll
+RUNTIME_NAME = $(notdir $(LLVM_RUNTIME_SOURCE))
+
+LDFLAGS = -m32
+
+$(PROGRAMS): $(RUNTIME_NAME:%.ll=%.s)
+
+$(RUNTIME_NAME): $(LLVM_RUNTIME_SOURCE)
+ sed -e 's/target triple = "i386-linux-gnu"/target triple = "i386-$(OS)"/' <$< >$@
+
+%.w32: %.w
+ echo "is64bit: false" >$@
+ cat <$< >>$@
+
+%.wo: %.w32
+ w-as <$< >$@
View
@@ -0,0 +1,12 @@
+LLVM_RUNTIME_SOURCE = ../llvm/runtime/runtime64.ll
+RUNTIME_NAME = $(notdir $(LLVM_RUNTIME_SOURCE))
+
+LDFLAGS = -m64
+
+$(PROGRAMS): $(RUNTIME_NAME:%.ll=%.s)
+
+$(RUNTIME_NAME): $(LLVM_RUNTIME_SOURCE)
+ sed -e 's/target triple = "x86_64-linux-gnu"/target triple = "x86_64-$(OS)"/' <$< >$@
+
+%.wo: %.w
+ w-as <$< >$@
View
@@ -1,5 +1,15 @@
Building Tungsten to native code requires several steps.
+==System Requirements==
+
+Tungsten supports 32- and 64-bit systems UNIX based systems. However,
+the examples here are 64-bit specific, and most will not run on 32-bit
+systems without some modification. The examples have been tested on
+Linux and OS X.
+
+If you have a 32-bit system that can compile and run 64-bit binaries
+(such as OS X on most Macs), you should be fine.
+
==Prerequisites==
You must have successfully run "buildr install" in the root directory
View
@@ -1,39 +1,24 @@
-SOURCES = $(wildcard *.w)
-PROGRAMS = $(SOURCES:%.w=%)
-
-LLVM_RUNTIME_SOURCE = ../llvm/runtime/runtime.ll
-
.PHONY: all, clean
+# SECONDARY designates all implicit intermediate files as secondary targets. This means
+# they won't be deleted when make runs. This can be kind of annoying if the program
+# generating the intermediate files errors out, but it's interesting to have these files
+# around.
.SECONDARY:
+SOURCES = $(wildcard *.w)
+PROGRAMS = $(SOURCES:%.w=%)
+
all: $(PROGRAMS)
clean:
- rm -f *.ll *.bc *.s *.wo *.wl *.wp $(PROGRAMS)
+ rm -f *.ll *.bc *.s *.w32 *.wo *.wl *.wp $(PROGRAMS)
$(foreach program,$(PROGRAMS),\
$(eval $(program):$(program).s))
-$(PROGRAMS): runtime.s
- gcc $^ -o $@
-
-runtime.ll: $(LLVM_RUNTIME_SOURCE)
- cp $< $@
-
-%.wo: %.w
- w-as <$< >$@
-
-%.wp: %.wo
- w-link -t program $^ -o $@
-
-%.ll: %.wp
- w-to-llvm <$< >$@
-
-%.bc: %.ll
- llvm-as <$< >$@
-
-%.s: %.bc
- llc <$< >$@
-
+$(PROGRAMS):
+ clang $(LDFLAGS) $^ -o $@
+include common.mk
+include 64.mk
View
@@ -0,0 +1,25 @@
+UNAME = $(shell uname -a)
+ifeq (Darwin,$(findstring Darwin,$(UNAME)))
+ OS=apple-darwin10.0.0
+else
+ ifeq (Linux,$(findstring Linux,$(UNAME)))
+ OS=linux-gnu
+ endif
+endif
+ifeq (i386,$(findstring i386,$(UNAME)))
+ ARCH=i386
+else
+ ARCH=x86_64
+endif
+
+%.wp: %.wo
+ w-link -t program $^ -o $@
+
+%.ll: %.wp
+ w-to-llvm <$< >$@
+
+%.bc: %.ll
+ llvm-as <$< >$@
+
+%.s: %.bc
+ llc <$< >$@

0 comments on commit f7eaa8b

Please sign in to comment.