makefile missing separator in Mac OS X - c
I have a makefile which gives the following error in OS X, I will be very grateful if someone have an idea about why is getting this error:
./../../../..//Source//templates/gcc/Makefile.posix:15: *** missing separator. Stop.
Here is the makefile:
GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-4_8-2014q3
GNU_VERSION := 4.8.3
GNU_PREFIX := arm-none-eabi
GDB_PORT_NUMBER := 9992
FLASH_START_ADDR = $(shell $(OBJDUMP) -h $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out -j .text | grep .text | awk '{print $$4}')
JLINK_OPTS = -device nrf51822 -if swd -speed 4000
JLINK_GDB_OPTS = -noir
JLINK = JLinkExe $(JLINK_OPTS)
JLINKD_GDB = JLinkGDBServer $(JLINK_GDB_OPTS)
flash-jlink: flash.jlink
$(JLINK) flash.jlink
flash.jlink:
printf "loadbin $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin $(FLASH_START_ADDR)\nr\ng\nexit\n" > flash.jlink
erase-all: erase-all.jlink
$(JLINK) erase-all.jlink
erase-all.jlink:
# Write to NVMC to enable erase, do erase all, wait for completion. reset
printf "w4 4001e504 2\nw4 4001e50c 1\nsleep 100\nr\nexit\n" > erase-all.jlink
run-debug:
$(JLINKD_GDB) $(JLINK_OPTS) $(JLINK_GDB_OPTS) -port $(GDB_PORT_NUMBER)
.PHONY: flash-jlink flash.jlink erase-all erase-all.jlink run-debug
TAB character in Brackets editor were replaced by 4 spaces (sp sp sp sp). Changing to other editor (TextMate) solved the problem
I was using VIM (on MacOS) and found that 'expandtab' was the issue when parsing Makefiles. If set, it turns your tab into 4 spaces. (so i commented it out)
" expand tabs into spaces
"set expandtab
On Mac OS X and SublimeText 3 I had to change the indentation from spaces to tabs to solve the same problem '"Makefile:4: *** missing separator. Stop."'.
So I did the following on SublimeText 3 in the lower left corner to fix the error:
Click on Spaces:4 > Tab Width: 4
Click on Spaces: 4 > Convert Indentation to Tab
Related
How to use make to keep a file synced?
If doing: ECHOCMD:=/bin/echo -e SHELL := /bin/bash GITIGNORE_SOURCE_PATH := ../.gitignore GITIGNORE_DESTINE_PATH := ./setup/.gitignore start_syncing: "${GITIGNORE_DESTINE_PATH}" printf '\n' "${GITIGNORE_DESTINE_PATH}": cp -vr "${GITIGNORE_SOURCE_PATH}" ./setup/ Make keeps running the rule "${GITIGNORE_DESTINE_PATH}" every time when I call make, but it should only call it when the source file ../.gitignore is modified. Update 3 This is the make file I was suggested to use on comment: ECHOCMD:=/bin/echo -e SHELL := /bin/bash GITIGNORE_SOURCE_PATH := ../.gitignore GITIGNORE_DESTINE_PATH := ./setup/.gitignore start_syncing: "${GITIGNORE_DESTINE_PATH}" printf '\n' ${GITIGNORE_DESTINE_PATH}: ${GITIGNORE_SOURCE_PATH} cp -vr "${GITIGNORE_SOURCE_PATH}" ./setup/ Running it, it says: $ ls -l ../.gitignore -rwx---r-x+ 1 User None 488 Apr 27 23:23 ../.gitignore $ ls -l ./setup/.gitignore -rwx---r-x+ 1 User None 488 Apr 28 07:41 ./setup/.gitignore $ make make: *** No rule to make target '"./setup/.gitignore"', needed by 'start_syncing'. Stop.
The solution is to remove double quotes from the target rules. In case they have a space on the name, there is nothing make can do about it other than you manually escape the values of the space with \ ECHOCMD:=/bin/echo -e SHELL := /bin/bash GITIGNORE_SOURCE_PATH := ../.gitignore GITIGNORE_DESTINE_PATH := ./setup/.gitignore start_syncing: ${GITIGNORE_DESTINE_PATH} printf '\n' ${GITIGNORE_DESTINE_PATH}: ${GITIGNORE_SOURCE_PATH} cp -vr "${GITIGNORE_SOURCE_PATH}" ./setup/
call program with arguments from an array containing items from another array wrapped in double quotes
(This is a more specific version of the problem discussed in bash - expand arguments from array containing double quotes .) I want bash to call cmake with arguments from an array with double quotes which itself contain items from another array. Here is an example for clarification: cxx_flags=() cxx_flags+=(-fdiagnostics-color) cxx_flags+=(-O3) cmake_arguments=() cmake_arguments+=(-DCMAKE_BUILD_TYPE=Release) cmake_arguments+=("-DCMAKE_CXX_FLAGS=\"${cxx_flags[#]}\"") The arguments shall be printed pretty like this: $ echo "CMake arguments: ${cmake_arguments[#]}" CMake arguments: -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-fdiagnostics-color -O3" Problem And finally cmake should be called (this does not work!): cmake .. "${cmake_arguments[#]}" It expands to (as set -x produces): cmake .. -DCMAKE_BUILD_TYPE=Release '-DCMAKE_CXX_FLAGS="-fdiagnostics-color' '-O3"' Workaround echo "cmake .. ${cmake_arguments[#]}" | source /dev/stdin Expands to: cmake .. -DCMAKE_BUILD_TYPE=Release '-DCMAKE_CXX_FLAGS=-fdiagnostics-color -O3' That's okay but it seems like a hack. Is there a better solution? Update If you want to iterate over the array you should use one more variable (as randomir and Jeff Breadner suggested): cxx_flags=() cxx_flags+=(-fdiagnostics-color) cxx_flags+=(-O3) cxx_flags_string="${cxx_flags[#]}" cmake_arguments=() cmake_arguments+=(-DCMAKE_BUILD_TYPE=Release) cmake_arguments+=("-DCMAKE_CXX_FLAGS=\"$cxx_flags_string\"") The core problem remains (and the workaround still works) but you could iterate over cmake_arguments and see two items (as intended) instead of three (-DCMAKE_BUILD_TYPE=Release, -DCMAKE_CXX_FLAGS="-fdiagnostics-color and -O3"): echo "cmake .. \\" size=${#cmake_arguments[#]} for ((i = 0; i < $size; ++i)); do if [[ $(($i + 1)) -eq $size ]]; then echo " ${cmake_arguments[$i]}" else echo " ${cmake_arguments[$i]} \\" fi done Prints: cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_FLAGS="-fdiagnostics-color -O3"
It seems that there's another layer of parsing that has to happen before cmake is happy; the | source /dev/stdin handles this, but you could also just move your CXX flags through an additional variable: #!/bin/bash -x cxx_flags=() cxx_flags+=(-fdiagnostics-color) cxx_flags+=(-O3) CXX_FLAGS="${cxx_flags[#]}" cmake_arguments=() cmake_arguments+=(-DCMAKE_BUILD_TYPE=Release) cmake_arguments+=("'-DCMAKE_CXX_FLAGS=${CXX_FLAGS}'") CMAKE_ARGUMENTS="${cmake_arguments[#]}" echo "CMake arguments: ${CMAKE_ARGUMENTS}" returns: + cxx_flags=() + cxx_flags+=(-fdiagnostics-color) + cxx_flags+=(-O3) + CXX_FLAGS='-fdiagnostics-color -O3' + cmake_arguments=() + cmake_arguments+=(-DCMAKE_BUILD_TYPE=Release) + cmake_arguments+=("'-DCMAKE_CXX_FLAGS=${CXX_FLAGS}'") + CMAKE_ARGUMENTS='-DCMAKE_BUILD_TYPE=Release '\''-DCMAKE_CXX_FLAGS=-fdiagnostics-color -O3'\''' + echo 'CMake arguments: -DCMAKE_BUILD_TYPE=Release '\''-DCMAKE_CXX_FLAGS=-fdiagnostics-color -O3'\''' CMake arguments: -DCMAKE_BUILD_TYPE=Release '-DCMAKE_CXX_FLAGS=-fdiagnostics-color -O3' There is probably a cleaner solution still, but this is better than the | source /dev/stdin thing, I think.
You basically want cxx_flags array expanded into a single word. This: cxx_flags=() cxx_flags+=(-fdiagnostics-color) cxx_flags+=(-O3) flags="${cxx_flags[#]}" cmake_arguments=() cmake_arguments+=(-DCMAKE_BUILD_TYPE=Release) cmake_arguments+=(-DCMAKE_CXX_FLAGS="$flags") will produce the output you want: $ set -x $ echo "${cmake_arguments[#]}" + echo -DCMAKE_BUILD_TYPE=Release '-DCMAKE_CXX_FLAGS=-fdiagnostics-color -O3' So, to summarize, running: cmake .. "${cmake_arguments[#]}" with array expansion quoted, ensures each array element (cmake argument) is expanded as only one word (if it contains spaces, the shell won't print quotes around it, but the command executed will receive the whole string as a single argument). You can verify that with set -x. If you need to print the complete command with arguments in a way that can be reused by copy/pasting, you can consider using printf with %q format specifier, which will quote the argument in a way that can be reused as shell input: $ printf "cmake .. "; printf "%q " "${cmake_arguments[#]}"; printf "\n" cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-fdiagnostics-color\ -O3 Note the backslash which escapes the space.
Pick 20 records each time and transpose from a big file
I have a big file with 1 column and 800,000 rows Example: 123 234 ... 5677 222 444 I want to transpose it into 20 numbers per line. Example: 123,234,.... 5677, 222, 444,.... I tried using while loop like this while [ $(wc -l < list.dat) -ge 1 ] do cat list.dat | head -20 | awk -vORS=, '{ print $1 }'| sed 's/,$/\n/' >> sample1.dat sed -i -e '1,20d' list.dat done but this is insanely slow. Can anyone suggest a faster solution?
pr is the right tool for this, for example: $ seq 100 | pr -20ats, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40 41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60 61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100 For your file, try pr -20ats, list.dat Based on width of column text, you might run into the error pr: page width too narrow. In that case, try: $ seq 100000 100100 | pr -40ats, pr: page width too narrow $ seq 100000 100100 | pr -J -W79 -40ats, 100000,100001,100002,100003,100004,100005,100006,100007,100008,100009,100010,100011,100012,100013,100014,100015,100016,100017,100018,100019,100020,100021,100022,100023,100024,100025,100026,100027,100028,100029,100030,100031,100032,100033,100034,100035,100036,100037,100038,100039 100040,100041,100042,100043,100044,100045,100046,100047,100048,100049,100050,100051,100052,100053,100054,100055,100056,100057,100058,100059,100060,100061,100062,100063,100064,100065,100066,100067,100068,100069,100070,100071,100072,100073,100074,100075,100076,100077,100078,100079 100080,100081,100082,100083,100084,100085,100086,100087,100088,100089,100090,100091,100092,100093,100094,100095,100096,100097,100098,100099,100100 Formula for -W value is (col-1)*len(delimiter) + col where col is number of columns required From man pr pr - convert text files for printing -a, --across print columns across rather than down, used together with -COLUMN -t, --omit-header omit page headers and trailers; implied if PAGE_LENGTH <= 10 -s[CHAR], --separator[=CHAR] separate columns by a single character, default for CHAR is the character without -w and 'no char' with -w. -s[CHAR] turns off line truncation of all 3 column options (-COLUMN|-a -COLUMN|-m) except -w is set -COLUMN, --columns=COLUMN output COLUMN columns and print columns down, unless -a is used. Balance number of lines in the columns on each page -J, --join-lines merge full lines, turns off -W line truncation, no column alignment, --sep-string[=STRING] sets separa‐ tors -W, --page-width=PAGE_WIDTH set page width to PAGE_WIDTH (72) characters always, truncate lines, except -J option is set, no inter‐ ference with -S or -s See also Why is using a shell loop to process text considered bad practice?
If you don't wish to use any other external binaries, you can refer the below SO link answering a similar question in depth. bash: combine five lines of input to each line of output
If you want to use sed: sed -n '21~20 { x; s/^\n//; s/\n/, /g; p;}; 21~20! H;' list.dat The first command 21~20 { x; s/^\n//; s/\n/, /g; p;}, is triggered at lines matching 21+(n*20); n>=0. Here everything that was put in the hold space at complement lines via the second command: 21~20! H; is processed: x; puts the content of the hold buffer (20 lines) in the pattern space and places the current line (21+(n*20)) in the hold buffer. In the pattern space: s/^\n// removes the trailing new line and: s/\n/, /g does the desired substitution.: p; prints the now 20-columned row. After that the next line is read in the hold buffer and the process continues.
Knowing the size of a C function in the compiled objectfile
It is easy to get the starting address of a function in C, but not its size. So I am currently doing an "nm" over the object file in order to locate my function and THEN locate the starting address of the next function. I need to do the "nm" because compiler could (and actually do, in my case) reorder functions, so source order can be different of object order. I wonder if there are other ways of doing this. For example, instructing the compiler to preserve source code order in the object file, etc. Maybe some ELF magic? My compilers are GCC, CLANG and Sun Studio. Platform: Solaris and derivatives, MacOSX, FreeBSD. To expand in the future.
I have found that the output of objdump -t xxx will give definitive function size/length values for program and object files (.o). For example: (From one of my projects) objdump -t emma | grep " F .text" 0000000000401674 l F .text 0000000000000376 parse_program_header 00000000004027ce l F .text 0000000000000157 create_segment 00000000004019ea l F .text 000000000000050c parse_section_header 0000000000402660 l F .text 000000000000016e create_section 0000000000401ef6 l F .text 000000000000000a parse_symbol_section 000000000040252c l F .text 0000000000000134 create_symbol 00000000004032e0 g F .text 0000000000000002 __libc_csu_fini 0000000000402240 g F .text 000000000000002e emma_segment_count 00000000004022f1 g F .text 0000000000000055 emma_get_symbol 00000000004021bd g F .text 000000000000002e emma_section_count 0000000000402346 g F .text 00000000000001e6 emma_close 0000000000401f00 g F .text 000000000000002f emma_init 0000000000403270 g F .text 0000000000000065 __libc_csu_init 0000000000400c20 g F .text 0000000000000060 estr 00000000004022c3 g F .text 000000000000002e emma_symbol_count 0000000000400b10 g F .text 0000000000000000 _start 0000000000402925 g F .text 000000000000074f main 0000000000401f2f g F .text 000000000000028e emma_open I've pruned the list a bit, it was lengthy. You can see that the 5th column (the second wide column with lots of zeros....) gives a length value for every function. main is 0x74f bytes long, emma_close is 0x1e6, parse_symbol_section is a paltry 0x0a bytes... 10 bytes! (wait... is that a stub?) Additionally, I grep'd for just the 'F'unctions in the .text section, thus limiting the list further. The -t option to objdump shows only the symbol tables, so it omits quite a bit of other information not particularly useful towards function length gathering. I suppose you could use it like this: objdump -t MYPROG | grep "MYFUNCTION$" | awk '{print "0x" $(NF-1)}' | xargs -I{} -- python -c 'print {}' An example: 00000000004019ea l F .text 000000000000050c parse_section_header $ objdump -t emma | grep "parse_section_header$" | awk '{print "0x" $(NF-1)}' | xargs -I{} -- python -c 'print {}' 1292 Checks out, since 0x50c == 1292. I used $(NF-1) to grab the column in awk since the second field can vary in content and spaces depending on the identifiers relevant to the symbol involved. Also, note the trailing $ in the grep, causing main to find the main function, not the entry with main.c as its name. The xargs -I{} -- python -c 'print {}' bit is to convert the value from hex to decimal. If anyone can think of an easier way, please chime in. (You can see where awk is sneaking the 0x prefix in there). Ah, I just remembered that I have an alias for objdump which presets the demangle option for objdump. It'll make things easier to match if you add --demangle to the objdump invocation. (I also use --wide, much easier to read, but doesn't affect this particular output). This works on any ELF object, library, program, object file, as long as it's NOT stripped. (I tested with and without debugging symbols too) Hope this helps. (I looked, parse_symbol_section IS a stub.)
Here is an all awk answer to this question to see size of all functions in certain section: # call objdump with -t to get list of symbols # awk filters out all the columns which are in text section # awk sums the values in 5th column (prefixed with 0x as they are considered hex and then converted to dec with strtonum function) objdump -t MYPROG | awk -F ' ' '($4 == ".text") {sum += strtonum("0x"$5)} END {print sum}' And here is if you want to see only certain functions from certain section # awk filters out all the columns which are in rom section and all function names which have anywhere in name funcname # (we convert to lowercase the value in column 6 to avoid case sensitive regex) # awk sums the values in 5th column (prefixed with 0x as they are considered hex and then converted to dec with strtonum function) objdump -t MYPROG | awk -F ' ' '($4 == ".rom") && (tolower($6) ~ /_*funcname*/) {sum += strtonum("0x"$5)} END {print sum}'
Monkeyrunner throwing "ShellCommandUnresponsiveException" - any work around?
I am facing some issues in device.shell('ping -c 2 192.168.1.1') inside a monkeyrunner script. Its throwing ShellCommandUnresponsiveException [main] [com.android.chimpchat.adb.AdbChimpDevice]com.android.ddmlib.ShellCommandUnresponsiveException while (count<1000) : device.shell('dmesg -c') print '****swithing OFF wifi in loop NO-',count device.touch(400,155,MonkeyDevice.DOWN_AND_UP) time.sleep(10) print '****switching ON wifi in loop NO-',count device.touch(400,155,MonkeyDevice.DOWN_AND_UP) time.sleep(25) fd=open('pingstats.txt','a+b') fd.write('***Loop-%i \n************\n%s\n****************\n' % (int(count),ping)) ping = device.shell('ping -c 2 192.168.1.1') status=re.search('unreachable',ping) if status: dmesg=device.shell('dmesg') fd.write(logcat) fd.close() count = count + 1 Please see above script. How can I fix this?
your ping waits to long add a -t start with -t 1
Just add -t . An example below works perfectly ! device.shell('pm enable packageName -t 15')