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

Now both Darwin and Linux versions of Nu can be built
and installed using the Nu two-stage build process.

Stage 1: Use rake to build a statically-linked Nu shell.

  % rake

Stage 2: Use the resulting 'mininush' to run nuke.

  % mininush tools/nuke

Installation Notes: On Darwin, Nu is installed as a
framework in /Library/Frameworks. On Linux, it is built
as a dynamic library and installed in /usr/local/lib
(or the lib dir of whatever is your desired installation
prefix). Because nush is linked against libNu.so,
running "nuke install" will crash on Linux when the
libNu.so is overwritten. So be sure to install with
"mininush tools/nuke install".

Linux builds require NuFound, a customized version of
libFoundation. Ports to other Foundation libraries are
welcome.
timburks (author)
Thu Mar 13 11:32:20 -0700 2008
commit  b46ed8403aba281d47619f71dd46fefa08e5c809
tree    3a2d149598801fe61b0931c0646c6cc54d2fd0c4
parent  f1e2e5b2e9e521bf6b3857d56b41120199b28bac
...
46
47
48
49
50
 
 
51
52
53
...
68
69
70
 
 
 
71
72
73
...
103
104
105
106
 
107
108
109
...
114
115
116
117
 
 
 
118
119
120
121
122
 
 
 
123
124
125
 
 
126
127
128
...
136
137
138
139
 
140
141
142
 
 
143
144
145
...
170
171
172
173
174
175
176
 
 
 
 
 
 
 
 
 
177
178
179
180
 
 
 
181
182
183
...
46
47
48
 
 
49
50
51
52
53
...
68
69
70
71
72
73
74
75
76
...
106
107
108
 
109
110
111
112
...
117
118
119
 
120
121
122
123
124
125
 
 
126
127
128
129
130
 
131
132
133
134
135
...
143
144
145
 
146
147
 
 
148
149
150
151
152
...
177
178
179
 
 
 
 
180
181
182
183
184
185
186
187
188
189
190
 
 
191
192
193
194
195
196
0
@@ -46,8 +46,8 @@ END)
0
 
0
 ;; includes
0
 (if (eq (uname) "Darwin")
0
- (then (set @includes ""))
0
- (else (set @includes " -I/usr/local/include")))
0
+ (then (set @includes " -I./include "))
0
+ (else (set @includes " -I./include -I/usr/local/include")))
0
 
0
 (if (NSFileManager directoryExistsNamed:"#{@prefix}/include") (@includes appendString:" -I #{@prefix}/include"))
0
 
0
@@ -68,6 +68,9 @@ END)
0
 (if (eq (uname) "Darwin") (then (set @framework_initializer "NuInit")))
0
 (set @framework_creator_code "????")
0
 
0
+;; for Linux, we build Nu as a dynamic library
0
+(set @dylib "libNu")
0
+
0
 ;; build configuration
0
 (set @cc "gcc")
0
 (set @leopard "")
0
@@ -103,7 +106,7 @@ END)
0
                 join)))
0
     (else (set @ldflags
0
                ((list
0
- "-lNuFoundation -L/usr/local/lib -lobjc -Wl,--rpath -Wl,/usr/local/lib"
0
+ "-lNuFound -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
@@ -114,15 +117,19 @@ END)
0
 ;; Setup the tasks for compilation and framework-building.
0
 ;; These are defined in the nuke application source file.
0
 (compilation-tasks)
0
-(framework-tasks)
0
+(if (eq (uname) "Darwin")
0
+ (then (framework-tasks))
0
+ (else (dylib-tasks)))
0
 
0
 (task "framework" => "#{@framework_headers_dir}/Nu.h")
0
 
0
-(file "#{@framework_headers_dir}/Nu.h" => "objc/Nu.h" @framework_headers_dir is
0
- (SH "cp objc/Nu.h #{@framework_headers_dir}"))
0
+(if (eq (uname) "Darwin")
0
+ (file "#{@framework_headers_dir}/Nu.h" => "objc/Nu.h" @framework_headers_dir is
0
+ (SH "cp objc/Nu.h #{@framework_headers_dir}")))
0
 
0
 (task "clobber" => "clean" is
0
- (SH "rm -rf nush #{@framework_dir} doc")
0
+ (if (eq (uname) "Darwin")
0
+ (SH "rm -rf nush #{@framework_dir} doc"))
0
       ((filelist "^examples/[^/]*$") each:
0
        (do (example-dir)
0
            (puts example-dir)
0
@@ -136,10 +143,10 @@ END)
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
+ (SH "#{@cc} #{@cflags} #{@mflags} main/main.m -arch #{architecture} -F. -framework Nu #{@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
+ (file nush_thin_binary => "dylib" (@c_objects objectForKey:architecture) (@m_objects objectForKey:architecture) is
0
+ (SH "#{@cc} #{@cflags} #{@mflags} main/main.m #{@library_executable_name} #{@ldflags} -o #{(target name)}"))))))
0
 
0
 (file "nush" => "framework" nush_thin_binaries is
0
       (if (eq (uname) "Darwin")
0
@@ -170,14 +177,20 @@ END)
0
 (task "install" => "nush" is
0
       ('("nuke" "nubile" "nutemplate" "nutest" "nudoc" "nubake") each:
0
         (do (program)
0
- (SH "sudo ditto tools/#{program} #{@installprefix}/bin")))
0
- (SH "sudo ditto nush #{@installprefix}/bin")
0
- (SH "sudo rm -rf #{@destdir}/Library/Frameworks/#{@framework}.framework")
0
- (SH "ditto #{@framework}.framework #{@destdir}/Library/Frameworks/#{@framework}.framework")
0
+ (SH "sudo cp tools/#{program} #{@installprefix}/bin")))
0
+ (SH "sudo cp nush #{@installprefix}/bin")
0
+ (if (eq (uname) "Darwin")
0
+ ;; install the framework
0
+ (SH "sudo rm -rf #{@destdir}/Library/Frameworks/#{@framework}.framework")
0
+ (SH "ditto #{@framework}.framework #{@destdir}/Library/Frameworks/#{@framework}.framework"))
0
+ (if (eq (uname) "Linux")
0
+ ;; install the dynamic library
0
+ (SH "sudo cp #{@library_executable_name} #{@installprefix}/lib"))
0
       (SH "sudo mkdir -p #{@installprefix}/share")
0
       (SH "sudo rm -rf #{@installprefix}/share/nu")
0
- (SH "sudo ditto share/nu #{@installprefix}/share/nu")
0
- (SH "sudo ditto examples #{@installprefix}/share/nu/examples"))
0
+ (SH "sudo cp -rp share/nu #{@installprefix}/share/nu")
0
+ (if (eq (uname) "Darwin")
0
+ (SH "sudo ditto examples #{@installprefix}/share/nu/examples")))
0
 
