-
Notifications
You must be signed in to change notification settings - Fork 236
/
Nukefile
322 lines (279 loc) · 14 KB
/
Nukefile
1
2
3
4
5
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
;; Nukefile for Nu framework and nush, the Nu shell
(set DEVROOT
(ifDarwin (then (NSString stringWithShellCommand:"xcode-select -print-path"))
(else nil)))
(global VERSION '(2 1 0)) #(major minor tweak)
(task "version" is
(set now (NSCalendarDate date))
(set version <<-END
#define NU_VERSION "#{(VERSION first)}.#{(VERSION second)}.#{(VERSION third)}"
#define NU_VERSION_MAJOR #{(VERSION first)}
#define NU_VERSION_MINOR #{(VERSION second)}
#define NU_VERSION_TWEAK #{(VERSION third)}
#define NU_RELEASE_DATE "#{(now yearOfCommonEra)}-#{(now monthOfYear)}-#{(now dayOfMonth)}"
#define NU_RELEASE_YEAR #{(now yearOfCommonEra)}
#define NU_RELEASE_MONTH #{(now monthOfYear)}
#define NU_RELEASE_DAY #{(now dayOfMonth)}
END)
(version writeToFile:"objc/NuVersion.h" atomically:NO encoding:NSUTF8StringEncoding error:(set error (NuReference new))))
;; read environment for prefix and destroot
(let ((env ((NSProcessInfo processInfo) environment)))
(if (env objectForKey:"PREFIX")
(then (set @prefix (env objectForKey:"PREFIX")))
(else (set @prefix "/usr/local")))
(if (env objectForKey:"DESTDIR")
(then (set @destdir (env objectForKey:"DESTDIR")))
(else (set @destdir ""))))
;; source files
(set @c_files (filelist "^objc/.*\.c$"))
(set @m_files (filelist "^objc/.*\.m$"))
(@m_files unionSet:(filelist "^baked/.*\.m$"))
(set @nu_files (filelist "^nu/.*\.nu$"))
(set @icon_files (filelist "^lib/.*\.icns$"))
(set @nib_files '("share/nu/resources/English.lproj/MainMenu.nib"))
;; libraries
(set @frameworks (NSMutableArray array))
(set @inc_dirs (NSMutableArray arrayWithList:(list "/usr/include")))
(set @lib_dirs (array)) ;; (NSMutableArray arrayWithList:(list "/usr/lib")))
(set @libs (NSMutableArray arrayWithList:(list "objc" "ffi")))
;(@inc_dirs addObjectsFromList:(list "./include" "./include/Nu"))
(ifDarwin
(then (@frameworks addObject:"Cocoa")
(@libs addObject:"edit"))
(else (@libs addObjectsFromList:(list "readline" "m" ))
;;(@inc_dirs addObject:"/usr/include/GNUstep/Headers")
;; this will be set by gnustep-config:
;; (@lib_dirs addObject:"/usr/lib/GNUstep/System/Library/Libraries")
))
(ifOpenSolaris
(then (@libs addObjectsFromList:(list "curses"))))
(if (NSFileManager directoryExistsNamed:"#{@prefix}/include") (@inc_dirs addObject:"#{@prefix}/include"))
(if (NSFileManager directoryExistsNamed:"#{@prefix}/lib") (@lib_dirs addObject:"#{@prefix}/lib"))
(ifDarwin
(then (if (NSFileManager fileExistsNamed:"/usr/lib/libffi.dylib")
(then ;; Use the libffi that ships with OS X.
(@inc_dirs addObject:"/usr/include/ffi"))
(else ;; Use the libffi that is distributed with Nu.
(@inc_dirs addObject:"./libffi/include")
(@lib_dirs addObject:"./libffi")))))
;; framework description
(set @framework "Nu")
(set @framework_identifier "nu.programming.framework")
(set @framework_icon_file "nu.icns")
(ifDarwin (then (set @framework_initializer "NuInit")))
(set @framework_creator_code "????")
;; for Linux, we build Nu as a dynamic library
(set @dylib "libNu")
;; build configuration
(set @sdkflags "")
(set @sdk
(cond ((NSFileManager directoryExistsNamed:"#{DEVROOT}/SDKs/MacOSX10.8.sdk")
(set @sdkflags "-D__OBJC2__")
("-isysroot #{DEVROOT}/SDKs/MacOSX10.8.sdk"))
((NSFileManager directoryExistsNamed:"#{DEVROOT}/SDKs/MacOSX10.7.sdk")
(set @sdkflags "-D__OBJC2__")
("-isysroot #{DEVROOT}/SDKs/MacOSX10.7.sdk"))
((NSFileManager directoryExistsNamed:"#{DEVROOT}/SDKs/MacOSX10.6.sdk")
(set @sdkflags "-D__OBJC2__")
("-isysroot #{DEVROOT}/SDKs/MacOSX10.6.sdk"))
((NSFileManager directoryExistsNamed:"#{DEVROOT}/SDKs/MacOSX10.5.sdk")
(set @sdkflags "-D__OBJC2__")
("-isysroot #{DEVROOT}/SDKs/MacOSX10.5.sdk"))
((NSFileManager directoryExistsNamed:"#{DEVROOT}/SDKs/MacOSX10.4u.sdk")
("-isysroot #{DEVROOT}/SDKs/MacOSX10.4u.sdk"))
(else "")))
(ifDarwin
(then (set @cflags ( "-Wall -g -fPIC -O2 -DMACOSX #{@sdk} #{@sdkflags}"))
(set @mflags "-fobjc-exceptions"))
(else (set @cflags "-Wall -g -fPIC")
(set @mflags ""))) ;((NSString stringWithShellCommand:"gnustep-config --objc-flags") chomp))))
(ifLinux (then (set @cflags (+ @cflags " -DLINUX"))))
(ifFreeBSD (then (set @cflags (+ @cflags " -DFREEBSD"))))
(ifOpenSolaris (then (set @cflags (+ @cflags " -DOPENSOLARIS"))))
;; for our bundled PCRE
(set @cflags (+ @cflags " -DHAVE_CONFIG_H"))
(ifDarwin
(then (set @arch '()))) ;; optionally add "ppc" or "ppc64" to the list
(if (or (isSnowLeopard) (isLion))
(then (set @arch (append @arch '("x86_64")))))
(set @includes
((@inc_dirs map: (do (inc) " -I#{inc}")) join))
(set @ldflags
((list
((@frameworks map: (do (framework) " -framework #{framework}")) join)
((@libs map: (do (lib) " -l#{lib}")) join)
(ifDarwin
(then ((@lib_dirs map:
(do (libdir) " -L#{libdir}")) join))
(else
(if (isOpenSolaris)
(then
((@lib_dirs map:
(do (libdir) " -L#{libdir} ")) join))
(else
((@lib_dirs map:
(do (libdir) " -L#{libdir} -Wl,--rpath #{libdir}")) join))))))
join))
(if YES
(set @public_headers (filelist "^objc/.*\.h$")))
;; REVIEW
(ifDarwin (then (set @cflags (+ @cflags " -DDARWIN"))))
(ifLinux (then (set @cflags (+ @cflags
" -DDEBUG"
" -DGNU_GUI_LIBRARY=1"
" -DGNU_RUNTIME=1"
" -DGNUSTEP"
" -DGNUSTEP_BASE_LIBRARY=1"
" -DGSDIAGNOSE"
" -DGSWARN"
" -DHAVE_CONFIG_H"
" -D_NATIVE_OBJC_EXCEPTIONS"
" -fblocks"
" -fconstant-string-class=NSConstantString"
" -fexceptions"
" -fgnu-runtime"
" -fno-omit-frame-pointer"
" -fno-strict-aliasing"
" -fobjc-exceptions"
" -fobjc-nonfragile-abi"
" -fPIC"
" -g"
" -I."
" -I./include"
" -I./include/Nu "
" -I./libffi/include"
" -I/usr/include "
" -I/usr/include/GNUstep "
" -I/usr/local/include"
" -MMD"
" -MP"
" -pthread"
" -Wall"
" -Wno-import"
" -Wno-array-bounds"
))
(set @ldflags (+ @ldflags
" -rdynamic"
" -pthread"
" -fexceptions"
" -fgnu-runtime"
" -L/usr/local/lib"
" -lgnustep-base"
" -lobjc"
" -lm"
))
))
;; Setup the tasks for compilation and framework-building.
;; These are defined in the nuke application source file.
(compilation-tasks)
(ifDarwin
(then (framework-tasks))
(else (dylib-tasks)))
(task "clobber" => "clean" is
(ifDarwin
(SH "rm -rf nush #{@framework_dir} doc"))
((filelist "^examples/[^/]*$") each:
(do (example-dir)
(if ((NSFileManager defaultManager) fileExistsAtPath:(+ example-dir "/Nukefile"))
(SH "cd #{example-dir}; nuke clobber")))))
;(ifGNUstep (set @gnustep_flags ((NSString stringWithShellCommand:"gnustep-config --base-libs") chomp)))
(set nush_thin_binaries (NSMutableArray array))
(@arch each:
(do (architecture)
(set nush_thin_binary "build/#{architecture}/nush")
(nush_thin_binaries addObject:nush_thin_binary)
(ifDarwin
(then
(file nush_thin_binary => "framework" "build/#{architecture}/main.o" is
(SH "#{@cc} #{@cflags} #{@mflags} main/main.m -arch #{architecture} -F. -framework Nu #{@ldflags} -o #{(target name)}")))
(else
(file nush_thin_binary => "dylib" (@c_objects objectForKey:architecture) (@m_objects objectForKey:architecture) is
(SH "#{@cc} #{@cflags} #{@mflags} main/main.m #{@library_executable_name} #{@ldflags} -o #{(target name)}"))))))
(file "nush" => "framework" nush_thin_binaries is
(ifDarwin
(then (SH "lipo -create #{(nush_thin_binaries join)} -output #{(target name)}"))
(else (SH "cp '#{(nush_thin_binaries objectAtIndex:0)}' '#{(target name)}'"))))
;; These tests were the first sanity tests for Nu. They require RubyObjC.
(task "test.rb" => "framework" is
(SH "ruby -rtest/unit -e0 -- -v --pattern '/test_.*\.rb^/'"))
(task "test" => "framework" "nush" is
(SH "./nush tools/nutest tests.nu"))
(task "doc" is
(SH "nudoc"))
(task "publish-doc" is
(SH "nudoc -site programming.nu")
(SH "scp -r doc programming.nu:/projects/sites/programming.nu/public/"))
(task "default" => "nush")
;; Except for the Nu.framework (installed in /Library/Frameworks),
;; all scripts and binaries are installed to #{@prefix}/bin
(set @installprefix "#{@destdir}#{@prefix}")
(task "install" => "nush" is
('("nuke" "nufmt" "nutemplate" "nutest" "nudoc" "nubake" "nutmbundle") each:
(do (program)
(SH "sudo cp tools/#{program} #{@installprefix}/bin")))
(SH "sudo cp nush #{@installprefix}/bin")
(ifDarwin
;; install the framework
(SH "sudo rm -rf #{@destdir}/Library/Frameworks/#{@framework}.framework")
(SH "sudo ditto #{@framework}.framework #{@destdir}/Library/Frameworks/#{@framework}.framework"))
(ifGNUstep
;; install the dynamic library
(SH "sudo mkdir -p #{@installprefix}/lib")
(SH "sudo cp #{@library_executable_name} #{@installprefix}/lib")
;; copy the headers
(SH "sudo rm -rf #{@installprefix}/include/Nu")
(SH "sudo mkdir -p #{@installprefix}/include/Nu")
(SH "sudo cp -Rp objc/*.h #{@installprefix}/include/Nu")
(SH "sudo rm -rf #{@installprefix}/share/libNu")
(SH "sudo mkdir -p #{@installprefix}/share/libNu")
(SH "sudo cp -Rp nu/* #{@installprefix}/share/libNu"))
(SH "sudo mkdir -p #{@installprefix}/share")
(SH "sudo rm -rf #{@installprefix}/share/nu")
(SH "sudo cp -Rp share/nu #{@installprefix}/share/nu")
(ifDarwin
(SH "sudo ditto examples #{@installprefix}/share/nu/examples")))
;; Build a disk image for distributing the framework.
(task "framework_image" => "framework" is
(SH "rm -rf '#{@framework}.dmg' dmg")
(SH "mkdir dmg; cp -Rp '#{@framework}.framework' dmg")
(SH "hdiutil create -srcdir dmg '#{@framework}.dmg' -volname '#{@framework}'")
(SH "rm -rf dmg"))
(cond ((NSFileManager fileExistsNamed:"#{DEVROOT}/usr/bin/packagemaker") (set PACKAGEMAKER "#{DEVROOT}/usr/bin/packagemaker"))
((NSFileManager fileExistsNamed:"#{DEVROOT}/Tools/packagemaker") (set PACKAGEMAKER "#{DEVROOT}/Tools/packagemaker"))
(else (set PACKAGEMAKER "/Applications/PackageMaker.app/Contents/MacOS/PackageMaker")))
;; Build an installer and wrap it in a disk image.
(task "installer" => "framework" "nush" is
(SH "sudo rm -rf package dmg Nu.dmg")
(SH "mkdir -p package/Library/Frameworks")
(SH "mkdir -p package/usr/local/bin")
(SH "mkdir -p package/usr/local/share")
(SH "cp -pRfv #{@framework}.framework package/Library/Frameworks/#{@framework}.framework")
(SH "cp -pRfv share/nu package/usr/local/share")
(SH "cp -pRfv examples package/usr/local/share/nu")
(SH "cp nush package/usr/local/bin")
(SH "cp tools/* package/usr/local/bin")
(SH "sudo chown -R root package")
(SH "sudo chgrp -R admin package")
(SH "#{PACKAGEMAKER} -build -f package -p Nu.pkg -d pkg/Description.plist -i pkg/Info.plist")
(SH "mkdir dmg; mv Nu.pkg dmg")
(set imagefile "Nu-#{(VERSION first)}.#{(VERSION second)}.#{(VERSION third)}.dmg")
(SH "sudo rm -f #{imagefile}")
(SH "hdiutil create -srcdir dmg #{imagefile} -volname Nu")
(SH "sudo rm -rf dmg package"))
;; alias for installer task
(task "dmg" => "installer")
;; Create a tgz file of the Nu sources.
(task "archive" is
(SH <<-END
git archive --format=tar --prefix=Nu-#{(VERSION first)}.#{(VERSION second)}.#{(VERSION third)}/ HEAD |\
gzip -c > Nu-#{(VERSION first)}.#{(VERSION second)}.#{(VERSION third)}.tgz
END))
;; "Bake" nu source files into compilable Objective-C files.
(task "bake" is
(set nu_files (((NSString stringWithShellCommand:"ls nu/*.nu") chomp) componentsSeparatedByString:"\n"))
(nu_files each:
(do (nu_file)
(set basename (((nu_file pathComponents) lastObject) stringByDeletingPathExtension))
(set command "nubake #{nu_file} -n 'baked_#{basename}' -o baked/baked_#{basename}.m")
(puts command)
(system command))))