Permalink
Browse files

make luvit report building flags

  • Loading branch information...
1 parent 95cbe82 commit ce241571553ec57ce9593c8730241788f4bc9e13 @dvv dvv committed Feb 27, 2012
Showing with 52 additions and 63 deletions.
  1. 0 bin/.keepme
  2. +0 −62 bin/luvit-config.lua
  3. +52 −1 lib/luvit/luvit.lua
View
No changes.
View
@@ -1,62 +0,0 @@
-#!/usr/bin/env luvit
---[[
-
-Copyright 2012 The Luvit Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS-IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
---]]
-
-local Table = require('table')
-local OS = require('os')
-local command = process.argv[1]
-if command == "--libs" then
- local flags = {
- "-shared",
- "-lm"
- }
- if OS.type() == "Darwin" then
- if false then -- TODO: check if 64 bit
- Table.insert(flags, "-pagezero_size 10000")
- Table.insert(flags, "-image_base 100000000")
- end
- Table.insert(flags, "-undefined dynamic_lookup")
- end
- print(Table.concat(flags, " "))
-elseif command == "--cflags" then
- local Path = require('path')
- local Fs = require('fs')
- -- calculate includes relative to the binary
- local include_dir = Path.resolve(Path.dirname(process.execPath), "../include/luvit")
- -- if not found...
- if not Fs.existsSync(include_dir) then
- -- calculate includes relative to the symlink to the binary
- include_dir = Path.resolve(__dirname, "../include/luvit")
- end
- local flags = {
- "-I" .. include_dir,
- "-I" .. include_dir .. "/http_parser",
- "-I" .. include_dir .. "/uv",
- "-I" .. include_dir .. "/luajit",
- "-D_LARGEFILE_SOURCE",
- "-D_FILE_OFFSET_BITS=64",
- "-Wall -Werror",
- "-fPIC"
- }
- print(Table.concat(flags, " "))
-elseif command == "--version" or command == "-v" then
- print(process.version)
-else
- print "Usage: luvit-config [--version] [--cflags] [--libs]"
- -- Also note about rebase for OSX 64bit? <http://luajit.org/install.html#embed>
-end
View
@@ -165,7 +165,10 @@ Options:
-e code_chunk Evaluate code chunk and print result.
-i, --interactive Enter interactive repl after executing script.
-n, --no-color Disable colors.
- (Note, if no script is provided, a repl is run instead.)]])
+ (Note, if no script is provided, a repl is run instead.)
+ --cflags Print CFLAGS.
+ --libs Print LDFLAGS.
+]])
end
local realAssert = assert
@@ -200,6 +203,54 @@ assert(xpcall(function ()
interactive = true
elseif value == "-n" or value == "--no-color" then
usecolors = false
+ -- pkgconfig's --cflags
+ elseif value == "--cflags" then
+ local Table = require('table')
+ local Path = require("path")
+ local FS = require("fs")
+ -- calculate includes relative to the binary
+ p(process.execPath, Path.dirname(process.execPath))
+ local include_dir = Path.resolve(
+ Path.dirname(process.execPath),
+ "../include/luvit"
+ )
+ -- do some minimal realpathing
+ local function partialRealpath(filepath)
+ local link
+ link = FS.lstatSync(filepath).is_symbolic_link
+ and FS.readlinkSync(filepath)
+ while link do
+ filepath = Path.resolve(Path.dirname(filepath), link)
+ link = FS.lstatSync(filepath).is_symbolic_link
+ and FS.readlinkSync(filepath)
+ end
+ return Path.normalize(filepath)
+ end
+ -- realpath include dir
+ include_dir = partialRealpath(include_dir)
+ local cflags = {
+ "-I" .. include_dir,
+ "-D_LARGEFILE_SOURCE",
+ "-D_FILE_OFFSET_BITS=64",
+ "-Wall -Werror",
+ "-fPIC"
+ }
+ print(Table.concat(cflags, " "))
+ -- pkgconfig's --libs
+ elseif value == "--libs" then
+ local Table = require('table')
+ local libs = {
+ "-shared",
+ "-lm"
+ }
+ if require('os').type() == "Darwin" then
+ if false then -- TODO: check if 64 bit
+ Table.insert(libs, "-pagezero_size 10000")
+ Table.insert(libs, "-image_base 100000000")
+ end
+ Table.insert(libs, "-undefined dynamic_lookup")
+ end
+ print(Table.concat(libs, " "))
elseif value:sub(1, 1) == "-" then
usage()
process.exit(1)

0 comments on commit ce24157

Please sign in to comment.