ariovistus avatar ariovistus committed c61874d

experiment with the tup build system.
is pretty cool. will it work on windows?
tried coaxing a shared lib out of gdc. no dice.

Comments (0)

Files changed (21)

 syntax: glob
 *.pyc
 *.o
+*.a
 *.so
 *.x
 *.lib
 *.obj
 junk.txt
 MANIFEST
+.tup
 examples/arraytest/tsetup.py
 examples/hello/tsetup.py
 examples/inherit/tsetup.py
+include_rules
+: $(PYD_FILES) |> $(DC) $(DFLAGS) $(PY27_VERSION) $(PYD_INCLUDE) -lib %f $(DOUT)%o |> pyd27.a 
+: $(PYD_FILES) |> $(DC) $(DFLAGS) $(PY32_VERSION) $(PYD_INCLUDE) -lib %f $(DOUT)%o |> pyd32.a 
+
+DC=dmd
+#DC=ldc2
+#DC=gdc
+
+ifeq ($(DC),dmd)
+DVERSION = -version=
+DFLAGS = -unittest -property
+DOUT = -of
+export DOUT
+DINCLUDE = -I
+DC_LIB = -L-l
+else
+ifeq ($(DC),ldc2)
+DVERSION = -d-version=
+DOUT = -of 
+DINCLUDE = -I
+DC_LIB = -L-l
+else
+ifeq ($(DC),gdc)
+# todo
+DVERSION = -version=
+DOUT = -o 
+DINCLUDE = -I
+DC_LIB = -l
+endif
+endif
+endif
+
+PY24_VERSION = $(DVERSION)Python_2_4_Or_Later 
+PY25_VERSION = $(PY24_VERSION) 
+PY25_VERSION += $(DVERSION)Python_2_5_Or_Later 
+PY26_VERSION = $(PY25_VERSION) 
+PY26_VERSION += $(DVERSION)Python_2_6_Or_Later 
+PY27_VERSION = $(PY26_VERSION) 
+PY27_VERSION += $(DVERSION)Python_2_7_Or_Later 
+PY32_VERSION = $(PY27_VERSION) 
+PY32_VERSION += $(DVERSION)Python_3_0_Or_Later 
+PY32_VERSION += $(DVERSION)Python_3_1_Or_Later 
+PY32_VERSION += $(DVERSION)Python_3_2_Or_Later 
+
+PY24_LIB = $(DC_LIB)python2.4
+PY25_LIB = $(DC_LIB)python2.5
+PY26_LIB = $(DC_LIB)python2.6
+PY27_LIB = $(DC_LIB)python2.7
+PY32_LIB = $(DC_LIB)python3.2mu
+
+TOPDIR = $(TUP_CWD)
+PYD_FILES += $(TOPDIR)/infrastructure/deimos/python/*.d
+PYD_FILES += $(TOPDIR)/infrastructure/pyd/*.d
+PYD_FILES += $(TOPDIR)/infrastructure/meta/*.d
+PYD_FILES += $(TOPDIR)/infrastructure/util/*.d
+
+PYD_INCLUDE = $(DINCLUDE)$(TOPDIR)/infrastructure
+
+#dc_py24
+#dc_py25
+#dc_py26
+!dc_py27 = | $(TOPDIR)/pyd27.a |> $(DC) $(DFLAGS) $(PY27_VERSION) $(PY27_LIB) $(PYD_INCLUDE) %f $(TOPDIR)/pyd27.a -of%o && rm -f %B.o |> %B.x
+!dc_py32 = | $(TOPDIR)/pyd32.a |> $(DC) $(DFLAGS) $(PY32_VERSION) $(PY32_LIB) $(PYD_INCLUDE) %f $(TOPDIR)/pyd32.a -of%o && rm -f %B.o |> %B.x
+#dc_py32
+

examples/deimos_unittests/Tupfile

+include_rules
+
+: foreach *.d |> !dc_py27 |>

examples/misc/dmd_sharedlibs/Tupfile

+
+include_rules
+BITSI = 32
+ifeq ($(BITSI),32)
+DMD_M=-m32
+GCC_M=-m32
+else	
+ifeq ($(BITSI),64)
+DMD_M=-m64
+GCC_M=-m64
+else
+DMD_M=
+GCC_M=
+endif
+endif
+DMD=dmd $(DMD_M) -unittest
+GCC=gcc $(GCC_M)
+
+!link_lib = | boilerplate.d so_ctor.o |> $(DMD) -fPIC -shared %f boilerplate.d so_ctor.o -of%o && rm -f lib%B.o |> lib%B.so 
+
+: so_ctor.c |> $(GCC) -c %f -o %o |> %B.o
+: test1.d |> !link_lib |> 
+: test2a.d |> !link_lib |> 
+: test2b.d |> !link_lib |>
+: test1.c libtest1.so |> $(GCC) test1.c $(TUP_CWD)/libtest1.so -o %o |> test1.x
+: test2.c libtest2a.so libtest2b.so |> $(GCC) test2.c $(TUP_CWD)/libtest2a.so $(TUP_CWD)/libtest2b.so -o %o |> test2.x
+
+: test3lib.c |> $(GCC) -fPIC -shared %f -o %o |> libtest3.so
+
+: test3.d libtest3.so |> $(DMD) test3.d -L$(TUP_CWD)/libtest3.so -of%o && rm test3.o |> test3.x

examples/misc/dmd_sharedlibs/makefile

 
 # build a shared lib with d, link to it from c.
 test1: test1.x libtest1.so
-	LD_LIBRARY_PATH=. ./test1.x
+	./test1.x
 # build two shared libs with d, link to both from c.
 test2: test2.x libtest2a.so libtest2b.so
-	LD_LIBRARY_PATH=. ./test2.x
+	./test2.x
 test3: test3.x libtest3.so
-	LD_LIBRARY_PATH=. ./test3.x
+	./test3.x
 clean:
 	rm -f *.o
 	rm -f *.so
 	rm -f *.x
 
-lib%.so: %.d boilerplate.d test1helper.o 
+lib%.so: %.d boilerplate.d so_ctor.o 
 	$(DMD) -unittest -fPIC -shared $^ -of$@
-test1helper.o: test1helper.c
-	$(GCC) -c test1helper.c -o test1helper.o
+so_ctor.o: so_ctor.c
+	$(GCC) -c so_ctor.c -o so_ctor.o
 
 test1.x: test1.c libtest1.so
-	LD_LIBRARY_PATH=. $(GCC) $< -L. -ltest1 -o $@
+	$(GCC) $< `pwd`/libtest1.so -o $@
 test2.x: test2.c libtest2a.so libtest2b.so
-	LD_LIBRARY_PATH=. $(GCC) $< -L. -ltest2a -ltest2b -o $@
+	$(GCC) $< `pwd`/libtest2a.so `pwd`/libtest2b.so -o $@
 test3.x: test3.d libtest3.so
-	LD_LIBRARY_PATH=. dmd $< -L-L. -L-ltest3 -of$@ 
+	dmd $< -L`pwd`/libtest3.so -of$@ 
 libtest3.so: test3lib.c
 	gcc -fPIC -shared $< -o $@
 

examples/misc/dmd_sharedlibs/so_ctor.c

+void my_init();
+void my_fini();
+
+__attribute__((__constructor__)) void actual_init() {
+    my_init();
+}
+

examples/misc/dmd_sharedlibs/test1helper.c

-void my_init();
-void my_fini();
-
-__attribute__((__constructor__)) void actual_init() {
-    my_init();
-}
-

examples/misc/gdc_sharedlibs/boilerplate.d

+extern(C) shared bool _D2rt6dmain212_d_isHaltingOb;
+alias _D2rt6dmain212_d_isHaltingOb _d_isHalting;
+extern(C) {
+
+    void rt_init();
+    void rt_term();
+
+    void my_init() {
+        rt_init();
+    }
+
+    void my_fini() {
+        if(!_d_isHalting){
+            rt_term();
+        }
+    }
+
+}
+
+// (*^*&%^(* druntime
+
+extern(C) void _Dmain(){}

examples/misc/gdc_sharedlibs/makefile

+# ###########################################################
+# from fedora repos
+GDC=gdc
+
+# build a shared library written in D, main program written in C.
+test1: test1.x libtest1.so
+	LD_LIBRARY_PATH=. ./test1.x
+
+# build 2 shared libraries written in D, main program written in C.
+# not working: druntime needs some tlc.
+test2: test2.x libtest2a.so libtest2b.so
+	LD_LIBRARY_PATH=. ./test2.x
+# build a shared library written in C with global data. Access global data in D
+test3: test3.x libtest3.so
+	LD_LIBRARY_PATH=. ./test3.x
+clean:
+	rm -f *.o
+	rm -f *.so
+	rm -f *.x
+
+LIBS= -lrt -lpthread -ldl -lm -lpython2.7 /usr/lib64/libgdruntime.a /usr/lib64/libgphobos2.a
+
+%.o: %.d
+	echo "building $@"
+	$(GDC) -fPIC -c $^ -o $@
+
+lib%.so: %.o boilerplate.o
+	echo "building $@"
+	gcc -nostartfiles -shared $(LIBS) $^ -o $@ 
+
+test1.x: test1.c libtest1.so
+	echo "building $@"
+	gcc $< -l:libtest1.so -o $@ 
+
+test2.x: test2.c libtest2a.so libtest2b.so
+	echo "building $@"
+	LD_LIBRARY_PATH=. gcc $< -L. -ltest2a -ltest2b -o $@
+
+test3.x: test3.d libtest3.so
+	LD_LIBRARY_PATH=. $(GDC) $< -L. -ltest3 -of $@ 
+libtest3.so: test3lib.c
+	gcc -fPIC -shared $< -o $@
+
+# ###########################################################

examples/misc/gdc_sharedlibs/test1.c

+#include <stdio.h>
+int foo(int);
+
+int main() {
+    printf("Success! foo(%d)=%d\n", 2, foo(2));
+    return 0;
+}
+

examples/misc/gdc_sharedlibs/test1.d

+// stuff in our library
+
+static this() {
+    import std.stdio;
+    writeln("yawn. stretch.");
+}
+
+unittest {
+    import std.stdio;
+    writeln("running a unittest");
+}
+
+extern(C) int foo(int i) {
+    return i+1;
+}
+

examples/misc/ldc_sharedlibs/Tupfile

+include_rules
+
+LDC = ldc2
+LIBS= -Wl,--no-as-needed -lphobos-ldc -ldruntime-ldc -lrt -lpthread -ldl -lm -lpython2.7
+
+!link_lib = | boilerplate.o |> gcc -nostartfiles -shared $(LIBS) %f boilerplate.o -o %o |> lib%B.so
+
+: foreach *.d |> $(LDC) -relocation-model=pic -c %f -of %o |> %B.o
+: test1.o |> !link_lib |> 
+: test2a.o |> !link_lib |> 
+: test2b.o |> !link_lib |>
+: test1.c libtest1.so |> gcc test1.c $(TUP_CWD)/libtest1.so -o %o |> test1.x
+: test2.c libtest2a.so libtest2b.so |> gcc test2.c $(TUP_CWD)/libtest2a.so $(TUP_CWD)/libtest2b.so -o %o |> test2.x
+
+: test3lib.c |> gcc -fPIC -shared %f -o %o |> libtest3.so
+
+: test3.o libtest3.so |> $(LDC) test3.o -L$(TUP_CWD)/libtest3.so -of %o |> test3.x

examples/misc/ldc_sharedlibs/boilerplate.d

+extern(C) shared bool _D2rt6dmain212_d_isHaltingOb;
+alias _D2rt6dmain212_d_isHaltingOb _d_isHalting;
+extern(C) {
+
+    void rt_init();
+    void rt_term();
+
+    void my_init() {
+        rt_init();
+    }
+
+    void my_fini() {
+        if(!_d_isHalting){
+            rt_term();
+        }
+    }
+
+}
+
+// (*^*&%^(* druntime
+
+extern(C) void _Dmain(){}

examples/misc/ldc_sharedlibs/makefile

 
 # build a shared library written in D, main program written in C.
 test1: test1.x libtest1.so
-	LD_LIBRARY_PATH=. ./test1.x
+	./test1.x
 
 # build 2 shared libraries written in D, main program written in C.
 # not working: druntime needs some tlc.
 test2: test2.x libtest2a.so libtest2b.so
-	LD_LIBRARY_PATH=. ./test2.x
+	./test2.x
 # build a shared library written in C with global data. Access global data in D
 test3: test3.x libtest3.so
-	LD_LIBRARY_PATH=. ./test3.x
+	./test3.x
 clean:
 	rm -f *.o
 	rm -f *.so
 	echo "building $@"
 	$(LDC) -relocation-model=pic -c $^ -of $@
 
-lib%.so: %.o
+lib%.so: %.o boilerplate.o
 	echo "building $@"
 	gcc -nostartfiles -shared $(LIBS) $^ -o $@ 
 
 test1.x: test1.c libtest1.so
 	echo "building $@"
-	gcc $< -l:libtest1.so -o $@ 
+	gcc $< `pwd`/libtest1.so -o $@ 
 
 test2.x: test2.c libtest2a.so libtest2b.so
 	echo "building $@"
-	LD_LIBRARY_PATH=. gcc $< -L. -ltest2a -ltest2b -o $@
+	gcc $< `pwd`/libtest2a.so `pwd`/libtest2b.so -o $@
 
 test3.x: test3.d libtest3.so
-	LD_LIBRARY_PATH=. $(LDC) $< -L-L. -L-ltest3 -of $@ 
+	$(LDC) $< -L`pwd`/libtest3.so -of $@ 
 libtest3.so: test3lib.c
 	gcc -fPIC -shared $< -o $@
 

examples/misc/ldc_sharedlibs/test1.d

     return i+1;
 }
 
-// stuff in infrastructure/d/python_so_boilerplate
-
-extern(C) shared bool _D2rt6dmain212_d_isHaltingOb;
-alias _D2rt6dmain212_d_isHaltingOb _d_isHalting;
-extern(C) {
-
-    void rt_init();
-    void rt_term();
-
-    void _init() {
-        rt_init();
-    }
-
-    void _fini() {
-        if(!_d_isHalting){
-            rt_term();
-        }
-    }
-
-}
-
-// (*^*&%^(* druntime
-
-extern(C) void _Dmain(){}

examples/misc/ldc_sharedlibs/test2a.d

     return i+2;
 }
 
-// stuff in infrastructure/d/python_so_boilerplate
-
-extern(C) shared bool _D2rt6dmain212_d_isHaltingOb;
-alias _D2rt6dmain212_d_isHaltingOb _d_isHalting;
-extern(C) {
-
-    void rt_init();
-    void rt_term();
-
-    void _init() {
-        rt_init();
-    }
-
-    void _fini() {
-        import std.c.stdio;
-        printf("_fini\n");
-        if(!_d_isHalting){
-            printf("rt_term\n");
-            rt_term();
-        }
-    }
-
-}
-
-// (*^*&%^(* druntime
-
-extern(C) void _Dmain(){}

examples/misc/ldc_sharedlibs/test2b.d

     return 3 + cast(int) d;
 }
 
-// stuff in infrastructure/d/python_so_boilerplate
-
-extern(C) shared bool _D2rt6dmain212_d_isHaltingOb;
-alias _D2rt6dmain212_d_isHaltingOb _d_isHalting;
-extern(C) {
-
-    void rt_init();
-    void rt_term();
-
-    void _init() {
-        rt_init();
-    }
-
-    void _fini() {
-            import std.c.stdio;
-            printf("_fini\n");
-        if(!_d_isHalting){
-            printf("rt_term\n");
-            rt_term();
-        }
-    }
-
-}
-
-// (*^*&%^(* druntime
-
-extern(C) void _Dmain(){}

examples/pyd_unittests/Tupfile

+include_rules
+: foreach *3.d |> !dc_py32 |> 
+: foreach *[^3].d |> !dc_py27 |>

examples/pyind/Tupfile

+include_rules
+
+
+#: |> echo $(TUP_CWD) | tee test.txt |> test.txt
+: pyind.d |> !dc_py27 |> 
+: pyind3.d |> !dc_py32 |>

infrastructure/deimos/python/object.d

 import deimos.python.structmember;
 import deimos.python.descrobject;
 
+pragma(msg, "lookie!");
+
 extern(C):
 // Python-header-file: Include/object.h:
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.