Makefile, foreach eval, missing separator in define - foreach

after reading through plenty of Q/A here, i cannont identify any missing tabs in my targets.mk leading to this error:
../targets.mk:84: *** missing separator. Stop.
Here goes a code excerpt:
define CORNER_TEMPLATE
.PHONY : ${1}
${1} : ${BASEFILENAME}_${1}.lib
TARGET_FILES += ${BASEFILENAME}${1}.lib
${BASEFILENAME}${1}.lib : override TMPDIR = ${BASEFILENAME}.tmp
${BASEFILENAME}_${1}.lib : export LIBERATE_CHAR_CORNER_TXT = ${call LIBERATE_CHAR_CORNER, ${1}, ${CELLNAMES}}
${BASEFILENAME}_${1}.lib : export LIBERATE_CHAR_TCL_TXT = ${call LIBERATE_CHAR_TCL, ${TMPDIR}, ${1}}
${BASEFILENAME}_${1}.lib : ${addsuffix .spi, ${CELLNAMES}}
#mkdir -p ${TMPDIR}
#echo "$${LIBERATE_CHAR_CORNER_TXT}" > ${TMPDIR}/corner.tcl
#echo "$${LIBERATE_CHAR_TCL_TXT}" > ${TMPDIR}/char.tcl
#cat ${addsuffix .spi, ${CELLNAMES}} > ${TMPDIR}/liberate.spi
cd ${TMPDIR} && liberate char.tcl
#touch $$#
endef
Line 84:
${foreach CORNER, ${CORNERS}, ${eval ${call CORNER_TEMPLATE,${CORNER}}}}

Related

How do I get the files in the build directory in another bazel rule

when use the python tool to generate the .cpp/.hpp code like the protobuf tool, but I don't know how many files will be generated, so it's a little not the same as protbuf tool.
In one genrule:
def __generate_core_ifce_impl(ctx):
...
output_file = ctx.actions.declare_directory(out)
cmd = """
mkdir -p {path};
""".format(path = output_file.path)
cmd += """
{tools} -i {src} -o {output_dir}
""".format(tools = tools, src = ctx.files.srcs, output_dir = output_file.path)
ctx.actions.run_shell(
command = cmd,
inputs = ctx.files.srcs,
outputs = [output_file]
)
return [DefaultInfo(files = depset([output_file])),]
_generate_core_ifce = rule (
implementation = __generate_core_ifce_impl,
attrs = {
"srcs": attr.label_list(mandatory = False, allow_files = True),
"tools": attr.label_list(mandatory = True, allow_files = True),
"out": attr.sting(mandatory = True),
},
)
In output_file directory , there will generate some *.cpp && *.hpp, but i can't know their names
then in another rule , cc_library will use *.cpp && *.hpp which are in output_file directory
the questions is: how to write this rule?
I can't get the files in the output_file diectory,
so I can't write the cc_library?
You should be able to use the name of the target, and the cc_library will use the files that are given in the DefaultInfo, e.g.:
_generate_core_ifce(
name = "my_generate_core_ifce_target",
...
)
cc_library(
name = "my_cc_library_target",
srcs = [":my_generate_core_ifce_target"],
...
)
edit: adding an example:
BUILD:
load(":defs.bzl", "my_rule")
my_rule(
name = "my_target",
)
cc_binary(
name = "cc",
srcs = [":my_target"],
)
defs.bzl:
def _impl(ctx):
output_dir = ctx.actions.declare_directory("my_outputs")
command = """
mkdir -p {output_dir}
cat > {output_dir}/main.c <<EOF
#include "stdio.h"
#include "mylib.h"
int main() {
printf("hello world %d\\n", get_num());
return 0;
}
EOF
cat > {output_dir}/mylib.c <<EOF
int get_num() {
return 42;
}
EOF
cat > {output_dir}/mylib.h <<EOF
int get_num();
EOF
""".replace("{output_dir}", output_dir.path)
ctx.actions.run_shell(
command = command,
outputs = [output_dir]
)
return [DefaultInfo(files = depset([output_dir])),]
my_rule = rule(
implementation = _impl,
)
usage:
$ bazel run cc
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:cc (15 packages loaded, 57 targets configured).
INFO: Found 1 target...
Target //:cc up-to-date:
bazel-bin/cc
INFO: Elapsed time: 3.626s, Critical Path: 0.06s
INFO: 8 processes: 4 internal, 4 linux-sandbox.
INFO: Build completed successfully, 8 total actions
INFO: Build completed successfully, 8 total actions
hello world 42

Ignore lines starting with # while reading a file in groovy

