Insert -l to each variable of set in makefile - makefile

I write makefile.
I have a variable set, which is the library I want to link to:
LIBS = core highgui
I want to make LIBS a VAR in some way:
#...some way, input is LIBS, output is VAR
VAR = -lcore -lhighgui
What is the some way?

Nothing is easier, just use addprefix:
VAR = $(addprefix -l,$(LIBS))

Related

map each item in list with a format in make

So I've got this variable:
ITEMS = item1 item2
and I want a function to do something like this:
ITEMS_AFTER := $(fmt prefix{}suffix, $(ITEMS))
so it will look like:
prefixitem1suffix prefixitem2suffix
how would I do it?
I hope i have a shorter way than using addprefix combined with addsuffix.
You can use foreach:
ITEMS_AFTER := $(foreach I,$(ITEMS),prefix$Isuffix)
or you can use patsubst:
ITEMS_AFTER := $(patsubst %,prefix%suffix,$(ITEMS))

How to generate 1 to 1 Source Map?

How to generate Source Map if the Source and Target are exactly the same?
One possible way is to write mapping for every single character in the file, like
x in source == x in target
It works, but the resulting Source Map size is huge. Is there any better way to do it?
P.S.
Why do I need such a strange thing? Because I need to join multiple source maps (batch).
a.js -- (possible) transformations --> |
... | -- join --> batch.js.map
x.js -- (possible) transformations --> |
In development we don't use minifications (so there's no initial source map for JS file), but still use batches, and I need source map (1to1 would be fine) to produce source map for the batch (I post-process source maps with special processor that sets correct offsets for batch source map, etc., but it needs a source map to start with).
There are several options to create an identity source map:
You could use the generate-source-map package. It works only for javascript files; it parses them and generates one mapping for each javascript token (operators, identifiers etc). Best quality maps but at the cost of generation time and map size.
var generate = require('generate-source-map');
var fs = require('fs');
var file = 'test.js';
var map = generate({
source: fs.readFileSync(file),
sourceFile: file
});
fs.writeFileSync(file + '.map', map.toString());
Then there's the more generic source-list-map. It works for any text file and generates 1-to-1 line mappings. Less detailed, probably faster and smaller maps.
var SourceListMap = require('source-list-map').SourceListMap;
var fs = require('fs');
var file = 'test.js';
var sourceListMap = new SourceListMap();
var fileContents = fs.readFileSync(file).toString();
sourceListMap.add(fileContents, file, fileContents);
var map = sourceListMap.toStringWithSourceMap({ file: file });
fs.writeFileSync(file + '.map', JSON.stringify(map));
For ultimate flexibility you could use the source-map package and do the splitting yourself:
var sourceMap = require('source-map');
var sourceMapResolve = require('source-map-resolve');
var fs = require('fs');
var file = 'test.js';
var fileContents = fs.readFileSync(file).toString();
var chunks = [];
var line = 1;
fileContents.match(/^[^\r\n]*(?:\r\n?|\n?)/mg).forEach(function(token) {
if (!/^\s*$/.test(token)) {
chunks.push(new sourceMap.SourceNode(line, 0, file, token));
}
++line;
});
var node = new sourceMap.SourceNode(null, null, null, chunks);
node.setSourceContent(file, fileContents);
var result = node.toStringWithSourceMap({file: file});
fs.writeFileSync(file + '.map', result.map);
The two last ones also provide additional functionality e.g. for merging multiple files together.

How do I translate this code from Visual Basic to Perl?