0
 ;; Build a disk image for distributing the framework.
0
 (task "framework_image" => "framework" is
...
49
50
51
52
 
53
54
55
...
67
68
69
70
 
71
72
73
...
49
50
51
 
52
53
54
55
...
67
68
69
 
70
71
72
73
0
@@ -49,7 +49,7 @@ CLEAN.include("*/*.o")
0
 CLOBBER.include("mininush")
0
 
0
 @c_files = FileList['objc/*.c']
0
-@objc_files = FileList['objc/*.m']
0
+@objc_files = FileList['objc/*.m'] + FileList['main/*.m']
0
 @gcc_files = @objc_files + @c_files
0
 @gcc_objects = @gcc_files.sub(/\.c$/, '.o').sub(/\.m$/, '.o')
0
 
0
@@ -67,7 +67,7 @@ end
0
 @ldflags += @lib_dirs.map {|libdir| " -L#{libdir}"}.join
0
 @ldflags += " #{FFI_LIB}"
0
 if SYSTEM == "Linux"
0
- @ldflags += " -lobjc -lNuFoundation"
0
+ @ldflags += " -lobjc -lNuFound"
0
   @ldflags += " -Wl,--rpath -Wl,/usr/local/lib"
0
 end
0
 
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 
0
-(set @nu_files (filelist "^[^/]*nu$")) ;; don't forget that filelist expects regular expressions.
0
+(set @nu_files (filelist "^nu/.*\.nu$")) ;; don't forget that filelist expects regular expressions.
0
 
0
 (set @application "Growler")
0
 (set @application_identifier "nu.programming.growler")
...
86
87
88
89
90
...
86
87
88
 
 
0
@@ -86,5 +86,3 @@
0
 (global NSOrderedAscending         -1)
0
 (global NSOrderedSame       0)
0
 (global NSOrderedDescending       1)
0
-(global NO 0)
0
-(global YES 1)
...
524
525
526
527
 
528
529
530
531
 
 
 
532
533
534
...
1272
1273
1274
1275
 
1276
1277
1278
...
1281
1282
1283
1284
 
1285
1286
1287
...
1324
1325
1326
1327
 
1328
1329
1330
 
1331
1332
1333
...
1746
1747
1748
 
 
1749
1750
1751
...
524
525
526
 
527
528
 
 
 
529
530
531
532
533
534
...
1272
1273
1274
 
1275
1276
1277
1278
...
1281
1282
1283
 
1284
1285
1286
1287
...
1324
1325
1326
 
1327
1328
1329
 
1330
1331
1332
1333
...
1746
1747
1748
1749
1750
1751
1752
1753
0
@@ -524,11 +524,11 @@ static bool valueIsTrue(id value)
0
             expressions = [expressions cdr];
0
         }
0
     }
0
-#ifdef DARWIN
0
+ #ifdef DARWIN
0
     @finally