I'm writing a code in groovy to read a file line by line and perform an action (for ex: build a code for a specific configuration) based on the information available in the line.
The following groovy code runs fine for me, except that i want to ignore or skip the first line or rather any line which starts with # or comment (//).
__SAMPLE_GROOVY_CODE__
input_file = '/home/user/inputFile.txt'
// read all the lines into a list, each line is an element in the list
File FH1 = new File(input_file)
def lines = FH1.readLines()
for (line in lines)
{
env.c_num = sh(returnStdout: true, script: "echo '${line}' | cut -d ':' -f 1").trim();
env.p_num = sh(returnStdout: true, script: "echo '${line}' | cut -d ':' -f 2").trim();
env.p_len = p_num.length();
println("INFO: Length is ${p_len} \n");
if(env.p_len != '0')
{
println ("INFO: Build is required !! \n");
println ("INFO: c_num is: ${c_num} \n");
println ("INFO: p_num is: ${p_num} \n");
// Code for build will come here..!!
}
else
{
println("INFO: Build is NOT required !! \n");
}
}
__INPUT_FILE__
$> cat /home/user/inputFile.txt
# Details of inputFile.txt
1234-A0: aa ab ac ad ae al
5678-B0:
2345-B0: ba
3456-B0:
4567-B0: ca

How tell qmake NOT to create a folder?

I want to configurate my qmake so it will make my executables go under ./build/debug (or release). I've done that sucessfully with the following code:
CONFIG(debug, debug|release) {
DESTDIR = ./build/debug
TARGET = mShareLibd
}
CONFIG(release, debug|release) {
DESTDIR = ./build/release
TARGET = mShareLib
}
Everything works fine apart from the fact that qmake still creates two folders, namely "debug" and "release" in the project's root directory - so I end up with a "build", a "debug" (always empty) and a "release" (always empty) folder.
How can I tell qmake NOT to create this two folders? I did this question in the QtCentre forum (here is the link), but the way provided didn't seem to me to be a reasonable one. Isn't there a more reasonable approach - such as just write a command which tells "qmake, don't create this folders"?
Thanks,
Momergil
EDIT
Bill asked me to copy and paste my .pro file here. Here are the resumed version (most of the header and source files not included)
#qmake defines
MSHARE_REPO = $${PWD}/..
MSHARE_COMMON = $${MSHARE_REPO}/Common
MSHARE_LIB = $${MSHARE_REPO}/mShareLib
MLOGGER = $${MSHARE_REPO}/../Classes/mLogger
#inclusion
QT += core gui network multimedia sql
qtHaveModule(printsupport): QT += printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += qwt
#CONFIG *= precompile_header
#PRECOMPILED_HEADER = stdafx.h
#HEADERS += stdafx.h
TARGET = mShare
TEMPLATE = app
VER_MAJ = 0
VER_MIN = 0
VER_PAT = 7
VERSION = $${VER_MAJ}.$${VER_MIN}.$${VER_PAT}
INCLUDEPATH += MSHARE_REPO \
MSHARE_COMMON \
C:\Qt\Qwt-6.1.0\include
LIBS += $${PWD}/SMTPEmail.dll
DEFINES += MGENERALDEFINES_GUI \
MGENERALDEFINES_DEBUG \
MGENERALDEFINES_GENERAL \
QWT_INCLUDED \
APP_VERSION=\\\"$$VERSION\\\"
win32 {
LIBS += -lpsapi
CONFIG(debug, debug|release) { #debug {
LIBS += C:/Qt/Qwt-6.1.0/lib/qwtd.dll \
$${MLOGGER}/build/debug/mLogger.dll \ #$${MLOGGER}/debug/mLoggerd.dll \
$${MSHARE_LIB}/build/debug/mShareLibd.dll
DEFINES += DEBUG
DESTDIR = ./build/debug
}
CONFIG(release, debug|release) { #release {
LIBS += C:/Qt/Qwt-6.1.0/lib/qwt.dll \
$${MLOGGER}/build/release/mLogger.dll \
$${MSHARE_LIB}/build/release/mShareLib.dll
DEFINES += RELEASE \
QT_NO_DEBUG \
QT_NO_DEBUG_OUTPUT
DESTDIR = ./build/release
}
} # win32
#others
MOC_DIR = $${DESTDIR}/.moc
OBJECTS_DIR = $${DESTDIR}/.obj
UI_DIR = $${DESTDIR}/.ui
RCC_DIR = $${DESTDIR}/.rcc
########################################################################
HEADERS += AppDefines.hpp \
mreadwrite.hpp \
system/appbrain.hpp \
...
SOURCES += main.cpp \
mreadwrite.cpp \
system/appbrain.cpp \
...
FORMS += \
interface/entracedialog.ui \
interface/validationdialog.ui \
...
OTHER_FILES += Files/CandlePatternProbabilities.txt \
Project_Files/Readme.txt \
...
RESOURCES += \
Icons.qrc \
Setups.qrc \
GeneralFiles.qrc
RC_FILE = icone.rc
#TRANSLATIONS += DEFAULT_THEME_PATH/translations/app_pt.ts \
# DEFAULT_THEME_PATH/translations/app_de.ts
I think I've found the solution by looking at the QMake's source code : set the "PRECOMPILED_DIR" variable.
It works with Qt 5. Since the QMake source code doesn't change a lot, I think it also works with Qt 4.
CONFIG(debug, debug|release) {
DESTDIR = ./build/debug
PRECOMPILED_DIR = ./build/debug
TARGET = mShareLibd
}
CONFIG(release, debug|release) {
DESTDIR = ./build/release
PRECOMPILED_DIR = ./build/release
TARGET = mShareLib
}