I am trying to export an Excel spreadsheet to SharePoint. I recorded the Visual Basic code, and now I want to translate it to Perl. I tried like this but it didn't work.
I don't get any error, but I also don't see the list in the Sharepoint. When I did it using the macro in Excel it worked
use Win32::OLE::Const 'Microsoft Excel';
my $excel = Win32::OLE->new('Excel.Application');
$excel->{'Visible'} = 1;
$excel->{DisplayAlerts} = 1;
my $book = $excel->Workbooks->Open("C:\\Book1.xlsx")
|| die("Unable to open document ", Win32::OLE->LastError());
my $list = $book->ActiveSheet->ListObjects("Table1")->Publish Array("https:\/\/sponsor\/sites\/dev_test_site", "myname"), False;
The original Visual Basic code
Sub Macro1()
ActiveSheet.ListObjects("Table1").Publish Array( _
"https://sponsor/sites/dev_test_site", "myname"), False
Range("C2").Select
End Sub
Eventually I came up with this code
my $excel = Win32::OLE->new('Excel.Application');
$excel->{'Visible'} = 1;
$excel->{DisplayAlerts} = 1;
my $book = $excel->Workbooks->Open("C:\\Book1.xlsm")
|| die("Unable to open document ", Win32::OLE->LastError());
my #array=("https:\/\/sponsor\/sites\/dev_test_site", "aaaa");
my $list= $book->ActiveSheet->ListObjects("hhhh")->Publish(#array, 0);
And this image shows the result
You should use strict and use warnings. It will proceed to tell you a number of error messages then.
What I can make out from the Perl code you posted without running it is:
my $list= $book->ActiveSheet->ListObjects("Table1")->Publish Array("https:\/\/sponsor\/sites\/dev_test_site", "myname"), False;
Note that there is a space between Publish and Array(. That has to be a problem. The only way to have a function cal followed by something other than ( or ; or , is if it has prototypes. But method calls in object oriented Perl cannot have prototypes. So that is definitely wrong.
Then there's Array(...). There is no built-in function called Array and I do not think that Win32::OLE::Const exports that, though I did not look. Even if it did, you told it to only export 'Microsoft Excel'. The same goes for False.
I suggest you read the documentation of Win32::OLE::Const and add use strict and use warnings. There are also some resources of how to work with Win32 modules on Sinan Ünürs blog.
You could take a look at this: Convert perl script to vba This already has some answers.
You may need to follow this script. % pp -o hello hello.pl or something like that.

Methods of declaring a variable in shell script

What is the difference between the following two methods of declaring a variable in shell script?
var='some/path'
var=${var:-"some/path"}
#this will set var value with some/path,
#no matter var is empty or not (overwrite)
var='some/path'
# this will set value of var to "some/path"
#only if var is empty/or not declared yet.
var=${var:-"some/path"}
var='some/path'
Will always set var to some/path
var=${var:-"some/path"}
Will only set var to some/path if var if not already set. If it is set, its value will not change.

Trying to get environment variables from a Widget widget.system()

I'm attempting to write some Dashcode to but can't seem to get the environment variables when I run the /env command. The environment doesn't appear to be sourced because it always returns "Undefined". Below is my code and I'm open for any suggestions (I need more than just LANG, LANG is just the example).
var textFieldToChange = document.getElementById("LangField");
var newFieldText = widget.system("/usr/bin/env | grep LANG").outputString;
textFieldToChange.value = newFieldText;
Is there an easy way to source my environment and cache it in Dashcode or do I need to attempt to write something that will cache the entire environment somehow?
Thanks for any ideas!
Have you allowed Command Line Access? Go to Widget Attributes (in the left hand menu) , then extensions and check Allow Command Line Access else the widget is prevented from talking to the system. Not sure if this is what is causing the problem though.
I know this thread is quite aged, but anyway, the question is still up to date :-)
Just having started with Dashcode and widgets myself, I did a quick hack on this:
function doGetEnv(event)
{
if (window.widget)
{
var out = widget.system("/bin/bash -c set", null).outputString;
document.getElementById("content").innerText = out;
}
}
For my experimental widget, I did use a scroll area and a button. The doGetEnv(event) is fired upon onclick, set via inspector. The Id "content" is the standard naming of the content within the scroll area.
The out var containes a string with '\n' charaters, to transform it into an array use split().
function doGetEnv(event)
{
if (window.widget)
{
var out = widget.system("/bin/bash -c set", null).outputString;
out = out.split("\n");
document.getElementById("content").innerText = out[0];
}
}
The first entry is "BASH..." in my case.
If you search for a particular item, use STRING's match method (see also http://www.w3schools.com/jsref/jsref_match.asp) along with the following pages on regular expressions:
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
http://www.w3schools.com/js/js_obj_regexp.asp
To cache the environment, you can use:
var envCache = "";
function cacheENV()
{
envCache = widget.system("/bin/bash -c set", null).outputString;
envCache = envCache.split("\n");
}
This will leave an array in envCache. Alternative:
function cacheENV()
{
var envCache = widget.system("/bin/bash -c set", null).outputString;
envCache = envCache.split("\n");
return envCache;
}

Resources