-
Notifications
You must be signed in to change notification settings - Fork 1
/
shake.hs
547 lines (471 loc) · 18.6 KB
/
shake.hs
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
{-# LANGUAGE TypeApplications #-} -- generic-lens
{-# LANGUAGE DataKinds #-} -- type-level strings
{-# LANGUAGE DeriveGeneric #-} -- generics
{-# LANGUAGE DeriveAnyClass #-} -- data-default
{-# LANGUAGE DuplicateRecordFields #-} -- generic-lens only handles the use site
import Control.Monad(forM_, join)
import Data.List(group, sort, (\\), stripPrefix)
import Data.Maybe(fromMaybe)
import System.FilePath.Glob
import GHC.Generics
import Data.Default
import Control.Lens hiding ((<.>))
import Data.Generics.Product
import System.Directory(createDirectoryIfMissing, getCurrentDirectory)
import Data.List.Extra(stripSuffix)
import Development.Shake
import Development.Shake.FilePath
import Development.Shake.Util
projectCfg :: ProjectCfg
projectCfg = def
main :: IO ()
main = shakeArgs (shakeOptions' (def :: DirCfg)) $ do
cwd <- liftIO $ getCurrentDirectory
let dircfg = projectCfg^.field @"dircfg"
action $ do
liftIO $ createDirectoryIfMissing True (dircfg^.field @"bld"</>"report")
-- base
let rolmodlDistPath = dircfg^.field @"dist"
let rolmodlLibPath = rolmodlDistPath</>"librolmodl.dylib"
let rolmodlTestPath = rolmodlDistPath</>"test"
let rolmodlTestSWTexPath = rolmodlDistPath</>"test_swtex"
-- rolmodl
let rolmodlLibCPPTargetCfg =
(def :: CPPTargetCfg)
& field @"name" .~ "rolmodl"
& field @"publicCPPObjs" .~ ["librolmodl.dylib"]
& field @"publicIncludeDirs" .~ ["hpp"]
let rolmodlLibCPPSourceCfg =
(def :: CPPSourceCfg)
& field @"fromInTarget" .~ ((<.> "cpp") <$> ["Base", "Event", "Kb", "Mouse", "PixelFmt", "Ren", "Tex", "Win", "SWTex"])
let rolmodlLibCPPIncludeListing =
(def :: CPPIncludeListing)
& field @"fromInTarget" .~ ["."]
let rolmodlLibSysCPPIncludeListing =
(def :: CPPIncludeListing)
& field @"fromWorld" .~ ["SDL2"]
let rolmodlLibCPPIncludeCfg =
(def :: CPPIncludeCfg)
& field @"warn" .~ rolmodlLibCPPIncludeListing
& field @"noWarn" .~ rolmodlLibSysCPPIncludeListing
let rolmodlLibCPPObjBuildCfg =
(def :: CPPObjBuildCfg)
& field @"target" .~ rolmodlLibCPPTargetCfg
& field @"srcs" .~ rolmodlLibCPPSourceCfg
& field @"includes" .~ rolmodlLibCPPIncludeCfg
genCPPObjBuildRules rolmodlLibCPPObjBuildCfg
let rolmodlLibCPPObjSourceCfg =
(def :: CPPObjSourceCfg)
& field @"fromCPPObjBuild" .~ [rolmodlLibCPPObjBuildCfg]
& field @"fromWorld" .~ ["libSDL2.dylib"]
let rolmodlLibCPPLinkBuildFlagCfg =
defaultCPPLinkBuildFlagCfg
& field @"common" <>~ ["-shared", "-install_name", "@rpath/librolmodl.dylib"]
let rolmodlLibCPPLinkBuildCfg =
(def :: CPPLinkBuildCfg)
& field @"name" .~ "librolmodl.dylib"
& field @"target" .~ rolmodlLibCPPTargetCfg
& field @"objs" .~ rolmodlLibCPPObjSourceCfg
& field @"flags" .~ rolmodlLibCPPLinkBuildFlagCfg
genCPPLinkBuildRules rolmodlLibCPPLinkBuildCfg
linkToDistRules (getCPPLinkPrimaryBuildOut rolmodlLibCPPLinkBuildCfg) rolmodlLibPath
-- test
let rolmodlTestCPPTargetCfg =
(def :: CPPTargetCfg)
& field @"name" .~ "test"
let rolmodlTestCPPSourceCfg =
(def :: CPPSourceCfg)
& field @"fromInTarget" .~ ((<.> "cpp") <$> ["main"])
let rolmodlTestCPPIncludeListing =
(def :: CPPIncludeListing)
& field @"fromInTarget" .~ ["."]
& field @"fromOtherTarget" .~ [rolmodlLibCPPTargetCfg]
let rolmodlTestSysCPPIncludeListing =
(def :: CPPIncludeListing)
& field @"fromWorld" .~ ["SDL2"]
let rolmodlTestCPPIncludeCfg =
(def :: CPPIncludeCfg)
& field @"warn" .~ rolmodlTestCPPIncludeListing
& field @"noWarn" .~ rolmodlTestSysCPPIncludeListing
let rolmodlTestCPPObjBuildCfg =
(def :: CPPObjBuildCfg)
& field @"target" .~ rolmodlTestCPPTargetCfg
& field @"srcs" .~ rolmodlTestCPPSourceCfg
& field @"includes" .~ rolmodlTestCPPIncludeCfg
genCPPObjBuildRules rolmodlTestCPPObjBuildCfg
let rolmodlTestCPPObjSourceCfg =
(def :: CPPObjSourceCfg)
& field @"fromCPPObjBuild" .~ [rolmodlTestCPPObjBuildCfg]
& field @"fromCPPLinkBuild" .~ [rolmodlLibCPPLinkBuildCfg]
& field @"fromWorld" .~ ["libSDL2.dylib"]
let rolmodlTestCPPLinkBuildFlagCfg =
defaultCPPLinkBuildFlagCfg
& field @"common" <>~ ["-rpath", "@executable_path"]
let rolmodlTestCPPLinkBuildCfg =
(def :: CPPLinkBuildCfg)
& field @"name" .~ "test"
& field @"target" .~ rolmodlTestCPPTargetCfg
& field @"objs" .~ rolmodlTestCPPObjSourceCfg
& field @"flags" .~ rolmodlTestCPPLinkBuildFlagCfg
genCPPLinkBuildRules rolmodlTestCPPLinkBuildCfg
let rolmodlTestSWTexCPPTargetCfg =
(def :: CPPTargetCfg)
& field @"name" .~ "test"
let rolmodlTestSWTexCPPSourceCfg =
rolmodlTestCPPSourceCfg
& field @"fromInTarget" .~ ((<.> "cpp") <$> ["main_swtex"])
let rolmodlTestSWTexCPPObjBuildCfg =
(def :: CPPObjBuildCfg)
& field @"target" .~ rolmodlTestSWTexCPPTargetCfg
& field @"srcs" .~ rolmodlTestSWTexCPPSourceCfg
& field @"includes" .~ rolmodlTestCPPIncludeCfg
genCPPObjBuildRules rolmodlTestSWTexCPPObjBuildCfg
let rolmodlTestSWTexCPPObjSourceCfg =
(def :: CPPObjSourceCfg)
& field @"fromCPPObjBuild" .~ [rolmodlTestSWTexCPPObjBuildCfg]
& field @"fromCPPLinkBuild" .~ [rolmodlLibCPPLinkBuildCfg]
& field @"fromWorld" .~ ["libSDL2.dylib"]
let rolmodlTestSWTexCPPLinkBuildCfg =
(def :: CPPLinkBuildCfg)
& field @"name" .~ "test_swtex"
& field @"target" .~ rolmodlTestSWTexCPPTargetCfg
& field @"objs" .~ rolmodlTestSWTexCPPObjSourceCfg
& field @"flags" .~ rolmodlTestCPPLinkBuildFlagCfg
genCPPLinkBuildRules rolmodlTestSWTexCPPLinkBuildCfg
linkToDistRules' (getCPPLinkPrimaryBuildOut rolmodlTestCPPLinkBuildCfg) rolmodlTestPath $ \out -> do
cmd_ "install_name_tool" "-add_rpath" [rolmodlDistPath] [out] -- changes the value of the dependency here because the changed file is actually just a link to the dep
return ()
linkToDistRules' (getCPPLinkPrimaryBuildOut rolmodlTestSWTexCPPLinkBuildCfg) rolmodlTestSWTexPath $ \out -> do
cmd_ "install_name_tool" "-add_rpath" [rolmodlDistPath] [out] -- changes the value of the dependency here because the changed file is actually just a link to the dep
return ()
want [rolmodlLibPath, rolmodlTestPath, rolmodlTestSWTexPath]
return ()
{-
ToDo:
- CPP: Check that CPPTargets' public outputs are actually produced
- CPP: Depend on separate CPP headers
- CPP: Depend on system libraries
- CPP: Add precompiled headers
- CPP: Add compile_commands generation
- Take clangCompDB out of ProjectCfg
- Look into record inheritance
- Allow querying actual outputs of targets for dependencies
- Allow for platform-specific compilation
- Look into proper named parameters
- Look into namespacing
- Handle dist outputs better
- Make a proper library out of this file
-}
shakeOptions' :: DirCfg -> ShakeOptions
shakeOptions' dc = shakeOptions{
shakeFiles = bldPath</>"builddb",
shakeReport = ((bldPath </> "report") </>) <$> [
"t"<.>"trace", "h"<.>"html"
],
shakeLint = Just LintBasic,
shakeTimings = True
}
where
bldPath :: FilePath
bldPath = projectCfg^.field @"dircfg".field @"bld"
data ProjectCfg = ProjectCfg {
dircfg :: DirCfg,
clangCompDB :: String
} deriving (Generic, Show)
instance Default ProjectCfg where
def = ProjectCfg {dircfg = def, clangCompDB = (def :: DirCfg)^.field @"bld" </> "compile_commands.json"}
data DirCfg = DirCfg {
src :: FilePath,
dist :: FilePath,
bld :: FilePath,
res :: FilePath,
world:: FilePath
} deriving (Generic, Show)
instance Default DirCfg where
def = DirCfg {
src = "src",
dist = "dist",
bld = "bld",
res = "res",
world = "world"
}
data CPPTargetCfg = CPPTargetCfg {
name :: String,
dircfgOverride :: Maybe DirCfg,
publicIncludeDirs :: [FilePath],
publicCPPObjs :: [FilePath],
publicCPPSources :: [FilePath]
} deriving (Generic, Default, Show)
defaultDircfgForCPPTargetNamed :: String -> DirCfg
defaultDircfgForCPPTargetNamed name =
foldr (\l cfg-> over l (</> name) cfg) (projectCfg^.field @"dircfg") [field @"src", field @"bld", field @"dist"]
dircfgForCPPTarget :: CPPTargetCfg -> DirCfg
dircfgForCPPTarget cfg =
case cfg^.field @"dircfgOverride" of
Just x -> x
Nothing -> defaultDircfgForCPPTargetNamed $ cfg^.field @"name"
data CPPIncludeListing = CPPIncludeListing {
fromInTarget :: [FilePath],
fromOtherTarget :: [CPPTargetCfg],
fromWorld :: [FilePath],
fromUnportablePath :: [FilePath]
} deriving (Generic, Default, Show)
cppIncludeListingToPaths :: CPPTargetCfg -> CPPIncludeListing -> [FilePath]
cppIncludeListingToPaths tcfg ilist =
join $
[(ilist^.field @"fromUnportablePath")] ++
[(tdircfg^.field @"src" </>) <$> (ilist^.field @"fromInTarget")] ++
[(tdircfg^.field @"world" </>) <$> (ilist^.field @"fromWorld")] ++
(includePathsForTarget <$> (ilist^.field @"fromOtherTarget"))
where
tdircfg :: DirCfg
tdircfg = dircfgForCPPTarget tcfg
includePathsForTarget :: CPPTargetCfg -> [FilePath]
includePathsForTarget tcfg =
let dircfg = dircfgForCPPTarget tcfg
in (dircfg^.field @"src" </>) <$> tcfg^.field @"publicIncludeDirs"
data CPPIncludeCfg = CPPIncludeCfg {
warn :: CPPIncludeListing,
noWarn :: CPPIncludeListing
} deriving (Generic, Default, Show)
data CPPFlagCfg = CPPFlagCfg {
common :: [String],
debug :: [String],
release :: [String]
} deriving (Generic, Default, Show)
defaultCPPObjectBuildFlagCfg :: CPPFlagCfg
defaultCPPObjectBuildFlagCfg =
CPPFlagCfg {
common = defaultCommon,
debug = ["-O0", "-g", "-glldb"],
release = ["-Ofast"]
}
where
defaultCommon :: [String]
defaultCommon =
let
warnFlags = [
"-Weverything", "-Wno-padded", -- "-Wno-float-equal",
"-Wno-c++98-compat", "-Wno-c++98-c++11-compat", "-Wno-c++98-c++11-compat-pedantic",
"-Wno-c++98-compat-pedantic", "-Wno-c99-extensions", "-Wno-c++98-c++11-c++14-compat"
]
diagFlags = ["-fcolor-diagnostics"]
in ["-std=c++1z"] ++ warnFlags ++ diagFlags
data CPPSourceCfg = CPPSourceCfg {
fromInTarget :: [FilePath],
fromOtherTarget :: [CPPTargetCfg],
fromWorld :: [FilePath],
fromUnportablePath :: [FilePath]
} deriving (Generic, Default, Show)
cppSourceCfgToPatterns :: CPPTargetCfg -> CPPSourceCfg -> [Pattern]
cppSourceCfgToPatterns tcfg cfg =
let strs = join $
[(tdircfg^.field @"src"</>) <$> (cfg^.field @"fromInTarget")] ++
(srcPatternsForTarget <$> (cfg^.field @"fromOtherTarget")) ++
[(tdircfg^.field @"world"</>) <$> (cfg^.field @"fromWorld")] ++
[cfg^.field @"fromUnportablePath"]
in compile <$> strs
where
tdircfg :: DirCfg
tdircfg = dircfgForCPPTarget tcfg
srcPatternsForTarget :: CPPTargetCfg -> [String]
srcPatternsForTarget tcfg =
let dircfg = dircfgForCPPTarget tcfg
in (dircfg^.field @"bld" </>) <$> tcfg^.field @"publicCPPSources"
cppSourceCfgToPaths :: CPPTargetCfg -> CPPSourceCfg -> IO [FilePath]
cppSourceCfgToPaths tcfg cfg =
dedup <$> join <$> globDir (cppSourceCfgToPatterns tcfg cfg) "."
data CPPObjBuildCfg = CPPObjBuildCfg {
target :: CPPTargetCfg,
dircfgOverride :: Maybe DirCfg,
srcs :: CPPSourceCfg,
includes :: CPPIncludeCfg,
compiler :: String,
debug :: Bool,
flags :: CPPFlagCfg
} deriving (Generic, Show)
instance Default CPPObjBuildCfg where
def = CPPObjBuildCfg {
target = def,
dircfgOverride = def,
srcs = def,
includes = def,
compiler = "clang++",
debug = True,
flags = defaultCPPObjectBuildFlagCfg
}
findCPPObjectBuildOuts :: CPPObjBuildCfg -> IO [FilePath]
findCPPObjectBuildOuts cfg = do
let outFromSrc = \x -> dircfg^.field @"bld"</>dropKnownDirname (dircfg^.field @"src") x-<.>"o"
(fmap outFromSrc) <$> cppSourceCfgToPaths (cfg^.field @"target") (cfg^.field @"srcs")
where
dircfg :: DirCfg
dircfg = dircfgForCPPObjBuild cfg
genCPPObjBuildRules :: CPPObjBuildCfg -> Rules ()
genCPPObjBuildRules cfg = do
files <- liftIO $ findCPPObjectBuildOuts cfg
let depFromOut = \x -> gendDepDir</>dropKnownDirname bldDir x-<.>"dep"
let outFromDep = \x -> bldDir</>dropKnownDirname gendDepDir x-<.>"o"
let clangCDBFromOut = \x -> clangCDBDir</>dropKnownDirname bldDir x-<.>"json"
let outFromClangCDB = \x -> bldDir</>dropKnownDirname clangCDBDir x-<.>"o"
files |%> \f -> buildFn f (depFromOut f) (clangCDBFromOut f)
fmap depFromOut files |%> \x -> need [outFromDep x]
fmap clangCDBFromOut files |%> \x -> need [outFromClangCDB x]
where
tcfg :: CPPTargetCfg
tcfg = cfg^.field @"target"
dircfg :: DirCfg
dircfg = dircfgForCPPObjBuild cfg
bldDir :: FilePath
bldDir = dircfg^.field @"bld"
gendDepDir :: FilePath
gendDepDir = bldDir</>"gendDep"
clangCDBDir :: FilePath
clangCDBDir = bldDir</>"clangCDB"
buildFn :: FilePath -> FilePath -> FilePath -> Action ()
buildFn out dep clangCDB = do
liftIO $ forM_ (takeDirectory <$> [out, dep, clangCDB]) (createDirectoryIfMissing True)
let src = (dircfg^.field @"src")</>dropKnownDirname (dircfg^.field @"bld") out-<.>"cpp"
need [src]
let command =
[cfg^.field @"compiler"] ++
(cfg^.field @"flags".field @"common") ++
(if cfg^.field @"debug" then cfg^.field @"flags".field @"debug" else cfg^.field @"flags".field @"release") ++
(("-isystem"++) <$> cppIncludeListingToPaths tcfg (cfg^.field @"includes".field @"noWarn")) ++
(("-I"++) <$> cppIncludeListingToPaths tcfg (cfg^.field @"includes".field @"warn")) ++
["-o", out]
cmd_ command "-M" "-MF" [dep] [src]
needMakefileDependencies dep
cmd_ command "-MJ" [clangCDB] "-c" [src]
return ()
dircfgForCPPObjBuild :: CPPObjBuildCfg -> DirCfg
dircfgForCPPObjBuild cfg =
case cfg^.field @"dircfgOverride" of
Just x -> x
Nothing -> over (field @"bld") (</> "cpp_o") (dircfgForCPPTarget $ cfg^.field @"target")
data CPPObjSourceCfg = CPPObjSourceCfg {
fromInTarget :: [FilePath],
fromCPPLinkBuild :: [CPPLinkBuildCfg],
fromWorld :: [FilePath],
fromUnportablePath :: [FilePath],
fromCPPObjBuild :: [CPPObjBuildCfg]
} deriving (Generic, Default, Show)
cppObjSourceCfgToPaths :: CPPTargetCfg -> CPPObjSourceCfg -> IO [FilePath]
cppObjSourceCfgToPaths tcfg cfg = do
cppObjBuildOuts <- mapM findCPPObjectBuildOuts (cfg^.field @"fromCPPObjBuild")
return . join $
[(tdircfg^.field @"src"</>) <$> (cfg^.field @"fromInTarget")] ++
(objPathsForLinkBuild <$> (cfg^.field @"fromCPPLinkBuild")) ++
[(tdircfg^.field @"world"</>) <$> (cfg^.field @"fromWorld")] ++
[cfg^.field @"fromUnportablePath"] ++
cppObjBuildOuts
where
tdircfg :: DirCfg
tdircfg = dircfgForCPPTarget tcfg
objPathsForLinkBuild :: CPPLinkBuildCfg -> [FilePath]
objPathsForLinkBuild cfg =
let dircfg = dircfgForCPPLinkBuild cfg
in (dircfg^.field @"bld" </>) <$> cfg^.field @"target".field @"publicCPPObjs"
data CPPLibSearchPathCfg = CPPLibSearchPathCfg {
fromWorld :: [FilePath],
fromUnportablePath :: [FilePath]
} deriving (Generic, Default, Show)
cppLibSearchPathCfgToPaths :: CPPTargetCfg -> CPPLibSearchPathCfg -> [FilePath]
cppLibSearchPathCfgToPaths tcfg cfg =
((tdircfg^.field @"world" </>) <$> (cfg^.field @"fromWorld")) ++ (cfg^.field @"fromUnportablePath")
where
tdircfg :: DirCfg
tdircfg = dircfgForCPPTarget tcfg
data CPPLostLibCfg = CPPLostLibCfg {
names :: [String],
searchPath :: CPPLibSearchPathCfg
} deriving (Generic, Default, Show)
data CPPLinkBuildCfg = CPPLinkBuildCfg {
name :: String,
target :: CPPTargetCfg,
dircfgOverride :: Maybe DirCfg,
objs :: CPPObjSourceCfg,
lostLibs :: CPPLostLibCfg,
linker :: String,
debug :: Bool,
flags :: CPPFlagCfg
} deriving (Generic, Show)
instance Default CPPLinkBuildCfg where
def = CPPLinkBuildCfg {
name = "dist",
target = def,
dircfgOverride = def,
objs = def,
lostLibs = def,
linker = "clang++",
debug = True,
flags = defaultCPPLinkBuildFlagCfg
}
defaultCPPLinkBuildFlagCfg :: CPPFlagCfg
defaultCPPLinkBuildFlagCfg =
CPPFlagCfg {
common = [],
debug = [],
release = []
}
genCPPLinkBuildRules :: CPPLinkBuildCfg -> Rules ()
genCPPLinkBuildRules cfg =
getCPPLinkPrimaryBuildOut cfg %> \out -> do
srcs <- liftIO $ cppObjSourceCfgToPaths tcfg (cfg^.field @"objs")
need srcs
let command =
[cfg^.field @"linker"] ++
(cfg^.field @"flags".field @"common") ++
(if cfg^.field @"debug" then cfg^.field @"flags".field @"debug" else cfg^.field @"flags".field @"release") ++
(("-L"++) <$> (cppLibSearchPathCfgToPaths tcfg $ cfg^.field @"lostLibs".field @"searchPath")) ++
(("-l"++) <$> (cfg^.field @"lostLibs".field @"names")) ++
["-o", out]
cmd_ command srcs
return ()
where
tcfg :: CPPTargetCfg
tcfg = cfg^.field @"target"
dircfg :: DirCfg
dircfg = dircfgForCPPLinkBuild cfg
dircfgForCPPLinkBuild :: CPPLinkBuildCfg -> DirCfg
dircfgForCPPLinkBuild cfg =
case cfg^.field @"dircfgOverride" of
Just x -> x
Nothing -> over (field @"bld") (</> "cpp_bin") (dircfgForCPPTarget $ cfg^.field @"target")
getCPPLinkPrimaryBuildOut :: CPPLinkBuildCfg -> FilePath
getCPPLinkPrimaryBuildOut cfg = (dircfgForCPPLinkBuild cfg)^.field @"bld"</>cfg^.field @"name"
getCPPLinkBuildOuts :: CPPLinkBuildCfg -> [FilePath]
getCPPLinkBuildOuts cfg =
[getCPPLinkPrimaryBuildOut cfg]
where
dircfg :: DirCfg
dircfg = dircfgForCPPLinkBuild cfg
linkToDistRules :: FilePath -> FilePath -> Rules ()
linkToDistRules inp out =
linkToDistRules' inp out (\_ -> return ())
linkToDistRules' :: FilePath -> FilePath -> (FilePath -> Action ()) -> Rules ()
linkToDistRules' inp out act =
out %> \_ -> do
cwd <- liftIO $ getCurrentDirectory
need [inp]
cmd_ "ln" "-sf" [cwd</>inp] out
act out
dropKnownDirname :: FilePath -> FilePath -> FilePath
dropKnownDirname base x = joinPath $ dropDir (splitPath base) (splitPath x)
where
dropDir :: [FilePath] -> [FilePath] -> [FilePath]
dropDir [] xs = xs
dropDir _ [] = []
dropDir (b:bs) (x:xs) =
if x == "." || x == "./" then
dropDir (b:bs) xs
else if b == "." || b == "./" then
dropDir bs (x:xs)
else
let diff = x \\ b
in if diff == "" || diff == "/" then
dropDir bs xs
else
error $ "Could not drop '"++(joinPath (b:bs))++"' from '"++(joinPath (x:xs))++"'\n" ++ show (b:bs) ++ " " ++ show (x:xs)
dedup :: (Eq a, Ord a) => [a] -> [a]
dedup = map head . group . sort