0
-#else
0
- NS_ENDHANDLER
0
-#endif
0
+ #else
0
+ NS_ENDHANDLER
0
+ #endif
0
     {
0
         // evaluate all the expressions that are in finally blocks
0
         id expressions = cdr;
0
@@ -1272,7 +1272,7 @@ id loadNuLibraryFile(NSString *nuFileName, id parser, id context, id symbolTable
0
     if ([split count] == 2) {
0
         id frameworkName = [split objectAtIndex:0];
0
         id nuFileName = [split objectAtIndex:1];
0
-#ifdef LINUX
0
+ #ifdef LINUX
0
         if ([frameworkName isEqual:@"Nu"]) {
0
             if (loadNuLibraryFile(nuFileName, parser, context, symbolTable) == nil) {
0
                 [NSException raise:@"NuLoadFailed" format:@"unable to load %@", nuFileName];
0
@@ -1281,7 +1281,7 @@ id loadNuLibraryFile(NSString *nuFileName, id parser, id context, id symbolTable
0
                 return [symbolTable symbolWithCString:"t"];
0
             }
0
         }
0
-#endif
0
+ #endif
0
         NSBundle *framework = [NSBundle frameworkWithName:frameworkName];
0
         if ([framework loadNuFile:nuFileName withContext:context])
0
             return [symbolTable symbolWithCString:"t"];
0
@@ -1324,10 +1324,10 @@ id loadNuLibraryFile(NSString *nuFileName, id parser, id context, id symbolTable
0
         if ([Nu loadNuFile:resourceName fromBundleWithIdentifier:@"nu.programming.framework" withContext:context])
0
             return [symbolTable symbolWithCString:"t"];
0
 
0
-#ifdef LINUX
0
+ #ifdef LINUX
0
         if (loadNuLibraryFile(resourceName, parser, context, symbolTable))
0
             return [symbolTable symbolWithCString:"t"];
0
-#endif
0
+ #endif
0
 
0
         // if no file was found, try to load a framework with the given name
0
         if ([NSBundle frameworkWithName:resourceName])
0
@@ -1746,6 +1746,8 @@ void load_builtins(NuSymbolTable *symbolTable)
0
 {
0
     [(NuSymbol *) [[symbolTable symbolWithCString:"t"] retain] setValue:[symbolTable symbolWithCString:"t"]];
0
     [(NuSymbol *) [[symbolTable symbolWithCString:"nil"] retain] setValue:Nu__null];
0
+ [(NuSymbol *) [[symbolTable symbolWithCString:"YES"] retain] setValue:[NSNumber numberWithInt:1]];
0
+ [(NuSymbol *) [[symbolTable symbolWithCString:"NO"] retain] setValue:[NSNumber numberWithInt:0]];
0
 
0
     install("car", Nu_car_operator);
0
     install("cdr", Nu_cdr_operator);
...
624
625
626
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
627
628
629
...
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
0
@@ -624,6 +624,39 @@
0
      
0
      (task "library" => @library_executable_name))
0
 
0
+;; use this to create all the linking and assembly tasks to build a dynamically-linkable library
0
+(macro dylib-tasks
0
+ (unless (and @arch (@arch length))
0
+ (set @arch (list (NSString stringWithShellCommand:"arch"))))
0
+ (set libext (if (eq (uname) "Darwin") (then "dylib") (else "so")))
0
+
0
+ ;; library architecture-specific executable
0
+ (set @library_executables (NSMutableArray array))
0
+ (@arch each:
0
+ (do (architecture)
0
+ (set library_executable "build/#{architecture}/#{@dylib}.#{libext}")
0
+ (@library_executables addObject:library_executable)
0
+ (if (eq (uname) "Darwin")
0
+ (then (set dylibflag "-dynamiclib"))
0
+ (else (set dylibflag "-shared")))
0
+ (if (eq (uname) "Darwin")
0
+ (then (set archflags "-arch #{architecture}"))
0
+ (else (set archflags "")))
0
+ (file library_executable => (@c_objects objectForKey:architecture) (@m_objects objectForKey:architecture) is
0
+ (set command "#{@cc} #{((@c_objects objectForKey:architecture) join)} #{((@m_objects objectForKey:architecture) join)} #{archflags} #{@cflags} #{@ldflags} #{dylibflag} -o '#{(target name)}'")
0
+ (SH command))))
0
+
0
+ ;; fat dynamic library
0
+ (set @library_executable_name "#{@dylib}.#{libext}")
0
+ (file @library_executable_name => @library_executables is
0
+ (if (eq (uname) "Darwin")
0
+ (then (set command "lipo -create #{(@library_executables join)} -output '#{@library_executable_name}'"))
0
+ (else (set command "cp '#{(@library_executables objectAtIndex:0)}' '#{@library_executable_name}'")))
0
+ (SH command))
0
+
0
+ (task "dylib" => @library_executable_name))
0
+
0
+
0
 ;; @abstract A project consisting of an interrelated set of NukeTasks.
0
 ;; @discussion NukeProjects gather together a related set of NukeTask task descriptions
0
 ;; and allow them to be more easily referred to by name. There is typically

Comments

    No one has commented yet.