forked from programming-nu/nu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nukefile
277 lines (236 loc) · 12 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
;; Nukefile for Nu framework and nush, the Nu shell
(global VERSION '(0 9 1)) #(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$"))
(@c_files unionSet:(filelist "^pcre/.*\.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")
(@inc_dirs addObject:"./pcre")
(@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")))))
(set @pcre_prefix "")
(let ((pcre_config ((NSString stringWithShellCommand:"which pcre-config 2>/dev/null") chomp)))
(if pcre_config
(then (set @pcre_prefix ((NSString stringWithShellCommand:"#{pcre_config} --prefix") chomp))
(@inc_dirs addObject:"#{@pcre_prefix}/include")
(@lib_dirs addObject:"#{@pcre_prefix}/lib"))))
;; 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 @cc "gcc")
(set @leopard "")
(set @sdk
(cond ((NSFileManager directoryExistsNamed:"/Developer/SDKs/MacOSX10.7.sdk")
(set @leopard "-DLEOPARD_OBJC2 -D__OBJC2__ -DSNOWLEOPARD -DLION")
("-isysroot /Developer/SDKs/MacOSX10.6.sdk")) ;; stay on the 10.6 SDK for now
((NSFileManager directoryExistsNamed:"/Developer/SDKs/MacOSX10.6.sdk")
(set @leopard "-DLEOPARD_OBJC2 -D__OBJC2__ -DSNOWLEOPARD")
("-isysroot /Developer/SDKs/MacOSX10.6.sdk"))
((NSFileManager directoryExistsNamed:"/Developer/SDKs/MacOSX10.5.sdk")
(set @leopard "-DLEOPARD_OBJC2 -D__OBJC2__")
("-isysroot /Developer/SDKs/MacOSX10.5.sdk"))
((NSFileManager directoryExistsNamed:"/Developer/SDKs/MacOSX10.4u.sdk")
("-isysroot /Developer/SDKs/MacOSX10.4u.sdk"))
(else "")))
(set @cflags "-Wall -g -std=gnu99 -fPIC")
(ifDarwin
(then (set @cflags (+ @cflags " -g -O2 -DDARWIN -DMACOSX #{@sdk} #{@leopard}"))
(set @mflags_nogc "-fobjc-exceptions")
(set @mflags (+ @mflags_nogc " -fobjc-gc"))) ;; To use garbage collection, add this flag: "-fobjc-gc"
(else (set @cflags "-Wall -g -std=gnu99 -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 '("i386")))) ;; optionally add "ppc" or "ppc64" to the list
(if (isSnowLeopard)
(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))
(ifDarwin
(set @public_headers (filelist "^include/Nu/Nu.h"))
(@public_headers unionSet:(filelist "^objc/.*\.h$")))
;; 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_nogc} 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} #{@gnustep_flags} -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 test/test_*.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" "nubile" "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 cp #{@library_executable_name} #{@installprefix}/lib")
;; copy the headers
(SH "sudo rm -rf #{@installprefix}/include/Nu")
(SH "sudo cp -rp include/Nu #{@installprefix}/include")
(SH "sudo cp -rp objc/*.h #{@installprefix}/include/Nu")
(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"))
(if (NSFileManager fileExistsNamed:"/Developer/usr/bin/packagemaker")
(then (set PACKAGEMAKER "/Developer/usr/bin/packagemaker"))
(else (set PACKAGEMAKER "/Developer/Tools/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))))