public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
Linux-related build changes.

Merged Linux and Darwin build files.
timburks (author)
Wed Mar 12 22:37:18 -0700 2008
commit  f1e2e5b2e9e521bf6b3857d56b41120199b28bac
tree    d915ed8dbf5f7fdc12ed4726b8ebd1ca8c99874e
parent  3aff2cd7234344cfca36985247f70f7c842dfb35
...
34
35
36
37
38
 
 
 
 
 
 
 
39
40
41
42
43
44
 
 
 
 
45
46
47
48
49
50
51
52
 
 
 
 
 
 
 
 
 
53
54
55
56
57
58
 
59
60
61
...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
...
98
99
100
101
102
103
104
...
109
110
111
112
113
 
 
 
 
 
 
 
114
115
116
 
 
 
117
118
119
...
34
35
36
 
 
37
38
39
40
41
42
43
44
 
45
46
47
 
48
49
50
51
52
53
 
 
 
 
 
 
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
68
69
70
71
...
78
79
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
123
124
125
 
126
127
128
...
133
134
135
 
 
136
137
138
139
140
141
142
143
144
 
145
146
147
148
149
150
0
@@ -34,28 +34,38 @@ END)
0
 (set @nib_files '("share/nu/resources/English.lproj/MainMenu.nib"))
0
 
0
 ;; libraries
0
-(set @frameworks '("Cocoa"))
0
-(set @libs '("edit" "ffi" ))
0
+(if (eq (uname) "Darwin")
0
+ (then (set @frameworks '("Cocoa"))
0
+ (set @libs '("edit" "ffi" ))
0
+ (set @lib_dirs (NSMutableArray arrayWithObject:"/usr/lib")))
0
+ (else (set @frameworks nil)
0
+ (set @libs (list "readline" "ffi" "m" ))
0
+ (set @lib_dirs (NSMutableArray arrayWithList:(list "../lib")))))
0
 
0
-(set @lib_dirs (NSMutableArray arrayWithObject:"/usr/lib"))
0
 (if (NSFileManager directoryExistsNamed:"#{@prefix}/lib") (@lib_dirs addObject:"#{@prefix}/lib"))
0
 
0
 ;; includes
0
-(set @includes "")
0
+(if (eq (uname) "Darwin")
0
+ (then (set @includes ""))
0
+ (else (set @includes " -I/usr/local/include")))
0
+
0
 (if (NSFileManager directoryExistsNamed:"#{@prefix}/include") (@includes appendString:" -I #{@prefix}/include"))
0
 
0
-(if (NSFileManager fileExistsNamed:"/usr/lib/libffi.dylib")
0
- (then ;; Use the libffi that ships with OS X.
0
- (@includes appendString:" -I /usr/include"))
0
- (else ;; Use the libffi that is distributed with Nu.
0
- (@includes appendString:" -I ./libffi/include")
0
- (@lib_dirs addObject:"./libffi")))
0
+(if (eq (uname) "Darwin")
0
+ (then (if (NSFileManager fileExistsNamed:"/usr/lib/libffi.dylib")
0
+ (then ;; Use the libffi that ships with OS X.
0
+ (@includes appendString:" -I /usr/include"))
0
+ (else ;; Use the libffi that is distributed with Nu.
0
+ (@includes appendString:" -I ./libffi/include")
0
+ (@lib_dirs addObject:"./libffi"))))
0
+ (else ;; Use the libffi that ships with Linux
0
+ (@includes appendString:" -I /usr/include")))
0
 
0
 ;; framework description
0
 (set @framework "Nu")
0
 (set @framework_identifier "nu.programming.framework")
0
 (set @framework_icon_file "nu.icns")
0
-(set @framework_initializer "NuInit")
0
+(if (eq (uname) "Darwin") (then (set @framework_initializer "NuInit")))
0
 (set @framework_creator_code "????")
0
 
0
 ;; build configuration
0
@@ -68,24 +78,39 @@ END)
0
            ((NSFileManager directoryExistsNamed:"/Developer/SDKs/MacOSX10.4u.sdk")
0
             (" -isysroot /Developer/SDKs/MacOSX10.4u.sdk"))
0
            (else "")))
0
-(set @cflags "-Wall -g -DDARWIN -DMACOSX #{@sdk} #{@leopard} -std=gnu99")
0
-(set @mflags "-fobjc-exceptions") ;; Want to try Apple's new GC? Add this: "-fobjc-gc"
0
-
0
-;; use this to build a universal binary
0
-(set @arch '("ppc" "i386"))
0
-;; or this to just build for your current platform
0
-;(set @arch nil)
0
-
0
-(set @ldflags
0
- ((list
0
- (cond ;; statically link in pcre since most people won't have it..
0
- ((NSFileManager fileExistsNamed:"#{@prefix}/lib/libpcre.a") ("#{@prefix}/lib/libpcre.a"))
0
- (else (NSException raise:"NukeBuildError" format:"Can't find static pcre library (libpcre.a).")))
0
- ((@frameworks map: (do (framework) " -framework #{framework}")) join)
0
- ((@libs map: (do (lib) " -l#{lib}")) join)
0
- ((@lib_dirs map: (do (libdir) " -L#{libdir}")) join))
0
- join))
0
 
0
+(if (eq (uname) "Darwin")
0
+ (then (set @cflags "-Wall -g -DDARWIN -DMACOSX #{@sdk} #{@leopard} -std=gnu99")
0
+ (set @mflags "-fobjc-exceptions")) ;; Want to try Apple's new GC? Add this: "-fobjc-gc"
0
+ (else (set @cflags "-Wall -DLINUX -g -std=gnu99 ")
0
+ (set @mflags "-fobjc-exceptions -fconstant-string-class=NSConstantString")))
0
+
0
+(if (eq (uname) "Darwin")
0
+ ;; use this to build a universal binary
0
+ (then (set @arch '("ppc" "i386")))
0
+ ;; or this to just build for your current platform
0
+ (else (set @arch '("i386"))))
0
+
0
+(if (eq (uname) "Darwin")
0
+ (then (set @ldflags
0
+ ((list
0
+ (cond ;; statically link in pcre since most people won't have it..
0
+ ((NSFileManager fileExistsNamed:"#{@prefix}/lib/libpcre.a") ("#{@prefix}/lib/libpcre.a"))
0
+ (else (NSException raise:"NukeBuildError" format:"Can't find static pcre library (libpcre.a).")))
0
+ ((@frameworks map: (do (framework) " -framework #{framework}")) join)
0
+ ((@libs map: (do (lib) " -l#{lib}")) join)
0
+ ((@lib_dirs map: (do (libdir) " -L#{libdir}")) join))
0
+ join)))
0
+ (else (set @ldflags
0
+ ((list
0
+ "-lNuFoundation -L/usr/local/lib -lobjc -Wl,--rpath -Wl,/usr/local/lib"
0
+ (cond ;; statically link in pcre since most people won't have it..
0
+ ((NSFileManager fileExistsNamed:"/usr/lib/libpcre.a") "/usr/lib/libpcre.a")
0
+ ((NSFileManager fileExistsNamed:"#{@prefix}/lib/libpcre.a") ("#{@prefix}/lib/libpcre.a"))
0
+ (else (NSException raise:"NukeBuildError" format:"Can't find static pcre library (libpcre.a).")))
0
+ ((@frameworks map: (do (framework) " -framework #{framework}")) join)
0
+ ((@libs map: (do (lib) " -l#{lib}")) join))
0
+ join))))
0
 ;; Setup the tasks for compilation and framework-building.
0
 ;; These are defined in the nuke application source file.
0
 (compilation-tasks)
0
@@ -98,7 +123,6 @@ END)
0
 
0
 (task "clobber" => "clean" is
0
       (SH "rm -rf nush #{@framework_dir} doc")
0
-
0
       ((filelist "^examples/[^/]*$") each:
0
        (do (example-dir)
0
            (puts example-dir)
0
@@ -109,11 +133,18 @@ END)
0
        (do (architecture)
0
            (set nush_thin_binary "build/#{architecture}/nush")
0
            (nush_thin_binaries addObject:nush_thin_binary)
0
- (file nush_thin_binary => "framework" "build/#{architecture}/main.o" is
0
- (SH "#{@cc} #{@cflags} -arch #{architecture} -F. -framework Nu build/#{architecture}/main.o #{@ldflags} -o #{(target name)}"))))
0
+ (if (eq (uname) "Darwin")
0
+ (then
0
+ (file nush_thin_binary => "framework" "build/#{architecture}/main.o" is
0
+ (SH "#{@cc} #{@cflags} -arch #{architecture} -F. -framework Nu build/#{architecture}/main.o #{@ldflags} -o #{(target name)}")))
0
+ (else
0
+ (file nush_thin_binary => (@c_objects objectForKey:architecture) (@m_objects objectForKey:architecture) is
0
+ (SH "#{@cc} #{@cflags} -F. build/#{architecture}/nu.o /usr/lib/libNu.so #{@ldflags} -o #{(target name)}"))))))
0
 
0
 (file "nush" => "framework" nush_thin_binaries is
0
- (SH "lipo -create #{(nush_thin_binaries join)} -output #{(target name)}"))
0
+ (if (eq (uname) "Darwin")
0
+ (then (SH "lipo -create #{(nush_thin_binaries join)} -output #{(target name)}"))
0
+ (else (SH "cp '#{(nush_thin_binaries objectAtIndex:0)}' '#{(target name)}'"))))
0
 
0
 ;; These tests were the first sanity tests for Nu. They require RubyObjC.
0
 (task "test.rb" => "framework" is
...
6
7
8
 
 
9
10
11
12
13
14
15
16
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
23
24
25
26
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
...
37
38
39
40
41
 
 
 
 
 
 
 
42
43
44
45
46
 
 
 
 
47
48
49
...
6
7
8
9
10
11
12
 
 
 
 
 
 
 
 
 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
33
 
 
 
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
54
55
56
 
 
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
0
@@ -6,27 +6,44 @@
0
 require 'rake'
0
 require 'rake/clean'
0
 
0
+SYSTEM = `uname`.chomp
0
+
0
 PREFIX = ENV["PREFIX"] ? ENV["PREFIX"] : "/usr/local"
0
 
0
-if File.exist? "/usr/lib/libffi.dylib"
0
- # Use the libffi that ships with OS X.
0
- FFI_LIB = "-L/usr/lib -lffi"
0
- FFI_INCLUDE = "-I /usr/include/ffi"
0
- LEOPARD_CFLAGS = "-DLEOPARD_OBJC2"
0
-else
0
- # Use the libffi that is distributed with Nu.
0
- FFI_LIB = "-L./libffi -lffi"
0
- FFI_INCLUDE = "-I ./libffi/include"
0
+if SYSTEM == "Darwin"
0
+ if File.exist? "/usr/lib/libffi.dylib"
0
+ # Use the libffi that ships with OS X.
0
+ FFI_LIB = "-L/usr/lib -lffi"
0
+ FFI_INCLUDE = "-I /usr/include/ffi"
0
+ LEOPARD_CFLAGS = "-DLEOPARD_OBJC2"
0
+ else
0
+ # Use the libffi that is distributed with Nu.
0
+ FFI_LIB = "-L./libffi -lffi"
0
+ FFI_INCLUDE = "-I ./libffi/include"
0
+ LEOPARD_CFLAGS = ""
0
+ end
0
+else # Linux
0
+ # Use the libffi that is distributed with Linux.
0
+ FFI_LIB = "-lffi"
0
+ FFI_INCLUDE = ""
0
   LEOPARD_CFLAGS = ""
0
 end
0
 
0
 @includes = FFI_INCLUDE
0
-@includes += " -I #{PREFIX}/include" if File.exist? "#{PREFIX}/include"
0
 
0
-@frameworks = %w{Cocoa}
0
-@libs = %w{objc pcre readline}
0
-@lib_dirs = []
0
-@lib_dirs << "#{PREFIX}/lib" if File.exist? "#{PREFIX}/lib"
0
+if SYSTEM == "Darwin"
0
+ @includes += " -I #{PREFIX}/include" if File.exist? "#{PREFIX}/include"
0
+ @frameworks = %w{Cocoa}
0
+ @libs = %w{objc pcre readline}
0
+ @lib_dirs = []
0
+ @lib_dirs << "#{PREFIX}/lib" if File.exist? "#{PREFIX}/lib"
0
+else
0
+ @includes += " -I /usr/local/include"
0
+ @frameworks = [] # %w{Cocoa}
0
+ @libs = %w{m pcre readline }
0
+ @lib_dirs = []
0
+end
0
+
0
 
0
 CLEAN.include("*/*.o")
0
 CLOBBER.include("mininush")
0
@@ -37,13 +54,22 @@ CLOBBER.include("mininush")
0
 @gcc_objects = @gcc_files.sub(/\.c$/, '.o').sub(/\.m$/, '.o')
0
 
0
 @cc = "gcc"
0
-@cflags = "-g -O2 -Wall -DMACOSX -DDARWIN -DMININUSH -std=gnu99 #{LEOPARD_CFLAGS}"
0
-@mflags = "-fobjc-exceptions"
0
+if SYSTEM == "Darwin"
0
+ @cflags = "-g -O2 -Wall -DMACOSX -DDARWIN -DMININUSH -std=gnu99 #{LEOPARD_CFLAGS}"
0
+ @mflags = "-fobjc-exceptions"
0
+else
0
+ @cflags = "-g -O2 -Wall -DLINUX -DMININUSH -std=gnu99 #{LEOPARD_CFLAGS} "
0
+ @mflags = "-fobjc-exceptions -fconstant-string-class=NSConstantString"
0
+end
0
 
0
 @ldflags = @frameworks.map {|framework| " -framework #{framework}"}.join
0
 @ldflags += @libs.map {|lib| " -l#{lib}"}.join
0
 @ldflags += @lib_dirs.map {|libdir| " -L#{libdir}"}.join
0
 @ldflags += " #{FFI_LIB}"
0
+if SYSTEM == "Linux"
0
+ @ldflags += " -lobjc -lNuFoundation"
0
+ @ldflags += " -Wl,--rpath -Wl,/usr/local/lib"
0
+end
0
 
0
 rule ".o" => [".m"] do |t|
0
   sh "#{@cc} #{@cflags} #{@mflags} #{@includes} -c -o #{t.name} #{t.source}"
...
210
211
212
213
214
215
216
217
218
219
220
 
221
 
222
 
223
224
225
...
210
211
212
 
 
213
214
215
216
217
218
219
220
221
222
223
224
225
226
0
@@ -210,16 +210,17 @@ static void transplant_nu_methods(Class destination, Class source)
0
         NSLog(@"method copy failed");
0
 }
0
 
0
-extern void nu_note_placeholders();
0
-
0
 void NuInit()
0
 {
0
     static int initialized = 0;
0
     if (!initialized) {
0
         initialized = 1;
0
 
0
+#ifdef DARWIN
0
         // note known placeholder classes
0
+ extern void nu_note_placeholders();
0
         nu_note_placeholders();
0
+#endif
0
 
0
         // check UTF8 support in PCRE
0
         void *pcre_query_result = 0;
...
49
50
51
 
 
 
 
 
 
 
52
 
 
 
 
 
53
54
55
...
228
229
230
 
 
 
231
232
 
233
234
235
...
241
242
243
 
 
 
244
245
 
246
247
248
...
310
311
312
 
 
 
313
314
 
315
316
317
318
 
 
 
319
320
321
...
432
433
434
 
 
 
435
436
 
437
438
439
440
441
442
 
 
 
443
444
445
...
524
525
526
 
 
 
527
528
 
529
530
531
...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
...
240
241
242
243
244
245
246
 
247
248
249
250
...
256
257
258
259
260
261
262
 
263
264
265
266
...
328
329
330
331
332
333
334
 
335
336
337
338
 
339
340
341
342
343
344
...
455
456
457
458
459
460
461
 
462
463
464
465
466
467
 
468
469
470
471
472
473
...
552
553
554
555
556
557
558
 
559
560
561
562
0
@@ -49,7 +49,19 @@
0
           (set components (self componentsSeparatedByString:"/"))
0
           (components objectAtIndex:(- (components count) 1))))
0
 
0
+(class NSDictionary
0
+ ;; Create a dictionary from a list.
0
+ (cmethod (id) dictionaryWithList: (id) l is
0
+ (set dict ((NSMutableDictionary alloc) init))
0
+ (l eachPair: (do (key object) (dict setObject:object forKey:key)))
0
+ dict))
0
+
0
 (class NSArray
0
+ ;; Create an array from a list.
0
+ (cmethod (id) arrayWithList:(id) list is
0
+ (set l ((NSMutableArray alloc) init))
0
+ (list each: (do (item) (if item (l addObject:item))))
0
+ l)
0
      
0
      ;; Join the non-null members of an array into a string with array elements separated by spaces.
0
      (imethod (id) join is
0
@@ -228,8 +240,11 @@
0
                          (set objectName "build/#{architecture}/")
0
                          (objectName appendString:((sourceName fileName) stringByReplacingPathExtensionWith:"o"))
0
                          ((@c_objects objectForKey:architecture) addObject: objectName)
0
+ (if (eq (uname) "Darwin")
0
+ (then (set archflags "-arch #{architecture}"))
0
+ (else (set archflags "")))
0
                          (file objectName => sourceName is
0
- (SH "#{@cc} #{@cflags} -arch #{architecture} #{@includes} -c -o #{(target name)} #{sourceName}"))))))
0
+ (SH "#{@cc} #{@cflags} #{archflags} #{@includes} -c -o #{(target name)} #{sourceName}"))))))
0
      
