Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, How to set .RECIPEPREFIX variable to whitespace(say 4 whitespces) , so that make uses this particular set of characters to identify the recipe for a particular target. In my ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    Location
    Bangalore,India
    Posts
    63

    Need help: How to set .RECIPEPRE​FIX variable to white spaces


    Hi,

    How to set .RECIPEPREFIX variable to whitespace(say 4 whitespces) , so that make uses this particular set of characters to identify the recipe for a particular target.
    In my $HOME/.vimrc file, for code indentation purpose, I've put the following entries to replace tabs with 4 whitespaces:

    <<<snip from my $HOME/.vimrc file>>>
    "replace tabs with spaces
    set expandtab
    set shiftwidth=4
    set tabstop=4
    <<<snip from my $HOME/.vimrc file>>>


    but the above will cause problem in case you write your own makefile for a kernel module,
    because now the tab stroke will be replaced by 4 whitespaces which 'make' will not understand. Quoting from 'make' manual,
    "Please note: you need to put a tab character at the beginning of every recipe line!"

    Seems .RECIPEPREFIX will come for resuce, but as of now I don't know how to use it to fix my problem.

    Regards,
    Amit

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,158
    I understand this problem of expanded tabs and make files. What I do is after inputting the tab, I use a regex substitution command to convert the 4 spaces to a tab. The editor takes the keyboard tab input to convert to spaces, but it won't convert a tab character already in the data. So, use this regex to convert the leading 4 white spaces on a line to a hard tab:

    Code:
    s/^    /\t/
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    Location
    Bangalore,India
    Posts
    63
    My apologies for updating this thread after a long time. Sometime back I asked this same question to Make gurus and this is what Paul D. Smith confirmed:
    "RECIPEPREFIX must be set to exactly one unique character. There's no
    way to set it to be "four spaces". Also note that this feature is only available in the latest version of
    GNU make and many systems do not include that version yet, so if you use
    this feature your makefiles will not be portable to older systems (you
    might not care about that). "
    But there is a way to tell vim to replace tabs according to language. Put following in your $HOME/.vimrc file:

    "-------- C -------------------------
    function! LANG_C()
    setlocal noexpandtab
    setlocal shiftwidth=8
    setlocal tabstop=8
    setlocal softtabstop=8
    setlocal formatoptions=tcroq
    endfunction
    autocmd FileType c call LANG_C()

    "------- Python ----------------
    function! LANG_PYTHON()
    setlocal shiftwidth=4
    setlocal tabstop=4
    setlocal softtabstop=4
    setlocal expandtab
    "--- python indent keywords --------
    setlocal cinwords=if,elif,else,for,while,try,except,finally ,def,class,with
    endfunction
    autocmd FileType python call LANG_PYTHON()

    "------- Makefile --------------
    function! LANG_MAKEFILE()
    setlocal noexpandtab " makefiles only work with tab-indents
    setlocal shiftwidth=8
    setlocal tabstop=8
    setlocal softtabstop=8
    endfunction
    autocmd FileType make call LANG_MAKEFILE()

    This way you don't need to edit your vimrc file every time you edit a makefile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •