3

What is the best solution for writing Makefile, GNU Makefile specifically?

For example:

FILES:= file0.cpp          \
        file1.cpp          \
        file2.cpp          \
        fileYetAnother.cpp

After typing the first \(or after saving the buffer), and ENTER, I want the file1.cpp to align with the file0.cpp, do not mind the \ at the end of each line, I can use align-regexp to align all of them after finished.

But it turns out this by default:

FILES:= file0.cpp  \
file1.cpp          \
file2.cpp          \
fileYetAnother.cpp

I know I can define my own indentation like Customizing indentation in makefile mode?, but it will fix the indentation to number like 4, that is not smart for different situations, what if the FILES word is long.

Besides it does not work for:

all:
        gcc ...

I have to type C-q TAB to indent the gcc ... line.

Another problem for this kind of situation, by default, if you keep typing TAB below the all: line and then type the real commands for all, Emacs will keep inserting Tab when typing TAB, AFAIK, it must be 8 spaces (a Tab exactly) at the beginning of the command line after all, so typing multiple typing-TABs should only remain one TAB.

Is there any package to handle all the messed up format in the Makefile, or you just do that manually?

12
  • 1
    I don't have an automatic solution, but the multiple-cursors library allows one to edit multiple lines simultaneously, so you can manually adjust several lines extremely quickly with just a couple of keystrokes. You could set up tab-stops, or a certain number of spaces to quickly indent multiple lines and likewise jump to the ends of all lines and move the back-slashes over a bit -- the same holds true for jumping to the beginning of multiple lines. I recently set up colors for multiple cursors so I can see whether I'm on an odd-col or an even-col and you could do that for tab-stops, etc.
    – lawlist
    Commented Apr 29, 2015 at 5:28
  • @lawlist yeah, I can do that using mc or other methods manually, but are all Emacs users manually doing this manually when writing Makefile or these problems cannot be automatically? I highly doubt that.
    – CodyChan
    Commented Apr 29, 2015 at 6:50
  • 1
    @Lindydancer It's my company's project, they don't use cmake
    – CodyChan
    Commented Apr 29, 2015 at 7:05
  • 1
    @wvxvw SCons is nice, not the solution for this post though.
    – CodyChan
    Commented Apr 29, 2015 at 7:33
  • 1
    @CodyChan For a wordaround, it's easier to write Makefile by binding TAB to just insert a tab character in makefile-mode. That's what I am doing.
    – Tu Do
    Commented Apr 29, 2015 at 11:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.