0
      ;; compile objc files
0
      (set @m_objects (NSMutableDictionary dictionary))
0
@@ -241,8 +256,11 @@
0
                          (set objectName "build/#{architecture}/")
0
                          (objectName appendString:((sourceName fileName) stringByReplacingPathExtensionWith:"o"))
0
                          ((@m_objects objectForKey:architecture) addObject: objectName)
0
+ (if (eq (uname) "Darwin")
0
+ (then (set archflags "-arch #{architecture}"))
0
+ (else (set archflags "")))
0
                          (file objectName => sourceName is
0
- (SH "#{@cc} #{@cflags} #{@mflags} -arch #{architecture} #{@includes} -c -o #{(target name)} #{sourceName}"))))))
0
+ (SH "#{@cc} #{@cflags} #{@mflags} #{archflags} #{@includes} -c -o #{(target name)} #{sourceName}"))))))
0
      
0
      ;(puts (@c_objects description))
0
      ;(puts (@m_objects description))
0
@@ -310,12 +328,17 @@
0
                      (do (architecture)
0
                          (set application_executable "build/#{architecture}/application-#{@application}")
0
                          (@application_executables addObject:application_executable)
0
+ (if (eq (uname) "Darwin")
0
+ (then (set archflags "-arch #{architecture}"))
0
+ (else (set archflags "")))
0
                          (file application_executable => (@c_objects objectForKey:architecture) (@m_objects objectForKey:architecture) is
0
- (set command "#{@cc} #{((@c_objects objectForKey:architecture) join)} #{((@m_objects objectForKey:architecture) join)} -arch #{architecture} #{@cflags} #{@ldflags} -o '#{(target name)}'")
0
+ (set command "#{@cc} #{((@c_objects objectForKey:architecture) join)} #{((@m_objects objectForKey:architecture) join)} #{archflags} #{@cflags} #{@ldflags} -o '#{(target name)}'")
0
                                (SH command))))
