date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,507,439,499,000
I have this bash code combined with getopts and if I understood getopts correctly OPTIND contains the index of the next command line option and all the command line options provided to shell script are presented in the variables $1, $2, $3 etc.. Correct me if I am wrong but basically the same concept as local variable...
It's because all of your logic depends on one of $OPT_[AB] being null. But even if you don't pass a -[ab] $OPTARG parameter, you're still setting them at the top of the script with OPT_[AB]=[AB]. So your logic chains never get past the root... if [[ -z $OPT_A ]]; then... ...statement. Well... not all of your logic de...
How do I use inserted values using getopts
1,507,439,499,000
I'm looking for way to process shell script arguments that is cleaner and more "self documenting" than getopt/getopts. It would need to provide... Full support of long options with or without a value after '=' or ' '(space). Proper handling of hyphenated option names (i.e. --ignore-case) Proper handling of quoted opt...
Since this question has been viewed so much (for me at least) but no answers were submitted, passing on the solution adopted... NOTE Some functions, like the multi-interface output functions ifHelpShow() and uiShow() are used but not included here as their calls contain relevant information but their implementatio...
Simpler processing of shell script options
1,507,439,499,000
I am using the customary way of using getopts through a variable named arg. I can capture the option names as follows. Is it possible to detect the moment getopts reaches "--" so that I can issue a message? while getopts "$shortopts" arg; do echo "--> arg: $arg" case $arg in ("V") printf '%s\n' "Versio...
Is it possible to detect the moment getopts reaches "--" so that I can issue a message? You shouldn't need to. getopts implements the standard option processing, which means that it stops looking for options when it either sees an argument that's not an option, or if it sees the argument --, which explicitly termina...
Detecting getopts `--` (double dash) to issue a message
1,507,439,499,000
I am switching away from BSD to completely Linux. Script in Ubuntu 16.04 #!/bin/sh while (( "$#" )); do case "$1" in -i | --ignore-case) [ $# -ne 2 ] && echo "2 arguments i needed" && exit 1 case_option=-i ;; -*) echo "Error: Unknown option: $1" >&2 exit 1 ;; ...
Here are two examples of options processing, first with the shell built-in getopts and then with getopt from util-linux. getopts doesn't support --long options, only short options. getopt supports both. If you want to use getopt, use ONLY the version from the util-linux package. DO NOT use any other version of getopt...
Why this while-case does not work in Ubuntu?
1,507,439,499,000
I am writing a simple bash script. My script installs ppa. The problem is I can't add two arguments. I want to write something simple like this: ./ppa.sh -i ppa:chris-lea/node.js nodejs I tried this, but doesn't read the second argument 'nodejs'... #! /bin/sh # Install/add PPA or Program while getopts ":i:e:" op...
You should put two arguments in quote or double quote: % ./ppa.sh -i 'ppa:chris-lea/node.js nodejs' received -i with ppa:chris-lea/node.js nodejs
How to input two arguments with getopts? [duplicate]
1,507,439,499,000
I'm trying to figure out a way to deny the usage of more than one getopts args in a certain situation. Say we have something like this: while getopts "a:b:c:def" variable; do case $variable in a)a=$OPTARG b)b=$OPTARG c)c=$OPTARG d)MODE=SMTH e)MODE=SMTH2 f)MODE=SMTH3 esac done What im trying to do is to deny the use o...
You need to initialize MODE as some value other than SMTH, SMTH2 and SMTH3. Then, check if MODE is at the initial value. If not, throw an error message and then exit. You have to exit after error, otherwise script will keep running. The modified version of your script below should get you started. MODE=0 EMSG="More th...
deny use of multiple getopts arguments
1,507,439,499,000
I have read the getopts man page and am still not sure about this use case. getopts is not detecting any available options the second time a function is called in the same script. As you can see from my debug echo outputs, all of the positional params $@ are present for both function calls. In the second create_db ...
Each time you call getopts, it uses $OPTIND; If the application sets OPTIND to the value 1, a new set of parameters can be used: either the current positional parameters or new arg values. Any other attempt to invoke getopts multiple times in a single shell execution environment with parame...
getopts in function that is called more than once in a script, getopts doesn't detect any opts after 1st function call [duplicate]
1,507,439,499,000
When using getopts with case clause, is a *) pattern subclause as the last pattern subclause equivalent to the union of \?) and :) pattern subclauses as the last two pattern subclauses? Specifically, while getopts "<optionString>" opt; do case $opt in a) a="$OPTARG" ;; b) b="$OPTARG" ...
You only really need to check for : and ? with the getopts in bash if you use silent error reporting (when the first character of the optstring is a colon). When getopts in not used in that way, it will produce its own diagnostic messages for invalid options and for missing option arguments (and these are usually quit...
When using `getopts` with `case`: `*)` as the last pattern subclause, or `\?)` and `:)` as the last two pattern subclauses?
1,507,439,499,000
I'm learning Bash, and I've written a basic function: wsgc () { # Wipe the global variable value for `getopts`. OPTIND=1; echo "git add -A"; while getopts m:p option; do case "${option}" in m) COMMIT_MESSAGE=$OPTARG if [ "$COMMIT_MESSAGE" ...
the if in m) isn't working, in that if I omit the argument, Bash intercedes and kicks me out of the session; You specify getopts m:p option. The : after the m means that you need an argument. If you don't provide it, it's an error. After running: wsgc -m "Yo!" -p, I get kicked out of the session. What do you mean ...
Bash: Help honing a custom function
1,507,439,499,000
I'm looking for a way to do option parsing in a Bash script (allowing for both short and long arguments as getopt does) that stops parsing at the first unrecognized argument, places a -- before that first unrecognized argument, and then copies the remaining arguments to the output string. For example, here's the behav...
The solution to this problem requires something other than getopt because getopt rearranges options that it finds that do match the option specification and terminates on unrecognized options. The Bash built-in getopts comes to the rescue, but needs to be able to handle long options. In a post by Arvid Requate and Tom...
How can options be parsed in a Bash script, leaving unrecognized options after the "--"?
1,507,439,499,000
I would be glad if someone clarified the need to use shift in this simple parser code: while getopts ":hp:" option do case "${option}" in p) some_parameter=${OPTARG} ;; h) print_usage_and_exit 0 ;; *) print_usage_and_exit 1 ...
You don’t need to shift (and shouldn’t) inside the loop because getopts tracks which positional parameter it’s processing by updating the OPTIND variable. You don’t need to shift after the loop: you can use OPTIND to determine which positional parameters to handle yourself. Using shift however is the simplest way of ...
shift in getopts loop - clarification needed
1,507,439,499,000
I'd like to have named parameters for my functions. I seem to only be able to use GETOPTS for the main function called from the command line. If I have multiple functions within one file is there any way I can get the same sort of functionality (named parameters) when calling other functions ? e.g. the following does ...
Your program does not work because you pass parameters to your program but inside the program you call your function my_test without the option flags -s and -p resp. Depending what you actually want, use either my_test -s 11 -p 20 or pass the arguments from outside and call your function as my_test "$@"
How to have getopts functionality when just calling another function within the file
1,507,439,499,000
I have to check if particular argument lets say 'java8' is present in my shell arguments to script and if it is present remove it . Also I want it to be stored in some other variable , but want it to be removed from my $*. One option I Trie checking if arg is present using getopts but I dont know how to remove argum...
Maybe something like this? I'm assuming you want to remove -f java8... #!/bin/bash while (( $# )); do if [[ $1 = "-f" ]] && [[ $2 = "java8" ]]; then shift 2 continue fi args+=( "$1" ) shift done echo "${args[*]}" Example usage: $ ./argtest.sh one two three one two three $ ./argtest....
identify if present and remove specific argument from shell args
1,507,439,499,000
I am writing a shell script and new to getopts for parameter parsing. What I have are 1 optional and 2 mandatory parameters and what I want to do is ensure that only one mandatory parameter is passed. Right now a basic validation exists but its practically useless long term. I looked at other examples using if conditi...
Set a variable deciding which task to run in the getopts loop, then manually check that only one task is chosen. You could do that in various ways, e.g.: #!/bin/sh task= set_task() { if [ -n "$task" ]; then echo "only one of -a and -b may be used" >&2 exit 1 fi task=$1 } while getopts ':n:a...
Ensuring only 1 mandatory parameter is passed to script
1,507,439,499,000
I'm trying to get it to call a function. Here is my code #!/bin/bash while getopts ":a:b:" opt; do case $opt in a) my_function "%e" ;; b) my_function "%s" ;; /?) echo "Invalid option: -$OPTARG" ;; esac done my_fu...
For a shell script to be able to call a function, that function has to have been defined before calling it. This is not the case in your code. To fix it, move the function to above the command line parsing loop. Also, I would make the last case test be *) to catch any unhandled option (/? would never match a single o...
Trying to get getopts to call a function [duplicate]
1,507,439,499,000
I want to escape the first string SOMETEXT in the getopts args. But I'm only able to do it in the first example. How can I make it work on the second example? while getopts p: opt do case $opt in p) result=$OPTARG;; esac done echo "The result is $result " Example 1: run_test.ksh -p3 SOMETEXT The result is ...
This is a consequence of using getopts. Parameters and their arguments must come before any other text. If you know that the first word is SOMETEXT you could strip it from the argument list that getopts processes: if [[ 'SOMETEXT' == "$1" ]] then echo "Found SOMETEXT at the beginning of the line" shift fi whi...
parsing getopts
1,507,439,499,000
I want to add a line of code that tells the user that enough arguments were not given (may be an error message somewhere. but i am not sure where?) blastfile= comparefile= referencegenome= referenceCDS= help=''' USAGE: sh lincRNA_pipeline.sh -c </path/to/cuffcompare_output file> -g </path/to/reference...
One approach would be to count the options as getopts parses them. Then, you can exit if less than a given number were passed: #!/usr/bin/env bash blastfile= comparefile= referencegenome= referenceCDS= help=''' USAGE: sh lincRNA_pipeline.sh -c </path/to/cuffcompare_output file> -g </path/to/reference ...
How can I detect that not enough options were passed with getopts
1,507,439,499,000
I have function port.sh as stand alone script and i'm wondering if is possible to put this function in the same script where getopts is and pass value of OPT_B into function and get output of it? OPT_B=B while getopts :a FLAG; do case $FLAG in b) #set option "b" OPT...
Don't use function port() - it doesn't actually make any sense. When declaring a bash or ksh function with the function command you don't use the () but the shell accepts it as a forgivable syntax oops and acts like you didn't use function at all. So don't. port() case ${1:--} in (B) OPT_B=8000;; (*[!0-9]*) !...
getopts passing value of declared parameter to function
1,507,439,499,000
I am trying to make script that has two switches -h and -d, -d having a mandatory number argument. After it there will be undetermined number of paths to file. So far, I have this, but the code seems to not recognize invalid switch -r (can be any name) and also does not work when I do not input any switches: while ge...
[ "$OPTARG" -eq "$OPTARG" ] ... is not the right way to check if $OPTARG is numeric -- it may print a nasty inscrutable error to the user if that's not the case, or it may just return true in all cases (in ksh), or also return true for an empty $OPTARG (in zsh). Also, an option taking an argument may be given as eithe...
GETOPTS parse empty and nonempty args
1,507,439,499,000
Bash manual says getopts optstring name [args] When the end of options is encountered, getopts exits with a return value greater than zero. OPTIND is set to the index of the first non-option argument and name is set to ?. In an example from the Bash Hackers Wiki getopts tutorial: while getopts ":a" opt; do ca...
It’s there to process invalid options. In the example, if you run script -a, the -a option is expected and results in “-a was triggered!”. If you run script -b, -b isn’t valid and will be handled by the \? case, resulting in “Invalid option: -b”.
What happens to getopts when the end of options is encountered
1,507,439,499,000
A stackoverflow post has a template for handling command line arguments. Does the test [ $# == 0 ] mean that a bash script shouldn't be run without any argument? As a template, I think that scripts generally do not necessarily require any argument. In the case statement, how different are the two cases *) and "?") ...
This script requires at least one arg, if not it displays usage info. It should do echo $USAGE >&2 as this is an error. Other scripts may work with zero arguments, so you will have to modify. Just as some don't take the argument i. "?", vs * Yes they are different: "?" says to case to look for a ?. This is what getop...
Questions about understanding a template of using bash's getopts
1,507,439,499,000
Bash manual says getopts optstring name [args] When the end of options is encountered, getopts exits with a return value greater than zero. OPTIND is set to the index of the first non-option argument and name is set to ?. Does it mean that getopts only read in options and option arguments, but not arguments w...
Yes, getopts is the tool to parse options in the POSIX way (even in bash, the GNU shell): In: cmd -abc -dxx -e yy arg -f -g (with an optspec of :abcd:e:fg) -f and -g are regular arguments. getopts stops at that arg. Generally, you do: while getopts... case...esac done shift "$((OPTIND - 1))" echo Remaining argument...
Does getopts read in command line arguments in some order?
1,507,439,499,000
My small POSIX shell scripts do not usually take any arguments, so this is kind of new to me... The minimal snippet would probably look like this: # default for hotkey variable on top of script is set hotkey=Print ... while getopts ':hk:' option; do case "$option" in k) # override default hotkey variable...
shift $(( OPTIND - 1 )) removes the arguments that were parsed by getopts. For example, if you do ./yourscript.sh -k x y z, that makes $1 be y instead of -k. If you aren't using $@, $1, etc. after your getopts loop, then you don't need that line for anything.
Manipulating arguments with OPTIND, OPTARG, getopts, and shift correctly
1,507,439,499,000
I have a script with this usage: myscript [options] positional-args... -- [fwd-params] Because [options] can have long, or short variants, I like using getopt. But I'm having troubles. I use getopt like this: args=$(getopt -o a:,b --long alpha:,gamma -- "$@") eval set -- "$args" while : ; do case "$1" in -a |...
Well, if the user passes the arguments -a 1 -b pos1 pos2 -- fwd1, getopt takes the -- as the marker making all following arguments non-options. It's not a positional argument itself here. If you want the -- to appear as-is, your user would have to explicly add the marker, and another -- one after to separate the two s...
getopt with several `--`
1,507,439,499,000
How can I use getopt or getopts with subcommands and long options, not with short options? I know how to implement short and long options with getopts. Solutions that I've found so far are using getopts in subcommand switch-case but with short options, for example: https://stackoverflow.com/questions/402377/using-geto...
Parse them manually in a function, and call the function with the "$@". After the call, any residual non-options are in $1, $2, etc. Note, in this example, I'm using associative arrays to hold the switches. If you don't have bash 3 or later, you can use global variables instead. The subcommand will be args[0] and its ...
Bash script with subcommand and long options only
1,507,439,499,000
I have a bash script which processes an input file with optional arguments. The script looks like this #!/bin/bash while getopts a:b:i: option do case "${option}" in a) arg1=${OPTARG};; b) arg2=${OPTARG};; i) file=${OPTARG};; esac done [ -z "$file" ] && { echo "No input file specified" ; exit; } carry out some stuff...
#!/bin/sh - # Beware variables can be inherited from the environment. So # it's important to start with a clean slate if you're going to # dereference variables while not being guaranteed that they'll # be assigned to: unset -v file arg1 arg2 # no need to initialise OPTIND here as it's the first and only # use of ge...
Processing optional arguments with getopts in bash
1,507,439,499,000
I have a script (let’s call it scriptC) that uses getopt to parse short and long options and works fine. This script is being called like this: scriptA runs scriptB which calls scriptC with the proper parameters. Question: Is it possible to pass the same parameters as arguments to scriptA and then those be passed over...
If scriptA calls scriptB like scriptB "$@" then the command line arguments that were used for invoking scriptA will be passed to scriptB provided that these have not been altered before the call. Likewise for the call from scriptB to scriptC. As long as scriptA and scriptB does not try to interpret, change or otherwi...
Pass params for getopt from a script that does not use getopt
1,507,439,499,000
I have the following snippet: #!/bin/bash OPTIND=1 while getopts ":m:t" params; do case "${params}" in m) bar=$OPTARG ;; t) foo=$OPTARG ;; \?) "Invalid option: -$OPTARG" >&2 print_usage exit 2 ;; :) ...
By piping the output to xargs, which converts its input into arguments: echo "this is the test" | xargs bash getoptscript.sh -m - Which will result in: bash getoptscript.sh -m - this is the test
How to output piped stdout in bash script from getopts?
1,507,439,499,000
#!/bin/bash while getopts ":r" opt; do case $opt in r) [ -f "$1" ] && input="$1" || input="-" read $userinp cat $input | tr -d "$userinp" ;; esac done That is my code. Essentially I'm trying to either parse a file or a string and have the user choose a character to delete from the text or ...
The character (or set, or range) to delete is given by the -r flags's argument, so there's no need to read it. The filename (if any) is left in the positional argument after command line processing is done. Don't process the file when you're not yet done with processing the command line flags. The option string to ge...
In a bash script, how may I use "tr -d" to delete a user entered char?
1,493,192,554,000
As I understand for text-based interaction with the Linux kernel, a program called init starts getty (or agetty) which connects to one of the TTY devices under /dev and prompts for a username. After this, a program called login is run which prompts for the user's password and if correct, then launches the user's prefe...
The shell uses a TTY device (if it’s connected to one) to obtain user input and to produce output, and not much else. The fact that a shell is connected to a TTY is determined by getty (and preserved by login); most of the time the shell doesn’t care whether it’s connected to a TTY or not. Its interaction with the ker...
How does X11 interact with the kernel / perform login
1,493,192,554,000
By default when I login to my Arch linux box in a tty, there is a timeout after I type my username but before I type my password. So it goes like this Login: mylogin <enter> Password: (+ 60 seconds) Login: As you can see, if I don't type the password it recycles the prompt -- I want it to wait indefinitely for my pa...
agetty calls login after reading in the user name, so any timeout when reading the password is done by login. To change this, edit /etc/login.defs and change the LOGIN_TIMEOUT value. # # Max time in seconds for login # LOGIN_TIMEOUT 60
change tty login timeout - ArchLinux
1,493,192,554,000
When I looked in the manual for agetty all I saw was alternative getty
There was a program named getty in 1st Edition Unix. The BSDs usually have a program named getty that is a (fairly) direct descendant of this. It (nowadays) reads /etc/ttys for the database of configured terminal devices and /etc/gettytab for the database of terminal line types (a line type being passed as an argume...
What is the difference between getty and agetty?
1,493,192,554,000
I have a line in my inittab like the following: # Put a getty on the serial port ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL If I try to perform a similar operation from an ssh session command line (this time towards a usb-serial adapter I have): /sbin/getty -L ttyUSB0 115200 vt100 I receive th...
I solved that problem running : su root -c "getty /dev/ttyXX" I am running busybox 1.23.1 on an ARM platform.
getty start from command line?
1,493,192,554,000
I have connected a USB-to-serial cable from OS X to a Banana Pi board running Arch Linux ARM, distributed by Lemaker. The connection itself works well - I see all the boot messages on startup, I can drop to U-Boot and issue commands etc.; I assume that the connection itself is working as expected. However, as soon as ...
After reading more on the internets I found out that a newer version of systemd requires a kernel with configuration option CONFIG_FHANDLE=y - however, this option is not present on the kernel version included in the official banana-pi ArchLinux image (3.4.90). I recompiled the kernel with the option included and now ...
No login prompt on serial console
1,493,192,554,000
Is it possible to use agetty from the command line? I tried the command sudo agetty -s 34800 tty8 linux but it returns after a few seconds and tty8 is not open. Is it the expected behaviour? Also, trying to start it in the background with sudo agetty -s 34800 tty8 linux &> /dev/null & returns immediately. Why?
I tried your line, I get the following in /var/log/secure (fedora19): getty[12336]: bad speed: 34800 try this: agetty -s 38400 -t 600 tty8 linux
How to use agetty from the command line
1,493,192,554,000
I am trying to set up getty to log in over serial (mainly as an experiment). With almost any configuration, the same thing happens. If my default shell is bash, I get this message after I log in: -bash: cannot set terminal process group (15297): Inappropriate ioctl for device -bash: no job control in this shell and ...
It's not the commands but the environment in which they run that is the difference. Normally getty is spawned directly from the system service manager (init) – both with systemd where it is a .service, and in the SysV world where it has an inittab entry (and not an init.d script!). This has several differences from be...
job control doesn't work when I try to set up getty over serial
1,493,192,554,000
I've got a FreeBSD (9.2) box that I'm trying to strip down as lightweight as possible. It's running on a VM server, so other than ttyv0, we don't ever use the console. I'd like (if possible and reasonable) to not start the extra getty processes that run ttyv1 through ttyv7. How do I accomplish that in a FreeBSD sup...
You can edit the /etc/inittab file and comment out the unneeded ttys. Take a look at the inittab manpage here. If inittab doesn't exist, take a look at the /etc/ttys file. It also has a manpage here.
How do I limit the number of getty processes started?
1,493,192,554,000
I have a few dark areas when trying to understands TTYs. On my system, I have /dev/tty[1-63]. Is udev creating these character devices? And how can I access them (like tty2 can be accessed with Ctrl+Alt+F2)? How can I access /dev/tty40 for example? As I understand, when I access /dev/tty1, agetty is called, which the...
These are virtual consoles, known in Linux as virtual terminals (VT). There is a single hardware console (a single screen and a single keyboard), but Linux pretends that there are multiple ones (as many as 63). At a given point in time, a single VT is active; keyboard input is routed to that console and the screen sho...
Access higher TTYs and the role of getty
1,493,192,554,000
From the man page: agetty opens a tty port, prompts for a login name and invokes the /bin/login command. It is normally invoked by init(8). But if you run login without any argument, it asks a username. So why not let login do the job of asking the username, instead of doing it inside agetty (also, if your l...
By reading in the username, agetty can automatically adapt the tty settings like parity bits, character size, and newline processing. If you disable it (--skip-login options), it needs to assume (possibly wrong) default settings.
Why does agetty ask for the username itself?
1,493,192,554,000
I want to remove the default newline inserted before the content of /etc/issue on login prompt in tty. I'm using agetty and systemd. I tried to add the --nonewline option to my [email protected] : ExecStart=/sbin/agetty --nonewline --noclear %I $TERM That result in : # systemctl status -l [email protected] ● [email ...
You have hit a bug! There's a F_NONL directive that never gets called in the agetty binary as can be seen in the sources: ... #define F_NONL (1<<17) /* No newline before issue */ ... /* Parse command-line arguments. */ static void parse_args(int argc, char **argv, struct options *op) { int c; enum { ...
Remove the newline before `/etc/issue` in tty
1,493,192,554,000
I have machines in pairs. They're connected to each other by a null modem serial cable. These machines sometimes go down, and the only way to diagnose them is through that cable, using the other node of the pair. These devices have Getty configured to run on the serial device /dev/ttyAMA0. This is by default, and I'd ...
(By the way, I've never seen the spelling "GeTTY". I don't think it's correct.) The short answer is that you can disable getty by commenting it out in /etc/inittab and running init q to reread configuration. Unless you're using systemd or Upstart but since you didn't say so I'll assume you aren't. The longer answer is...
How to free a serial port owned by Getty
1,493,192,554,000
I have a service that execs a command when a user connects to it through a socket, and redirects everything it receives to the executed program. It works ok with shells like bash, giving the user a remote shell. Instead of forking bash or sh, I'd like to run something that asks for user and password, like /bin/login ...
How to ask for a password? print $prompt read $response If you want to know how to authenticate your users, ideally you'd write your program as being pam-aware, following one of the pam developer guides all ofer the Interwebs. One example is http://www.linux-pam.org/Linux-PAM-html/Linux-PAM_ADG.html. You may also h...
present users a login prompt? /bin/login? getty?
1,493,192,554,000
What is this command really doing (step by step)? openvt -c 40 /bin/agetty tty40 linux I tried this command instead : openvt -c 41 /bin/agetty tty40 linux and agetty was started on tty40 (not tty41). Why is that? It seems the -c 41 option is not necessary. Removing it yields the same result.
openvt -c 40 /bin/agetty tty40 linux runs openvt, directing it to use VT 40; so it opens that VT, and runs agetty on it. But specifying tty40 as an argument to agetty tells the latter to use VT 40 (regardless of where it was started), so it opens VT 40 itself and runs there. Thus, openvt -c 41 /bin/agetty tty40 linux...
What is this openvt command doing?
1,493,192,554,000
I'm trying to colorize the console and I'm having success with the following in root's .bash_profile: echo -en "\e]P7000000" echo -en "\e]P0F0F0F0" clear The problem is that this is obviously only going to be kicked off the first time the root user logs in. Is there a way to get mingetty to automatically set the prop...
You can put literal escape characters into /etc/issue as suggested in a comment (Red Hat does this, sometimes). In a quick test, that works, but only colors the text. The background is uncolored. In vi, the text might look like ^[]P7000000^[]P0F0F0F0\S Kernel \r on an \m and the result like this: If you clear the...
Is it possible to send color code escape sequences before login?
1,493,192,554,000
I have been experimenting with an RS-232 null modem cable and am curious to know how one would allow FreeBSD to use a serial port as a terminal, like in the days of the PDP-11 where all users had dumb terminals connected to the computer via serial connections. I wish to do the same with a headless FreeBSD machine with...
Take a look at the /etc/ttys file. It's kind of like gettytab in Linux. There's one line for each... terminal line. The "ttyuX" are for serial ports (different drivers have different device names, consult man pages, eg man uart for physical serial ports . What you need to do to enable them is to change the "off" ...
How do I use a serial terminal with a FreeBSD server?
1,493,192,554,000
Qingy is a getty replacement. I'd like to use it for a tty terminal on Linux Mint 15 (in hopes of getting tmux to get proper 256 colors in tty which fails with fbterm) which means replacing getty. I'm not sure how to do so, as it says I need to edit /etc/inittab, which doesn't exist in current versions of Ubuntu.
/etc/init/tty1.conf (and others) has a line that says: exec /sbin/getty -8 38400 tty1 just change the binary to qingy in some versions, these files may be under /etc/event.d you can do a lookup such as sudo locate tty1.conf
How can I replace a tty using getty with qingy on ubuntu 12.04 or later?
1,493,192,554,000
I’m running virtual linux machine (debian12) on QEMU with -device virtconsole argument. That argument adds /dev/hvcX device nodes to VM. QEMU can connect that device to unix socket on host. If i pass “console=hvc0” parameter to VM’s kernel i get console on host socket and can launch tty on it. However it works only if...
Debian(12) builds its kernels with CONFIG_VIRTIO_CONSOLE set to 'm' as opposed to 'y'. This means that your initrd needs to contain the virtio_console module in order for hvc0 to be available early enough in the booting process. You can verify if your initrd has the required module by running this command: $ lsinitram...
Debian VM doesn’t boot on QEMU with "console=hvc0" kernel parameter
1,493,192,554,000
Normally systemd will spawn a getty on the virtual terminals just before it starts graphical mode. I have always thought that is the wrong time to spawn a getty: The time when you need the getty is when the booting fails, and it needs a helping hand to get back. How do I change the order, so getty is spawned as soon a...
Check out man systemd-debug-generator. It is talking about boot options, but says you can also enable the feature permanently, as for any service: If the systemd.debug-shell option is specified, the debug shell service "debug-shell.service" is pulled into the boot transaction. It will spawn a debug shell ...
systemd: spawn gettys ASAP
1,493,192,554,000
On a Debian Jessie system with systemd, how can I configure the terminals so that a message like Press enter to activate this console is displayed and the login prompt does not appear before hitting enter? With inittab this could be done by configuring askfirst, but how to do it with systemd? If possible I'd prefer to...
With /etc/inittab this could be done by configuring askfirst … Actually, it could not. That's a BusyBox init mechanism that doesn't exist in the Linux System 5 init clone, one of several ways in which their /etc/inittab configuration files are not the same things. The way to do similar things on a systemd Linux ope...
"askfirst" getty with systemd ("press enter to activate this console")
1,493,192,554,000
is it possible to start the x server on a virtual console that is running getty already? i like the responsiveness of getty - scrolling through the man pages or scrolling in vi is much quicker than xterm (gnome terminal). but i also like being able to alt+tab between web browser and xterm. it would be great if i could...
No. Once you start X, the VT stops being handled as a "text device" and becomes a "graphical" one. In the olden days the distinction was clear: either the VT was relying on BIOS (at least to some extent), knew just a few text modes and was blazingly fast, or it was switched to a graphical mode, had more colours and/or...
run x and getty on the same virtual console?
1,493,192,554,000
Init typically will start multiple instances of "getty" which waits for console logins which spawn one's user shell process. Upon shutdown, init controls the sequence and processes for shutdown. The init process is never shut down. It is a user process and not a kernel system process although it does run as root. If t...
To clarify, you seem to be running systemd on Ubuntu rather than the (current) default of upstart. systemd, by default, sets up only one getty, tty1. Other gettys are set up "on the fly". There is a default setting of a maximum of 6 ttys. If you want to increase the number of gettys available to autostart, then increa...
Getty instances in init process
1,493,192,554,000
I found that, in /etc/inittab, this modification (-a username) for the user u disables the login/password check for all tty:s: 1:2345:respawn:/sbin/getty -a u 38400 tty1 2:23:respawn:/sbin/getty -a u 38400 tty2 3:23:respawn:/sbin/getty -a u 38400 tty3 4:23:respawn:/sbin/getty -a u 38400 tty4 5:23:respawn:/sbin/getty -...
I use autologin, not just disable the password ;-) If your disk is not encrypted, they could just boot from external media and steal your data. So autologin isn't a problem for thieves, but people near you (that can access your computer when you're not here). Just don't let people around you know that they could login...
Security drawbacks of disabling tty password check
1,493,192,554,000
On my embedded system, I use linux kernel 4.19.102 and systemd 240. Everything is generated using buildroot 2019.02.9. I use the serial port of my device to output console. bootargs = "console=ttyS0,115200"; With the previous version I used, everything were fine one the console side (buildroot 2018.05, kernel 4.16....
The problem is that BR2_TARGET_GENERIC_GETTY_PORT was set on 'console' on buildroot 2018.05. It needs to be changed by 'ttyS0' in buildroot 2019.02.9.
How to prevent console-getty.service to start?
1,493,192,554,000
A framebuffer is a device file which allows for a simplified interface to the screen. For example running the below code on a RaspberryPi with a HDMI display connected: cat /dev/urandom > /dev/fb1 There are commands (fbi, fim) which allow for injecting full images into the framebuffer. There are multiple resources on...
The “hidden relationship” is related to the fact that Linux supports multiple virtual terminals, which means that the framebuffer can be used by a number of different terminals. Programs which manipulate the framebuffer directly need to be aware of which terminal currently owns the framebuffer: When such a program st...
Relationship between framebuffer and a tty
1,493,192,554,000
I have a clean Debian Stretch installation. It used to be the case that after booting I would end up on tty1 with a login prompt, and after logging X is started. I wanted to automate the logging in (because I'm the only user and my disk is encrypted already) so I followed the exact instructions given here: In /etc/sy...
You should enable the [email protected] again: systemctl enable [email protected]
tty1 missing login prompt
1,493,192,554,000
My Ubuntu 20.04 system has a serial port over which I would like to provide console access. I can confirm that I can communicate over the serial port with sudo picocom -b 115200 /dev/ttyS5 I start the Getty instance with sudo systemctl start serial-getty@ttyS5 which starts the command /sbin/agetty -o '-p -- \u' --ke...
I used strace to monitor agetty's activity, and I did see that it is writing to and reading from the serial device, even though nothing appeared on the remote side. After using strace to monitor the system calls, I saw that whenever I typed on the remote side, agetty was only seeing the byte 0xFF, which suggested a ba...
No login prompt from Getty over serial console
1,493,192,554,000
I have a Stretch system n which I would like to replace agetty with ngetty (for various reasons like because I have no use for serial lines, and I like the way ngetty can be configured, for examples). I know how to do that in runit or sysvinit, but I can't find where the info is with systemd. I can find nothing which...
Seems like you may be on a virtual environment where getty is useless. You may switch to mingetty (default at Amazon AWS now), which uses minimal resources and still be able to look at the "Console Logs" (via Amazon vm GUI ..eeeek). To switch from agetty to ngetty or mingetty, (you just need one): # apt install mgett...
how to change the getty binary in Debian Stretch?
1,493,192,554,000
The unix haters handbook says: /etc/getty, which asks for your username, and /bin/login, which asks for your pass- word, are no different from any other program. They are just programs. They happen to be programs that ask you for highly confidential and sensi- tive information to verify that you are who you claim to b...
By default there is no particular integrity protection for system program and library files beyond file permissions (and possibly read-only mounting); there is no such thing as specially protected system files. In this sense, the answer is yes, this is true. You could follow a host-based IDS approach using programs li...
How can one verify the authenticity of `getty` running on linux?
1,463,417,513,000
Problem I want to see the dependencies for one or more targets of a makefile. So I am looking for a program that can parse makefiles and then will represent the dependencies in some tree-like format (indentation, ascii-art, ...) or as a graph (dot, ...). Similar There are programs that do this for other situations: p...
Try makefile2graph from the same author there is a a similar tool MakeGraphDependencies written in java instead of c. make -Bnd | make2graph | dot -Tsvg -o out.svg Then use some vector graphics editor to highlight connections you need.
How to display dependencies given in a makefile as a tree?
1,463,417,513,000
I was using a Makefile from the book "Advanced Linux Programming (2001)" [code]. It was strange for me to see that GNU make does compile the code correctly, without even specifying a compiler in the Makefile. It's like baking without any recipe! This is a minimal version of the code: test.c int main(){} Makefile all:...
Make does this using its built-in rules. These tell it in particular how to compile C code and how to link single-object programs. You actually don't even need a Makefile: make test would work without one. To see the hidden rules that make all of this possible, use the -p option with no Makefile: make -p -f /dev/null...
How does this Makefile makes C program without even specifying a compiler?
1,463,417,513,000
I am trying to instruct GNU Make 3.81 to not stop if a command fails (so I prefix the command with -) but I also want to check the exit status on the next command and print a more informative message. However my Makefile below fails: $ cat Makefile all: -/bin/false ([ $$? -eq 0 ] && echo "success!") || echo "...
Each update command in a Makefile rule is executed in a separate shell. So $? does not contain the exit status of the previous failed command, it contains whatever the default value is for $? in a new shell. That's why your [ $? -eq 0 ] test always succeeds.
Don't stop make'ing if a command fails, but check exit status
1,463,417,513,000
I am trying to compile a program written in Fortran using make (I have a Makefile and, while in the directory containing the Makefile, I type the command $ make target, where "target" is a system-specific target specification is present in my Makefile. As I experiment with various revisions of my target specification...
The error codes aren't from make: make is reporting the return status of the command that failed. You need to look at the documentation of each command to know what each status value means. Most commands don't bother with distinctions other than 0 = success, anything else = failure. In each of your examples, ./dpp can...
Where can I find a list of 'make' error codes?
1,463,417,513,000
I am playing around with makefiles and I came across %.o or %.c. From what I understood, it specify all c or o files. But why this work: %.o: %.c $(CC) -c $^ -o $@ and this doesn't work SOURCE := $(wildcard *.c) $(SOURCE:.c=.o): SOURCE $(CC) -c $^ -o $@ Both expression specify all the files. s...
Both expression specify all the files. Nope, the first rule tells make how to obtain an .o file given the corresponding .c file. Note the singular: a single file. The second rule (claims to) tell make how to obtain a bunch of .o files, given another bunch of corresponding .c files. Note the plural: all .c files re...
What does % symbol in Makefile mean
1,463,417,513,000
I have a Makefile that has a variable that needs to have a default value in case when variable is unset or if set but has null value. How can I achieve this? I need this, as I invoke make inside a shell script and the value required by the makefile can be passed from the shell as $1. And to pass this to makefile I ha...
Since you’re using GNU make, you could use the ?= operator: FOO ?= bar but that doesn’t deal with pre-existing null (or rather, empty) values. The following deals with absent and empty values: ifndef FOO override FOO = bar endif test: echo "$(FOO)" .PHONY: test (Make sure line 6 starts with a real tab.) You’d ...
Makefile: Default Value of Variable that is set but has null value
1,463,417,513,000
I was writing a Makefile (on Ubuntu 20.04, if it's relevant) and noticed some interesting behavior with echo. Take this simple Makefile: test.txt: @echo -e 'hello\nworld' @echo -e 'hello\nworld' > test.txt When I run make, I would expect to see the same thing on stdout as in test.txt, but in fact I do...
UNIX compliant implementations of echo are required to output -e<space>hello<newline>world<newline> there. Those that don't are not compliant. Many aren't which means it's almost impossible to use echo portably, printf should be used instead. bash's echo, in some (most) builds of it, is only compliant when you enable ...
Why is echo -e behaving weird in a Makefile?
1,463,417,513,000
Currently I am working with Makefiles that have definitions like MYLIB=/.../mylib-1.2.34 The problem is that these are different for different developers, and it is a pain having to re-edit the file after every checkout. So I tried exporting a specific environment variable, and then doing MYLIBX:=$(MYLIB_ENV) MYLIBX?...
The problem with MYLIB:=$(MYLIB_ENV) MYLIB?=/.../mylib-1.2.34 is that MYLIB is always defined in the first line, so the second never applies. The typical approach in this situation is just MYLIB?=/.../mylib-1.2.34 That way individual developers can specify their own value from the shell, either on the make command l...
gnuMake, How to have an environment variable override
1,463,417,513,000
Closely related to How to display dependencies given in a makefile as a tree? But the answers given there is not satisfactory (i.e. do not work). Is there a tool to visualize the Directed Acylic Graphs (DAGs) coded up in standard Makefiles? eg, a shell-script for post-processing through Unix pipes can be an acceptable...
I believe makefile2graph does exactly what the original post author wanted. For the full installation and usage example: Installation (make sure graphviz is installed, e.g. with sudo apt install graphviz on Debian systems) cd /my/install/dir git clone https://github.com/lindenb/makefile2graph cd makefile2graph make ...
Visualizing dependencies coded up in makefiles as a graph
1,463,417,513,000
My Makefile: all: ...(other rules) clean clean: rm $(find . -type f -executable) When I delete clean rule from the above Makefile everything works as expected. After adding, make (also make clean) command results in: rm rm: missing operand Try 'rm --help' for more information. make: *** [Makefile:46: clean] Err...
There are several issues. Passing a $ sign in a Makefile to the shell You want to run the command rm $(find . -type f -executable) to let the shell do the command substitution. To do this you need to write clean: rm $$(find . -type f -executable) with the dollar doubled as Make itself uses $. Handing the cas...
Makefile command substitution
1,463,417,513,000
When I have a make task where a specific target needs to be made before another, while in parallel mode, this is simple when using SunPro Make (dmake). The following makefile: install: dir dir/file dir: mkdir dir dir/file: cp source dir/file could be made parallel make safe by changing the first line to: i...
Here is the my own answer that has been derived from the idea presented by Filipe Brandenburger and from generic methods used in the Schily Makefile system: The makefile system makes sure that the following make macros are set up this way: WAIT= # empty with GNU make WAIT= .WAIT # .WAIT special target with SunPr...
How can I partially serialize with GNU make
1,463,417,513,000
Assume doc.pdf is the target. The following rule triggers a regeneration of doc.pdf whenever doc.refer is updated, but is also happy when doc.refer does not exist at all: doc.pdf: doc.mom $(wildcard doc.refer) pdfmom -e -k < $< > $@ However the following pattern rule does not accomplish the same (the PDF is gener...
The GNU Make function wildcard takes a shell globbing pattern and expands it to the files matching that pattern. The pattern %.refer does not contain any shell globbing patterns. You probably want something like %.pdf: %.mom %.refer pdfmom -e -k < $< > $@ %.pdf: %.mom pdfmom -e -k < $< > $@ The firs...
Using wildcard in GNU Make pattern rule
1,463,417,513,000
I have a set of directories, some of which contain makefiles, and some of the makefiles have clean targets. In the parent directory, I have a simple script: #!/bin/bash for f in *; do if [[ -d $f && -f $f/makefile ]]; then echo "Making clean in $f..." make -f $f/makefile clean...
That behaviour is not a bug. It is a feature. A feature and a possible user error to be precise. The feature in question is one of the implicit rules of Make. In your case the implicit rule to "build" *.sh files. The user error, your error, is not changing the working directory before invoking the makefile in the subd...
Strange behavior automating with "make -f"
1,463,417,513,000
I know GNU Make is by far the most commonly used, but I'm looking for a way to verify that GNU Make is the actual make program that is being used. Is there a special variable I can print from within the Makefile like: @echo "$(MAKE_VERSION)" What if I have both GNU Make and another variant installed? which make /usr...
Using: $(MAKE) --version works here. My output is: make --version GNU Make 3.82 Built for i686-pc-linux-gnu Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WA...
How to tell whether GNU make is being used in a makefile?
1,463,417,513,000
I'm trying to understand why some Makefiles have prerequisites with %.txt and others have *.txt. I've created this folder layout. $ tree . . ├── hi1.txt ├── hi2.txt ├── hi3.txt └── Makefile First, I tried this. foo.txt: *.txt echo $^ And it does what I expect. $ make echo hi1.txt hi2.txt hi3.txt hi1.txt hi2.txt ...
In make, the percent sign is used for pattern matching, and it requires one in the target as well as (at least) one in the prerequisites: %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< With this makefile, we specify that in order to build something whose file name ends with .o, you need to have a file that has the same...
What's the difference between percent vs asterisk (star) makefile prerequisite
1,463,417,513,000
I just solved a problem with my Makefile(s). Make trips over every <<< with the error message /bin/sh: 1: Syntax error: redirection unexpected And I would like to know why. (I am using Bash as SHELL) In my current projects I tried a lot of recipies along the lines of: target: read FOO <<< "XXX"; \ read BAR <<...
/bin/sh: 1: Syntax error: redirection unexpected means you’re not using bash as your shell, in spite of your expectations to the contrary. bash as sh recognises here strings fine (so your Makefile would work on Fedora), but for example dash as sh doesn’t. Unless told otherwise, Make uses /bin/sh as its shell; it igno...
Why don't here strings in Makefiles using Bash work?
1,463,417,513,000
I have written a rule where a directory should be removed if it exists: .PHONY: distclean distclean: -rmdir release make distclean prints: rmdir release rmdir: failed to remove ‘release’: No such file or directory test.mak:3: recipe for target 'distclean' failed make: [distclean] Error 1 (ignored) Shouldn't the ...
Make is ignoring the error: make: [distclean] Error 1 (ignored) It still prints the error messages, but if you add another rule in the distclean target it should be processed in spite of the rmdir failure. In more detail: rmdir release This is make printing the command it's about to run. rmdir: failed to remove ‘rel...
GNU Make does not ignore failed command
1,463,417,513,000
How do I properly configure pkgconf and libffi to allow the python3 build process to correctly use my libffi version at every step of the build process, in order to import the _ctypes module correctly? Which piece am I missing here? Some background I am trying to build Python3 from source to build a GUI with PyQt5, an...
I had exactly the same problem. build/lib.linux-x86_64-3.9/_ctypes.cpython-39-x86_64-linux-gnu.so would be generated by make, but wasn't linked with libffi (as I found out with ldd). When, subsequently, make runs setup.py, I'd get exactly the same error: *** WARNING: renaming "_ctypes" since importing it failed: buil...
How do I build PKGCONF and LIBFFI and subsequently Python3.9 with ctypes support without sudo and write access to /usr/local?
1,463,417,513,000
I'm implementing a simple build system that's actually just a wrapper around Make. Since this build system already emits its own error messages, I don't want Make to produce error messages like make: *** [/cool/makefile:116: /fun/target.o] Error 1 on failure. I'm already using the -s flag to suppress most of Make's o...
Since your system is a wrapper around make, I presume that it generates the makefile. Tweak your generator to add 2>&3 to all the shell commands in the makefile, and make your program redirect file descriptor 3 to standard error (file descriptor 2) and file descriptor 2 to /dev/null. This way the make program itself w...
Make - How to suppress make error messages without suppressing other output
1,463,417,513,000
Say I have a variable with a path release/linux/x86, and want the relative path from a different directory (i.e. ../../.. for current working directory), how would I get that in a shell command (or possibly GNU Make)? Soft link support not required. This question has been heavily modified based on the accepted answer...
Absolutely not clear the purpose of it, but this will do exactly what was asked, using GNU realpath: realpath -m --relative-to=release/linux/x86 . ../../.. realpath -m --relative-to=release///./linux/./x86// . ../../..
How to get the relative path between two directories?
1,463,417,513,000
How do I set more than one target specific variable? If I try: x: Y := foo Z := bar I end up with Y = "foo Z := bar". There must be some syntax which will allow for multiple variables...
In GNU make you specify the target multiple times to accommodate the required number of variable assignments, like as: x: Y := foo x: Z := bar x: @echo Y=$(Y) -- Z=$(Z)
multiple target specific gnu make variables?
1,463,417,513,000
When I enable make V=s to read the full log of make. I always see make[numer] in the log. e.g: datle@debian:~/workspace/cpx/trunk$ make rm -rf openwrt/tmp cp config/defaut.config openwrt/.config cd openwrt && make make[1]: Entering directory `/home/datle/workspace/cpx/trunk/openwrt' make[1]: Leaving directory `/home/d...
Those numbers is represent for makelevel, which let us know how sub-make relates to top-level make. This is the recursive use of make, see more details here. Digging into make source code, you can see something clearer. In main.c: /* Value of the MAKELEVEL variable at startup (or 0). */ unsign...
What does make[number] mean in make V=s?
1,463,417,513,000
Goal I write my slides in a markdown file and compile it to reveal afterwards, uploading it to my webserver and do other things. I wanted to organise the steps after the markdown is written in a makefile: PROJNAME = `pwd | grep -oP '(\w|-)+' | tail -n 2 | head -n 1 | tr '[:upper:]' '[:lower:]'` presentation: slides.p...
The value of the make variable PROJNAME is `pwd | grep -oP '(\w|-)+' | tail -n 2 | head -n 1 | tr '[:upper:]' '[:lower:]'` The backquote character is not special in make. If you use the variable in a shell command, the shell sees the backquotes and parses them as a command substitution. But if you use the variable in...
Why does make stop with "Makefile:6: *** multiple target patterns. Stop."?
1,463,417,513,000
What is the meaning of sed command sed -i 's,-m64,,g' Makefile? Does it simply remove -m64 argument from Makefile? Is it the same with sed -i 's/-m64//g' Makefile, just use / delimiter in place of commas?
Yes, it's the same as with / delimiter. Sometimes you may use different delimiters not to confuse sed. In this case, you replace all -m64 instances with empty string, not remove as such. See this resource on using delimiters in sed.
What is "sed -i 's,-m64,,g'" doing to this Makefile?
1,463,417,513,000
I'm using a Makefile to compile my Clean code. My Clean files have file names of the format *.icl and are compiled to binaries with the same name but without .icl. This is done with the rule: $(EXE): % : %.icl | copy $(CLM) $(CLM_LIBS) $(CLM_INC) $(CLM_OPTS) $@ -o $@ I would now like to add a rule which allows me...
You can inspect MAKECMDGOALS to detect the presence of one goal while building another goal. Either make the %: %.icl run detect the presence of the run goal, or make the run goal inspect what executables are mentioned as targets. If you pass more than one executable as a target, the first method causes each to be run...
Make target with two words
1,463,417,513,000
If I have a makefile I have to use that is using recursive make, is there an easy option to disable that? http://aegis.sourceforge.net/auug97.pdf
No. If you invoke make even once in Makefile, it would be called a recursive make. There's no easy option in GNU Make to prevent it. Once you read the paper mentioned in your post, you could understand it's determined by how you write Makefiles whether the make is recursive or non-recursive. Linux kernel build syste...
Is there a way to disable recursive make?
1,463,417,513,000
I've been reading the documentation but it's still unclear to me how the order is processed. In the example: myrule: | myrule_step1 myrule_step2 @echo "$(@)" myrule_step1: @echo "$(@)" myrule_step2: @echo "$(@)" what will print first? myrule_step1 or myrule_step2?
The order is unspecified and can run in either order. This isn't just a theoretical concern. It can happen during parallel builds. Assuming the same Makefile as in the question, I ran: watch -n 0.1 make -j8 It only took a few seconds to print: myrule_step2 myrule_step1 myrule See also this StackOverflow answer by Jö...
What is the order order-only prerequisites are processed in a GNU Make file?
1,463,417,513,000
According to GNU Make Manual A rule with multiple targets is equivalent to writing many rules, each with one target, and all identical aside from that. The same recipe applies to all the targets, but its effect may vary because you can substitute the actual target name into the recipe using ‘$@’. The rule contributes...
Your rules tell make that a single invocation of the recipe will create both the .in and .out targets. https://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html explains this. It says (in the penultimate paragraph): "Pattern rules may have more than one target; however, every target must contain a % char...
Why does make behave strangely when rule has multiple targets with the % character?
1,463,417,513,000
I'm trying to follow a guide to compile a program for Debian in FreeBSD. I have the following makefile: obj-m += kernelinfo.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean I'm confused as to how I would compile this on Fre...
This looks like it may be from a Linux kernel module. You will probably not be able to compile or use the code associated with the Linux kernel module on FreeBSD, as it's written specifically for Linux, and the Linux kernel is totally different from the FreeBSD kernel. In short, it's not the Makefile that needs transl...
Convert Debian Makefile for FreeBSD
1,463,417,513,000
why doesn't this simple recipe work ? .PHONY: test test: foo := $(shell ls | grep makefile) ;\ echo $(foo) results in $> make test makefile:65: warning: undefined variable 'foo' foo := makefile ;\ echo /bin/sh: 1: foo: not found So, as far as I understand, the variable foo is well set to value makefile but ...
I looked at your loop... quoted here: .PHONY: test test: @$(eval export files = $(shell ls)) for f in $(files) ; do \ t = $(ls | grep $$f) ; \ echo $$t;\ done So... $(eval ... ) runs a command in make. $(shell ls) runs command ls in the shell, and substitutes its output. The command run b...
Variable not found in makefile recipe
1,463,417,513,000
Suppose I am in an empty directory. If I now create a Makefile containing nothing but all: randomFilename and an empty file called randomFilename.sh, then GNU Make will perform cat randomFilename.sh >randomFilename; chmod a+x randomFilename when make is called. $ echo 'all: randomFilename' > Makefile $ make make: *** ...
This behaviour is the result of the built-in suffix rules of Make (in this case for legacy versions of the Source Code Control System [1]). The built-in suffix rules can be disabled by specifying an empty .SUFFIXES pseudo-target [2]: $ echo '.SUFFIXES:' > Makefile $ echo 'all: randomFilename' >> Makefile $ m...
How to prevent Make from randomly overriding files?
1,463,417,513,000
Let's say that I have a Makefile that has two “main” targets: foo.o and clean. The former one has a recipe to create the foo.o file. The latter one removes all the temporary files. To remove the need of specifying the dependencies of foo.o manually, I have target foo.d that is valid makefile specifying the dependencie...
The solution is quite simple, but results into somewhat unreadable Makefile code. First, we must know that include directive tries to include the file, and if it does not exist, fails. There is also -include (or sinclude) that does simply does not include the file, if it does not exist. But that is not the thing we wa...
Remake included makefile only when needed
1,463,417,513,000
I'm calling make from a bash script. Part of the rest of the script only needs to be executed if make actually did something (i.e. it doesn't say nothing to be done for...). How would I check on that in bash? The return code is the same as when something does happen (and doesn't fail), so I can't use that. Is there a...
If your workflow can accomodate it, you can send make on a trial run before you run it to update files: -q, --question ‘‘Question mode’’. Do not run any commands, or print anything; just return an exit status that is zero if the specified targets are already up to date, nonzero otherwise. (I ...
Check in bash if make has done something
1,463,417,513,000
Is it possible to display variables outside rules using GNU Make? Consider the following Makefile: x = foo bar baz ifdef x @echo $(x) endif This results in Makefile:4: *** commands commence before first target. Stop. However, if I add a rule, it works: x = foo bar baz ifdef x t: @echo $(x) endif Is it rea...
GNU make has a feature for doing exactly that and it is called $(info ....). You could place the following line outside of a rule and GNU make will execute it: $(info variable x = $x)) And if you find yourself doing this sort of a task repeatedly, you can abstract it away in a macro and call it where ever needed: ma...
Is it possible to display variables outside rules using GNU Make?
1,463,417,513,000
I'm writing a Makefile recipe that needs to execute IF AND ONLY IF a certain file exists... Here's what I have: clean: $(if $(shell test -s ${MFN_LSTF}), \ $(foreach mfn, $(shell cat ${MFN_LSTF}), \ $(MAKE) -f mfd/${mfn} clean;), ) .PHONY: clean ${MFN_LSTF} holds a filename that contains a one...
This might be a possible and simpler solution, emulating the shell: $(eval mfn_lstf := $(shell cat ${MFN_LSTF})) $(foreach mfn, ${mfn_lstf}, $(MAKE) -f mfd/${mfn} clean;) And, the following works, without emulating the shell: if [ -s "$${MFN_LSTF}" ]; then \ while IFS= read -r mfn; do \ ...
How can I execute recipe iff a file exists?
1,463,417,513,000
I am trying to run make for an open-source project on my Debian virtual machine but I do not understand why the commands based on pkg-config are not being recognized. One of the commands is as follows: tempgui-qrps.so: tempgui-qrps.cc refpersys.hh tempgui-qrps.hh tempgui-qrps.moc.hh | $(RPS_CORE_OBJECTS) $(RPS_BUI...
Having pkg-config isn’t sufficient: you also need the .pc files corresponding to the packages named in each pkg-config command. For pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets $(RPS_PKG_NAMES), you need to install qtbase5-dev, and whatever is necessary for the packages in $(RPS_PKG_NAMES). You can install and use ap...
Why are the pkg-config commands in the makefile not being recognized when I run the script?
1,463,417,513,000
I have a info.properties file where I have this MY_NAME property and I can use this property on my Makefile. I already tried but I can't use that property directly on myScript.sh file. So I'm trying to pass that property as argument to myScript.sh. And I'm doing like this: On Makefile: my_stage: chmod 777 myScript...
Since your script can source .build/utils.bash, you have already proved that you in fact can read it. For example, try less .build/utils.bash in the directory that contains the Makefile. To fix the actual problem without modifying .build/utils.bash, you might try assigning the contents of $1 into your MY_NAME variable...
"Command not found" passing argument from Makefile to shell script
1,463,417,513,000
I am aware of LatexMk, but can't install that on the machine where I want to run pdflatex, so I need to write a Makefile of which %.pdf files are targets that depend on %.tex and the *.tex files that %.tex is inputting. For this I wrote the following: %.pdf : %.tex $(shell perl -lne 'print "$$1\n" if /\\input{([\w-]+\...
Probably what you're trying to do is better solved by creating a file listing dependencies, which you can then include from your Makefile. This is a common pattern in C and C++ makefiles. SOURCES=foo.tex bar.tex all: $(SOURCES:.tex=.pdf) %.dep: %.tex perl -lne 'print "$*.pdf: $$1\n" if /\\input{([\w-]+\.tex)}/'...
Percentage symbol in $(shell) in GNU Makefile dependency
1,463,417,513,000
I have recorded that it took 50 minutes for an initial compilation of the OpenWrt firmware image, assuming all the necessary packages have been installed via sudo apt-get install. My BuildRoot Root Dir is openwrt. Subsequently, I found that if I rename the directory above the openwrt folder, with a minor change in a f...
No, it doesn't change the timestamps of contained files and directories, only on the directory itself. However, if the Makefile contains targets or dependencies that use absolute paths or even just $(src_dir) it will remake them, b/c it's a different/new target. See the GNU make documentation for conventions and advic...
How to make OpenWrt Makefile compile faster?
1,483,481,088,000
Trying a Makefile rule like the following did not work (GNU Make 4.0): foo: [email protected] other.o bar: bar.o other.o The file foo.c was compiled (to foo.o), but the link command was cc -o .o. In contrast, bar was compiled and linked correctly as cc bar.o other.o -o bar. Who can explain the difference (or the...
This is addressed in the section on Automatic variables in the GNU Make manual: It’s very important that you recognize the limited scope in which automatic variable values are available: they only have values within the recipe. In particular, you cannot use them anywhere within the target list of a rule; they have no...
Using `[email protected]` in Makefile dependency won't work
1,483,481,088,000
I want to add another option to the CFLAGS make variable, depending on the result of a shell command that i want to execute outside of a recipe in my "configuration" section of the makefile. This is what i have come up with: GCC_VERSION := $(shell gcc -dumpversion); \ if [[ ${GCC_VERSION} > 5.0 ]] ; then \ CFLAGS ...
There are many solutions, including this one. In your Makefile use VERSION5 := $(shell \ GCC_VERSION=$$(gcc -dumpversion); \ [[ $$GCC_VERSION > 5.0 ]]; \ echo $$? ) ifeq (${VERSION5}, 0) CFLAGS += -D _POSIX_C_SOURCE=199309L endif Note in particular, that you need to use $$ for every $ in your shell script. This...
GNU make - How to concatenate to variable depending on shell command result (GCC version)?
1,483,481,088,000
I have a makefile and want to make sure that all the rules are executed sequentially, that is, that no parallel execution is performed. I believe I have three ways of achieving this: With .NOTPARALLEL target, By calling make using make -j 1, By setting the flag directly in the makefile, e.g., MAKEFLAGS := -j 1 Is th...
Yes, this is overkill. As far as the three options go: You should never set MAKEFLAGS, for two reasons: it will cause issues with any flags passed on the command-line, and MAKEFLAGS doesn’t work in a way that can be robustly modified externally. To see both of these problems in action, add an @echo $(MAKEFLAGS) rule ...
Serialize all rules in GNU make: best practise?