Is it possible to prevent perforce submit without filename?

My usual way to submit a file is:
p4 submit –d “some description” filename
I could do:
p4 submit
and use the editor, but I always have many files open, so that method is inconvenient
Several times, I have mistakenly typed
p4 submit –d "some description"
(forgot the filename)
This submitted dozens of open files to production, with unintended consequences.
Time to panic and spend the afternoon doing damage control.
I would like to prevent p4 -d when the filename is not specified.
If you are using Linux you can define function in your .bashrs file that validates number of arguments and won't let you submit if you miss4th parameter.
function p4()
{
# validate what parameters are passed and if they are correct
# pass them to /opt/perforce/p4 ...
}
Thanks #pitseeker
I created a Perl wrapper "p4s" which checks the arguments and forwards the call to the real "p4 submit".
#!/usr/bin/perl
use warnings;
use strict;
use Capture::Tiny 'capture_merged';
die "Description and file is required!\n" if #ARGV < 2;
my ($description, #files) = #ARGV;
if ( -f $description ) {
die "It looks like you forgot the description before the filenames";
}
my $cmd;
my %summary;
print `date`;
for my $file (#files) {
if ( ! -f $file ) {
$summary{$file} = "File $file not found!";
next;
}
my $pwd = `pwd`;
chomp $pwd;
# print p4 filelog to screen
print `ls -l $file`;
$cmd = "p4 filelog $file | head -n 2";
$cmd = "p4 fstat -T 'headRev' $file";
print $cmd . "\n";
my $filelog = `$cmd`;
print "$filelog" . "\n";
$cmd = "p4 diff -sa $file";
my ($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
if ( ! $merged ) {
$summary{$file} = "Skipped since the local file does not differ from p4";
next;
}
# p4 submit
$cmd = "p4 submit -r -d \"$description\" $file";
print $cmd . "\n";
($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
chomp $merged;
print $merged . "\n";
if ( $merged =~ /No files to submit from the default changelist/ ) {
$summary{$file} = "$merged (You may need to 'p4 add' or 'p4 edit' this file)";
next;
}
$summary{$file} = "Success";
}
if ( scalar #files > 0 ) {
print "\nSummary:\n";
for my $file (#files) {
printf "%s %s\n", $file, $summary{$file};
}
}

Print Field into Terminal Command

Sorry for confusing you,
well, actually i want to send serial message to my arduino which is connected to /dev/ttyACM0 and it can be done by typing this command into terminal
$ echo "Hello Arduino" > /dev/ttyACM0
so, i need my awk to send a command just like that.
Here is my PBH.awk file:
BEGIN{
FS = "[ .]";
RS = "\0";
IGNORECASE = 1;
}{
for (i=1;i<NF;i++){
if(i == 1){
printf("Diketahui : %s\n",$18);}
if($i=="y" && $(i+1)=="=")
{
printf(" Persamaan : %s %s %s %s %s %s %s %s %s %s %s\n",$(i),$(i+1),$(i+2),$(i+3),$(i+4),$(i+5),$(i+6),$(i+7),$(i+8),$(i+9),$(i+10))
inisialisasi = "stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts"
kirim = "echo \"Field2 contains: $2""\" > /dev/ttyACM0"
print | inisialisasi
print | kirim
}
}
}
and here is the soalPBH.txt:
Persamaan gelombang berjalan pada seutas tali dinyatakan dengan y = 0,02 sin (20 π t – 0,2 π x). Jika x dan y dalam cm dan t dalam sekon, tentukan:
Then i run my awk with
$ awk -f PBH.awk soalPBH.txt
My program doesnt send the text on field number 2.
Is there something wrong with this??
kirim = "echo \"Field2 contains: $2""\" > /dev/ttyACM0"
Its VERY unclear what you're trying to do. Is this it:
$ cat file
field1 field2 field3
$ awk '{printf "echo \"Hello Arduino %s\" > /dev/ttyACM0\n", $2}' file
echo "Hello Arduino field2" > /dev/ttyACM0
If not, clarify your question and provide some clear sample input and expected output.
Given your updated question, just move the quote so $2 is outside of the quotes instead of inside of them, i.e. "$2 instead of $2":
kirim = "echo \"Field2 contains: " $2 "\" > /dev/ttyACM0"
Then tell us if you still have a problem.

Resources