0
               ;; application fat executable
0
               (file @application_executable_name => @application_executable_dir @application_executables is
0
- (set command "lipo -create #{(@application_executables join)} -output '#{@application_executable_name}'")
0
+ (if (eq (uname) "Darwin")
0
+ (then (set command "lipo -create #{(@application_executables join)} -output '#{@application_executable_name}'"))
0
+ (else (set command "cp '#{(@application_executables objectAtIndex:0)}' '#{@application_executable_name}'")))
0
                     (SH command)))
0
          (else
0
               (file @application_executable_name => @application_executable_dir is
0
@@ -432,14 +455,19 @@
0
             (do (architecture)
0
                 (set framework_executable "build/#{architecture}/framework-#{@framework}")
0
                 (@framework_executables addObject:framework_executable)
0
+ (if (eq (uname) "Darwin")
0
+ (then (set archflags "-arch #{architecture}"))
0
+ (else (set archflags "")))
0
                 (file framework_executable => (@c_objects objectForKey:architecture) (@m_objects objectForKey:architecture) is
0
- (set command "#{@cc} #{((@c_objects objectForKey:architecture) join)} #{((@m_objects objectForKey:architecture) join)} -arch #{architecture} #{@cflags} #{@ldflags} #{@initflags} -install_name #{@framework_executable_name} -dynamiclib -o '#{(target name)}'")
0
+ (set command "#{@cc} #{((@c_objects objectForKey:architecture) join)} #{((@m_objects objectForKey:architecture) join)} #{archflags} #{@cflags} #{@ldflags} #{@initflags} -install_name #{@framework_executable_name} -dynamiclib -o '#{(target name)}'")
0
                       (SH command))))
0
      
0
      ;; framework fat executable
0
      (set @framework_executable_name "#{@framework_contents_dir}/#{@framework}")
0
      (file @framework_executable_name => @framework_contents_dir @framework_executables is
0
- (set command "lipo -create #{(@framework_executables join)} -output '#{@framework_executable_name}'")
0
+ (if (eq (uname) "Darwin")
0
+ (then (set command "lipo -create #{(@framework_executables join)} -output '#{@framework_executable_name}'"))
0
+ (else (set command "cp '#{(@framework_executables objectAtIndex:0)}' '#{@framework_executable_name}'")))
0
            (SH command))
0
      
0
      ;; framework_resources
0
@@ -524,8 +552,11 @@
0
             (do (architecture)
0
                 (set bundle_executable "build/#{architecture}/bundle-#{@bundle}")
0
                 (@bundle_executables addObject:bundle_executable)
0
+ (if (eq (uname) "Darwin")
0
+ (then (set archflags "-arch #{architecture}"))
0
+ (else (set archflags "")))
0
                 (file bundle_executable => (@c_objects objectForKey:architecture) (@m_objects objectForKey:architecture) is
0
- (set command "#{@cc} #{((@c_objects objectForKey:architecture) join)} #{((@m_objects objectForKey:architecture) join)} -arch #{architecture} #{@cflags} #{@ldflags} -bundle -o '#{(target name)}'")
0
+ (set command "#{@cc} #{((@c_objects objectForKey:architecture) join)} #{((@m_objects objectForKey:architecture) join)} #{archflags} #{@cflags} #{@ldflags} -bundle -o '#{(target name)}'")
0
                       (SH command))))
0
      
0
      ;; bundle fat executable

Comments

    No one has commented yet.