diff -urN tinycc.old/libtcc.c tinycc/libtcc.c
--- tinycc.old/libtcc.c	2015-04-11 14:20:22.000000000 +0300
+++ tinycc/libtcc.c	2015-04-11 13:48:37.000000000 +0300
@@ -1141,15 +1141,36 @@
     ElfW(Ehdr) ehdr;
     int fd, ret, size;
 
+    int sf,cf;
+    static char s_ext[10];
+    static char c_ext[10];
+
     /* find source file type with extension */
     ext = tcc_fileextension(filename);
     if (ext[0])
         ext++;
 
+    if (s1->file_extension_type == TCC_FILE_EXT_NONE)
+	*c_ext = *s_ext = 0;
+    else
+    if (s1->file_extension_type == TCC_FILE_EXT_C)
+	strncpy(c_ext, ext, sizeof(c_ext));
+    else
+    if (s1->file_extension_type == TCC_FILE_EXT_ASM)
+	strncpy(s_ext, ext, sizeof(s_ext));
+
+    if (s1->file_extension_type == TCC_FILE_EXT_UNDEF)
+	sf = cf = 0;
+    else {
+	sf = *s_ext;
+	cf = *c_ext;
+    }
+
     parse_flags = 0;
 #ifdef CONFIG_TCC_ASM
     /* if .S file, define __ASSEMBLER__ like gcc does */
-    if (!strcmp(ext, "S") || !strcmp(ext, "s")) {
+    if (!strcmp(ext, "S") || !strcmp(ext, "s") || (sf && !strcmp(ext, s_ext)))
+    {
         tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
         parse_flags = PARSE_FLAG_ASM_FILE;
     }
@@ -1172,14 +1193,17 @@
         goto the_end;
     }
 
-    if (!ext[0] || !PATHCMP(ext, "c") || !PATHCMP(ext, "i")) {
+    if (!ext[0] || !PATHCMP(ext, "c") || !PATHCMP(ext, "i") ||
+       (cf && !PATHCMP(ext, c_ext)))
+    {
         /* C file assumed */
         ret = tcc_compile(s1);
         goto the_end;
     }
 
 #ifdef CONFIG_TCC_ASM
-    if (!strcmp(ext, "S")) {
+    if (!strcmp(ext, "S") || (sf && !strcmp(ext, s_ext)))
+    {
         /* non preprocessed assembler */
         ret = tcc_assemble(s1, 1);
         goto the_end;
@@ -1280,21 +1304,37 @@
 {
     char buf[1024];
     int i;
+    int j, rc;
+
+    rc = -1;
+    j = s->file_extension_type;
+    s->file_extension_type = TCC_FILE_EXT_UNDEF;
 
     for(i = 0; i < nb_paths; i++) {
         snprintf(buf, sizeof(buf), fmt, paths[i], filename);
-        if (tcc_add_file_internal(s, buf, flags) == 0)
-            return 0;
+        if (tcc_add_file_internal(s, buf, flags) == 0) {
+            rc = 0;
+            break;
+        }
     }
-    return -1;
+    s->file_extension_type = j;
+    return rc;
 }
 
 /* find and load a dll. Return non zero if not found */
 /* XXX: add '-rpath' option support ? */
 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
 {
-    return tcc_add_library_internal(s, "%s/%s", filename, flags,
+    int j, rc;
+
+    j = s->file_extension_type;
+    s->file_extension_type = TCC_FILE_EXT_UNDEF;
+
+    rc = tcc_add_library_internal(s, "%s/%s", filename, flags,
         s->library_paths, s->nb_library_paths);
+        
+    s->file_extension_type = j;
+    return rc;
 }
 
 ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
@@ -1986,10 +2026,21 @@
         case TCC_OPTION_s:
             s->do_strip = 1;
             break;
+        case TCC_OPTION_x:
+    	    if (*optarg == 'c')
+    		s->file_extension_type = TCC_FILE_EXT_C;
+    	    else
+    	    if (*optarg == 'a')
+    		s->file_extension_type = TCC_FILE_EXT_ASM;
+    	    else
+    	    if (*optarg == 'n')
+    		s->file_extension_type = TCC_FILE_EXT_NONE;
+    	    else
+                tcc_warning("unsupported language '%s'", optarg);
+    	    break;
         case TCC_OPTION_O:
         case TCC_OPTION_pedantic:
         case TCC_OPTION_pipe:
-        case TCC_OPTION_x:
             /* ignored */
             break;
         default:
diff -urN tinycc.old/tccelf.c tinycc/tccelf.c
--- tinycc.old/tccelf.c	2015-04-10 17:35:47.000000000 +0300
+++ tinycc/tccelf.c	2015-04-11 14:16:02.000000000 +0300
@@ -1543,6 +1543,11 @@
 static int tcc_add_support(TCCState *s1, const char *filename)
 {
     char buf[1024];
+    int rc, j;
+
+    j = s1->file_extension_type;
+    s1->file_extension_type = TCC_FILE_EXT_UNDEF;
+
     snprintf(buf, sizeof(buf), "%s/%s/%s", s1->tcc_lib_path,
     /* an cpu specific path inside tcc_lib_path, mainly for keeping libtcc1.a */
     #ifdef TCC_TARGET_I386
@@ -1562,7 +1567,9 @@
     #endif
 	,filename);
 
-    return tcc_add_file(s1, buf);
+    rc = tcc_add_file(s1, buf);
+    s1->file_extension_type = j;
+    return rc;
 }
 
 ST_FUNC void tcc_add_bcheck(TCCState *s1)
diff -urN tinycc.old/tcc.h tinycc/tcc.h
--- tinycc.old/tcc.h	2015-04-11 14:20:22.000000000 +0300
+++ tinycc/tcc.h	2015-04-11 13:24:30.000000000 +0300
@@ -621,6 +621,12 @@
     /* compile with built-in memory and bounds checker */
     int do_bounds_check;
 #endif
+    int file_extension_type;	/* assume file have extension of the specidied type */
+				#define TCC_FILE_EXT_UNDEF 0
+				#define TCC_FILE_EXT_NONE  1
+				#define TCC_FILE_EXT_C     2
+				#define TCC_FILE_EXT_ASM   3
+
 #ifdef TCC_TARGET_ARM
     enum float_abi float_abi; /* float ABI of the generated code*/
 #endif
