34326

How can I automatically add '.s' to a target in my Makefile?

Question:

I have a phony debug and asm target. debug works by updating the variable CFLAGS and then compiles the normal target, which uses these new CFLAGS to produce debug symbols. This works as intended.

Analogously I want to define the asm target set the -S switch and to change the output name from file to file.s. However, the last part does not work, and I get:

$ make asm -B gcc -fmessage-length=0 -ansi -pedantic -Werror -Wall -Wextra -Wwrite-strings -Winit-self -Wcast-align -Wcast-qual -Wpointer-arith -Wstrict-aliasing -Wformat=2 -Wmissing-declarations -Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized -Wold-style-definition -Wstrict-prototypes -Wmissing-prototypes -Wdouble-promotion -S -masm=intel file.c -o file

notice the last part [..] -S -masm=intel file.c -o file with the extra parameters but without the .s extension.

What am I missing?

Makefile:

TARGET=file SOURCE=*.c HEADERS=*.h TESTS=*.sh PROJECT=$(TARGET) $(SOURCE) $(HEADERS) $(TESTS) Makefile CC=gcc CFLAGS=\ -ansi \ -pedantic \ -Wall \ # makefile-rules that don't produce files directly .PHONY: default all debug asm default: $(TARGET) # Compile $(TARGET): $(SOURCE) $(HEADERS) $(TESTS) $(CC) $(CFLAGS) $< -o $@ debug: CFLAGS += -DDEBUG -ggdb debug: $(TARGET) asm: CFLAGS +=-S -masm=intel asm: TARGET +=.s <------------------ THIS LINE !!!!!! asm: $(TARGET)

Answer1:

You could just add a $(TARGET).s target to the rule and use that in asm:

$(TARGET) $(TARGET).s: $(SOURCE) $(HEADERS) $(TESTS) $(CC) $(CFLAGS) $< -o $@ asm: CFLAGS += -S -masm=intel asm: $(TARGET).s

Recommend

  • How can I automatically add '.s' to a target in my Makefile?
  • VB6 Memory Leak
  • error: field ‘children’ has incomplete type ‘Node [2]
  • Visual Studio equivalent for these G++ flags?
  • makefile include *.h file in other directory
  • What version of .Net framework ships with SQL Server 2008?
  • How can find using c-program whether my machine is 16-bit or 32-bit or 64-bit
  • Bitwise NOT operator returning unexpected and negative value? [duplicate]
  • printf in C doesn't occupy memory?
  • C's pow() doesn't work with a variable exponent
  • Why doesn't gcc o warn when size of array is uninitialized in this code?
  • C++11: Why is private member template accessible outside class?
  • Calling exit() in C++ library terminates python script that wrapps that library using swig
  • How to link curses.h in Cmake?
  • Symbol not found when using template defined in a library
  • Including external C library with Xcode
  • How to link curses.h in Cmake?
  • In C++, Do I need to deallocate memory before close a program [duplicate]
  • Xcode 5.1 unused consts treated as error
  • C++: Do not show glibc's Backtrace and Memory map on crash
  • Warning “ISO C++ forbids variable-size array” with constant size array
  • Mac gcc non-virtual thunk error
  • JPasswordField returning some hash code converted into string type
  • Windows 10 - Compile C++ in cmd
  • compiling openmp, macports gcc, and eclipse cdt
  • gcc treat all warnings as errors EXCEPT X
  • How to map inherited entities in EF code-first
  • two ways of displaying a decimal
  • How To Configure SonarQube GitHub Plugin With Jenkins
  • Collecting wall posting permission when using the Facebook Registration plugin
  • vue-router and Express
  • Creating a EditorTemplate MVC3
  • update record in database using jdatabase
  • several dataProvider per one Test in TestNG
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • GridView breaks while scrolling
  • When should I choose bucket sort over other sorting algorithms?
  • Change div Background jquery
  • apache spark aggregate function using min value